PRIVATE PicHandle pict_from_gworld (GWorldPtr gp, int *lenp) { PicHandle retval; if (!gp) retval = NULL; else { Rect pict_frame; PixMapHandle pm; pm = GetGWorldPixMap (gp); pict_frame = PIXMAP_BOUNDS (pm); retval = OpenPicture (&pict_frame); if (retval) { ClipRect (&pict_frame); HLock ((Handle) pm); CopyBits ((BitMap *) STARH (pm), PORT_BITS_FOR_COPY (thePort), &pict_frame, &pict_frame, srcCopy, NULL); HUnlock ((Handle) pm); ClosePicture (); } } return retval; }
void _draw_screen_shape_at_x_y( shape_descriptor shape, short x, short y) { PixMapHandle pixmap; RGBColor old_fore, old_back; Rect destination; /* Avoid unwanted coloring.. */ GetForeColor(&old_fore); GetBackColor(&old_back); RGBForeColor(&rgb_black); RGBBackColor(&rgb_white); /* Draw the panels... */ pixmap= get_shape_pixmap(shape, FALSE); /* Offset to zero base, and add in x, y */ destination= (*pixmap)->bounds; OffsetRect(&destination, x-destination.left, y-destination.top); /* Slam the puppy... */ assert(destination_graphics_port); CopyBits((BitMapPtr) *pixmap, &destination_graphics_port->portBits, //&screen_window->portBits, &(*pixmap)->bounds, &destination, srcCopy, (RgnHandle) nil); /* Restore the colors.. */ RGBForeColor(&old_fore); RGBBackColor(&old_back); }
int Ticker::quasi_pulse(int column, int speed) { //printf("quasi_pulse(%d)\ncurrent_char = %c\n", column, current_char); // column is the vertical column in the current glyph that we are drawing // speed is the number of columns to be drawn // we return column when we're done // Scroll the display 5*speed pixels to the left BRect src(Bounds()), dst; src.top += 1.0; // top line doesn't need to be scrolled dst = src; src.left += 5.0*speed; dst.right -= 5.0*speed; CopyBits(src, dst); // Draw 'speed' columns of dots on the far right of the ticker for(int j=4-(speed-1);j<5;j++) // loop for the number of columns that need to be drawn { for(int k=0;k<6;k++) // row draw_dot(19,j,k,(glyphlist[transform(current_char)-32].bits & ((0x80000000)>>((k*5)+column)) )); if(column == 4) // end of the current char. grab a fresh one. { column = 0; // reset column current_char = parent->next_char(); // parent is the BView that owns the bitmap that we draw into } else if(j < 5) // if we still have columns left to draw, iterate column column++; } Sync(); return column; }
void drawPixelImageData() { int row, col; Rect rect; unsigned char value; char *image; int index = 0; Str255 string; RGBColor color = { 32000, 32000, 32000 }; //Byte mode; Rect tempRect1; ForeColor( blackColor ); SetRect( &rect, 0, 0, 20, 20 ); /* For this example, let's just use only the upper left corner of the image. */ // Draw the offscreen image to the screen to see what it looks like. //CopyBits( (BitMap *)*gPixmap, &gWindow->portBits, &rect, // &gWindow->portRect, srcCopy, 0 ); //(**gPixmap).rowBytes ^= 0x8000; CopyBits( (BitMap *)*gPixmap, GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &rect, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0 ); //(**gPixmap).rowBytes ^= 0x8000; RGBForeColor( &color ); // Again, set the pointer to the beginning of the pixel image. image = GetPixBaseAddr( gPixmap ); /***************************************************************/ /* Finally let's display the pixel values on top of the image. */ /***************************************************************/ /* Loop through the first 20 rows of the pixel image. */ for (row = 0; row < rect.bottom; row++) { // Loop through the first 20 columns of the pixel image. for (index = 0, col = 0; col < rect.right; col++) { // Get the value at this index into the pixel image. value = (unsigned char)*(image + index); MoveTo( col * 30, row * 20 ); LineTo( col * 30, (row + 1) * 20 ); LineTo( (col + 1) * 30, (row + 1) * 20 ); MoveTo( (col * 30) + 6, (row * 20) + 14 ); NumToString( (long)value, string ); DrawString( string ); index++; } // Increment the pointer to the next row of the pixel image. image += ((**gPixmap).rowBytes & 0x7fff); } }
//////////////////////////////////////// // 输出压缩码 // code - 要输出的数 // bits - 要输出的位数(对isGamma=TRUE时无效) // isGamma - 是否输出为γ编码 void _OutCode(BYTE* dest, DWORD code, int bits, BOOL isGamma) { if ( isGamma ) { BYTE* pb; DWORD out; // 计算输出位数 int GammaCode = (int)code - 1; int q = LowerLog2(GammaCode); if (q > 0) { out = 0xffff; pb = (BYTE*)&out; // 输出q个1 CopyBits(dest + CurByte, CurBit, pb, 0, q); MovePos(&CurByte, &CurBit, q); } // 输出一个0 out = 0; pb = (BYTE*)&out; CopyBits(dest + CurByte, CurBit, pb + 3, 7, 1); MovePos(&CurByte, &CurBit, 1); if (q > 0) { // 输出余数, q位 int sh = 1; sh <<= q; out = GammaCode - sh; pb = (BYTE*)&out; InvertDWord(&out); CopyBits(dest + CurByte, CurBit, pb + (32 - q) / 8, (32 - q) % 8, q); MovePos(&CurByte, &CurBit, q); } } else { DWORD dw = (DWORD)code; BYTE* pb = (BYTE*)&dw; InvertDWord(&dw); CopyBits(dest + CurByte, CurBit, pb + (32 - bits) / 8, (32 - bits) % 8, bits); MovePos(&CurByte, &CurBit, bits); } }
void doUpdateWindow(EventRecord *eventStrucPtr) { IMAGE *img; WindowRef windowRef; Rect srcRect, destRect, fillRect; PixMapHandle srcPixmapHdl, destPixmapHdl; RGBColor grayColour = { 0xC000,0xC000,0xC000 }; SInt32 hScroll, vScroll; windowRef = (WindowRef) eventStrucPtr->message; img = (IMAGE*)GetWRefCon(windowRef); srcPixmapHdl = img->pixmapHdl; destPixmapHdl = GetPortPixMap(GetWindowPort(windowRef)); hScroll = GetControl32BitValue(img->scrollbarHorizRef); vScroll = GetControl32BitValue(img->scrollbarVertRef); if (srcPixmapHdl) { PixMap *pixmap = *srcPixmapHdl; PixPatHandle hdlPixPat = NewPixPat(); MakeRGBPat(hdlPixPat, &grayColour); GetWindowPortBounds(windowRef,&destRect); destRect.right -= kScrollBarWidth; destRect.bottom -= kScrollBarWidth; if (destRect.right > pixmap->bounds.right) { fillRect.top = destRect.top; fillRect.bottom = destRect.bottom; fillRect.left = pixmap->bounds.right; fillRect.right = destRect.right; FillCRect(&fillRect, hdlPixPat); destRect.right = pixmap->bounds.right; } if (destRect.bottom > pixmap->bounds.bottom) { fillRect.top = pixmap->bounds.bottom; fillRect.bottom = destRect.bottom; fillRect.left = destRect.left; fillRect.right = destRect.right; FillCRect(&fillRect, hdlPixPat); destRect.bottom = pixmap->bounds.bottom; } DisposePixPat(hdlPixPat); srcRect = destRect; srcRect.left += hScroll; srcRect.right += hScroll; srcRect.top += vScroll; srcRect.bottom += vScroll; CopyBits((BitMap*)*srcPixmapHdl, (BitMap*)*destPixmapHdl, &srcRect, &destRect, srcCopy, NULL); } DrawGrowIcon(windowRef); }
static boolean plotsmallicon (Rect r, short iconlist, short iconnum, boolean flinvert) { hdlsmalliconbits hbits; short mode; BitMap bmap; GrafPtr w; GetPort (&w); hbits = (hdlsmalliconbits) GetResource ('SICN', iconlist); if (hbits == nil) /*failed to load the resource*/ return (false); r.right = r.left + widthsmallicon; /*we only pay attention to the top, left fields of rectangle*/ r.bottom = r.top + heightsmallicon; bmap.baseAddr = (Ptr) &(*hbits) [iconnum]; bmap.rowBytes = 2; bmap.bounds.top = bmap.bounds.left = 0; bmap.bounds.bottom = r.bottom - r.top; bmap.bounds.right = r.right - r.left; if (flinvert) mode = notSrcCopy; else mode = srcOr; //Code change by Timothy Paustian Saturday, May 20, 2000 10:06:20 PM //Changed to Opaque call for Carbon //I have not tested this yet. #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 CopyBits(&bmap, GetPortBitMapForCopyBits(w), &bmap.bounds, &r, mode, nil); #else CopyBits (&bmap, &(*w).portBits, &bmap.bounds, &r, mode, nil); #endif return (true); } /*plotsmallicon*/
void _HYPlatformGraphicPane::_CopyToClipboard (void) { _HYGraphicPane* parent = (_HYGraphicPane*)this; #ifdef TARGET_API_MAC_CARBON ClearCurrentScrap(); #else ZeroScrap(); #endif Rect bRect; bRect.left = bRect.top = 0; bRect.right = parent->w; bRect.bottom = parent->h; PicHandle pic = OpenPicture (&bRect); GrafPtr topPort; GetPort (&topPort); LockPixels (GetGWorldPixMap(thePane)); #ifdef OPAQUE_TOOLBOX_STRUCTS CopyBits (GetPortBitMapForCopyBits(thePane),GetPortBitMapForCopyBits(topPort), &bRect,&bRect,srcCopy,(RgnHandle)nil); #else CopyBits ((BitMap*)*GetGWorldPixMap(thePane), (BitMap*)&(topPort->portBits),&bRect,&bRect, srcCopy,(RgnHandle)nil); #endif UnlockPixels (GetGWorldPixMap(thePane)); ClosePicture (); HLock ((Handle)pic); #ifdef TARGET_API_MAC_CARBON ScrapRef theScrapRef; GetCurrentScrap(&theScrapRef); PutScrapFlavor(theScrapRef, 'PICT', kScrapFlavorMaskNone,GetHandleSize((Handle)pic),*pic); #else PutScrap (GetHandleSize((Handle)pic),'PICT',*pic); #endif KillPicture (pic); }
void createImage() { GDHandle mainDevice; mainDevice = GetMainDevice(); /* Store the screen's pixmap image in the offscreen pixmap. */ CopyBits( (BitMap *)*(**mainDevice).gdPMap, (BitMap *)(&gPixMap), &(**(**mainDevice).gdPMap).bounds, &gPixMap.bounds, srcCopy, 0l ); }
PicHandle PixMapToPict(PixMapHandle inMap,Rect *sourceRect,Rect *destRect) { PicHandle recordPic=0L; recordPic=OpenPicture(destRect); if (!recordPic) return 0L; CopyBits((BitMap *)*inMap,(BitMap *)*inMap,sourceRect,destRect,srcCopy,0L); ClosePicture(); return recordPic; }
// MessageReceived void TestView::MessageReceived(BMessage* message) { if (message->what == MSG_COPY_BITS) { printf("MSG_COPY_BITS\n"); fSourceRect.PrintToStream(); fDestRect.PrintToStream(); CopyBits(fSourceRect, fDestRect); fCopyBitsJustCalled = true; } else BView::MessageReceived(message); }
void drawImage(WindowPtr theWindow) { Rect tempRect1; /* Copy the offscreen image back onto the window. */ //CopyBits( (BitMap *)&gPixMap, &gWindow->portBits, &gPixMap.bounds, // &gWindow->portRect, srcCopy, 0l); CopyBits( (BitMap *)&gPixMap, GetPortBitMapForCopyBits(GetWindowPort(theWindow)), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ShowWindow( gWindow ); }
void slide_stamps(void) { int i; bitmap *b = thePort->portBMap; if (stamp_err) { stamp_err = 0; return; } HideCursor(); for (i = 2; i > 0; i--) { CopyBits(b, b, &stampingR[i - 1], &stampingR[i], &stampingR[i], zREPz); PenColor(WHITE); FrameRect(&stampingR[i]); } CopyBits(b, b, &stampR, &stampingR[0], &stampingR[0], zREPz); FrameRect(&stampingR[0]); ShowCursor(); }
void _draw_screen_shape_centered( shape_descriptor shape, screen_rectangle *rectangle, short flags) { PixMapHandle pixmap; RGBColor old_fore, old_back; Rect destination, source; short left_offset, top_offset; return; /* Avoid unwanted coloring.. */ GetForeColor(&old_fore); GetBackColor(&old_back); RGBForeColor(&rgb_black); RGBBackColor(&rgb_white); /* Draw the panels... */ pixmap= get_shape_pixmap(shape, FALSE); /* Offset to zero base, and add in x, y */ destination= source= (*pixmap)->bounds; if(flags & _center_horizontal) { left_offset= (RECTANGLE_WIDTH(rectangle)-RECTANGLE_WIDTH(&source))/2; } else { left_offset= 0; } if(flags & _center_vertical) { top_offset= (RECTANGLE_HEIGHT(rectangle)-RECTANGLE_HEIGHT(&source))/2; } else if (flags & _bottom_justified) { top_offset= RECTANGLE_HEIGHT(rectangle)-RECTANGLE_HEIGHT(&destination); } else { top_offset= 0; } OffsetRect(&destination, rectangle->left+left_offset, rectangle->top+top_offset); /* Slam the puppy... */ assert(destination_graphics_port); CopyBits((BitMapPtr) *pixmap, &destination_graphics_port->portBits, // &screen_window->portBits, &source, &destination, srcCopy, (RgnHandle) nil); /* Restore the colors.. */ RGBForeColor(&old_fore); RGBBackColor(&old_back); }
void Trimmer::CopyFixedSubframe(BitIStream& bis, BitOStream& bos, FLACFrameHeader * fh, FLACMetaStreamInfo * msi, FLACSubframeHeader * sfh) { //-------------------------------------------------- // size_t size // if (GetWarmUpSamplesBitSize(fh, msi, sfh) % BITSINBYTE != 0) cerr << "GetWarmUpSamplesBitSize(fh, msi) % BITSINBYTE != 0" << endl; // CopyBytes(bis, bos, GetWarmUpSamplesBitSize(fh, msi, sfh) / BITSINBYTE); //-------------------------------------------------- size_t bitSize = GetWarmUpSamplesBitSize(fh, msi, sfh); CopyBits(bis, bos, bitSize); /*if (bitSize % BITSINBYTE != 0) CopyBits(bis, bos, bitSize); else CopyBytes(bis, bos, bitSize / BITSINBYTE);*/ CopyResidual(bis, bos, fh, msi, sfh); }
/* If source==NULL, source= the shapes bounding rectangle */ void _draw_screen_shape( shape_descriptor shape_id, screen_rectangle *destination, screen_rectangle *source) { PixMapHandle pixmap; RGBColor old_fore, old_back; Rect actual_source; /* Avoid unwanted coloring.. */ GetForeColor(&old_fore); GetBackColor(&old_back); RGBForeColor(&rgb_black); RGBBackColor(&rgb_white); /* Draw the panels... */ pixmap= get_shape_pixmap(shape_id, FALSE); if(!source) { actual_source= (*pixmap)->bounds; #ifdef DEBUG { short dest_width, source_width; short dest_height, source_height; dest_width= destination->right-destination->left; source_width= (*pixmap)->bounds.right-(*pixmap)->bounds.left; dest_height= destination->bottom-destination->top; source_height= (*pixmap)->bounds.bottom-(*pixmap)->bounds.top; if(source_height != dest_height || source_width != dest_width) { dprintf("Changing size of %d Original: %d %d New: %d %d", shape_id, source_width, source_height, dest_width, dest_height); } } #endif } else { actual_source= *((Rect *) source); } assert(destination_graphics_port); CopyBits((BitMapPtr) *pixmap, &destination_graphics_port->portBits, &actual_source, (Rect *) destination, srcCopy, (RgnHandle) nil); /* Restore the colors.. */ RGBForeColor(&old_fore); RGBBackColor(&old_back); }
void pxBuffer::blit(pxSurfaceNative s, int dstLeft, int dstTop, int dstWidth, int dstHeight, int srcLeft, int srcTop) { Rect pr; MacSetRect(&pr, 0, 0, width(), height()); GWorldPtr gworld; NewGWorldFromPtr (&gworld, 32, &pr, NULL, NULL, 0, (char*)base(), 4*width()); Rect dr, sr; MacSetRect(&dr, dstLeft, dstTop, dstLeft + dstWidth, dstTop + dstHeight); MacSetRect(&sr, srcLeft, srcTop, srcLeft + dstWidth, srcTop + dstHeight); CopyBits((BitMapPtr)*GetGWorldPixMap(gworld),(BitMapPtr)*GetGWorldPixMap(s),&sr,&dr,srcCopy,NULL); DisposeGWorld(gworld); }
void Trimmer::CopyLPCSubframe(BitIStream& bis, BitOStream& bos, FLACFrameHeader * fh, FLACMetaStreamInfo * msi, FLACSubframeHeader * sfh) { uint8_t qlp = 0; // quantized linear predictor uint8_t qlpCoeffShift = 0; uint16_t unencQLPCoeffsBitSize = 0; if (GetWarmUpSamplesBitSize(fh, msi, sfh) % BITSINBYTE != 0) cerr << "GetWarmUpSamplesBitSize(fh, msi) % BITSINBYTE != 0" << endl; CopyBytes(bis, bos, GetWarmUpSamplesBitSize(fh, msi, sfh) / BITSINBYTE); bis.ReadInteger(&qlp, 4); bos.WriteInteger(qlp, 4); bis.ReadInteger(&qlpCoeffShift, 5); bos.WriteInteger(qlpCoeffShift, 5); unencQLPCoeffsBitSize = (qlp + 1) * GetPredictorOrder(sfh); if (unencQLPCoeffsBitSize != 0) CopyBits(bis, bos, unencQLPCoeffsBitSize); CopyResidual(bis, bos, fh, msi, sfh); }
void drawSourceImage() { Rect rect; Rect outlineRect; Rect tempRect1; GetPortBounds(gGWorld, &tempRect1); SetRect( &rect, 20, 37, 20 + tempRect1.right, 37 + tempRect1.bottom); outlineRect = rect; InsetRect( &outlineRect, -5, -5 ); drawDeepBox( &outlineRect ); ForeColor( blackColor ); BackColor( whiteColor ); CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), &rect, srcCopy, nil ); }
BitMapPtr TkMacMakeStippleMap( Drawable drawable, /* Window to apply stipple. */ Drawable stipple) /* The stipple pattern. */ { MacDrawable *destDraw = (MacDrawable *) drawable; GWorldPtr destPort; BitMapPtr bitmapPtr; int width, height, stippleHeight, stippleWidth; int i, j; char * data; Rect bounds; destPort = TkMacGetDrawablePort(drawable); width = destPort->portRect.right - destPort->portRect.left; height = destPort->portRect.bottom - destPort->portRect.top; bitmapPtr = (BitMap *) ckalloc(sizeof(BitMap)); data = (char *) ckalloc(height * ((width / 8) + 1)); bitmapPtr->bounds.top = bitmapPtr->bounds.left = 0; bitmapPtr->bounds.right = (short) width; bitmapPtr->bounds.bottom = (short) height; bitmapPtr->baseAddr = data; bitmapPtr->rowBytes = (width / 8) + 1; destPort = TkMacGetDrawablePort(stipple); stippleWidth = destPort->portRect.right - destPort->portRect.left; stippleHeight = destPort->portRect.bottom - destPort->portRect.top; for (i = 0; i < height; i += stippleHeight) { for (j = 0; j < width; j += stippleWidth) { bounds.left = j; bounds.top = i; bounds.right = j + stippleWidth; bounds.bottom = i + stippleHeight; CopyBits(&((GrafPtr) destPort)->portBits, bitmapPtr, &((GrafPtr) destPort)->portRect, &bounds, srcCopy, NULL); } } return bitmapPtr; }
A3 (PRIVATE, void, drawicon, INTEGER, id, INTEGER, offsetx, INTEGER, offsety) { struct idef *ip; BitMap bm; Rect old_loc; ip = (struct idef *) findid (id); if (id && ip) { bm.baseAddr = RM ((Ptr) ip->ike); bm.rowBytes = CWC (4); bm.bounds.left = bm.bounds.top = CWC (0); bm.bounds.right = bm.bounds.bottom = CWC (32); old_loc = ip->loc; C_OffsetRect (&ip->loc, offsetx, offsety); CopyBits (&bm, PORT_BITS_FOR_COPY (thePort), &bm.bounds, &ip->loc, srcCopy, NULL); ip->loc = old_loc; } }
void drawWindowFrame(WindowRef window) { /*------------------------------------------------------ Draw the frame of our window. This function needs to draw the title bar, the grow box, the title string and the structural aspects of the window. --------------------------------------------------------*/ static GWorldPtr framePict=NULL; static Rect pictureRect; GrafPtr thePort; Rect frame; if(!framePict){//haven't cached our picture PicHandle myPicture=GetPicture(kPictureID); GrafPtr origPort; GDHandle origDev; GetGWorld(&origPort,&origDev); pictureRect=(*myPicture)->picFrame; NewGWorld(&framePict,0,&pictureRect,NULL,NULL,0); SetGWorld(framePict,NULL); DrawPicture(myPicture,&pictureRect); SetGWorld(origPort,origDev); ReleaseResource((Handle)myPicture); } getCurrentPortBounds(&frame); GetPort(&thePort); CopyBits(GetPortBitMapForCopyBits(framePict), GetPortBitMapForCopyBits(thePort), &pictureRect,&frame,srcCopy,NULL);//draw our picture myWindowDrawGrowBox(window,0);//draw grow box as part of frame if(IsWindowHilited(window)) { //do any hilighting } }
static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects) { GWorldPtr memworld; GrafPtr saveport; CGrafPtr thePort; const BitMap *memBits; const BitMap *winBits; int i; Rect update; /* Copy from the offscreen GWorld to the window port */ GetPort(&saveport); SetPortWindowPort(SDL_Window); thePort = GetWindowPort(SDL_Window); memworld = (GWorldPtr)GetWRefCon(SDL_Window); #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld); #else memBits = &((GrafPtr)memworld)->portBits; #endif #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS winBits = GetPortBitMapForCopyBits(thePort); #else winBits = &SDL_Window->portBits; #endif for ( i=0; i<numrects; ++i ) { update.left = rects[i].x; update.right = rects[i].x+rects[i].w; update.top = rects[i].y; update.bottom = rects[i].y+rects[i].h; CopyBits(memBits, winBits, &update, &update, srcCopy, nil); } #if TARGET_API_MAC_CARBON if ( QDIsPortBuffered(thePort) ) { QDFlushPortBuffer(thePort, NULL); } #endif SetPort(saveport); }
void XCopyArea( Display* display, /* Display. */ Drawable src, /* Source drawable. */ Drawable dest, /* Destination drawable. */ GC gc, /* GC to use. */ int src_x, /* X & Y, width & height */ int src_y, /* define the source rectangle */ unsigned int width, /* the will be copied. */ unsigned int height, int dest_x, /* Dest X & Y on dest rect. */ int dest_y) { Rect srcRect, destRect; BitMapPtr srcBit, destBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *destDraw = (MacDrawable *) dest; GWorldPtr srcPort, destPort; CGrafPtr saveWorld; GDHandle saveDevice; short tmode; RGBColor origForeColor, origBackColor, whiteColor, blackColor; destPort = TkMacGetDrawablePort(dest); srcPort = TkMacGetDrawablePort(src); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); GetForeColor(&origForeColor); GetBackColor(&origBackColor); whiteColor.red = 0; whiteColor.blue = 0; whiteColor.green = 0; RGBForeColor(&whiteColor); blackColor.red = 0xFFFF; blackColor.blue = 0xFFFF; blackColor.green = 0xFFFF; RGBBackColor(&blackColor); TkMacSetUpClippingRgn(dest); /* * We will change the clip rgn in this routine, so we need to * be able to restore it when we exit. */ if (tmpRgn2 == NULL) { tmpRgn2 = NewRgn(); } GetClip(tmpRgn2); if (((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) { RgnHandle clipRgn = (RgnHandle) ((TkpClipMask*)gc->clip_mask)->value.region; int xOffset, yOffset; if (tmpRgn == NULL) { tmpRgn = NewRgn(); } xOffset = destDraw->xOff + gc->clip_x_origin; yOffset = destDraw->yOff + gc->clip_y_origin; OffsetRgn(clipRgn, xOffset, yOffset); GetClip(tmpRgn); SectRgn(tmpRgn, clipRgn, tmpRgn); SetClip(tmpRgn); OffsetRgn(clipRgn, -xOffset, -yOffset); } srcBit = &((GrafPtr) srcPort)->portBits; destBit = &((GrafPtr) destPort)->portBits; SetRect(&srcRect, (short) (srcDraw->xOff + src_x), (short) (srcDraw->yOff + src_y), (short) (srcDraw->xOff + src_x + width), (short) (srcDraw->yOff + src_y + height)); SetRect(&destRect, (short) (destDraw->xOff + dest_x), (short) (destDraw->yOff + dest_y), (short) (destDraw->xOff + dest_x + width), (short) (destDraw->yOff + dest_y + height)); tmode = srcCopy; CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); RGBForeColor(&origForeColor); RGBBackColor(&origBackColor); SetClip(tmpRgn2); SetGWorld(saveWorld, saveDevice); }
void TkPutImage( unsigned long *colors, /* Unused on Macintosh. */ int ncolors, /* Unused on Macintosh. */ Display* display, /* Display. */ Drawable d, /* Drawable to place image on. */ GC gc, /* GC to use. */ XImage* image, /* Image to place. */ int src_x, /* Source X & Y. */ int src_y, int dest_x, /* Destination X & Y. */ int dest_y, unsigned int width, /* Same width & height for both */ unsigned int height) /* distination and source. */ { MacDrawable *destDraw = (MacDrawable *) d; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; int i, j; BitMap bitmap; char *newData = NULL; Rect destRect, srcRect; destPort = TkMacGetDrawablePort(d); SetRect(&destRect, dest_x, dest_y, dest_x + width, dest_y + height); SetRect(&srcRect, src_x, src_y, src_x + width, src_y + height); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); if (image->depth == 1) { /* * This code assumes a pixel depth of 1 */ bitmap.bounds.top = bitmap.bounds.left = 0; bitmap.bounds.right = (short) image->width; bitmap.bounds.bottom = (short) image->height; if ((image->bytes_per_line % 2) == 1) { char *newPtr, *oldPtr; newData = (char *) ckalloc(image->height * (image->bytes_per_line + 1)); newPtr = newData; oldPtr = image->data; for (i = 0; i < image->height; i++) { for (j = 0; j < image->bytes_per_line; j++) { *newPtr = InvertByte((unsigned char) *oldPtr); newPtr++, oldPtr++; } *newPtr = 0; newPtr++; } bitmap.baseAddr = newData; bitmap.rowBytes = image->bytes_per_line + 1; } else { newData = (char *) ckalloc(image->height * image->bytes_per_line); for (i = 0; i < image->height * image->bytes_per_line; i++) { newData[i] = InvertByte((unsigned char) image->data[i]); } bitmap.baseAddr = newData; bitmap.rowBytes = image->bytes_per_line; } CopyBits(&bitmap, &((GrafPtr) destPort)->portBits, &srcRect, &destRect, srcCopy, NULL); } else { /* Color image */ PixMap pixmap; pixmap.bounds.left = 0; pixmap.bounds.top = 0; pixmap.bounds.right = (short) image->width; pixmap.bounds.bottom = (short) image->height; pixmap.pixelType = RGBDirect; pixmap.pmVersion = 4; /* 32bit clean */ pixmap.packType = 0; pixmap.packSize = 0; pixmap.hRes = 0x00480000; pixmap.vRes = 0x00480000; pixmap.pixelSize = 32; pixmap.cmpCount = 3; pixmap.cmpSize = 8; pixmap.planeBytes = 0; pixmap.pmTable = NULL; pixmap.pmReserved = 0; pixmap.baseAddr = image->data; if (image->bytes_per_line >= 0x4000) { panic("TkImage too wide!"); } pixmap.rowBytes = image->bytes_per_line | 0x8000; CopyBits((BitMap *) &pixmap, &((GrafPtr) destPort)->portBits, &srcRect, &destRect, srcCopy, NULL); } if (newData != NULL) { ckfree(newData); } SetGWorld(saveWorld, saveDevice); }
void XCopyPlane( Display* display, /* Display. */ Drawable src, /* Source drawable. */ Drawable dest, /* Destination drawable. */ GC gc, /* The GC to use. */ int src_x, /* X, Y, width & height */ int src_y, /* define the source rect. */ unsigned int width, unsigned int height, int dest_x, /* X & Y on dest where we will copy. */ int dest_y, unsigned long plane) /* Which plane to copy. */ { Rect srcRect, destRect; BitMapPtr srcBit, destBit, maskBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *destDraw = (MacDrawable *) dest; GWorldPtr srcPort, destPort, maskPort; CGrafPtr saveWorld; GDHandle saveDevice; RGBColor macColor; TkpClipMask *clipPtr = (TkpClipMask*)gc->clip_mask; short tmode; destPort = TkMacGetDrawablePort(dest); srcPort = TkMacGetDrawablePort(src); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(dest); srcBit = &((GrafPtr) srcPort)->portBits; destBit = &((GrafPtr) destPort)->portBits; SetRect(&srcRect, (short) (srcDraw->xOff + src_x), (short) (srcDraw->yOff + src_y), (short) (srcDraw->xOff + src_x + width), (short) (srcDraw->yOff + src_y + height)); SetRect(&destRect, (short) (destDraw->xOff + dest_x), (short) (destDraw->yOff + dest_y), (short) (destDraw->xOff + dest_x + width), (short) (destDraw->yOff + dest_y + height)); tmode = srcOr; tmode = srcCopy + transparent; if (TkSetMacColor(gc->foreground, &macColor) == true) { RGBForeColor(&macColor); } if (clipPtr == NULL || clipPtr->type == TKP_CLIP_REGION) { /* * Case 1: opaque bitmaps. */ TkSetMacColor(gc->background, &macColor); RGBBackColor(&macColor); tmode = srcCopy; CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); } else if (clipPtr->type == TKP_CLIP_PIXMAP) { if (clipPtr->value.pixmap == src) { /* * Case 2: transparent bitmaps. If it's color we ignore * the forecolor. */ if ((**(srcPort->portPixMap)).pixelSize == 1) { tmode = srcOr; } else { tmode = transparent; } CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); } else { /* * Case 3: two arbitrary bitmaps. */ tmode = srcCopy; maskPort = TkMacGetDrawablePort(clipPtr->value.pixmap); maskBit = &((GrafPtr) maskPort)->portBits; CopyDeepMask(srcBit, maskBit, destBit, &srcRect, &srcRect, &destRect, tmode, NULL); } } SetGWorld(saveWorld, saveDevice); }
void x_async_refresh(CGContextRef myContext,CGRect myBoundingBox) { #ifdef ENABLEQD CEmulatorMac* pEmu = (CEmulatorMac*)CEmulator::theEmulator; if (!pEmu) return ; #endif #ifndef DRIVER_IOS x_vbl_count++; #endif addFrameRate(0); CHANGE_BORDER(1,0xFF); // OG if (macUsingCoreGraphics) { if(r_sim65816.is_emulator_offscreen_available() && g_kimage_offscreen.dev_handle) { /* void addConsoleWindow(Kimage* _dst); addConsoleWindow(&g_kimage_offscreen); */ CGContextSaveGState(myContext); #ifndef DRIVER_IOS // CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT); CGContextTranslateCTM(myContext,0.0, myBoundingBox.size.height); CGContextScaleCTM(myContext,1.0,-1.0); #endif CGImageRef myImage = CGBitmapContextCreateImage((CGContextRef)g_kimage_offscreen.dev_handle); CGContextDrawImage(myContext, myBoundingBox, myImage);// 6 #ifndef VIDEO_SINGLEVLINE if (r_sim65816.get_video_fx() == VIDEOFX_CRT) { CGContextSetRGBFillColor(myContext,0,0,0,0.5); for(int h=0;h<g_kimage_offscreen.height;h+=2) { CGRect r = CGRectMake(0,h,g_kimage_offscreen.width_act,1); CGContextFillRect(myContext,r); } } #endif CGImageRelease(myImage); CGContextRestoreGState(myContext); #ifndef DRIVER_IOS if (!messageLine.IsEmpty()) { CGContextSaveGState(myContext); CGContextSetTextMatrix(myContext,CGAffineTransformIdentity); CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT); CGContextScaleCTM(myContext,1.0,-1.0); CGContextSelectFont(myContext, "Courier", 14.0, kCGEncodingMacRoman); CGContextSetTextDrawingMode(myContext, kCGTextFill); CGContextSetRGBFillColor (myContext, 1,1, 1, 1); CGContextSetShouldAntialias(myContext, true); #define SHADOW 4.0 CGFloat myColorValues[] = {0.5, 0.5, 0.5, 1.0}; CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9 CGColorRef myColor = CGColorCreate (myColorSpace, myColorValues); CGContextSetShadowWithColor(myContext, CGSizeMake(SHADOW, -SHADOW), 4, myColor //CGColorCreateGenericGray(0.5,1.0) ); CGContextShowTextAtPoint(myContext, 20.0, X_A2_WINDOW_HEIGHT-20.0, messageLine.c_str(), messageLine.GetLength()); CGContextRestoreGState(myContext); messageLineVBL--; if (messageLineVBL<0) messageLine.Empty(); else x_refresh_video(); } #endif } else { CGContextSaveGState(myContext); #if defined(DRIVER_IOS) // efface en noir si l'émulateur n'avait pas encore démarré (le cas sur 3GS) CGContextSetRGBFillColor (myContext, 0, 0, 0, 1); #else CGContextSetRGBFillColor (myContext, 0, 0, 1, 1); #endif CGContextFillRect (myContext, CGRectMake (0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT)); CGContextRestoreGState(myContext); } } else { #ifdef ENABLEQD CGrafPtr window_port = pEmu->window_port; Rect src_rect; Rect dest_rect; SetRect(&src_rect,0,0,704,462); SetRect(&dest_rect,0,0,704,462); if (pixmap_backbuffer) CopyBits( (BitMap *)(*pixmap_backbuffer), GetPortBitMapForCopyBits(window_port), &src_rect, &dest_rect, srcCopy, NULL); #endif } CHANGE_BORDER(1,0); if (r_sim65816.is_emulator_offscreen_available() && g_driver.x_handle_state_on_paint) g_driver.x_handle_state_on_paint(myBoundingBox.size.width,myBoundingBox.size.height); }
// uses copy bits void BlastCopyCB(BCPtr source,BCPtr dest,const Rect *sourceRect,const Rect *destRect) { CopyBits((BitMap*)*source->pixMap,(BitMap *)*dest->pixMap,sourceRect,destRect,srcCopy,0L); }
void ViewBuffer::Blit(int32 srcx, int32 srcy, int32 width, int32 height, int32 destx, int32 desty) { // blit inside the glyph grid if (fGlyphGrid) { int32 xOffset = destx - srcx; int32 yOffset = desty - srcy; int32 xIncrement; int32 yIncrement; uint16* src = fGlyphGrid + srcy * fColumns + srcx; if (xOffset > 0) { // copy from right to left xIncrement = -1; src += width - 1; } else { // copy from left to right xIncrement = 1; } if (yOffset > 0) { // copy from bottom to top yIncrement = -fColumns; src += (height - 1) * fColumns; } else { // copy from top to bottom yIncrement = fColumns; } uint16* dst = src + yOffset * fColumns + xOffset; for (int32 y = 0; y < height; y++) { uint16* srcHandle = src; uint16* dstHandle = dst; for (int32 x = 0; x < width; x++) { *dstHandle = *srcHandle; srcHandle += xIncrement; dstHandle += xIncrement; } src += yIncrement; dst += yIncrement; } } height *= CHAR_HEIGHT; width *= CHAR_WIDTH; srcx *= CHAR_WIDTH; srcy *= CHAR_HEIGHT; BRect source(srcx, srcy, srcx + width, srcy + height); destx *= CHAR_WIDTH; desty *= CHAR_HEIGHT; BRect dest(destx, desty, destx + width, desty + height); if (LockLooper()) { CopyBits(source, dest); Sync(); UnlockLooper(); } }
//----------------------------------------------------------------------------- // QutTexture_CreateGWorldFromPICT : Create a GWorld from a PICT. //----------------------------------------------------------------------------- GWorldPtr QutTexture_CreateGWorldFromPICT(PicHandle thePicture, TQ3PixelType pixelType) { GWorldPtr deepGWorld, theGWorld; Boolean shouldDither; GDHandle saveDevice; CGrafPtr savePort; TQ3Uns32 theDepth; OSErr theErr; // Work out the depth of GWorld, and if it should be dithered if (pixelType == kQ3PixelTypeARGB16 || pixelType == kQ3PixelTypeRGB16) theDepth = 16; else theDepth = 32; shouldDither = (theDepth == 16); // Create a GWorld to hold the image data theErr = NewGWorld(&theGWorld, theDepth, &(*thePicture)->picFrame, NULL, NULL, useTempMem | kQ3NativeEndianPixMap ); if (theErr != noErr || theGWorld == NULL) return(NULL); // If we should dither, create a deep GWorld if (theDepth == 16 && shouldDither) theErr = NewGWorld(&deepGWorld, 32, &(*thePicture)->picFrame, NULL, NULL, useTempMem | kQ3NativeEndianPixMap ); else deepGWorld = NULL; // If we have a deep GWorld, draw the image into that and then // copy it into the output GWorld. If we don't have a deep GWorld, // just draw it directly into the output GWorld. if (deepGWorld != NULL) { // Draw the picture into the deep GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(deepGWorld, NULL); LockPixels(GetGWorldPixMap(deepGWorld)); DrawPicture(thePicture, &(*thePicture)->picFrame); UnlockPixels(GetGWorldPixMap(deepGWorld)); SetGWorld(savePort, saveDevice); // Copy this into the output GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(theGWorld, NULL); LockPixels(GetGWorldPixMap(theGWorld)); CopyBits(GetPortBitMapForCopyBits(deepGWorld), GetPortBitMapForCopyBits(theGWorld), &(*thePicture)->picFrame, &(*thePicture)->picFrame, ditherCopy, NULL); UnlockPixels(GetGWorldPixMap(theGWorld)); SetGWorld(savePort, saveDevice); // Clean up DisposeGWorld(deepGWorld); deepGWorld = NULL; } else { // Draw the picture into the output GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(theGWorld, NULL); LockPixels(GetGWorldPixMap(theGWorld)); DrawPicture(thePicture, &(*thePicture)->picFrame); UnlockPixels(GetGWorldPixMap(theGWorld)); SetGWorld(savePort, saveDevice); } return(theGWorld); }