//******************************************************************************* // Decompress RGB24 RLE // BOOL DecompressRGB24RLE(FILE *pFile, TGAHEADER *pHeader, IMAGE_DATA *pContext) { unsigned int u32Stride, i, j, u32PixelDepth; unsigned char *pu8Src1, *pu8Src2; //--- Allocate image buffer pContext->pu8Pixels = new unsigned char[3*pContext->u32Width*pContext->u32Height]; pContext->PixelFormat = PIXELFORMAT_R8G8B8; u32PixelDepth = 3; if (!pContext->pu8Pixels) return(FALSE); //--- RLE decompression from file RLEDecompress(pContext->pu8Pixels, pFile, pContext->u32Width*pContext->u32Height, u32PixelDepth); //--- Swap bytes and image to get proper format u32Stride = pContext->u32Width*u32PixelDepth; for (j=0; j<pContext->u32Height>>1; ++j) { pu8Src1 = pContext->pu8Pixels + j*u32Stride; pu8Src2 = pContext->pu8Pixels + (pContext->u32Height-1-j)*u32Stride; for (i=0; i<pContext->u32Width*u32PixelDepth; i+=u32PixelDepth) { pu8Src1[i] ^= pu8Src2[i+2]; pu8Src2[i+2] ^= pu8Src1[i]; pu8Src1[i] ^= pu8Src2[i+2]; } } //--- Flip image if (pContext->u32Height & 1) { j = (pContext->u32Height>>1)+1; pu8Src1 = pContext->pu8Pixels + j*u32Stride; pu8Src2 = pContext->pu8Pixels + (pContext->u32Height-1-j)*u32Stride; for (i=0; i<pContext->u32Width*u32PixelDepth; i+=u32PixelDepth) { pu8Src1[i] ^= pu8Src2[i+2]; pu8Src2[i+2] ^= pu8Src1[i]; pu8Src1[i] ^= pu8Src2[i+2]; } }
bool IMI::FlashRead(Port &port, void *buffer, unsigned address, unsigned size) { if (!_connected) return false; if (size == 0) return true; const TMsg *pMsg = SendRet(port, MSG_FLASH, 0, 0, MSG_FLASH, -1, IMICOMM_BIGPARAM1(address), IMICOMM_BIGPARAM2(address), size, 300, 2); if (pMsg == NULL || size != pMsg->parameter3) return false; return RLEDecompress((IMIBYTE*)buffer, pMsg->payload, pMsg->payloadSize, size); }
//******************************************************************************* // Decompress RGB16 RLE // BOOL DecompressRGB16RLE(FILE *pFile, TGAHEADER *pHeader, IMAGE_DATA *pContext) { unsigned int u32Stride, i, j, k; unsigned short *pu16RLEBuffer; unsigned char *pu8Ptr; //--- Check alpha channel if (pHeader->cImageDescriptor & 0xF) { //--- Allocate image buffer pContext->pu8Pixels = new unsigned char[4*pContext->u32Width*pContext->u32Height]; pContext->PixelFormat = PIXELFORMAT_R8G8B8A8; u32Stride = pContext->u32Width*4; } else { //--- Allocate image buffer pContext->pu8Pixels = new unsigned char[3*pContext->u32Width*pContext->u32Height]; pContext->PixelFormat = PIXELFORMAT_R8G8B8; u32Stride = pContext->u32Width*3; } if (!pContext->pu8Pixels) return(FALSE); //--- Allocate decompression buffer pu16RLEBuffer = new unsigned short[pContext->u32Width*pContext->u32Height]; if (!pu16RLEBuffer) { delete [] pContext->pu8Pixels; pContext->pu8Pixels = NULL; return(FALSE); } //--- Decompress data RLEDecompress((unsigned char *)pu16RLEBuffer, pFile, pContext->u32Width*pContext->u32Height, 2); //--- Reformat data for (j=0; j<pContext->u32Height; ++j) { pu8Ptr = pContext->pu8Pixels + (pContext->u32Height-1-j)*u32Stride; for (i=0; i<pContext->u32Width; ++i) { k = i*j; *(pu8Ptr++) = (unsigned char)((((pu16RLEBuffer[k] & 0x7C00)>>10)*255)/31); *(pu8Ptr++) = (unsigned char)((((pu16RLEBuffer[k] & 0x3E0)>>5)*255)/31); *(pu8Ptr++) = (unsigned char)(((pu16RLEBuffer[k] & 0x1F)*255)/31); if (pHeader->cImageDescriptor & 0xF) *(pu8Ptr++) = ((pu16RLEBuffer[k] & 0x8000) == 0x8000)?255:0; } } //--- Destroy work buffer delete [] pu16RLEBuffer; return(TRUE); }