LCD_COLOR LCD_GetPixelColor(int x, int y) { return LCD_Index2Color(LCD_GetPixelIndex(x,y)); }
/********************************************************************* * * _Serialize */ static void _Serialize(int x0, int y0, int xSize, int ySize, HANDLE hFile) { int i; int x, y; int BPP = LCD_GetBitsPerPixelEx(GUI_Context.SelLayer);/**/ int NumColors = (BPP > 8) ? 0 : (1 << BPP); int Cnt = 0; int DataNew; int Data = -1; char aIsUsed[256] = {0}; char aIndex2Index[256]; GUI_LOCK(); /* Analyze which indices are really used */ if (NumColors) { NumColors = 0; for (y = 0; y < ySize; y++) { for (x = 0; x < xSize; x++) { aIsUsed[LCD_GetPixelIndex(x0 + x, y0 + y)] = 1; } } for (i = 0; i < 256; i++) { if (aIsUsed[i]) { aIndex2Index[i] = NumColors++; } } } /* Write header */ _WriteByteToFile('S', hFile); _WriteByteToFile('B', hFile); _WriteU16ToFile((U16)xSize, hFile); _WriteU16ToFile((U16)ySize, hFile); _WriteU16ToFile((U16)NumColors, hFile); /* Write index colors */ for (i = 0; i < 256; i++) { if (aIsUsed[i]) { GUI_COLOR Color = GUI_Index2Color(i); _WriteRGBToFile(Color, hFile); } } /* Write pixels */ for (y = 0; y < ySize; y++) { for (x = 0; x < xSize; x++) { if (NumColors) { DataNew = aIndex2Index[LCD_GetPixelIndex(x0 + x, y0 + y)]; } else { DataNew = LCD_GetPixelColor(x0 + x, y0 + y); } /* Write data record if necessary */ if ((Cnt == 0xFFFF) | (Data != DataNew)) { if (Cnt) { _WriteU16ToFile(Cnt, hFile); _WritePixel(Data, NumColors, hFile); } Data = DataNew; Cnt = 0; } Cnt++; } } /* Write last record */ _WriteU16ToFile(Cnt, hFile); _WritePixel(DataNew, NumColors, hFile); GUI_UNLOCK(); }