Results 1 to 13 of 13

Thread: How to decode GIF pixel blocks?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    How to decode GIF pixel blocks?

    I need to know how to decode GIF pixel blocks.
    I have read on wikipedia http://en.wikipedia.org/wiki/Gif and I cant get that working, what am I doing wrong?

    The example block that they are using look like this "00 51 FC 1B 28 70 A0 C1 83 01 01" and i cant under stand how they converts that to "100 028 0FF 103 102 103 106 107 101" !?!?

    I mean... 00 51 FC 1B 28 70 A0 C1 83 01 01 === 00000000 01010001 11111100 00011011 00101000 01110000 10100000 11000001 10000011 00000001 00000001 if I read that like 9bit each it no way I get this result != "100 028 0FF 103 102 103 106 107 101" ?

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to decode GIF pixel blocks?

    what am I doing wrong?
    I can say with 100% confidence that I don't see any errors in your code.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    If I splitt that into 9bits the code will look like this:

    000000000 = 0
    101000111 = 327
    111100000 = 480
    110110010 = 434
    100001110 = etc...
    000101000
    001100000
    110000011
    000000010
    0000001

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to decode GIF pixel blocks?

    My hint was obviously too subtle.. how do you expect people to tell you what's wrong with your code if you don't show what you are doing?

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    Since I havnt read pixel block manually with success yet, I have not done the programming done.

    The problem is that if I do like that example says and split the block into 9bits numbers it wont be the same as in the example.

    Hope you understand what i mean, my english sucks

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to decode GIF pixel blocks?

    Your english is fine... its just you are asking what you are doing wrong without actually telling us what you are doing in the first place.

    Without seeing what you are doing you are basically asking us to look at a calculation on wikipedia, then see if we can get it wrong but showing the same results as you, and then describe what we did wrong to match your results.

    Even if you just describe the steps you take in mathematical steps that would at least give us something to go on... as it is it is pure guesswork.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    This is how I think I should read the gif file in some kind off psuedo code :P

    > Read file into memory bitmap

    > Reading header from memory, Heigth, width, size of color table and so on.

    > Reading color table

    > Check start of image data.

    So far so good. But this is where the problem starts...

    Basiclly the image data ImageBitmap look like this:
    Hex = "08 0B 00 51 FC 1B 28 70 A0 C1 83 01 01"
    Binary = "00001000 00001011 00000000 01010001 11111100 00011011 00101000 01110000 10100000 11000001 10000011 00000001 00000001"

    > The first Byte (8bit) of the ImageBitmap tells us the minimum length of bits to read LzwMinLength + 1 which is "00001000" = "08" + 1 = 9 bit.
    LzwMinLength = 9

    > The secound byte (the BlockSize) tells us how big the pixel block is in Bytes. In this case "00001011" = "0B" = 11 bytes long.
    BlockSize = 11

    > Now I read 11 Bytes (BlockSize) from ImageBitmap and then I Split the Block into 9 bits pieces.
    Orginal Block look like this:
    000000000101000111111100000110110010100001110000101000001100000110000011 0000000100000001

    In splitted version like this:
    000000000 = 0
    101000111 = 327
    111100000 = 480
    110110010 = 434
    100001110 = 270
    000101000 = 40
    001100000 = 96
    110000011 = 387
    000000010 = 2
    0000001


    Maybe you understand me better now, I not sure how to explain me better

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    No one knows whats wrong with my calculation? I would be greatful to get some help or just a hint off what im doing wrong..

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    If a change the question. Is there anyone that has read a GIF with success? If so, I would love to see some code for that project

    All help I can get is good, I have tryed in many ways to decode that picture and cant make it

  10. #10
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to decode GIF pixel blocks?

    I'm afraid I can't really help with the detail on how to read a GIF, but can I ask what you are actually trying to do?

    Obviously VB will allow you to load a GIF into a picturebox, and from there you can examine the colour of each pixel.

    Do you actually need to be able to read the GIF file format yourself or can you let VB do what you need and then look at the result?

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: How to decode GIF pixel blocks?

    Ok.
    The thing is that i want to get 100% full control to editing the gif file.
    Plus its much more fun to understand the format and get a working code...

    But it seems that no one is able to decode this, and I havnt successly done it myself either, so I think I have to give up

  12. #12
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to decode GIF pixel blocks?

    I know what you mean, unfortunately as no one one here seems to have experience of doing it you could try asking on the games and graphic programming forum.

  13. #13
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: How to decode GIF pixel blocks?

    Whether it's fun...

    Anywayz, in the wikipedia article it is mentioned that the LZW encoding is used. So obviously you went there and can't figure it out. Why not looking for something with vb syntax that illustrates that?

    http://www.codeproject.com/KB/recipes/VB_LZW.aspx
    VB 2005, Win Xp Pro sp2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width