void Tk_FreeBitmapFromObj( Tk_Window tkwin, /* The window this bitmap lives in. Needed for * the display value. */ Tcl_Obj *objPtr) /* The Tcl_Obj * to be freed. */ { FreeBitmap(GetBitmapFromObj(tkwin, objPtr)); }
//============================================================================================== // FUNCTION: Destructor. // PURPOSE: Object cleanup. // CDisplaySurface::~CDisplaySurface() { MEMBERASSERT(); Lock(); FreeBitmap(); if (m_hdcBM) { DeleteDC(m_hdcBM); m_hdcBM = NULL; } Unlock(); }
static void SetWorkBitmap (Bitmap* N) /* Delete an old working bitmap and set a new one. The new one may be NULL ** to clear it. */ { /* If we have a distinct work bitmap, delete it */ if (C != 0 && C != B) { FreeBitmap (C); } /* Set the new one */ C = N; }
void CloseDevice(DeviceHandle *dh) { if(dh->fd) close(dh->fd); if(dh->device) g_free(dh->device); if(dh->rs02Header) g_free(dh->rs02Header); if(dh->mediumDescr) g_free(dh->mediumDescr); if(dh->isoInfo) FreeIsoInfo(dh->isoInfo); if(dh->defects) FreeBitmap(dh->defects); g_free(dh); }
void Tk_FreeBitmap( Display *display, /* Display for which bitmap was allocated. */ Pixmap bitmap) /* Bitmap to be released. */ { Tcl_HashEntry *idHashPtr; TkDisplay *dispPtr = TkGetDisplay(display); if (!dispPtr->bitmapInit) { Tcl_Panic("Tk_FreeBitmap called before Tk_GetBitmap"); } idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, (char *) bitmap); if (idHashPtr == NULL) { Tcl_Panic("Tk_FreeBitmap received unknown bitmap argument"); } FreeBitmap(Tcl_GetHashValue(idHashPtr)); }
void ReloadCustomImage(Bitmap *bitmap, char *basename) { char *filename = getCustomImageFilename(basename); Bitmap *new_bitmap; if (filename == NULL) /* (should never happen) */ { Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename); return; } if (strEqual(filename, bitmap->source_filename)) { /* The old and new image are the same (have the same filename and path). This usually means that this image does not exist in this graphic set and a fallback to the existing image is done. */ return; } if ((new_bitmap = LoadImage(filename)) == NULL) { Error(ERR_WARN, "LoadImage() failed: %s", GetError()); return; } if (bitmap->width != new_bitmap->width || bitmap->height != new_bitmap->height) { Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions", filename); FreeBitmap(new_bitmap); return; } TransferBitmapPointers(new_bitmap, bitmap); free(new_bitmap); }
/*********************************************************************** ** FreeNomadInfo() ** ** This function will return the space of a NomadInfo structure. ************************************************************************/ void FreeNomadInfo(NomadInfo *NPtr) { if(NPtr->key_ptr!=NULL) free(NPtr->key_ptr); if(NPtr->BitmapPtr!=NULL) FreeBitmap(NPtr->BitmapPtr); free(NPtr); } /* end: FreeNomadInfo() */
Resources::~Resources() { for (int i = 0; i < FILE_COUNT; i++) { FreeBitmap(*bitmaps[i]); } }
//============================================================================================== // FUNCTION: Resize. // PURPOSE: Sizes/Resizes the bitmap to the dimensions given. // void CDisplaySurface::Resize(LPCRECT prDisplay) { MEMBERASSERT(); ASSERT(m_hdcBM); WPTRASSERT(prDisplay); int nPaletteSize = m_nPaletteSize; int nBitsPerPixel = m_nBitsPerPixel; if (m_bMatchScreen) { ASSERT(m_hdcWin); nPaletteSize = GetDeviceCaps(m_hdcWin, SIZEPALETTE); nBitsPerPixel = GetDeviceCaps(m_hdcWin, BITSPIXEL); } // If nothing has changed, just get out. if (m_rDisplay.EqualRect(prDisplay) && (nPaletteSize == m_nPaletteSize) && (nBitsPerPixel == m_nBitsPerPixel)) return; HDC hDC = Lock(); // Save the new surface properties. m_nPaletteSize = nPaletteSize; m_nBitsPerPixel = nBitsPerPixel; m_rDisplay = *prDisplay; // If a DIB was created previously, delete it. FreeBitmap(); int nWidth = m_rDisplay.Width(); nWidth = max(nWidth, 1); int nHeight = m_rDisplay.Height(); nHeight = max(nHeight, 1); // Match the screen color depth. UINT uDIBWidthBits = nWidth * nBitsPerPixel; UINT uDIBWidthBytes = ((uDIBWidthBits + 31) & (~31)) >> 3; m_ActualSize.cx = uDIBWidthBytes; m_ActualSize.cy = nHeight; if (m_bInverted) nHeight = -nHeight; // add the storage for the DIB colors, if we have any! // m_nPaletteSize will be 256 for an 8 bit DIB, and 0 for all other DIBs int nBytes = sizeof(BITMAPINFOHEADER) + m_nPaletteSize * sizeof(RGBQUAD); ASSERT(m_pBitmapInfo==NULL); m_pBitmapInfo = (BITMAPINFO *)malloc(nBytes); memset(m_pBitmapInfo, 0, nBytes); // if we've run out of memory, get out of here if (!m_pBitmapInfo) return; // set up the information that we need BITMAPINFOHEADER *pBitmapInfoHeader = &(m_pBitmapInfo->bmiHeader); pBitmapInfoHeader->biSize = sizeof(BITMAPINFOHEADER); // always this pBitmapInfoHeader->biWidth = nWidth; // the width of the bitmap pBitmapInfoHeader->biHeight = nHeight; // the height, but negative so we display it upside down pBitmapInfoHeader->biPlanes = 1; // Always 1 pBitmapInfoHeader->biBitCount = WORD(m_nBitsPerPixel); // BPP for DIB pBitmapInfoHeader->biCompression = BI_RGB; // no compression pBitmapInfoHeader->biSizeImage = 0; // Calculation not needed for BI_RGB pBitmapInfoHeader->biXPelsPerMeter = 0; // These are arbitrary pBitmapInfoHeader->biYPelsPerMeter = 0; // These are arbitrary pBitmapInfoHeader->biClrUsed = m_nPaletteSize; // Use biBitCount to determine colors used pBitmapInfoHeader->biClrImportant = 0; // All colors important, set to 0 m_Palette.DeleteObject(); if (m_nPaletteSize > 0) { #ifdef _MFC_VER m_Palette.CreateHalftonePalette( CDC::FromHandle(m_hdcWin) ); #else m_Palette.CreateHalftonePalette(m_hdcWin); #endif ASSERT(m_nPaletteSize <= 256); PALETTEENTRY PalEntries[256] = { 0 }; PALETTEENTRY IdentityPalEntries[256] = { 0 }; // fill them in int nEntries = m_Palette.GetPaletteEntries(0, m_nPaletteSize, PalEntries); LPPALETTEENTRY pPalEntries = PalEntries; CreateIdentityPalette(PalEntries, IdentityPalEntries, nEntries); pPalEntries = IdentityPalEntries; // now convert to DIB color RGBQUAD *pDIBColorTable = m_pBitmapInfo->bmiColors; for (int i = 0; i < m_nPaletteSize; i++) { pDIBColorTable[i].rgbBlue = pPalEntries[i].peBlue; pDIBColorTable[i].rgbGreen = pPalEntries[i].peGreen; pDIBColorTable[i].rgbRed = pPalEntries[i].peRed; pDIBColorTable[i].rgbReserved = 0; } } // Create the DIB section. m_hBitmap = CreateDIBSection( hDC, m_pBitmapInfo, DIB_RGB_COLORS, (LPVOID *)(&m_pDibBits), NULL, 0); ASSERT(m_hBitmap); m_hbmSave = SelectBitmap( hDC, m_hBitmap ); SetViewportOrgEx( hDC, -m_rDisplay.left, -m_rDisplay.top, NULL); Clear( &m_rDisplay ); Unlock(); }
void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, int dst_x, int dst_y) { int dst_x_unclipped = dst_x; int dst_y_unclipped = dst_y; if (DrawingDeactivated(dst_x, dst_y, width, height)) return; #if 1 if (!InClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height, FALSE) || !InClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height, TRUE)) return; /* source x/y might need adjustment if destination x/y was clipped top/left */ src_x += dst_x - dst_x_unclipped; src_y += dst_y - dst_y_unclipped; #else /* skip if rectangle starts outside bitmap */ if (src_x >= src_bitmap->width || src_y >= src_bitmap->height || dst_x >= dst_bitmap->width || dst_y >= dst_bitmap->height) return; /* clip if rectangle overlaps bitmap */ if (src_x + width > src_bitmap->width) width = src_bitmap->width - src_x; if (src_y + height > src_bitmap->height) height = src_bitmap->height - src_y; if (dst_x + width > dst_bitmap->width) width = dst_bitmap->width - dst_x; if (dst_y + height > dst_bitmap->height) height = dst_bitmap->height - dst_y; #endif #if 0 /* !!! 2009-03-30: Fixed by using self-compiled, patched SDL.dll !!! */ /* (This bug still exists in the actual (as of 2009-06-15) version 1.2.13, but is already fixed in SVN and should therefore finally be fixed with the next official SDL release, which is probably version 1.2.14.) */ #if 1 /* !!! 2009-03-24: It seems that this problem still exists in 1.2.12 !!! */ #if defined(TARGET_SDL) && defined(PLATFORM_WIN32) if (src_bitmap == dst_bitmap) { /* !!! THIS IS A BUG (IN THE SDL LIBRARY?) AND SHOULD BE FIXED !!! */ /* needed when blitting directly to same bitmap -- should not be needed with recent SDL libraries, but apparently does not work in 1.2.11 directly */ static Bitmap *tmp_bitmap = NULL; static int tmp_bitmap_xsize = 0; static int tmp_bitmap_ysize = 0; /* start with largest static bitmaps for initial bitmap size ... */ if (tmp_bitmap_xsize == 0 && tmp_bitmap_ysize == 0) { tmp_bitmap_xsize = MAX(gfx.win_xsize, gfx.scrollbuffer_width); tmp_bitmap_ysize = MAX(gfx.win_ysize, gfx.scrollbuffer_height); } /* ... and allow for later re-adjustments due to custom artwork bitmaps */ if (src_bitmap->width > tmp_bitmap_xsize || src_bitmap->height > tmp_bitmap_ysize) { tmp_bitmap_xsize = MAX(tmp_bitmap_xsize, src_bitmap->width); tmp_bitmap_ysize = MAX(tmp_bitmap_ysize, src_bitmap->height); FreeBitmap(tmp_bitmap); tmp_bitmap = NULL; } if (tmp_bitmap == NULL) tmp_bitmap = CreateBitmap(tmp_bitmap_xsize, tmp_bitmap_ysize, DEFAULT_DEPTH); sysCopyArea(src_bitmap, tmp_bitmap, src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE); sysCopyArea(tmp_bitmap, dst_bitmap, dst_x, dst_y, width, height, dst_x, dst_y, BLIT_OPAQUE); return; } #endif #endif #endif sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE); }
static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, boolean create_small_bitmaps) { Bitmap swap_bitmap; Bitmap *new_bitmap; Bitmap *tmp_bitmap_1; Bitmap *tmp_bitmap_2; Bitmap *tmp_bitmap_4; Bitmap *tmp_bitmap_8; Bitmap *tmp_bitmap_16; Bitmap *tmp_bitmap_32; int width_1, height_1; int width_2, height_2; int width_4, height_4; int width_8, height_8; int width_16, height_16; int width_32, height_32; int new_width, new_height; /* calculate new image dimensions for normal sized image */ width_1 = old_bitmap->width * zoom_factor; height_1 = old_bitmap->height * zoom_factor; /* get image with normal size (this might require scaling up) */ if (zoom_factor != 1) tmp_bitmap_1 = ZoomBitmap(old_bitmap, width_1, height_1); else tmp_bitmap_1 = old_bitmap; /* this is only needed to make compilers happy */ tmp_bitmap_2 = NULL; tmp_bitmap_4 = NULL; tmp_bitmap_8 = NULL; tmp_bitmap_16 = NULL; tmp_bitmap_32 = NULL; if (create_small_bitmaps) { /* calculate new image dimensions for small images */ width_2 = width_1 / 2; height_2 = height_1 / 2; width_4 = width_1 / 4; height_4 = height_1 / 4; width_8 = width_1 / 8; height_8 = height_1 / 8; width_16 = width_1 / 16; height_16 = height_1 / 16; width_32 = width_1 / 32; height_32 = height_1 / 32; UPDATE_BUSY_STATE(); /* get image with 1/2 of normal size (for use in the level editor) */ if (zoom_factor != 2) tmp_bitmap_2 = ZoomBitmap(tmp_bitmap_1, width_1 / 2, height_1 / 2); else tmp_bitmap_2 = old_bitmap; UPDATE_BUSY_STATE(); /* get image with 1/4 of normal size (for use in the level editor) */ if (zoom_factor != 4) tmp_bitmap_4 = ZoomBitmap(tmp_bitmap_2, width_2 / 2, height_2 / 2); else tmp_bitmap_4 = old_bitmap; UPDATE_BUSY_STATE(); /* get image with 1/8 of normal size (for use on the preview screen) */ if (zoom_factor != 8) tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_4, width_4 / 2, height_4 / 2); else tmp_bitmap_8 = old_bitmap; UPDATE_BUSY_STATE(); /* get image with 1/16 of normal size (for use on the preview screen) */ if (zoom_factor != 16) tmp_bitmap_16 = ZoomBitmap(tmp_bitmap_8, width_8 / 2, height_8 / 2); else tmp_bitmap_16 = old_bitmap; UPDATE_BUSY_STATE(); /* get image with 1/32 of normal size (for use on the preview screen) */ if (zoom_factor != 32) tmp_bitmap_32 = ZoomBitmap(tmp_bitmap_16, width_16 / 2, height_16 / 2); else tmp_bitmap_32 = old_bitmap; UPDATE_BUSY_STATE(); } #if 0 /* if image was scaled up, create new clipmask for normal size image */ if (zoom_factor != 1) { #if defined(TARGET_X11) if (old_bitmap->clip_mask) XFreePixmap(display, old_bitmap->clip_mask); old_bitmap->clip_mask = Pixmap_to_Mask(tmp_bitmap_1->drawable, width_1, height_1); XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask); #else SDL_Surface *tmp_surface_1 = tmp_bitmap_1->surface; if (old_bitmap->surface_masked) SDL_FreeSurface(old_bitmap->surface_masked); SDL_SetColorKey(tmp_surface_1, SDL_SRCCOLORKEY, SDL_MapRGB(tmp_surface_1->format, 0x00, 0x00, 0x00)); if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); SDL_SetColorKey(tmp_surface_1, 0, 0); /* reset transparent pixel */ #endif } #endif if (create_small_bitmaps) { new_width = width_1; new_height = height_1 + (height_1 + 1) / 2; /* prevent odd height */ new_bitmap = CreateBitmap(new_width, new_height, DEFAULT_DEPTH); BlitBitmap(tmp_bitmap_1, new_bitmap, 0, 0, width_1, height_1, 0, 0); BlitBitmap(tmp_bitmap_2, new_bitmap, 0, 0, width_1 / 2, height_1 / 2, 0, height_1); BlitBitmap(tmp_bitmap_4, new_bitmap, 0, 0, width_1 / 4, height_1 / 4, width_1 / 2, height_1); BlitBitmap(tmp_bitmap_8, new_bitmap, 0, 0, width_1 / 8, height_1 / 8, 3 * width_1 / 4, height_1); BlitBitmap(tmp_bitmap_16, new_bitmap, 0, 0, width_1 / 16, height_1 / 16, 7 * width_1 / 8, height_1); BlitBitmap(tmp_bitmap_32, new_bitmap, 0, 0, width_1 / 32, height_1 / 32, 15 * width_1 / 16, height_1); UPDATE_BUSY_STATE(); } else { new_width = width_1; new_height = height_1; new_bitmap = tmp_bitmap_1; /* directly use tmp_bitmap_1 as new bitmap */ } if (create_small_bitmaps) { /* if no small bitmaps created, tmp_bitmap_1 is used as new bitmap now */ if (zoom_factor != 1) FreeBitmap(tmp_bitmap_1); if (zoom_factor != 2) FreeBitmap(tmp_bitmap_2); if (zoom_factor != 4) FreeBitmap(tmp_bitmap_4); if (zoom_factor != 8) FreeBitmap(tmp_bitmap_8); if (zoom_factor != 16) FreeBitmap(tmp_bitmap_16); if (zoom_factor != 32) FreeBitmap(tmp_bitmap_32); } /* replace image with extended image (containing 1/1, 1/2, 1/4, 1/8 size) */ #if defined(TARGET_SDL) swap_bitmap.surface = old_bitmap->surface; old_bitmap->surface = new_bitmap->surface; new_bitmap->surface = swap_bitmap.surface; #else swap_bitmap.drawable = old_bitmap->drawable; old_bitmap->drawable = new_bitmap->drawable; new_bitmap->drawable = swap_bitmap.drawable; #endif old_bitmap->width = new_bitmap->width; old_bitmap->height = new_bitmap->height; #if 1 /* this replaces all blit masks created when loading -- maybe optimize this */ { #if defined(TARGET_X11) if (old_bitmap->clip_mask) XFreePixmap(display, old_bitmap->clip_mask); old_bitmap->clip_mask = Pixmap_to_Mask(old_bitmap->drawable, new_width, new_height); XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask); #else SDL_Surface *old_surface = old_bitmap->surface; if (old_bitmap->surface_masked) SDL_FreeSurface(old_bitmap->surface_masked); SDL_SetColorKey(old_surface, SDL_SRCCOLORKEY, SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00)); if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); SDL_SetColorKey(old_surface, 0, 0); /* reset transparent pixel */ #endif } #endif UPDATE_BUSY_STATE(); FreeBitmap(new_bitmap); /* this actually frees the _old_ bitmap now */ }
bool SetSize(CSBitmap* pBitmap, int width, int height, int channels) { // Make sure that the InitBitmap() function was called before calling // SetSize() for the first time. assert(HasBitmap(pBitmap) || pBitmap->mWidth == -1); assert(HasBitmap(pBitmap) || pBitmap->mHeight == -1); assert(HasBitmap(pBitmap) || pBitmap->mChannels == -1); // This function doesn't support allocating zero size or negative // size bitmaps. rassert(width > 0); rassert(height > 0); rassert(channels == 1 || channels == 3 || channels == 4); FreeBitmap(pBitmap); pBitmap->mWidth = width; pBitmap->mHeight = height; pBitmap->mChannels = channels; // Define a DIBData object, and clear it to zero. DIBData Info = {0}; // Initialize the parameters that we care about, based on the // documentation and our needs. Info.InfoHeader.biSize = sizeof(BITMAPINFOHEADER); Info.InfoHeader.biWidth = width; Info.InfoHeader.biHeight = height; Info.InfoHeader.biPlanes = 1; Info.InfoHeader.biBitCount = channels * 8; Info.InfoHeader.biCompression = BI_RGB; // Support for 256 colour bitmaps. Info.InfoHeader.biClrUsed = (channels == 1 ? 256 : 0); // Create a temporary DC. Alternately we could pass one in. // This is needed for the call to CreateDIBSection. HDC TempDC = CreateDC("Display", 0, 0, 0); if (TempDC) { // Create a DIBSection. Note that this returns us two // things - an HBITMAP handle and a memory pointer, in // mSurfaceBits. pBitmap->mBitmapNew = CreateDIBSection(TempDC, (BITMAPINFO *)&Info, DIB_RGB_COLORS, (void **)&pBitmap->mSurfaceBits, 0, 0L); if (pBitmap->mBitmapNew) { // Create a copy of our DC that we can keep around pBitmap->mBitmapDC = CreateCompatibleDC(TempDC); if (pBitmap->mBitmapDC) { // Select our DIBSection bitmap into our DC. This // allows us to draw to the bitmap using GDI functions. pBitmap->mBitmapMonochrome = SelectBitmap( pBitmap->mBitmapDC, pBitmap->mBitmapNew); } else DisplayLastError("CreateCompatibleDC failed."); } else DisplayLastError("CreateDIBSection failed."); // Delete our temporary device context - we don't need it any more. DeleteDC(TempDC); } else DisplayLastError("CreateDC failed."); // If the allocation failed, clean up. if (!pBitmap->mBitmapMonochrome) FreeBitmap(pBitmap); // Initialize derived data that GetLinePtr() and other functions need to run efficiently. // Here is where we have to calculate the actual number of bytes per line, // respecting the Win32 rules for bitmap allocations. When we requested // the bitmap we specified a width, which Windows will have padded to // a multiple of four bytes - so we'd better allow for that. pBitmap->mBytesPerLine = (pBitmap->mWidth * pBitmap->mChannels + 3) & ~3; // Calculate the address of line zero - defined here as the line that is // at the top when the bitmap is copied to the screen. This is the last // line in memory. pBitmap->mLineZeroPointer = pBitmap->mSurfaceBits + (pBitmap->mHeight - 1) * pBitmap->mBytesPerLine; // Calculate the distance from line to line to be consistent with // mLineZeroPointer. pBitmap->mStride = -pBitmap->mBytesPerLine; return HasBitmap(pBitmap); }