BOOL WritePalette( /************************************************************************/ LPSTR lpFileName, LPPALETTE lpPalette) { int ofh; /* file handle( unbuffered) */ FILEBUF ofd; /* file descriptor( buffered) */ int i; VERSIONINFO version; RECINFO rec; if (!lpPalette) return(FALSE); /* open the output file */ if ( ( ofh = _lcreat( lpFileName, 0)) < 0 ) { Message( IDS_EWRITE, lpFileName); return( NO); } /* create a buffered stream to speed access */ FileFDOpenWrt( &ofd, ofh, (LPTR)LineBuffer[0], 16*1024); // write palette version version.Length = sizeof(version.Number); version.Type = PALFILE_VERSION; version.Number = CURRENT_VERSION; FileWrite(&ofd, (LPTR)&version, sizeof(version)); while (lpPalette) { if (lpPalette->iColors || TRUE) { // write palette name rec.Length = lstrlen(lpPalette->szName)+1; rec.Type = PALFILE_NAME; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); FileWrite(&ofd, (LPTR)lpPalette->szName, rec.Length); // write palette colors rec.Length = sizeof(WORD)+(lpPalette->iColors * sizeof(COLOR)); rec.Type = PALFILE_COLORS; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); intelWriteWord( &ofd, lpPalette->iColors); for (i = 0; i < lpPalette->iColors; ++i) { intelWriteDWord(&ofd, RGB2long(lpPalette->lpColorInfo[i].rgb)); } // write color lables if (lpPalette->lpLabels && lpPalette->LabelsLength) { rec.Length = lpPalette->LabelsLength; rec.Type = PALFILE_LABELS; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); FileWrite(&ofd, lpPalette->lpLabels, rec.Length); } // write formating information if (lstrlen(lpPalette->szFormat) > 0) { rec.Length = lstrlen(lpPalette->szFormat)+1; rec.Type = PALFILE_FORMAT; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); FileWrite(&ofd, (LPTR)lpPalette->szFormat, rec.Length); } // write palette grouping rec.Length = 4; rec.Type = PALFILE_GROUP; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); intelWriteDWord( &ofd, lpPalette->dwGroup); lpPalette = lpPalette->lpNext; } } // write palette end record rec.Length = 0; rec.Type = PALFILE_END; FileWrite(&ofd, (LPTR)&rec, sizeof(rec)); FileFlush(&ofd); _lclose(ofh); if ( ofd.err) { Message( IDS_EWRITE, lpFileName); return( NO); } return( YES); }
LOCAL void Palette_Paint( HDC hDC, HWND hWindow ) /***********************************************************************/ { RECT ClientRect; LPPALETTE lpPalette; int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols; int iStart, iEntry, r, c, xCount, yCount; LPRGB lpRGB, lpLine; LFIXED xrate, yrate; BLTSESSION BltSession; FRMTYPEINFO TypeInfo; // get pointer to palette information lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette) return; GetClientRect(hWindow, &ClientRect); FrameRect(hDC, &ClientRect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); if (!lpPalette->iColors) return; // get ClientRect and allocate buffer for SuperBlt GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); lpRGB = (LPRGB)Alloc((long)iWidth*3L); if (!lpRGB) return; yrate = FGET(iHeight, iRows); xrate = FGET(iWidth, iCols); FrameSetTypeInfo(&TypeInfo, FDT_RGBCOLOR, NULL); StartSuperBlt( &BltSession, hDC, NULL, lpBltScreen, &ClientRect, TypeInfo, 10, 0, 0, YES, NULL, NULL ); for (r = 0; r < iRows; ++r) { yCount = FMUL(r+1, yrate) - FMUL(r, yrate); set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); yCount -= 2; while (--yCount >= 0) { iEntry = iStart + (r * iRowIncr); lpLine = lpRGB; set24(lpLine, iWidth, RGB(255,255,255)); for (c = 0; c < iCols; ++c) { xCount = FMUL(c+1, xrate) - FMUL(c, xrate); if (iEntry < lpPalette->iColors) set24(lpLine+1, xCount-2, RGB2long(lpPalette->lpColorInfo[iEntry].rgb)); lpLine += xCount; iEntry += iColIncr; } SuperBlt(&BltSession, (LPTR)lpRGB); } set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); } SuperBlt(&BltSession, NULL); FreeUp((LPTR)lpRGB); }