CImage *CImageYCbCrtoRGB(CImage *cimg) { CImage *ncimg=NULL; int p,n,i; ncimg = CreateCImage(cimg->C[0]->ncols,cimg->C[0]->nrows); n = ncimg->C[0]->ncols*ncimg->C[0]->nrows; for (p=0; p < n; p++){ i = triplet(cimg->C[0]->val[p],cimg->C[1]->val[p],cimg->C[2]->val[p]); i = YCbCr2RGB(i); ncimg->C[0]->val[p]=t0(i); ncimg->C[1]->val[p]=t1(i); ncimg->C[2]->val[p]=t2(i); } return(ncimg); }
ILboolean iLoadPcdInternal() { ILubyte VertOrientation; ILuint Width, Height, i, Total, x, CurPos = 0; ILubyte *Y1=NULL, *Y2=NULL, *CbCr=NULL, r = 0, g = 0, b = 0; ILuint PicNum; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } iseek(72, IL_SEEK_CUR); if (iread(&VertOrientation, 1, 1) != 1) return IL_FALSE; iseek(-72, IL_SEEK_CUR); // Can't rewind PicNum = iGetInt(IL_PCD_PICNUM); switch (PicNum) { case 0: iseek(0x02000, IL_SEEK_CUR); Width = 192; Height = 128; break; case 1: iseek(0x0b800, IL_SEEK_CUR); Width = 384; Height = 256; break; case 2: iseek(0x30000, IL_SEEK_CUR); Width = 768; Height = 512; break; default: ilSetError(IL_INVALID_PARAM); return IL_FALSE; } if (itell() == IL_EOF) // Supposed to have data here. return IL_FALSE; Y1 = (ILubyte*)ialloc(Width); Y2 = (ILubyte*)ialloc(Width); CbCr = (ILubyte*)ialloc(Width); if (Y1 == NULL || Y2 == NULL || CbCr == NULL) { ifree(Y1); ifree(Y2); ifree(CbCr); return IL_FALSE; } if (!ilTexImage(Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; Total = Height >> 1; for (i = 0; i < Total; i++) { iread(Y1, 1, Width); iread(Y2, 1, Width); if (iread(CbCr, 1, Width) != Width) { // Only really need to check the last one. ifree(Y1); ifree(Y2); ifree(CbCr); return IL_FALSE; } for (x = 0; x < Width; x++) { YCbCr2RGB(Y1[x], CbCr[x / 2], CbCr[(Width / 2) + (x / 2)], &r, &g, &b); iCurImage->Data[CurPos++] = r; iCurImage->Data[CurPos++] = g; iCurImage->Data[CurPos++] = b; } for (x = 0; x < Width; x++) { YCbCr2RGB(Y2[x], CbCr[x / 2], CbCr[(Width / 2) + (x / 2)], &r, &g, &b); iCurImage->Data[CurPos++] = r; iCurImage->Data[CurPos++] = g; iCurImage->Data[CurPos++] = b; } } ifree(Y1); ifree(Y2); ifree(CbCr); // Not sure how it is...the documentation is hard to understand if ((VertOrientation & 0x3F) != 8) iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; else iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; return ilFixImage(); }