Palette storage... Shifting...

This is a discussion on Palette storage... Shifting... within the Game Programming forums, part of the General Programming Boards category; 13h game. DJGPP. Windows95 Will someone please explain to me what Brackeen is doing when he's shifing the return value ...

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    Palette storage... Shifting...

    13h game. DJGPP. Windows95

    Will someone please explain to me what Brackeen
    is doing when he's shifing the return value
    of fgetc(fp)?

    Code:
    for(index=0;index<num_colors;index++)
    {
      b->palette[(int)(index*3+2)] = fgetc(fp) >> 2;
      b->palette[(int)(index*3+1)] = fgetc(fp) >> 2;
      b->palette[(int)(index*3+0)] = fgetc(fp) >> 2;
      x=fgetc(fp);
    }
    Is there a specific reason why he's doing this
    (as in, does it have to be done in order for
    the palette to be stored correctly?), or is
    it just for speed? I understand what shifting does,
    but I'm not quite comfortable with it, yet.

    Thanks,
    static.
    Staying away from General.

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    ultimately it depends upon the context of the program... but it looks to me like he's reading a palette from a 256 color bitmap... and translating 8 bit rgb values to 6 bit... which is what you'd pass to the pallete ports... [you have 2^18 colors... but only 256 indexes for them...]

    anything else?

    hth!
    hasafraggin shizigishin oppashigger...

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    That's exactly what he is doing. If you do not do this, your palette will look ugly since you will lose significant bits in your color info if you try to set palette entries in mode 13h.

    He is dividing by 4.

  4. #4
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    I thought shifting gave the effect of multiplication
    (that's what Brackeen says).

    If the Red-value that was read was shifted twice,
    wouldn't it be the same as multiplying by four,
    instead of dividing. Yeah, I know you're right
    (my program even shows that the RGB values were
    divided by 4), but why does this work?

    If the value that fgetc() returned was shifted
    to the left twice, wouldn't that be like saying:

    2^2fgetc();
    4 * fgetc();

    Please explain...

    Thanks,
    static.
    Staying away from General.

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    since binary is base two, shifting it per position would be increasing it by a factor of 2, or decreasing it by a factor of 2... so, if you shift multiple times, you get the compound effect...
    hasafraggin shizigishin oppashigger...

  6. #6
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    Am I an idiot...?

    fgetc(file) >> 2; is shifing to the right, which
    means the number is being divided by 4...

    fgetc(file) << 2; is shifing to the left, which
    means the number is being multiplied by 4...

    Am I correct? Eh, I didn't even know about
    shifting-right... Argh! Sometimes I just feel
    so stupid!!!
    Staying away from General.

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >Am I an idiot...?

    sure you want me to answer that? hehe... worry not! logik to the resque!
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21