/********************************************************************* * * _WriteAlphaToActiveAt */ static void _WriteAlphaToActiveAt(GUI_MEMDEV_Handle hMem, int Intens, int x, int y) { /* Make sure the memory handle is valid */ if (hMem) { GUI_MEMDEV * pDev = GUI_MEMDEV_H2P(hMem); GUI_USAGE_h hUsage = pDev->hUsage; GUI_USAGE* pUsage; int YSize = pDev->YSize; int yi; if (hUsage) { pUsage = GUI_USAGE_H2P(hUsage); for (yi = 0; yi < YSize; yi++) { int xOff = 0; int XSize; XSize = GUI_USAGE_GetNextDirty(pUsage, &xOff, yi); /* Draw the partial line which needs to be drawn */ for (; XSize; ) { U8* pData; pData = (U8*)GUI_MEMDEV__XY2PTREx(pDev, xOff, yi); do { LCD_COLOR Color, BkColor; int xPos, yPos, Index; if (pDev->BitsPerPixel == 8) { Index = *pData++; } else { Index = *(U16*)pData; pData += 2; } Color = LCD_Index2Color(Index); xPos = xOff + x; yPos = yi +y; BkColor = LCD_GetPixelColor(xPos, yPos); Color = LCD_MixColors256(Color, BkColor, Intens); Index = LCD_Color2Index(Color); LCD_SetPixelIndex(xPos, yPos, Index); xOff++; } while (--XSize); XSize = GUI_USAGE_GetNextDirty(pUsage, &xOff, yi); } } } } }
/********************************************************************* * * _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(); }