Thread: Problem reading 8 bit greyscale images !

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by swoopy View Post
    You're writing one too many bytes for the color table:
    Code:
    >void copyColorTable(FILE* inputFile, FILE* outputFile, int nColors)
    >.
    >.
    >  for(i=0; i<=(4*nColors); i++)  /* there are (4*nColors) bytesin color table */
    Should be:
    Code:
      for(i=0; i<(4*nColors); i++)  /* there are (4*nColors) bytesin color table */
    For this file nColors = 0

    The original program is only writing one byte where it should be writing 1024. That's why the original program gave an output file that was 1023 bytes shorter than the original file. In fact, with this file, there is a 1024 byte color table (gray ramp) between the end of the header(s) and the beginning of the pixel bytes.

    I'm not talking about how it is supposed to be (nColors = 256, I'm thinking), I am talking about the specific file that was attached. It is apparently defective.

    This is the answer to the original question about why some files weren't converted properly: it's a bad file. But with a little detective work it can be salvaged. Some viewers work one way, some work another. For example, Firefox could open and display the original file OK, but not Microsoft's whatever.


    With swoopy's fix and a proper file, I'm thinking that the program should be OK (after the superfluous pixel array is deleted, of course).

    Edit
    (As a matter of fact, I just replaced the nColors value with the proper value in the original file and now all is just swell--- with the loop fix swoopy posted.)


    Bottom line: the output file size should be exactly the same size as the input file. All file contents other than pixel data should match exactly.


    D
    Last edited by Dave Evans; 06-29-2007 at 04:28 PM.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    Hey guys thanks a lot !!!
    After fixing the ncolors = 256 and the loop change , i can run all my 8 bit images....
    Thanks a lot !!
    Wish i cud buy you guys dinner

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 12-23-2008, 01:53 PM
  2. 32 bit color depth bitmap problem with XP
    By kalabala in forum C++ Programming
    Replies: 0
    Last Post: 12-22-2008, 06:56 AM
  3. Accessing bit fields using a union problem.
    By samdomville in forum C Programming
    Replies: 6
    Last Post: 12-10-2008, 04:39 PM
  4. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 09:55 AM
  5. problem reading files in C
    By angelfly in forum C Programming
    Replies: 9
    Last Post: 10-10-2001, 11:58 AM