void CDib::CreatePaletteFromImage( CPalette& palette)const { if( palette.m_hObject ) palette.DeleteObject(); ASSERT( IsIndexed() == GetBPP() <= 8); if( GetBPP() <= 8) { GetPalette(palette); //CPalette* pal = CPalette::FromHandle(m_hPalette); //PALETTEENTRY colors[256] = {0}; //pal->GetPaletteEntries(0, 256, colors); //palette.SetPaletteEntries( 0, 256, colors ); } else { LPLOGPALETTE pLogPal = (LPLOGPALETTE) new char[2 * sizeof(WORD) + 256 * sizeof(PALETTEENTRY)]; pLogPal->palVersion = 0x300; pLogPal->palNumEntries = 256; palette.CreatePalette(pLogPal); delete pLogPal; pLogPal = NULL; CArray<COLORREF, COLORREF> colorArray; int height= GetHeight(); int width = GetWidth(); for(int i=0; i<width; i++) { for(int j=0; j<height; j++) { COLORREF color = GetPixel(i, j); if( UtilWin::FindInArray( colorArray, color) == -1) colorArray.Add(color); if( colorArray.GetSize() == 256) break; } if( colorArray.GetSize() == 256) break; } PALETTEENTRY pe[256]={0}; for (int i = 0; i < colorArray.GetSize(); i++) { COLORREF color = colorArray[i]; pe[i].peRed = GetRValue(color); pe[i].peGreen = GetGValue(color); pe[i].peBlue = GetBValue(color); } palette.SetPaletteEntries(0, 256, pe); } }
void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event) { /* realize palette if this is *not* the current window */ if ( GetPalette() && GetPalette()->Ok() && (this != event.GetChangedWindow()) ) { ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::RealizePalette(GetHDC()); Refresh(); } }
void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event) { /* realize palette if this is the current window */ if ( GetPalette()->Ok() ) { ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::RealizePalette(GetHDC()); Refresh(); event.SetPaletteRealized(true); } else event.SetPaletteRealized(false); }
///////////////////////////////////////////////////////////////////////////// // // Draw DIB on caller's DC. Does stretching from source to destination // rectangles. Generally, it's OK to let the following default to zero: // // bUseDrawDib = whether to use use DrawDib, default TRUE // pPalette = palette, default = 0, (use DIB's palette) // bForeground = realize in foreground (default FALSE) // // If handling palette messages, use bForeground = FALSE, since the // foreground palette will be realized in WM_QUERYNEWPALETTE. // ///////////////////////////////////////////////////////////////////////////// zBOOL ZDib::Draw( CDC& dc, const CRect *rectTgt, const CRect *rectSrc, zBOOL bUseDrawDib, CPalette *pPalette, zBOOL bForeground ) { if ( m_hObject == 0 ) return( FALSE ); // Select, realize palette. if ( pPalette == 0 ) // no palette specified: pPalette = GetPalette( ); // use default CPalette *pOldPal = dc.SelectPalette( pPalette, !bForeground ); dc.RealizePalette( ); zBOOL bRC = FALSE; if ( bUseDrawDib ) { // Compute rectangles where 0 specified. CRect rect( 0, 0, -1, -1 ); // default for ::DrawDibDraw if ( rectSrc == 0 ) rectSrc = ▭ if ( rectTgt == 0 ) rectTgt = rectSrc; if ( m_hdd == 0 ) VERIFY( (m_hdd = ::DrawDibOpen( )) != 0 ); // Get BITMAPINFOHEADER/color table. Copy into stack object each time. // This doesn't seem to slow things down visibly. DIBSECTION ds; VERIFY( GetObject( sizeof( ds ), &ds ) == sizeof( ds ) ); char buf[ sizeof( BITMAPINFOHEADER ) + MAXPALCOLORS * sizeof( RGBQUAD ) ]; BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER *) buf; RGBQUAD *colors = (RGBQUAD *) (&bmih + 1); zmemcpy( &bmih, &ds.dsBmih, sizeof( bmih ) ); GetColorTable( colors, MAXPALCOLORS ); // Let DrawDib do the work! bRC = ::DrawDibDraw( m_hdd, dc, rectTgt->left, rectTgt->top, rectTgt->Width( ), rectTgt->Height( ), &bmih, // ptr to BITMAPINFOHEADER + colors m_bitmap.bmBits, // bits in memory rectSrc->left, rectSrc->top, rectSrc->Width( ), rectSrc->Height( ), bForeground ? 0 : DDF_BACKGROUNDPAL ); } else { // Use normal draw function. bRC = DrawBitmap( dc, this, rectTgt, rectSrc ); } if ( pOldPal ) dc.SelectPalette( pOldPal, TRUE ); return( bRC ); }
void convertFalseColor(const cv::Mat& srcmat, cv::Mat& dstmat, palette::palettetypes paltype){ palette pal = GetPalette(paltype); dstmat.create(srcmat.rows, srcmat.cols, CV_8UC3); cv::Size sz = srcmat.size(); const uchar* src = srcmat.data; uchar* dst = dstmat.data; if( srcmat.isContinuous() && dstmat.isContinuous() ) { sz.width *= sz.height; sz.height = 1; } for(int i = 0;i<sz.width;++i){ for(int j = 0;j<sz.height;++j){ int idx = j*sz.width + i; uint8_t val = src[idx]; dst[idx*dstmat.channels() + 0] = pal.colors[val].rgbBlue; dst[idx*dstmat.channels() + 1] = pal.colors[val].rgbGreen; dst[idx*dstmat.channels() + 2] = pal.colors[val].rgbRed; } } }
int GUIAPI LoadMyBitmapEx (PMYBITMAP my_bmp, RGB* pal, MG_RWops* area, const char* ext) { int type, ret; void* init_info; if ((type = get_image_type(ext)) < 0) return ERR_BMP_UNKNOWN_TYPE; my_bmp->flags = MYBMP_LOAD_NONE; my_bmp->bits = NULL; my_bmp->frames = 1; my_bmp->depth = GetGDCapability (HDC_SCREEN, GDCAP_DEPTH); if (my_bmp->depth <= 8) GetPalette (HDC_SCREEN, 0, 256, (GAL_Color*)pal); #ifdef _GRAY_SCREEN my_bmp->flags |= MYBMP_LOAD_GRAYSCALE; #endif init_info = bitmap_types [type].init (area, my_bmp, pal); if (init_info == NULL) return ERR_BMP_CANT_READ; my_bmp->bits = malloc (my_bmp->pitch * my_bmp->h); if (my_bmp->bits) ret = bitmap_types [type].load (area, init_info, my_bmp, NULL, NULL); else ret = ERR_BMP_MEM; bitmap_types [type].cleanup (init_info); return ret; }
// ---------------------------------------------------------------------------- void Main() { PushBank( BANKC1 ); LoadFile( ANGELTITLE1BIGFILE_TRACKFILEID, ANGELTITLE1H_DATAPTR ); // TITLE TOP IN C1-CODESEGMENT4000 memcpy( CODESEGMENT4000, ANGELTITLEBMPTOPBINPCK_PTR, ANGELTITLEBMPTOPBINPCK_SIZE ); PopBank(); // TITLE BOTTOM IN C3-CODESEGMENT4000 bank_memcpy( 0xC0, CODESEGMENTC000, ANGELTITLEBMPBOTTOMBINPCK_PTR, ANGELTITLEBMPBOTTOMBINPCK_SIZE ); Unpack( VIDEOSEGMENTC000, ANGELTILEBMPSPRRAWDATA1PCK_PTR ); ShiftTile( VIDEOSEGMENTC000 ); SetPaletteFrom8( GetPalette() ); // Cloud BankUnpack( 0xC4, CODESEGMENT0000, VIDEOSEGMENT0000 ); // Draw Cloud PushBank( BANKC1 ); DrawTiles(MASKTYPE_NOMASK, VIDEOSEGMENT0000, VIDEOSEGMENT4000, VIDEOSEGMENTC000 ); PopBank(); DrawCloud_VIDEOSEGMENT8000(); // Apply Part palette UnshiftTile( VIDEOSEGMENTC000 ); PushBank( BANKC1 ); DrawTiles(MASKTYPE_NOMASK, VIDEOSEGMENT0000, VIDEOSEGMENT4000, VIDEOSEGMENTC000 ); PopBank(); WaitVBL(); SetPalette( GetPalette() ); FlipScreen(); // Load Cloud LoadFile( ANGELTITLECLOUDBMPBINPCK_TRACKFILEID, VIDEOSEGMENT8000 ); BankUnpack( 0xC4, CODESEGMENT0000, VIDEOSEGMENT8000 ); BankUnpack( 0xC1, VIDEOSEGMENT8000, CODESEGMENT4000 ); BankUnpack( 0xC0, VIDEOSEGMENTC000, CODESEGMENTC000 ); PushBank( BANKC3 ); DrawTiles(MASKTYPE_MASK, VIDEOSEGMENT8000, VIDEOSEGMENT4000, VIDEOSEGMENTC000 ); PopBank(); DrawCloudReverse_VIDEOSEGMENT0000(); }
CBitmap *CImage::MakeBitmap() { HDC dc = ::CreateCompatibleDC(NULL); if (dc) { // tmpBitmap is a dummy, to satisfy ::CreateCompatibleDC (it // is a memory dc that must have a bitmap selected into it) HDC dc2 = GetDC(NULL); HBITMAP tmpBitmap = ::CreateCompatibleBitmap(dc2, GetWidth(), GetHeight()); ReleaseDC(NULL, dc2); HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap); if ( GetPalette() ) { HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) GetPalette()->m_hObject, FALSE); ::RealizePalette(dc); } HBITMAP hBitmap = ::CreateDIBitmap(dc, GetImplementation()->GetBits(), CBM_INIT, GetRawImage(), (LPBITMAPINFO) GetImplementation()->GetBits(), DIB_PAL_COLORS); ::SelectPalette(dc, NULL, TRUE); ::SelectObject(dc, oldBitmap); ::DeleteObject(tmpBitmap); ::DeleteDC(dc); if ( hBitmap ) { CBitmap *bitmap = new CBitmap; bitmap->Attach(hBitmap); return bitmap; } else { return NULL; } } else { return NULL; } }
static void MacGetPaletteEntry (long index, short *r, short *g, short *b) { RGBColor theColor; PaletteHandle myPalette; myPalette = GetPalette(MAC_WIN(currgw)); GetEntryColor(myPalette,(short) index,&theColor); *r = theColor.red/2; *g = theColor.green/2; *b = theColor.blue/2; }
static int PaletteWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam) { HDC hdc; int x, y; static GAL_Color colorPal[256], myPal[256]; switch (message) { case MSG_CREATE: GetPalette(HDC_SCREEN, 0, 256, colorPal); #ifdef _DEBUG int i; for (i = 0; i < 256; i++) { printf ("i = %d\n, red = %d\n, green = %d\n, blue = %d\n\n", i, colorPal[i].r, colorPal[i].g, colorPal[i].b); } #endif break; case MSG_PAINT: { if (g_bShowBall) SendMessage (hWnd, MSG_LBUTTONDOWN, 0, 0); } break; case MSG_LBUTTONDOWN: g_bShowBall = TRUE; hdc = GetClientDC(hWnd); InitMyPalette(myPal); SetPalette(hdc, 0, 256, myPal); SetBrushColor(hdc, COLOR_red); FillCircle(hdc, 10, 10, 8); for (y = 0; y < 240; y += 20) { for (x = 0; x < 320; x += 20) { BitBlt(hdc, 0, 0, 20, 20, hdc, x, y, 0); SetColorfulPalette(hdc); } } ReleaseDC(hdc); break; case MSG_RBUTTONDOWN: SetColorfulPalette(HDC_SCREEN); SetBrushColor(HDC_SCREEN, PIXEL_yellow); FillCircle(HDC_SCREEN, 50, 50, 15); break; case MSG_CLOSE: DestroyAllControls (hWnd); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam); }
void CProgressCtrlX::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CRect rc; GetClientRect(&rc); CPalette *pOldPal = NULL; if (GetCreatePalette() && GetPalette().GetSafeHandle()) { pOldPal = dc.SelectPalette(&GetPalette(), FALSE); dc.RealizePalette(); } Draw(&dc, rc); if(pOldPal) dc.SelectPalette(pOldPal, TRUE); // Do not call CProgressCtrl::OnPaint() for painting messages }
static void MacSetPaletteEntry (long index, short r, short g, short b) { RGBColor newColor; PaletteHandle myPalette; myPalette = GetPalette(MAC_WIN(currgw)); newColor.red = 2*r; newColor.green = 2*g; newColor.blue = 2*b; SetEntryColor(myPalette,(short) index,&newColor); ActivatePalette(MAC_WIN(currgw)); }
void GUI::SelectPalettePage(PaletteType pt) { if(palettes.empty()) CreatePalette(); PaletteWindow* p = GetPalette(); if(!p) return; ShowPalette(); p->SelectPage(pt); aui_manager->Update(); SelectBrushInternal(p->GetSelectedBrush()); }
//////////////////////////////////////////////////////////////// // Draw DIB on caller's DC. Does stretching from source to destination // rectangles. Generally, you can let the following default to zero/NULL: // // bUseDrawDib = whether to use use DrawDib, default TRUE // pPal = palette, default=NULL, (use DIB's palette) // bForeground = realize in foreground (default FALSE) // // If you are handling palette messages, you should use bForeground=FALSE, // since you will realize the foreground palette in WM_QUERYNEWPALETTE. // BOOL CDib::Draw(CDC& dc, const CRect* rcDst, const CRect* rcSrc, BOOL bUseDrawDib, CPalette* pPal, BOOL bForeground) { if (!m_hObject) return FALSE; // Select, realize palette if (pPal==NULL) // no palette specified: pPal = GetPalette(); // use default CPalette* pOldPal = dc.SelectPalette(pPal, !bForeground); dc.RealizePalette(); BOOL bRet = FALSE; if (bUseDrawDib) { // Compute rectangles where NULL specified // CRect rc(0,0,-1,-1); // default for DrawDibDraw if (!rcSrc) rcSrc = &rc; if (!rcDst) rcDst=rcSrc; if (!m_hdd) VERIFY(m_hdd = DrawDibOpen()); // Get BITMAPINFOHEADER/color table. I copy into stack object each time. // This doesn't seem to slow things down visibly. // DIBSECTION ds; VERIFY(GetObject(sizeof(ds), &ds)==sizeof(ds)); char buf[sizeof(BITMAPINFOHEADER) + MAXPALCOLORS*sizeof(RGBQUAD)]; BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER*)buf; RGBQUAD* colors = (RGBQUAD*)(&bmih+1); memcpy(&bmih, &ds.dsBmih, sizeof(bmih)); GetColorTable(colors, MAXPALCOLORS); // Let DrawDib do the work! bRet = DrawDibDraw(m_hdd, dc, rcDst->left, rcDst->top, rcDst->Width(), rcDst->Height(), &bmih, // ptr to BITMAPINFOHEADER + colors m_bm.bmBits, // bits in memory rcSrc->left, rcSrc->top, rcSrc->Width(), rcSrc->Height(), bForeground ? 0 : DDF_BACKGROUNDPAL); } else { // use normal draw function bRet = PLDrawBitmap(dc, this, rcDst, rcSrc); } if (pOldPal) dc.SelectPalette(pOldPal, TRUE); return bRet; }
void gr_palette_load( ubyte *pal ) { int i, j; GDHandle old_device; ColorSpec colors[256]; // PaletteHandle palette; // RGBColor color; // CTabHandle ctable; for (i=0; i<768; i++ ) { // gr_current_pal[i] = pal[i] + gr_palette_gamma; gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; } for (i = 0, j = 0; j < 256; j++) { colors[j].value = j; colors[j].rgb.red = gr_mac_gamma[gr_current_pal[i++]]; colors[j].rgb.green = gr_mac_gamma[gr_current_pal[i++]]; colors[j].rgb.blue = gr_mac_gamma[gr_current_pal[i++]]; } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); #if 0 palette = GetPalette(GameWindow); for (i = 0; i < 768; i += 3) { color.red = gr_current_pal[i] << 9; color.green = gr_current_pal[i+1] << 9; color.blue = gr_current_pal[i+2] << 9; SetEntryColor(palette, i / 3, &color); } ctable = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctable); AnimatePalette(GameWindow, ctable, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctable); if (GameGWorld != NULL) { ctable = (**GetGWorldPixMap(GameGWorld)).pmTable; // get the color table for the gWorld. CTabChanged(ctable); (**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed; } #endif gr_palette_faded_out = 0; init_computed_colors(); }
void setUpPalette(Lcd *x, RGBColor *oldColor, PaletteHandle *oldPalette) { if (hasColorQD) { if (numPaletteColors>2){ GetForeColor(oldColor); *oldPalette = GetPalette(&x->lcd_box.b_patcher->p_wind->w_gp); SetPalette(&x->lcd_box.b_patcher->p_wind->w_gp,x->lcd_palette,FALSE); PmForeColor(x->lcd_pIndex); } } GetPenState(&x->lcd_penState); PenMode(x->lcd_penMode); PenSize(1,1); }
static gal_pixel anim_get_color_key (ANIMATIONINFO* anim_info) { int i; gal_pixel pixel; struct gal_pixel_table table; GAL_Color* colors; ANIMATIONFRAME* f; if (anim_info == NULL) return PIXEL_black; if (anim_info->anim == NULL) return PIXEL_black; table.size = 256; table.count = 0; table.colors = NULL; f = anim_info->anim->frames; colors = calloc(256, sizeof(GAL_Color)); while(f) { int colornum = GetGDCapability(f->mem_dc, GDCAP_COLORNUM); if(colornum > 256) colornum = 256; GetPalette(f->mem_dc, 0, colornum, colors); for(i=0; i< colornum; i++) { pixel = RGB2Pixel(anim_info->mem_dc, colors[i].r, colors[i].g, colors[i].b); add_pixel_to_gal_colors(&table, pixel); } f = f->next; } free (colors); for(i=0; i<256; i++) // we try 256 times. { int r, g, b; r = rand()/(RAND_MAX/256); g = rand()/(RAND_MAX/256); b = rand()/(RAND_MAX/256); pixel = RGB2Pixel(anim_info->mem_dc, r, g, b); if(!is_pixel_in_gal_colors(&table, pixel)) { free (table.colors); return pixel; } } free (table.colors); return PIXEL_lightwhite; }
void POPUP_DISPLAY::init() { free(); // fill scr_bmp palette with current palette colors PALETTEENTRY* color_palette = GetPalette(); for (int i = 0; i < 256; ++i) { screenshotBmi->bmiColors[i].rgbRed = color_palette[i].peRed; screenshotBmi->bmiColors[i].rgbGreen = color_palette[i].peGreen; screenshotBmi->bmiColors[i].rgbBlue = color_palette[i].peBlue; } HDC win_hdc = GetWindowDC(pianoRoll.hwndList); screenshotHBitmap = CreateDIBSection(win_hdc, screenshotBmi, DIB_RGB_COLORS, (void**)&screenshotRasterPointer, 0, 0); // calculate coordinates of popup windows (relative to TAS Editor window) updateBecauseParentWindowMoved(); }
wxIDirectFBSurfacePtr wxIDirectFBSurface::CreateCompatible(const wxSize& sz, int flags) { wxSize size(sz); if ( size == wxDefaultSize ) { if ( !GetSize(&size.x, &size.y) ) return NULL; } wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, "invalid size" ); DFBSurfaceDescription desc; desc.flags = (DFBSurfaceDescriptionFlags)( DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); GetCapabilities(&desc.caps); GetPixelFormat(&desc.pixelformat); desc.width = size.x; desc.height = size.y; // filter out caps that don't make sense for a new compatible surface: int caps = desc.caps; caps &= ~DSCAPS_PRIMARY; caps &= ~DSCAPS_SUBSURFACE; if ( flags & CreateCompatible_NoBackBuffer ) { caps &= ~DSCAPS_DOUBLE; caps &= ~DSCAPS_TRIPLE; } desc.caps = (DFBSurfaceCapabilities)caps; wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc)); if ( !snew ) return NULL; if ( desc.pixelformat == DSPF_LUT8 ) { wxIDirectFBPalettePtr pal(GetPalette()); if ( pal ) { if ( !snew->SetPalette(pal) ) return NULL; } } return snew; }
static void MacSetNewPalette (long start, long count, short *r, short *g, short *b) { RGBColor newColor; PaletteHandle myPalette; long i; myPalette = GetPalette(MAC_WIN(currgw)); assert(myPalette!=NULL); for (i=start; i<start+count; i++) { newColor.red = r[i]; newColor.green = g[i]; newColor.blue = b[i]; SetEntryColor(myPalette,(short) i,&newColor); } ActivatePalette(MAC_WIN(currgw)); }
int Palette256::SavePalette(char* s) { int i; RGB p; char ss[100]; strcpy(ss,s); strcat(ss,".pal"); FILE *f=fopen(ss,"wb"); for(i=0;i<256;i++) { p=GetPalette(i); fputc(p.r,f); fputc(p.g,f); fputc(p.b,f); } fclose(f); return 1; }
void gr_palette_clear() { int i; ColorSpec colors[256]; GDHandle old_device; // PaletteHandle palette; // RGBColor color; // CTabHandle ctable; for (i = 0; i < 256; i++) { colors[i].value = i; colors[i].rgb.red = 0; colors[i].rgb.green = 0; colors[i].rgb.blue = 0; } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); #if 0 palette = GetPalette(GameWindow); for (i=0; i<256; i++) { color.red = 0x0; color.green = 0x0; color.blue = 0x0; SetEntryColor(palette, i, &color); } ctable = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctable); AnimatePalette(GameWindow, ctable, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctable); // make the seeds match for the gworld clut and the window palette. I don't know if // this is necessary, but it doesn't hurt. if (GameGWorld != NULL) { ctable = (**GetGWorldPixMap(GameGWorld)).pmTable; CTabChanged(ctable); (**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed; } #endif gr_palette_faded_out = 1; }
void* GUIAPI InitMyBitmapSL (MG_RWops* area, const char* ext, MYBITMAP* my_bmp, RGB* pal) { int type; LOAD_MYBITMAP_INFO* load_info; load_info = calloc (1, sizeof (LOAD_MYBITMAP_INFO)); if (load_info == NULL) return NULL; if ((type = get_image_type(ext)) < 0) { free (load_info); return NULL; } load_info->type_info = bitmap_types + type; my_bmp->flags = MYBMP_LOAD_ALLOCATE_ONE; my_bmp->bits = NULL; my_bmp->frames = 1; my_bmp->depth = GetGDCapability (HDC_SCREEN, GDCAP_DEPTH); if (my_bmp->depth <= 8) GetPalette (HDC_SCREEN, 0, 256, (GAL_Color*)pal); #ifdef _GRAY_SCREEN my_bmp->flags |= MYBMP_LOAD_GRAYSCALE; #endif load_info->init_info = load_info->type_info->init (area, my_bmp, pal); if (load_info->init_info == NULL) goto fail; my_bmp->bits = malloc (my_bmp->pitch); if (my_bmp->bits == NULL) goto fail; return load_info; fail: if (my_bmp->bits != NULL) free (my_bmp->bits); free (load_info); return NULL; }
void CDib::GetSelectionIndex(COLORREF crColor, UtilWin::CIntArray& selectionArray) { selectionArray.RemoveAll(); CPalette palette; GetPalette(palette); int nbColor = palette.GetEntryCount(); ASSERT(nbColor >= 0 && nbColor <=256); PALETTEENTRY pe[256]; palette.GetPaletteEntries(0, nbColor, pe); for(int i=0; i<nbColor;i++) { if( RGB( pe[i].peRed, pe[i].peGreen, pe[i].peBlue) == crColor) selectionArray.Add(i); } }
//************************************************************************ BOOL CCreditsScene::StartNext() //************************************************************************ { if ( !m_pContributors ) return( NO ); m_dwLastTime = timeGetTime(); int i = m_nNextContributor; if ( ++m_nNextContributor >= m_nContributors ) m_nNextContributor = 0; PDIB pDib; int iType = m_pContributors[i].m_iType; if ( !(pDib = TextToDib(m_pContributors[i].m_szName, m_szFaceName[iType], m_ptSize[iType], m_fItalic[iType], m_Color[iType], GetPalette(), m_BackgrndColor)) ) return(NO/*fStarted*/); POINT ptOrigin; ptOrigin.x = 0; ptOrigin.y = 0; LPSPRITE lpSprite = m_pAnimator->CreateSprite( &ptOrigin ); lpSprite->AddCell( pDib, 0, 0 ); lpSprite->SetSpeed( m_pContributors[i].m_iSpeed ); lpSprite->SetNotifyProc(::OnSpriteNotify, (DWORD)this); int x; if (m_fCenter) { int iWidth, iHeight; lpSprite->GetMaxSize(&iWidth, &iHeight); x = (RectWidth(&m_rGameArea) - iWidth) / 2; x += m_rGameArea.left; } else x = m_pContributors[i].m_ptStart.x; lpSprite->Jump(x, m_pContributors[i].m_ptStart.y); lpSprite->Show(TRUE); if (!m_fCenter) x = m_pContributors[i].m_ptEnd.x; lpSprite->AddCmdMove(x, m_pContributors[i].m_ptEnd.y); return(YES/*fStarted*/); }
_WCRTLINK long _WCI86FAR _CGRAPH _remappalette( short pixval, long colour ) /*========================================================== This routine sets the colour indexed by pixval to the new colour. It returns the previous colour at pixval or -1 if unsuccessful. */ { long prev; if( pixval < 0 || pixval >= _CurrState->vc.numcolors ) { _ErrorStatus = _GRINVALIDPARAMETER; return( -1 ); } if( _CurrState->vc.adapter < _MCGA ) { _ErrorStatus = _GRERROR; return( -1 ); } prev = GetPalette( pixval ); PutPalette( pixval, colour ); return( prev ); }
//converts to 24bpp static void do_video_conversion(const unsigned char* buffer) { // memset(avi_file->convert_buffer, 0, VIDEO_WIDTH*(avi_file->end_scanline-avi_file->start_scanline)*3); buffer += avi_file->start_scanline * VIDEO_WIDTH; PALETTEENTRY* color_palette = GetPalette(); for(int y=avi_file->start_scanline; y<avi_file->end_scanline; ++y) { uint8* pix = avi_file->convert_buffer + (avi_file->end_scanline-1-y)*VIDEO_WIDTH*3; const uint8* prevbuf = buffer; for(int x=0; x<VIDEO_WIDTH; ++x) { uint8 *cp = (uint8*)(color_palette + *buffer++)+2; *pix++ = *cp--; *pix++ = *cp--; *pix++ = *cp; } buffer = prevbuf + VIDEO_WIDTH; } }
static void MacShadedPolygon (SHORT_POINT *points, INT n, DOUBLE intensity) { PaletteHandle myPalette; RGBColor theColor; /*short r,g,b;*/ if (n<3) return; /* change color */ /*MacGetPaletteEntry(CurrColor,&r,&g,&b);*/ /*MacSetPaletteEntry(CurrColor,r*intensity,g*intensity,b*intensity);*/ myPalette = GetPalette(MAC_WIN(currgw)); GetEntryColor(myPalette,(short) CurrColor,&theColor); theColor.red *= intensity; theColor.green *= intensity; theColor.blue *= intensity; RGBForeColor(&theColor); MacintoshPolygon(points,n); /* restore color */ /*MacSetPaletteEntry(CurrColor,r,g,b);*/ }
BOOL CImageTIFF::Write(FILE* stream) { //prepare the palette struct RGBQUAD pal[256]; if (GetPalette()){ BYTE b; memcpy(pal,GetPalette(),GetPaletteSize()); for(WORD a=0;a<m_header.biClrUsed;a++){ //swap blue and red components b=pal[a].rgbBlue; pal[a].rgbBlue=pal[a].rgbRed; pal[a].rgbRed=b; } } TIFF *m_tif=NULL; // = (TIFF *)new(byte[512]); uint32 height=m_header.biHeight; uint32 width=m_header.biWidth; // uint32 rowsperstrip = (uint32) -1; uint16 bitspersample=m_header.biBitCount; uint16 samplesperpixel; uint16 photometric; uint16 compression; uint16 pitch; int line; uint32 x, y; samplesperpixel = ((bitspersample == 24) || (bitspersample == 32)) ? 3 : 1; photometric = (samplesperpixel==3) ? PHOTOMETRIC_RGB : PHOTOMETRIC_PALETTE; line = CalculateLine(width, bitspersample * samplesperpixel); pitch = CalculatePitch(line); m_tif=TIFFOpenEx(stream, "wb"); if (m_tif==NULL) return FALSE; // handle standard width/height/bpp stuff TIFFSetField(m_tif, TIFFTAG_IMAGEWIDTH, width); TIFFSetField(m_tif, TIFFTAG_IMAGELENGTH, height); TIFFSetField(m_tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); TIFFSetField(m_tif, TIFFTAG_BITSPERSAMPLE, ((bitspersample == 32) ? 24 : bitspersample) / samplesperpixel); TIFFSetField(m_tif, TIFFTAG_PHOTOMETRIC, photometric); TIFFSetField(m_tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); // single image plane TIFFSetField(m_tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, 1); // TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(m_tif, rowsperstrip)); // handle metrics TIFFSetField(m_tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); TIFFSetField(m_tif, TIFFTAG_XRESOLUTION, 72.0); TIFFSetField(m_tif, TIFFTAG_YRESOLUTION, 72.0); // multi-paging // if (page >= 0) { // char page_number[20]; // sprintf(page_number, "Page %d", page); // // TIFFSetField(m_tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); // TIFFSetField(m_tif, TIFFTAG_PAGENUMBER, page); // TIFFSetField(m_tif, TIFFTAG_PAGENAME, page_number); // } else { TIFFSetField(m_tif, TIFFTAG_SUBFILETYPE, 0); // } // palettes (image colormaps are automatically scaled to 16-bits) if (photometric == PHOTOMETRIC_PALETTE) { uint16 *r, *g, *b; r = (uint16 *) _TIFFmalloc(sizeof(uint16) * 3 * 256); g = r + 256; b = g + 256; for (int i = 255; i >= 0; i--) { b[i] = SCALE((uint16)pal[i].rgbRed); g[i] = SCALE((uint16)pal[i].rgbGreen); r[i] = SCALE((uint16)pal[i].rgbBlue); } TIFFSetField(m_tif, TIFFTAG_COLORMAP, r, g, b); _TIFFfree(r); } // compression switch(bitspersample) { case 1 : compression = COMPRESSION_CCITTFAX4; break; case 8 : case 24 : case 32 : compression = COMPRESSION_PACKBITS; break; default : compression = COMPRESSION_NONE; break; } TIFFSetField(m_tif, TIFFTAG_COMPRESSION, compression); // read the DIB lines from bottom to top // and save them in the TIF // ------------------------------------- BYTE *bits; switch(bitspersample) { case 1 : case 4 : case 8 : { for (y = 0; y < height; y++) { bits= m_info.pImage + (height - y - 1)*m_info.dwEffWidth; TIFFWriteScanline(m_tif,bits, y, 0); } break; } case 24: case 32 : { BYTE *buffer = (BYTE *)malloc(m_info.dwEffWidth); for (y = 0; y < height; y++) { // get a pointer to the scanline memcpy(buffer, m_info.pImage + (height - y - 1)*m_info.dwEffWidth, m_info.dwEffWidth); // TIFFs store color data RGB instead of BGR BYTE *pBuf = buffer; for (x = 0; x < width; x++) { BYTE tmp = pBuf[0]; pBuf[0] = pBuf[2]; pBuf[2] = tmp; pBuf += 3; } // write the scanline to disc TIFFWriteScanline(m_tif, buffer, y, 0); } free(buffer); break; } } TIFFClose(m_tif); return true; }
static int RasterizeFile (FILE *stream, AWindowRecord *myWindow, short wx, short wy) { char *buffer; /* input buffer */ long blockSize; /* METABUFFERSIZE */ long blockUsed; /* actual buffer size used */ long itemCounter; /* number of commands in buffer */ char *data; /* data pointer in buffer */ short fx,fy; /* file screen size */ Fixed sx,sy; /* scaling factors */ int i,error,j,size; char opCode; short x,y,r,g,b,n,lw,ts,m,ms,w; short x1,y1,x2,y2; short xx[SIZE],yy[SIZE]; PolyHandle myPoly; char s[CSIZE]; unsigned char c; RGBColor newColor; PaletteHandle myPalette; long l; /* get file parameters */ rewind(stream); error = fread(&blockSize,4,1,stream); if (error!=1) return(1); /* block size */ error = fread(&fx,2,1,stream); if (error!=1) return(1); /* x size */ error = fread(&fy,2,1,stream); if (error!=1) return(1); /* y size */ /* compute scaling factors */ sx = FixRatio(wx-1,fx-1); sy = FixRatio(wy-1,fy-1); /* default values */ lw = 1; ts = 12; m = 0; ms = 6; /* allocate input buffer */ buffer = malloc(blockSize); if (buffer==NULL) return(1); SetPort((GrafPtr)(myWindow->theWindow)); EraseRect(&(myWindow->usableRect)); /* loop through the blocks */ while (!feof(stream)) { /* read block parameters */ error = fread(&blockUsed,4,1,stream); if (error!=1) {free(buffer); return(1);} error = fread(&itemCounter,4,1,stream); if (error!=1) {free(buffer); return(1);} error = fread(buffer,blockUsed,1,stream);if (error!=1) {free(buffer); return(1);} /* init pointer to next item */ data = buffer; /* for all items */ for (i=0; i<itemCounter; i++) { /* get op code */ opCode = *(data++); switch (opCode) { case opMove : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); MoveTo(x,y); break; case opDraw : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); LineTo(x,y); break; case opPolyline : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); break; case opPolygon : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } if (n<3) break; myPoly = OpenPoly(); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); LineTo(xx[0],yy[0]); ClosePoly(); PaintPoly(myPoly); FramePoly(myPoly); KillPoly(myPoly); break; case opPolymark : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]); break; case opText : n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; DrawString((ConstStr255Param)c2pstr(s)); break; case opCenteredText : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; c2pstr(s); w = StringWidth((ConstStr255Param)s); MoveTo(x-w/2,y+ts/2); DrawString((ConstStr255Param)s); break; case opSetLineWidth : n = *((short *)data); data += 2; lw = n; PenSize(n,n); break; case opSetTextSize : n = *((short *)data); data += 2; ts = n; TextSize(n); break; case opSetMarker : n = *((short *)data); data += 2; m = n; break; case opSetMarkerSize : n = *((short *)data); data += 2; ms = n; break; case opSetColor : c = *((unsigned char *)data); data++; PmForeColor((short)c); break; case opSetEntry : c = *((unsigned char *)data); data++; r = (short) (*((unsigned char *)data)); data++; g = (short) (*((unsigned char *)data)); data++; b = (short) (*((unsigned char *)data)); data++; myPalette = GetPalette(myWindow->theWindow); myWindow->red[c] = newColor.red = r<<8; myWindow->green[c] = newColor.green = g<<8; myWindow->blue[c] = newColor.blue = b<<8; SetEntryColor(myPalette,(short) c,&newColor); ActivatePalette(myWindow->theWindow); break; case opSetPalette : x = (short) (*((unsigned char *)data)); data++; y = (short) (*((unsigned char *)data)); data++; myPalette = GetPalette(myWindow->theWindow); for (j=x; j<=y; j++) { r = (short) (*((unsigned char *)data)); data++; g = (short) (*((unsigned char *)data)); data++; b = (short) (*((unsigned char *)data)); data++; myWindow->red[j] = newColor.red = r<<8; myWindow->green[j] = newColor.green = g<<8; myWindow->blue[j] = newColor.blue = b<<8; SetEntryColor(myPalette,(short) j,&newColor); } ActivatePalette(myWindow->theWindow); break; case opNewLine : lw = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x1 = *((short *)data); data += 2; y1 = *((short *)data); data += 2; x2 = *((short *)data); data += 2; y2 = *((short *)data); data += 2; TRFMX(x1); TRFMY(y1); TRFMX(x2); TRFMY(y2); PenSize(lw,lw); PmForeColor((short)c); MoveTo(x1,y1); LineTo(x2,y2); break; case opNewPolyline : lw = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } PenSize(lw,lw); PmForeColor((short)c); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); break; case opNewPolygon : c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } if (n<3) break; PmForeColor((short)c); myPoly = OpenPoly(); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); LineTo(xx[0],yy[0]); ClosePoly(); PaintPoly(myPoly); FramePoly(myPoly); KillPoly(myPoly); break; case opNewPolymark : m = *((unsigned char *)data); data++; ms = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } PmForeColor((short)c); for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]); break; case opNewText : ts = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; MoveTo(x,y); TextSize(ts); PmForeColor((short)c); DrawString((ConstStr255Param)c2pstr(s)); break; case opNewCenteredText : ts = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; c2pstr(s); w = StringWidth((ConstStr255Param)s); TextSize(ts); PmForeColor((short)c); MoveTo(x-w/2,y+ts/2); DrawString((ConstStr255Param)c2pstr(s)); break; default : break; } } } return(0); }