code for loading and saving ted21 color palettes

About Monkey 2 Forums Monkey 2 Projects code for loading and saving ted21 color palettes

This topic contains 7 replies, has 2 voices, and was last updated by  AdamStrange 2 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3497

    AdamStrange
    Participant

    With ted21 I am trying to be as open as possible.

    Here is the first code to load and save color palettes

    a color palette is a block of colors (up 256) with additions 8×8 grid information

    The file extension is .mx2palette

    layout of the saved file is:

    String:”mx2palette”

    UInt:count

    Uint:gridx

    Uint:gridy

    colors. these are saved as

    float:red

    float:green

    float:blue

    float:alpha

     

    and here is the loading code

    and here is the saving code

    #3501

    degac
    Participant

    Ok, some (stupid maybe!) questions :D!
    1. what is for the ‘grid’?
    2. why choose a proprietary (even if public) format and not use the .json system – already built in MX2? Considering the possibility to open them directly in TED2?

    #3502

    AdamStrange
    Participant

    simple. speed

    grid is the uxcolorgrid control

    as to not using .json:

    text is a very poor storage format for anything other than text. you need to parse it and it also needs carful construction.

    It is also editable. which means unknown errors creep in

     

    finally. There is no reason for the color table to be readable by humans. its a color! in the same way as a sound is stored in the best format for it, etc

     

    They can be opened in ted2. but Mark will have to provide that.

     

    let say the read file has a grid of 7,3

    the shown grid will be 7 cell wide, and 3 cells high with a total of 21 color cells

    It would look like this:

    #3504

    degac
    Participant

    Ok, understood what is the ‘grid’ 🙂
    It would better if the ‘grid layout’ will be managed automatically, and not based on what is ‘stored’… I mean, I need the colors, not the way they are shown.
    Yes, I admit json is quite a bit ‘redundant’ for low information.
    for a plain text I would use ToARGB and FromARGB method to store colors… it should be faster (in reading/writing I mean).

    #3505

    AdamStrange
    Participant

    Here’s a thing. I did initially write the input/output with ToARGB and FromARGB.

    But… for some really odd reason ToARGB never gave the correct output, so I went with just writing  the direct values instead.

    the gridx and gridy values can be completely ignored. They are there for display only and to prevent problems with counts that could be multiples. E.G. a count of 36. is that 6×6 or 4X8 or 3×12, etc

    similarly a count of 12 is that 3×4 or 4×3.

    So to just read the colors,

    read the header, the count and then ignore the next two read in numbers and then just read the colors. 😉

     

    Here’s a shot of the new palette grid view in operation with Ted21. You can see the color panel is also open. pressing “use color” will change the current selected color in the palette and make the document “dirty” so it is automatically saved

    #3507

    degac
    Participant

    But… for some really odd reason ToARGB never gave the correct output, so I went with just writing  the direct values instead.

    What does this means? There’s an error in the conversion?

     

    Anyway, as user, I would like to ‘save’ my preferred color (maybe the first 8/16 etc).

    #3515

    AdamStrange
    Participant

    i think i used something like colout:uint = colin.ToARGB and it never set.

    The other thing was when I looked at the code I expected it to be ABGR and it wasn’t it was the reversed ARGB. which looks fine on paper, but is actually reversed in code.

    OK Saving and using color palettes of different sizes – no problem. Here’s a few different ones. I tried to be as flexible as I could be. It also shows where the grid properties are used.

    #3520

    AdamStrange
    Participant

    Here’s the code from std/color.monkey2

    Great. But it really should be this:

    where the first byte is the red byte, the second green, third blue and finally alpha

    This makes it really ABGR. but you read from right to left so it is actually RGBA which is the proper representation.

    If I recall correctly, Microsoft had to rewrite an entire windows codebase because of this (long before xp).

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.