comparison os2/dw.c @ 1837:d7e13f446c41

Initial attempt at code to generate icon masks on OS/2 from the background color when creating icons from file. This doesn't quite work, I clearly don't understand the format of the masks... the documentation says there are AND and XOR masks in the double sized mask bitmap.... not sure which goes where and how they are used... but this is a step in the needed direction.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 10 Nov 2012 16:33:02 +0000
parents 692c3a18a112
children 4790589f52a9
comparison
equal deleted inserted replaced
1836:692c3a18a112 1837:d7e13f446c41
7195 { 7195 {
7196 /* Using CLR_PALEGRAY as a default alpha background... we can 7196 /* Using CLR_PALEGRAY as a default alpha background... we can
7197 * change this to use WinQuerySysColor() later, but pale gray is 7197 * change this to use WinQuerySysColor() later, but pale gray is
7198 * already hardcoded elsewhere so just continue using it here. 7198 * already hardcoded elsewhere so just continue using it here.
7199 */ 7199 */
7200 char options[101] = "back_rgb=52020_52020_52020"; 7200 char options[101] = "back_rgb=52224_52224_52224";
7201 7201
7202 /* Ask the control if it has another color set */ 7202 /* Ask the control if it has another color set */
7203 if(backrgb == DW_CLR_DEFAULT && handle) 7203 if(backrgb == DW_CLR_DEFAULT && handle)
7204 { 7204 {
7205 RGB rgb = {0}; 7205 RGB rgb = {0};
7206 7206
7207 if(WinQueryPresParam(handle, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, NULL, sizeof(rgb), &rgb, QPF_NOINHERIT | QPF_PURERGBCOLOR | QPF_ID2COLORINDEX)) 7207 if(WinQueryPresParam(handle, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, NULL, sizeof(rgb), &rgb, QPF_NOINHERIT | QPF_PURERGBCOLOR | QPF_ID2COLORINDEX))
7208 sprintf(options, "back_rgb=%d_%d_%d", rgb.bRed * 255, rgb.bGreen * 255, rgb.bBlue * 255); 7208 sprintf(options, "back_rgb=%d_%d_%d", rgb.bRed * 256, rgb.bGreen * 256, rgb.bBlue * 256);
7209 } 7209 }
7210 else if(backrgb & DW_RGB_COLOR) 7210 else if(backrgb & DW_RGB_COLOR)
7211 { 7211 {
7212 sprintf(options, "back_rgb=%d_%d_%d", (int)DW_RED_VALUE(backrgb) * 255, (int)DW_GREEN_VALUE(backrgb) * 255, (int)DW_BLUE_VALUE(backrgb) * 255); 7212 sprintf(options, "back_rgb=%d_%d_%d", (int)DW_RED_VALUE(backrgb) * 256, (int)DW_GREEN_VALUE(backrgb) * 256, (int)DW_BLUE_VALUE(backrgb) * 256);
7213 } 7213 }
7214 7214
7215 /* Read the file header */ 7215 /* Read the file header */
7216 if((err = _gbm_read_header(file, fd, z, &gbm, options)) == 0) 7216 if((err = _gbm_read_header(file, fd, z, &gbm, options)) == 0)
7217 break; 7217 break;
7270 if(_To24Bit(&gbm, gbmrgb, &BitmapFileBegin)) 7270 if(_To24Bit(&gbm, gbmrgb, &BitmapFileBegin))
7271 *depth = 24; 7271 *depth = 24;
7272 else 7272 else
7273 { 7273 {
7274 #ifdef DEBUG 7274 #ifdef DEBUG
7275 dw_debug("GBM: Failed 24bpp conversion\n", z, file, err, _gbm_err(err)); 7275 dw_debug("GBM: Failed 24bpp conversion \"%s\"\n", file);
7276 #endif 7276 #endif
7277 DosFreeMem(BitmapFileBegin); 7277 DosFreeMem(BitmapFileBegin);
7278 return 0; 7278 return 0;
7279 } 7279 }
7280 7280
9466 HICN API dw_icon_load(unsigned long module, unsigned long id) 9466 HICN API dw_icon_load(unsigned long module, unsigned long id)
9467 { 9467 {
9468 return WinLoadPointer(HWND_DESKTOP,module,id); 9468 return WinLoadPointer(HWND_DESKTOP,module,id);
9469 } 9469 }
9470 9470
9471 #if 0
9472 /* Internal function to create pointer/icon masks */
9473 void _create_mask(HPIXMAP src, HPIXMAP mask, unsigned long backrgb)
9474 {
9475 LONG maskcolor = (DW_RED_VALUE(backrgb) << 16) | (DW_GREEN_VALUE(backrgb) << 8) | DW_BLUE_VALUE(backrgb);
9476 int x, y;
9477
9478 for(x=0; x < src->width; x++)
9479 {
9480 for(y=0; y < src->height; y++)
9481 {
9482 POINTL pt = {x, y};
9483 LONG color = GpiQueryPel(src->hps, &pt);
9484
9485 dw_debug("Mask color %x (%dx%d) %x\n", (int)maskcolor, x, y, (int)color);
9486 if(color == maskcolor)
9487 {
9488 GpiSetColor(mask->hps, CLR_WHITE);
9489 GpiSetPel(mask->hps, &pt);
9490 pt.y = y + src->height;
9491 GpiSetPel(mask->hps, &pt);
9492 }
9493 }
9494 }
9495 }
9496 #endif
9497
9471 /* Internal function to create an icon from an existing pixmap */ 9498 /* Internal function to create an icon from an existing pixmap */
9472 HICN _create_icon(HPIXMAP src) 9499 HICN _create_icon(HPIXMAP src, unsigned long backrgb)
9473 { 9500 {
9474 HPIXMAP pntr = dw_pixmap_new(hwndApp, WinQuerySysValue(HWND_DESKTOP, SV_CXICON), WinQuerySysValue(HWND_DESKTOP, SV_CYICON), src->depth); 9501 HPIXMAP pntr = dw_pixmap_new(hwndApp, WinQuerySysValue(HWND_DESKTOP, SV_CXICON), WinQuerySysValue(HWND_DESKTOP, SV_CYICON), src->depth);
9475 HPIXMAP mask = dw_pixmap_new(hwndApp, pntr->width, pntr->height*2, 1); 9502 HPIXMAP mask = dw_pixmap_new(hwndApp, pntr->width, pntr->height*2, 1);
9476 HPIXMAP minipntr = dw_pixmap_new(hwndApp, pntr->width/2, pntr->height/2, src->depth); 9503 HPIXMAP minipntr = dw_pixmap_new(hwndApp, pntr->width/2, pntr->height/2, src->depth);
9477 HPIXMAP minimask = dw_pixmap_new(hwndApp, minipntr->width, minipntr->height*2, 1); 9504 HPIXMAP minimask = dw_pixmap_new(hwndApp, minipntr->width, minipntr->height*2, 1);
9484 9511
9485 /* Create the masks, all in black */ 9512 /* Create the masks, all in black */
9486 dw_color_foreground_set(DW_CLR_BLACK); 9513 dw_color_foreground_set(DW_CLR_BLACK);
9487 dw_draw_rect(0, mask, DW_DRAW_FILL, 0, 0, mask->width, mask->height); 9514 dw_draw_rect(0, mask, DW_DRAW_FILL, 0, 0, mask->width, mask->height);
9488 dw_draw_rect(0, minimask, DW_DRAW_FILL, 0, 0, minimask->width, minimask->height); 9515 dw_draw_rect(0, minimask, DW_DRAW_FILL, 0, 0, minimask->width, minimask->height);
9516 #if 0
9517 /* If we have a background color... create masks */
9518 if(backrgb & DW_RGB_COLOR)
9519 {
9520 _create_mask(pntr, mask, backrgb);
9521 _create_mask(minipntr, minimask, backrgb);
9522 }
9523 #endif
9489 _foreground = oldcol; 9524 _foreground = oldcol;
9490 9525
9491 /* Assemble the Pointer Info structure */ 9526 /* Assemble the Pointer Info structure */
9492 pi.hbmPointer = mask->hbm; 9527 pi.hbmPointer = mask->hbm;
9493 pi.hbmColor = pntr->hbm; 9528 pi.hbmColor = pntr->hbm;
9494 pi.hbmMiniPointer = minimask->hbm; 9529 pi.hbmMiniPointer = minimask->hbm;
9495 pi.hbmMiniColor = minipntr->hbm; 9530 pi.hbmMiniColor = minipntr->hbm;
9496 9531
9497 /* Destroy the pixmaps but not the bitmaps */ 9532 /* Destroy the temporary pixmaps */
9498 mask->hbm = pntr->hbm = minimask->hbm = minipntr->hbm = 0; 9533 mask->hbm = pntr->hbm = minimask->hbm = minipntr->hbm = 0;
9499 dw_pixmap_destroy(mask); 9534 dw_pixmap_destroy(mask);
9500 dw_pixmap_destroy(pntr); 9535 dw_pixmap_destroy(pntr);
9501 dw_pixmap_destroy(minimask); 9536 dw_pixmap_destroy(minimask);
9502 dw_pixmap_destroy(minipntr); 9537 dw_pixmap_destroy(minipntr);
9515 HICN API dw_icon_load_from_file(char *filename) 9550 HICN API dw_icon_load_from_file(char *filename)
9516 { 9551 {
9517 char *file = alloca(strlen(filename) + 6); 9552 char *file = alloca(strlen(filename) + 6);
9518 HPIXMAP src = alloca(sizeof(struct _hpixmap)); 9553 HPIXMAP src = alloca(sizeof(struct _hpixmap));
9519 HICN icon = 0; 9554 HICN icon = 0;
9555 unsigned long defcol = DW_RGB(204, 204, 204);
9520 9556
9521 if(!file || !src) 9557 if(!file || !src)
9522 return 0; 9558 return 0;
9523 9559
9524 strcpy(file, filename); 9560 strcpy(file, filename);
9537 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) 9573 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++)
9538 { 9574 {
9539 strcpy(file, filename); 9575 strcpy(file, filename);
9540 strcat(file, image_exts[z]); 9576 strcat(file, image_exts[z]);
9541 if(access(file, 04) == 0 && 9577 if(access(file, 04) == 0 &&
9542 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, DW_CLR_DEFAULT)) 9578 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, defcol))
9543 { 9579 {
9544 icon = _create_icon(src); 9580 icon = _create_icon(src, defcol);
9545 break; 9581 break;
9546 } 9582 }
9547 } 9583 }
9548 } 9584 }
9549 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, DW_CLR_DEFAULT)) 9585 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, defcol))
9550 icon = _create_icon(src); 9586 icon = _create_icon(src, defcol);
9551 /* Free temporary resources if in use */ 9587 /* Free temporary resources if in use */
9552 if(icon) 9588 if(icon)
9553 { 9589 {
9554 GpiSetBitmap(src->hps, NULLHANDLE); 9590 GpiSetBitmap(src->hps, NULLHANDLE);
9555 GpiDeleteBitmap(src->hbm); 9591 GpiDeleteBitmap(src->hbm);