From: <bto...@us...> - 2008-01-28 00:14:34
|
Revision: 2708 http://hugin.svn.sourceforge.net/hugin/?rev=2708&view=rev Author: btownshend Date: 2008-01-27 16:14:30 -0800 (Sun, 27 Jan 2008) Log Message: ----------- Fixed handling of 16-bit files Fixed memory overrun during malloc of images Modified Paths: -------------- autopano-sift-C/trunk/DisplayImage.c Modified: autopano-sift-C/trunk/DisplayImage.c =================================================================== --- autopano-sift-C/trunk/DisplayImage.c 2008-01-27 23:10:30 UTC (rev 2707) +++ autopano-sift-C/trunk/DisplayImage.c 2008-01-28 00:14:30 UTC (rev 2708) @@ -45,7 +45,7 @@ im->width = width; im->height = height; - im->bytesPerLine = self->width * 4; + im->bytesPerLine = im->width * im->bitsPerPixel/8; im->dataSize = im->bytesPerLine * im->height; im->data = (unsigned char**) mymalloc( im->dataSize ); if (im->data == NULL) { @@ -200,7 +200,7 @@ result->width = width; result->height = height; - result->bytesPerLine = self->width * 4; + result->bytesPerLine = result->width * result->bitsPerPixel/8; result->dataSize = result->bytesPerLine * result->height; result->data = (unsigned char**) mymalloc( result->dataSize ); if (result->data == NULL) { @@ -326,8 +326,21 @@ ImageMap* DisplayImage_ConvertToImageMap(DisplayImage* self) { ImageMap* result = ImageMap_new(self->width, self->height); - LOOP_IMAGE(self,{ - result->values[x][y] = (idata[1]+idata[2]+idata[3])/(255.0 * 3.0); - }); + unsigned char *idata=*self->data; + if (self->bitsPerPixel == 32) { + LOOP_IMAGE(self,{ + /* Data is (alpha,R,G,B) */ + result->values[x][y] = ((double)idata[1]+idata[2]+idata[3])/(255.0 * 3.0); + }); + } else if (self->bitsPerPixel == 64) { + LOOP_IMAGE(self,{ + unsigned short *udata=(unsigned short *)idata; + /* Data is (alpha,R,G,B) */ + result->values[x][y] = ((double)udata[1]+udata[2]+udata[3])/(65535 * 3.0); + }); + } else { + /* It appears that TIFF library calls used (TIFFReadRGBA), will always return 32 or 64-bit, but just in case... */ + FatalError("DisplayImage: Unsupported pixel size"); + } return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |