svanderburg / libilbm

Parser library for the ILBM: IFF Interleaved BitMap format
MIT License
32 stars 8 forks source link

error decoding a ilbm image #3

Open congpp opened 4 years ago

congpp commented 4 years ago

Hello there, Recently, I've got a .iff image and i want to decode it to rgb stream using libilbm. But libilbm crashed on ILBM_unpackByteRun, it looks like the index of "decompressedChunkData" exceeded the Array boundary. Even though I fixed it by limiting the index, I still got a error image with random pixels while it shall be a image of a young lady, AND PhotoShop can open it successfully. link of that image: [https://github.com/congpp/libilbm/blob/master/tests/image/lady.iff]

My code: int LoadILBM() { unsigned int imagesLength; IFF_Chunk *chunk = ILBM_read("F:\cyc\test\lady.iff"); ILBM_Image *image = ILBM_extractImages(chunk, &imagesLength); if (imagesLength == 1 && image[0]->bitMapHeader->nPlanes == 24) { / Retrieve an image from the array and access its properties here / if (ILBM_imageIsILBM(image[0])) / It makes no sense for PBM or ACBM images / { //GDI+ Bitmap Bitmap pBmp = new Bitmap(image[0]->bitMapHeader->pageHeight, image[0]->bitMapHeader->pageWidth, PixelFormat32bppRGB); BitmapData bmd; Rect rc(0, 0, pBmp->GetWidth(), pBmp->GetHeight()); pBmp->LockBits(&rc, ImageLockModeWrite, PixelFormat32bppRGB, &bmd); unsigned imageLineSize = image[0]->bitMapHeader->pageWidth (image[0]->bitMapHeader->nPlanes / 8); ILBM_unpackByteRun(image[0]); IFF_UByte bitplanes = ILBM_deinterleave(image[0]); / Produce a deinterleaved version of the body in the resulting array / for (unsigned h = 0; h < bmd.Height; ++h) { IFF_UByte pSrcLine = bitplanes + h imageLineSize; LPBYTE pDstLine = (LPBYTE)bmd.Scan0 + h * bmd.Stride; for (unsigned w = 0; w < bmd.Width; ++w) { pDstLine[0] = pSrcLine[0]; pDstLine[1] = pSrcLine[1]; pDstLine[2] = pSrcLine[2]; pDstLine += 4; pSrcLine += 3; } } pBmp->UnlockBits(&bmd); g_pBmp = pBmp; } } return 0; }

Any help is appreciated! Thanks Conn

steffest commented 3 months ago

@congpp Did you ever find a solution for that image?

I made an IFF parser myself and bumped into the same issue opening your sample image so now I am SUPER intrigued what is different in this image that is causing the garbled output.