Handle Widget_shape( Handle self, Bool set, Handle mask) { if ( var-> stage > csFrozen) return nilHandle; if ( !set) { if ( apc_widget_get_shape( self, nilHandle)) { HV * profile = newHV(); Handle i = Object_create( "Prima::Image", profile); sv_free(( SV *) profile); apc_widget_get_shape( self, i); --SvREFCNT( SvRV((( PAnyObject) i)-> mate)); return i; } else return nilHandle; } if ( mask && !kind_of( mask, CImage)) { warn("RTC008A: Illegal object reference passed to Widget::shape"); return nilHandle; } if ( mask && (( PImage( mask)-> type & imBPP) != imbpp1)) { Handle i = CImage( mask)-> dup( mask); ++SvREFCNT( SvRV( PImage( i)-> mate)); CImage( i)-> set_conversion( i, ictNone); CImage( i)-> set_type( i, imBW); apc_widget_set_shape( self, i); --SvREFCNT( SvRV( PImage( i)-> mate)); Object_destroy( i); } else apc_widget_set_shape( self, mask); return nilHandle; }
static SV * image_server( Handle self, PClipboardFormatReg instance, int function, SV * data) { ClipboardDataRec c; switch( function) { case cefInit: return ( SV *) cfBitmap; case cefFetch: { HV * profile = newHV(); c. image = Object_create( "Prima::Image", profile); sv_free(( SV *) profile); if ( apc_clipboard_get_data( self, cfBitmap, &c)) { --SvREFCNT( SvRV( PImage(c. image)-> mate)); return newSVsv( PImage(c. image)-> mate); } Object_destroy( c. image); } break; case cefStore: c. image = gimme_the_mate( data); if ( !kind_of( c. image, CImage)) { warn("Not an image passed to clipboard"); return nilSV; } instance-> success = apc_clipboard_set_data( self, cfBitmap, &c); instance-> written = true; break; } return nilSV; }
Bool apc_image_begin_paint( Handle self) { apcErrClear; objCheck false; if ( !( sys ps = CreateCompatibleDC( 0))) apiErrRet; if ( sys bm == nil) { Handle deja = image_enscreen( self, self); if ( !image_set_cache( deja, self)) { DeleteDC( sys ps); sys ps = nil; return false; } if ( deja != self) Object_destroy( deja); } sys stockBM = SelectObject( sys ps, sys bm); if ( !sys pal) sys pal = image_make_bitmap_palette( self); hwnd_enter_paint( self); if (( PImage( self)-> type & imBPP) == imbpp1) sys bpp = 1; if ( sys pal) { SelectPalette( sys ps, sys pal, 0); RealizePalette( sys ps); } return true; }
HBITMAP image_make_bitmap_handle( Handle img, HPALETTE pal) { HBITMAP bm; XBITMAPINFO xbi; BITMAPINFO * bi = image_get_binfo( img, &xbi); HPALETTE old = nil, xpal = pal; HWND foc = GetFocus(); HDC dc = GetDC( foc); if ( !dc) apiErr; if ( bi-> bmiHeader. biClrUsed > 0) bi-> bmiHeader. biClrUsed = bi-> bmiHeader. biClrImportant = PImage(img)-> palSize; if ( xpal == nil) xpal = image_make_bitmap_palette( img); if ( xpal) { old = SelectPalette( dc, xpal, 1); RealizePalette( dc); } if ((( PImage) img)-> type != imBW) bm = CreateDIBitmap( dc, &bi-> bmiHeader, CBM_INIT, (( PImage) img)-> data, bi, DIB_RGB_COLORS); else { bm = CreateBitmap( bi-> bmiHeader. biWidth, bi-> bmiHeader. biHeight, 1, 1, NULL); SetDIBits( dc, bm, 0, bi-> bmiHeader. biHeight, (( PImage) img)-> data, bi, DIB_RGB_COLORS); } if ( !bm) { apiErr; if ( old) { SelectPalette( dc, old, 1); RealizePalette( dc); } if ( xpal != pal) DeleteObject( xpal); ReleaseDC( foc, dc); return nil; } if ( old) { SelectPalette( dc, old, 1); RealizePalette( dc); } if ( xpal != pal) DeleteObject( xpal); ReleaseDC( foc, dc); return bm; }
static Bool rgn_image(Handle self, Handle image) { REGION = prima_region_create(image); if ( !REGION ) REGION = XCreateRegion(); else HEIGHT = PImage(image)->h; return true; }
Bool apc_image_begin_paint_info( Handle self) { apcErrClear; objCheck false; if ( !( sys ps = CreateCompatibleDC( 0))) apiErrRet; if ( !sys pal) sys pal = image_make_bitmap_palette( self); if ( sys pal) SelectPalette( sys ps, sys pal, 0); hwnd_enter_paint( self); if (( PImage( self)-> type & imBPP) == imbpp1) sys bpp = 1; return true; }
PImage createImage(int width, int height, int type) { return PImage(width, height, type); }
Region prima_region_create( Handle mask) { unsigned long w, h, x, y, size = 256, count = 0; Region rgn = None; Byte * idata; XRectangle * current, * rdata; Bool set = 0; if ( !mask) return None; w = PImage( mask)-> w; h = PImage( mask)-> h; /* XUnionRegion is actually SLOWER than the image scan - - uncomment if this is wrong if ( X( mask)-> cached_region) { rgn = XCreateRegion(); XUnionRegion( rgn, X( mask)-> cached_region, rgn); return rgn; } */ idata = PImage( mask)-> data + PImage( mask)-> dataSize - PImage( mask)-> lineSize; rdata = ( XRectangle*) malloc( size * sizeof( XRectangle)); if ( !rdata) { warn("Not enough memory"); return None; } count = 0; current = rdata; current--; for ( y = 0; y < h; y++) { for ( x = 0; x < w; x++) { if ( idata[ x >> 3] == 0) { x += 7; continue; } if ( idata[ x >> 3] & ( 1 << ( 7 - ( x & 7)))) { if ( set && current-> y == y && current-> x + current-> width == x) current-> width++; else { set = 1; if ( count >= size) { void * xrdata = realloc( rdata, ( size *= 3) * sizeof( XRectangle)); if ( !xrdata) { warn("Not enough memory"); free( rdata); return None; } rdata = xrdata; current = rdata; current += count - 1; } count++; current++; current-> x = x; current-> y = y; current-> width = 1; current-> height = 1; } } } idata -= PImage( mask)-> lineSize; } if ( set) { rgn = XCreateRegion(); for ( x = 0, current = rdata; x < count; x++, current++) XUnionRectWithRegion( current, rgn, rgn); /* X( mask)-> cached_region = XCreateRegion(); XUnionRegion( X( mask)-> cached_region, rgn, X( mask)-> cached_region); */ } free( rdata); return rgn; }