0

Due to being new, I can only have two links and can not post my images. Sorry for the inconvenience of having to copy+paste addresses

I am parsing a Targa (.tga) image file with code similar to that found at steinsoft.net/index.php?site=Programming/Code%20Snippets/Cpp/no8

After retrieving the data into the unsigned char array, I print it out into a log to check manually. It seems that darker colors are not being parsed for whatever reason.


The Simple Print Code

file.open( save );

//using while( tga.data[ i ] != NULL ) resulted in ~400,000 lines of garbage being appended
for( unsigned i = 1; i <= ( tga.width * tga.height * tga.byteCount ); i++ )
{
    if( tga.data[ i ] == NULL )
        break;

    file << ( int )tga.data[ i ] << ",";

    if( ( i % 3 ) == 0 )
        file << "\n";
}

file.close( );

Example

Dark : https://i.stack.imgur.com/qefIA.png : http://pastebin.com/8JeJwP2w

Light : https://i.stack.imgur.com/XNTIK.png : http://pastebin.com/s2sW0XfM

As you can see, the line at the top of the image is not included when it is a dark color (black in this instance), but it is there when it is light (a pink [255,53,204]).

Does anyone have any information on why this may be happening?


Specs

Windows Vista

Microsoft Visual C++ 2010 Professional

Targa is saved as 24-bit NOT compressed.

ssell
  • 6,429
  • 2
  • 34
  • 49

1 Answers1

1

First of all, why do you check if the data[i]==NULL? There might be 0-pixels (black), so keep them all in. You basically check if the color is 0 and then you exit your loop. Just read all pixels no matter the value.

Anteru
  • 19,042
  • 12
  • 77
  • 121
  • d'oh! It was late at night and that never even crossed my mind. I just didn't want crash from accessing beyond the size of the array (though there are better ways to do that). – ssell Jul 04 '11 at 17:16