UINT16 gdi_get_color_16bpp(HGDI_DC hdc, GDI_COLOR color) { BYTE r, g, b; UINT16 color16; GetRGB32(r, g, b, color); if (hdc->rgb555) { if (hdc->invert) { color16 = BGR15(r, g, b); } else { color16 = RGB15(r, g, b); } } else { if (hdc->invert) { color16 = BGR16(r, g, b); } else { color16 = RGB16(r, g, b); } } return color16; }
uint16 gdi_get_color_16bpp(HDC hdc, COLORREF color) { uint8 r, g, b; uint16 color16; GetRGB32(r, g, b, color); if(hdc->rgb555) { if (hdc->invert) { color16 = BGR15(r, g, b); } else { color16 = RGB15(r, g, b); } } else { if (hdc->invert) { color16 = BGR16(r, g, b); } else { color16 = RGB16(r, g, b); } } return color16; }
// Get a 32 bit palette, even under <39 void LIBFUNC L_GetPalette32( REG(a0, struct ViewPort *vp), REG(a1, unsigned long *palette), REG(d0, unsigned short count), REG(d1, short first)) { // If under 39+ we get it directly if( ((struct Library *)GfxBase)->lib_Version>=39) GetRGB32(vp->ColorMap,first,count,palette); // Otherwise, we have to convert from 4 bit colour else { unsigned short pen; unsigned long colour; // Go through each pen for (pen=0;pen<count;pen++) { // Get colour value of this pen colour=GetRGB4(vp->ColorMap,pen+first); // Convert from 4 to 32 bit colour *palette++=(((colour>>8)&0xf)<<28)|0x0fffffff; *palette++=(((colour>>4)&0xf)<<28)|0x0fffffff; *palette++=((colour&0xf)<<28)|0x0fffffff; } } }
uint16 GetPenColor_16bpp(HPEN pen) { uint16 p; int r, g, b; GetRGB32(r, g, b, pen->color); RGB_888_565(r, g, b); p = RGB16(r, g, b); return p; }
void test_color_GetRGB32(void) { int r, g, b; UINT32 rgb32 = 0x00AABBCC; GetRGB32(r, g, b, rgb32); CU_ASSERT(r == 0xAA); CU_ASSERT(g == 0xBB); CU_ASSERT(b == 0xCC); }
uint32 gdi_get_color_32bpp(HGDI_DC hdc, GDI_COLOR color) { uint32 color32; uint8 a, r, g, b; a = 0xFF; GetRGB32(r, g, b, color); if (hdc->invert) { color32 = ABGR32(a, r, g, b); } else { color32 = ARGB32(a, r, g, b); } return color32; }
unsigned long xf_gdi_get_color(xfContext* xfc, GDI_COLOR color) { XColor x11_color; x11_color.flags = DoRed | DoGreen | DoBlue; GetRGB32(x11_color.red, x11_color.green, x11_color.blue, color); x11_color.red = x11_color.red << 8; x11_color.green = x11_color.green << 8; x11_color.blue = x11_color.blue << 8; if (XAllocColor(xfc->display, xfc->colormap, &x11_color) != 0) { XFreeColors(xfc->display, xfc->colormap, &x11_color.pixel, 1, 0); } else { x11_color.pixel = BlackPixel(xfc->display, xfc->screen_number); } return x11_color.pixel; }
void Amiga_ConfigColors(void){ FILE *file; UWORD depth; long num_colors=1; long lokke; int lokke2; ULONG *table; rtPaletteRequest( "Color Config. Saved as radium:radiumcolors.conf",NULL, RT_Screen,mainscreen, TAG_END ); file=fopen("radium:radiumcolors.conf","w"); if(file==NULL){ RError("Could not save radium:radiumcolors.conf\n"); return; } depth=GetBitMapAttr(mainscreen->RastPort.BitMap,BMA_DEPTH); for(lokke=0;lokke<depth;lokke++){ num_colors*=2; } fprintf(file,"%d\n",num_colors); table=talloc_atomic((size_t)(sizeof(ULONG)*num_colors*3)); GetRGB32(mainscreen->ViewPort.ColorMap,0,num_colors,table); for(lokke=0;lokke<num_colors;lokke++){ if(lokke==256) break; for(lokke2=0;lokke2<3;lokke2++){ fprintf(file,"%lu\n",table[lokke*3+lokke2]); } } fclose(file); }
struct DragObj * PRIVATE CreateDragObj(struct DragGadget *dg,int x,int y) { struct Screen *scr; struct RastPort *rp; struct DragObj *gdo; ULONG line; int wordwidth; int width,height,depth; int i = 0,xpos,ypos; scr = dg->dg_Window->WScreen; rp = &scr->RastPort; if (dg->dg_Flags & DGF_IMAGES && ((struct ImageNode *)dg->dg_Object.od_Object)->in_Image) dg->dg_Image = ((struct ImageNode *)dg->dg_Object.od_Object)->in_Image; if (!dg->dg_Width || !dg->dg_Height) { if ((dg->dg_Type == LISTVIEW_KIND) && !dg->dg_Image) { dg->dg_Width = dg->dg_Gadget->Width-20; dg->dg_Height = dg->dg_ItemHeight; } else if (!dg->dg_RenderHook && dg->dg_Image) { dg->dg_Width = dg->dg_Image->Width; dg->dg_Height = dg->dg_Image->Height; } else /* be sure width & height are not zero */ { dg->dg_Width = dg->dg_Gadget->Width; dg->dg_Height = dg->dg_Gadget->Height; } } width = dg->dg_Width; height = dg->dg_Height; memset(&dm,0,sizeof(struct DropMessage)); if (dg->dg_Type == LISTVIEW_KIND) { xpos = dg->dg_Gadget->LeftEdge+2; ypos = dg->dg_Gadget->TopEdge+2; dg->dg_Object.od_Object = NULL; if (y < ypos || y > ypos+dg->dg_Gadget->Height-5) return(NULL); line = (y-ypos)/dg->dg_ItemHeight; ypos += line*dg->dg_ItemHeight; GT_GetGadgetAttrs(dg->dg_Gadget,dg->dg_Window,NULL,GTLV_Labels,&dg->dg_List,TAG_END); if (dg->dg_List && !IsListEmpty(dg->dg_List)) { GT_GetGadgetAttrs(dg->dg_Gadget,dg->dg_Window,NULL,GTLV_Top,&i,TAG_END); i += line; if (i < CountNodes(dg->dg_List)) { struct Node *ln; dm.dm_SourceEntry = i; for(ln = dg->dg_List->lh_Head;i;i--,ln = ln->ln_Succ); if (dg->dg_Flags & DGF_TREEVIEW && TREENODE(ln)->tn_Flags & TNF_STATIC) { mx = ~0L; // avoid a following drag return(NULL); } dg->dg_Object.od_Object = ln; if (dg->dg_ObjectFunc) dg->dg_ObjectFunc(dg->dg_Window,dg->dg_Gadget,&dg->dg_Object,dm.dm_SourceEntry); } } } else { if (dg->dg_ObjectFunc) dg->dg_ObjectFunc(dg->dg_Window,dg->dg_Gadget,&dg->dg_Object,0L); dm.dm_SourceEntry = dg->dg_SourceEntry; xpos = x-width/2; ypos = y-height/2; } if (!dg->dg_Object.od_Object) { mx = ~0L; // avoid a following drag return(NULL); } wordwidth = (width + 15) >> 4; depth = GetBitMapAttr(rp->BitMap,BMA_DEPTH); if (dg->dg_Object.od_Object && (gdo = AllocMem(sizeof(struct DragObj), MEMF_CLEAR | MEMF_PUBLIC))) { #ifdef LOCKLAYERS LockLayers(&scr->LayerInfo); UnlockLayer(dg->dg_Window->RPort->Layer); #endif gdo->do_Screen = scr; gdo->do_ScrRPort = rp; gdo->do_BitMap = AllocBitMap(width,height,depth,BMF_CLEAR | BMF_MINPLANES,!(GetBitMapAttr( rp->BitMap, BMA_FLAGS ) & BMF_INTERLEAVED) ? rp->BitMap : NULL); gdo->do_SaveBack = AllocBitMap(width,height,depth,BMF_CLEAR | BMF_MINPLANES,rp->BitMap); gdo->do_RefreshMap = AllocBitMap(width*2,height*2,depth,BMF_CLEAR | BMF_MINPLANES,rp->BitMap); if (GetBitMapAttr(gdo->do_BitMap,BMA_FLAGS) & BMF_STANDARD) i = MEMF_CHIP | MEMF_PUBLIC; else i = 0; gdo->do_FullShadow = AllocMem(2*wordwidth*height,i | MEMF_CLEAR); gdo->do_HalfShadow = AllocMem(2*wordwidth*height,i); if (gdo->do_BitMap && gdo->do_SaveBack && gdo->do_RefreshMap && gdo->do_FullShadow && gdo->do_HalfShadow) { InitRastPort(&gdo->do_RPort); gdo->do_RPort.BitMap = gdo->do_BitMap; InitRastPort(&gdo->do_RefreshRPort); gdo->do_RefreshRPort.BitMap = gdo->do_RefreshMap; gdo->do_DragGadget = dg; CopyMem(&dg->dg_Object,&dm.dm_Object,sizeof(struct ObjectDescription)); dm.dm_Window = dg->dg_Window; dm.dm_Gadget = dg->dg_Gadget; /*** create the drag&drop image ***/ if (dg->dg_RenderHook) { struct LVDrawMsg lvdm; SetFont(&gdo->do_RPort,scr->RastPort.Font); lvdm.lvdm_MethodID = LV_DRAW; lvdm.lvdm_RastPort = &gdo->do_RPort; lvdm.lvdm_DrawInfo = GetScreenDrawInfo(scr); lvdm.lvdm_Bounds.MinX = 0; lvdm.lvdm_Bounds.MinY = 0; lvdm.lvdm_Bounds.MaxX = width-1; lvdm.lvdm_Bounds.MaxY = height-1; lvdm.lvdm_State = LVR_SELECTED; CallHookPkt(dg->dg_RenderHook,dm.dm_Object.od_Object,&lvdm); FreeScreenDrawInfo(scr,lvdm.lvdm_DrawInfo); } else if (dg->dg_Image) DrawImage(&gdo->do_RPort,dg->dg_Image,0,0); else ClipBlit(dg->dg_Window->RPort,xpos,ypos,&gdo->do_RPort,0,0,width,height,0xc0); /*** initialize drag object structure ***/ gdo->do_X = -9999; gdo->do_Y = ypos+dg->dg_Window->TopEdge; gdo->do_PX = -9999; gdo->do_Width = width; gdo->do_Height = height; gdo->do_DeltaX = xpos-x+dg->dg_Window->LeftEdge; gdo->do_DeltaY = ypos-y+dg->dg_Window->TopEdge; gdo->do_Mask = gdo->do_FullShadow; /*** create masks (transparent and full imagery) ***/ if (CyberGfxBase && (GetBitMapAttr(gdo->do_BitMap,BMA_FLAGS) & BMF_STANDARD) == 0L) { struct BitMap tbm; ULONG col; InitBitMap(&tbm,1,width,height); tbm.Planes[0] = (UBYTE *)gdo->do_FullShadow; /* if (!GetCyberMapAttr(gdo->do_BitMap, CYBRMATTR_PIXELFMT)) */ if (GetBitMapAttr(gdo->do_BitMap, BMA_DEPTH) > 8L) { ULONG triplet[3]; GetRGB32(scr->ViewPort.ColorMap,0L,1L,triplet); col = (triplet[0] & 0xff0000) | (triplet[1] & 0xff00) | (triplet[2] & 0xff); } else col = 0; // ExtractColor(rp,&tbm,col,xpos,ypos,width,height); ExtractColor(&gdo->do_RPort,&tbm,col,0,0,width,height); BltBitMap(&tbm,0,0,&tbm,0,0,width,height,0x50,0xff,NULL); // invertieren der Maske } else { UWORD *p = gdo->do_FullShadow; for(ypos = 0;ypos < height;ypos++) { for(xpos = 0;xpos < wordwidth;xpos++,p++) { for(i = 0;i < depth;i++) *p |= *((UWORD *)gdo->do_BitMap->Planes[i]+ypos*(gdo->do_BitMap->BytesPerRow >> 1)+xpos); } } } { UWORD *p = gdo->do_HalfShadow; CopyMem(gdo->do_FullShadow,p,2*wordwidth*height); for(line = 0x5555,ypos = 0;ypos < height;ypos++) { line = ~line; for(xpos = 0;xpos < wordwidth;xpos++,p++) *p &= (UWORD)line; } } if (!boopsigad) FakeInputEvent(); UpdateDragObj(gdo,gdo->do_X,gdo->do_Y); /* show drag object */ return(gdo); }
/// IdentifyPointerColors() static void IdentifyPointerColors(Object *obj) { int i; ULONG colors[3*3]; LONG blackDiff[3]; LONG whiteDiff[3]; LONG blackIndex; LONG whiteIndex; ENTER(); // get the current screen's pointer colors (17 to 19) GetRGB32(_window(obj)->WScreen->ViewPort.ColorMap, 17, 3, colors); for(i=0; i < 3; i++) { LONG dr; LONG dg; LONG db; // normalize the colors to 8 bit per gun as GetRGB32() returns // 32bit left aligned values colors[i*3+0] >>= 24; colors[i*3+1] >>= 24; colors[i*3+2] >>= 24; // calculate the geometric difference to the color black (=0x00000000) dr = 0x00000000 - colors[i*3+0]; dg = 0x00000000 - colors[i*3+1]; db = 0x00000000 - colors[i*3+2]; blackDiff[i] = dr * dr + dg * dg + db * db; // calculate the geometric difference to the color white (=0x000000ff) dr = 0x000000ff - colors[i*3+0]; dg = 0x000000ff - colors[i*3+1]; db = 0x000000ff - colors[i*3+2]; whiteDiff[i] = dr * dr + dg * dg + db * db; } // the smallest difference defines the color which is closest to black or // equal to black if(blackDiff[0] > blackDiff[1]) { if(blackDiff[1] > blackDiff[2]) blackIndex = 19; else blackIndex = 18; } else if(blackDiff[0] > blackDiff[2]) blackIndex = 19; else blackIndex = 17; // the smallest difference defines the color which is closest to white or // equal to white if(whiteDiff[0] > whiteDiff[1]) { if(whiteDiff[1] > whiteDiff[2]) whiteIndex = 19; else whiteIndex = 18; } else if(whiteDiff[0] > whiteDiff[2]) whiteIndex = 19; else whiteIndex = 17; // Here we expect the user to have set up quite "different" colors. That // means the color closest to white will never be close to black and vice // versa. According to these differences we spread the required bitplanes. if(whiteIndex == 17) { if(blackIndex == 18) { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp0; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp1; } else // blackIndex == 19 { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp2; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp1; } } else if(whiteIndex == 18) { if(blackIndex == 17) { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp1; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp0; } else // blackIndex == 19 { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp1; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp2; } } else // whiteIndex == 19 { if(blackIndex == 17) { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp2; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp0; } else // blackIndex == 18 { selectPointerBitmap.Planes[0] = (PLANEPTR)selectPointer_bp0; selectPointerBitmap.Planes[1] = (PLANEPTR)selectPointer_bp2; } } LEAVE(); }
void main() { ULONG class,code; struct Gadget *gadget; struct IntuiMessage *message; struct DrawInfo *dri; BOOL running=TRUE; unless(Scr=LockPubScreen("Workbench")) LEAVE; unless(dri=GetScreenDrawInfo(Scr)) LEAVE; unless(SmartBitMapBase=OpenLibrary("images/smartbitmap.image",36L)) LEAVE; unless(ImClass=GetSmartBitMapClass()) LEAVE; GetRGB32(Scr->ViewPort.ColorMap,0,1,&pal[0].R); unless(Im=NewObject(ImClass,NULL, IA_Left,25, IA_Top,25, IA_Width,20, SMBM_Border,FALSE, SMBM_SelBorder,TRUE, SMBM_Screen,Scr, SMBM_BitMap,&TBCOLORWHEELBitMap, // SMBM_BitMap,&Size45UDBitMap, SMBM_Palette,pal, TAG_DONE)) LEAVE; unless(MainWnd=OpenWindowTags(NULL, WA_Left,0, WA_Top,0, WA_Width,600, WA_Height,200, WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_GADGETUP, WA_Flags,WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_ACTIVATE|WFLG_SIZEGADGET, WA_CustomScreen,Scr, TAG_DONE)) LEAVE; DrawImageState(MainWnd->RPort,(struct Image *)Im,0,0,IDS_NORMAL,dri); while(running) { Wait(1L<<MainWnd->UserPort->mp_SigBit); while(message=GT_GetIMsg(MainWnd->UserPort)) { class=message->Class; code=message->Code; gadget=(struct Gadget *)message->IAddress; GT_ReplyIMsg(message); switch(class) { case IDCMP_CLOSEWINDOW: running=FALSE; break; } } } end: if(MainWnd) { CloseWindow(MainWnd); } if(Im) DisposeObject(Im); if(SmartBitMapBase) CloseLibrary(SmartBitMapBase); if(dri) FreeScreenDrawInfo(Scr,dri); if(Scr) UnlockPubScreen(NULL,Scr); }