don't click here

Indexed colour palette Image

Discussion in 'Engineering & Reverse Engineering' started by Linaru, Nov 24, 2015.

  1. Linaru

    Linaru

    Member
    Does anyone have an Indexed colour image of the mega drives colour palette?

    I noticed that when SonLVL exports colour palettes it saves them as indexed colour images and can import indexed colour images too..
    unfortunately it does not seem to save the full range mega drive colours.

    an indexed image would be really useful for me to convert all of my pixel arts colour palettes as accurately as possible.


    for those who don't know a indexed colour image is a a form of limited colour image file. when editing it it can only draw in a limited selection of colours
    but I am not used to using this format in Photoshop as my pixel art is usually in a different format



    I did try taking an image of all available mega-drive colours making it indexed and importing a megadrive.ACO but for some reason half the colours I should have been able to use were not available
     
  2. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,971
    76
    28
    USA
    rom-properties
    Mega Drive uses 9-bit color values, resulting in a total of 512 colors. Indexed color images typically use 8-bit values (256).

    That'd be why you're only seeing half of the possible colors.
     
  3. Linaru

    Linaru

    Member
    I see perhaps I have Mis-understood this, I was hoping to create an indexed file in Photoshop using all of the mega-drives colours so that any image I transferred over to it would be automatically converted.
    this would give me an environment where I could better select the colour and adjust the sprites shading.


    the colour palette I have been using to develop all the art for a hack may not have been compatible:
    [​IMG]

    its a great selection of colours.. looks really pretty in photoshop..
     
  4. Shadow Hog

    Shadow Hog

    "I'm a superdog!" Member
    You are not going to be able to make an indexed file in Photoshop that contains all of the Genesis's colors, because it has a set of 512 colors and Photoshop's indexed mode only supports 256. No matter how you slice that, you would be losing data.

    Best you can do is have an image on-hand that contains all 512 colors, like this:

    [​IMG]
     
  5. Linaru

    Linaru

    Member
    I have learnt an interesting trick while trying to work this out.
    when I was trying to create an indexed image I was using a .ACO file.. a palette containing a bunch of megadrive colours
    apparently when I tried to import the indexed image created with that into son level it ignores the image and loads each of the colours in the pallet in order..

    I tried making an indexed image set up to use the colours of my colour pallet.. as its colour index and when I imported it, sonLVL imported my colour palette near perfectly..

    only one or two colours are off ever so slightly, presumable because they are not mega-drive colours.
     
  6. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    Another problem with MD colors is that different programs have different methods of converting the 9-bit values to 24-bit RGB, so colors may be darker or lighter depending on what you're using. If you want to ensure that the colors in your palette are directly matching MD colors in SonLVL, you can either save and reload the level if you import a palette from an image or enter 24-bit RGB values, or use the number boxes on the left side to change the colors.
     
  7. Linaru

    Linaru

    Member
    ah, well my problems been solved by that SonLVL update it seems. got all the colours into the palette at the exact values by importing from a png.
     
  8. RetroKoH

    RetroKoH

    Member
    1,662
    22
    18
    Project Sonic 8x16
    I've been looking for a way to make 512 colors take up less space... I'm gonna reappropriate this image for Triad if you don't mind


     
  9. nineko

    nineko

    I am the Holy Cat Tech Member
    6,298
    475
    63
    italy
    For reference, on Sega Retro.

    I forgot where I got the MD and the MS palettes, probably from the 1536 colors demo (the former) and from some doc on smspower (the latter). I created the GG palette from scratch with a small program I wrote, instead.

    Back to the original topic, I'm not sure why you'd want more than 61 colors in your palette file, since you can't really display more colors than that on a Mega Drive without using black magic, not to mention that each 8×8 tile is furtherly limited to a single palette line.
     
  10. Korama

    Korama

    Tech Member
    272
    2
    0
    That's true many old programs were lazy and simply bit-shifted the MD color component values once. An 0xE (hexadecimal) shifted 4 bits to the left (same as multiplication by 16) equals 0xE0, or 224 decimal. Add/Or the original value, as shown in nineko's link, and you get 0xEE (238).
    However, that method is wrong. Because that way, pure white on the MD (0xEEE) would not map to pure white in 24-bit RGB (255, 255, 255).
    The mathematically correct conversion formula is obviously RGB = 255/7 * (MD / 2).
    That is, one step on the MD side equals 255/7 = 36.428571... steps on the 24-bit RGB side.
    If you're worried about performance, instead of having to do floating point math for this, you could just as well precompute a lookup table - there are only 8 possible values on the MD side, after all.

    Or you could use this little known trick (which is the reason why I'm writing all this):
    To mathematically extend a value of size N bits to a value of size M bits (M > N), just repeat/duplicate the N bits over and over until all M bits are filled.
    Example: let's take an MD component value of 0xC, which is actually a value of six (0xC shifted one bit to the right, or divided by 2). MD components are 3 bit, and six in binary is 110.
    Let's extend those 3 bits to 8 bits by repeating:
    11011011 = 0xDB = 219.
    Test: 255/7 * 6 = 218.57... rounded = 219. :)

    In C notation, that operation would be x << 5 | x << 2 | x >> 1.

    PS: people have measured the voltage levels that the MD VDP outputs in order to get the "correct" values. They are slightly different, but I'd say it doesn't matter much, because the actual colors you'll end up seeing also greatly depend on your screen and its settings.
     
  11. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    I once made a topic about this very issue, though at the time we somehow came to the conclusion that 0xEE was correct. SonLVL currently uses a precomputed table in MD mode. Oddly enough, S&KC doesn't mask off the low bit of each component, meaning you have 12-bit colors instead of the proper 9 bits.
     
  12. rata

    rata

    Member
    689
    72
    28
    Argentina
    Trying to be useful somehow.
    I wonder why Puggsy's developers lied us in such a big way...
    [​IMG]


    Can 68k make software scaling, or is it just another lie?
     
  13. amphobius

    amphobius

    doing more important things with my life Member
    2,120
    0
    16
    life
    It's not 'lying', because things like sprite rotation and scaling can be done in software if you're clever enough. It's also possible to use that many colours on screen with 'black magic' as nineko said - the Puggsy devs were pretty smart.
     
  14. rata

    rata

    Member
    689
    72
    28
    Argentina
    Trying to be useful somehow.
    Well, my only actual doubt was the colour count, since we all know that 32x does software rotation and scaling. I guess that 32bit or 16 bit only matters in how much effort will you have to put to do it then. But with 'black magic' I took that it was just not possible. I will take random screenshots in the game to see if I can count more than 61 colours.I imagine that it would be something very resouce demanding, right? I mean, no chance to see something like this in a sonic hack then?
     
  15. nineko

    nineko

    I am the Holy Cat Tech Member
    6,298
    475
    63
    italy
    Sonic games already show more than 61 colors in the water levels. You can change any palette entry at the middle of the screen, though it has to be done carefully to prevent snow from appearing around the picture. This is as much as I can explain without getting too technical, unless you know what an H-int is.
     
  16. Shadow Hog

    Shadow Hog

    "I'm a superdog!" Member
    Is that any different from an H-blank? Y'know, that very brief period between the CRT monitor finishing one scanline and starting the next.
     
  17. rata

    rata

    Member
    689
    72
    28
    Argentina
    Trying to be useful somehow.
    Oh, of course... what a dumbass I am. So, what's the real deal with the colours? Is it then 61 the maximium per scanline?
    Also, can shadow colours get mixed with normal ones, or the whole mode has to be changed? Can it be done in a single frame, for example, to simulate glare?
     
  18. Korama

    Korama

    Tech Member
    272
    2
    0
    It's the same. A horizontal interrupt (HInt) is triggered at the start of each H-blank.


    Yes, it's pretty much 61 per scanline, but you can only change a limited amount of those from one scanline to the next, if I remember correctly.
    I don't understand what you mean with the shadow colors. Shadow/highlight mode is either active or not. If it is active, it does influence the colors in combination with certain sprites and pattern priority bits. You can play around with this old program of mine to test it.
     
  19. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    Actually, the MD only generates a horizontal interrupt every Nth scanline from the top of the screen/previous H-Int, with N being the value in VDP register $A.
     
  20. rata

    rata

    Member
    689
    72
    28
    Argentina
    Trying to be useful somehow.
    Usually when tech members talk I just don't understand a thing, but I did learn something today, as small as it is. Thank you very much both of you.