wxBitmap LoadScaledBitmap(const wxString& name) { const wxString filename(name + ".png"); if (!wxFileExists(filename)) return wxNullBitmap; #ifdef NEEDS_MANUAL_HIDPI if (HiDPIScalingFactor() > 1.0) { wxImage img; double imgScale = HiDPIScalingFactor(); const wxString filename_2x(name + "@2x.png"); if (wxFileExists(filename_2x)) { LoadPNGImage(img, filename_2x); if (HiDPIScalingFactor() == 2.0) return wxBitmap(img); else imgScale /= 2.0; } else { LoadPNGImage(img, filename); } img.Rescale(img.GetWidth() * imgScale, img.GetHeight() * imgScale, imgScale == 2.0 ? wxIMAGE_QUALITY_NEAREST : wxIMAGE_QUALITY_BICUBIC); return wxBitmap(img); } // else: load normally #endif return wxBitmap(wxImage(filename, wxBITMAP_TYPE_PNG)); }
static int LoadImage(char *path, Image * img, Pixel color) { char *extn; extn = strrchr(path, '.'); #ifndef NO_XPM_SUPPORT if (strcasecmp(extn, ".xpm") == 0) LoadXPMImage(path, img, color); #endif /* NO_XPM_SUPPORT */ #ifndef NO_PNG_SUPPORT if (strcasecmp(extn, ".png") == 0) LoadPNGImage(path, img); #endif /* NO_PNG_SUPPORT */ if (img->type != IMAGE_TYPE_NONE) return (TRUE); return (FALSE); }
HBITMAP MakeDockPanelBitmap(RECT *rect) { int width = GetRectWidth(rect); int height = GetRectHeight(rect); DWORD *pdwBox; static HBITMAP hbmBox, hbm; HDC hdcBox, hdcDIB, hdcSrc; HANDLE hOldBox, hOldDIB; RECT *sprite = 0; POINT pos = { 0 }; // 32bpp bitmap BITMAPINFOHEADER bih = { sizeof(bih) }; bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; bih.biSizeImage = 0; hdcSrc = GetDC(0); if(hbmBox == 0) { hbmBox = LoadPNGImage(IDB_SELBOX, (void **)&pdwBox); } hdcBox = CreateCompatibleDC(hdcSrc); hOldBox = SelectObject(hdcBox, hbmBox); hbm = CreateDIBSection(hdcSrc, (BITMAPINFO *)&bih, DIB_RGB_COLORS, (void**)&pdwBox, 0, 0); hdcDIB = CreateCompatibleDC(hdcSrc); hOldDIB = SelectObject(hdcDIB, hbm); if(1)//type & DOCKRECT_TYPE_THICK) { // corners BitBlt(hdcDIB, 0, 0, 32, 32, hdcBox, 0, 0, SRCCOPY); BitBlt(hdcDIB, width - 32, 0, 32, 32, hdcBox, 32, 0, SRCCOPY); BitBlt(hdcDIB, 0, height-32, 32, 32, hdcBox, 0, 32, SRCCOPY); BitBlt(hdcDIB, width-32, height-32, 32, 32, hdcBox, 32, 32, SRCCOPY); // sides StretchBlt(hdcDIB, 0, 32, 32, height-64, hdcBox, 0,32,32,1,SRCCOPY); StretchBlt(hdcDIB, width-32, 32, 32, height-64, hdcBox, 32,32,32,1,SRCCOPY); StretchBlt(hdcDIB, 32, 0, width-64, 32, hdcBox, 32,0,1,32,SRCCOPY); StretchBlt(hdcDIB, 32, height-32, width-64, 32, hdcBox, 32,32,1,32,SRCCOPY); //if(type & DOCKRECT_TYPE_SHADED) { // middle StretchBlt(hdcDIB, 32, 32, width-64, height-64, hdcBox, 32,32,1,1,SRCCOPY); } } /*else if(type & DOCKRECT_TYPE_SHADED) { StretchBlt(hdcDIB, 0, 0, width, height, hdcBox, 32,32,1,1,SRCCOPY); }*/ SelectObject(hdcDIB, hOldDIB); SelectObject(hdcBox, hOldBox); DeleteDC(hdcBox); DeleteDC(hdcDIB); ReleaseDC(0, hdcSrc); return hbm; }
wxImage LoadScaledBitmap(const wxString& name) { const wxString filename(name + ".png"); if (!wxFileExists(filename)) return wxNullImage; wxImage img; #ifdef NEEDS_MANUAL_HIDPI // On Windows, arbitrary scaling factors are possible and "ugly" values like 125% // or 150% scaling are not only possible, but common. It is unrealistic to provide // custom-drawn bitmaps for all of them, so we make do with a basic set of 100%/@1x, // 200%/@2x (used on macOS too) and one more for 150%/@1.5x for Windows use. // To eliminate smudged scaling artifacts, we use these fixed sizes even for zoom // factors in-between (such as the very common 125% or less common 175%). This looks // better and the size difference is negligible. auto const screenScaling = HiDPIScalingFactor(); if (screenScaling > 1.25) { if (screenScaling <= 1.75) // @1.5x is reasonable { const wxString filename_15x(name + "@1.5x.png"); if (wxFileExists(filename_15x)) { LoadPNGImage(img, filename_15x); if (img.IsOk()) return img; } } double imgScale = screenScaling; const wxString filename_2x(name + "@2x.png"); if (wxFileExists(filename_2x)) { LoadPNGImage(img, filename_2x); if (screenScaling > 1.75 && screenScaling <= 2.50) // @2x is reasonable return img; else imgScale /= 2.0; } else // fall back to upscaled @1x { LoadPNGImage(img, filename); } if (!img.IsOk()) return wxNullImage; wxImageResizeQuality quality; if (imgScale == 2.0) quality = wxIMAGE_QUALITY_NEAREST; else if (imgScale == 1.5) quality = wxIMAGE_QUALITY_BILINEAR; else quality = wxIMAGE_QUALITY_BICUBIC; img.Rescale(img.GetWidth() * imgScale, img.GetHeight() * imgScale, quality); return img; } // else if screenScaling <= 1.25: @1x size is good enough, load normally #endif LoadPNGImage(img, filename); return img; }
/** Load an image from the specified file. */ ImageNode *LoadImage(const char *fileName, int width, int height, char preserveAspect) { unsigned nameLength; ImageNode *result = NULL; if(!fileName) { return result; } nameLength = strlen(fileName); if(JUNLIKELY(nameLength == 0)) { return result; } /* Attempt to load the file as a PNG image. */ #ifdef USE_PNG if(nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".png")) { result = LoadPNGImage(fileName); if(result) { return result; } } #endif /* Attempt to load the file as a JPEG image. */ #ifdef USE_JPEG if( (nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".jpg")) || (nameLength >= 5 && !StrCmpNoCase(&fileName[nameLength - 5], ".jpeg"))) { result = LoadJPEGImage(fileName, width, height); if(result) { return result; } } #endif /* Attempt to load the file as an SVG image. */ #if defined USE_RSVG || defined USE_NANOSVG if(nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".svg")) { result = LoadSVGImage(fileName, width, height, preserveAspect); if(result) { return result; } } #endif /* Attempt to load the file as an XPM image. */ #ifdef USE_XPM if(nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".xpm")) { result = LoadXPMImage(fileName); if(result) { return result; } } #endif /* Attempt to load the file as an XBM image. */ #ifdef USE_XBM if(nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".xbm")) { result = LoadXBMImage(fileName); if(result) { return result; } } #endif /* Attempt to load a PNG, JPEG, GIf, TGA, BMP, PNM, PSD or PIC image. */ #ifdef USE_STB_IMAGE result = LoadstbImage(fileName); #endif return result; }
HBITMAP MakeDockPanelBitmap(RECT *rect, DWORD side, DWORD type) { int width = RectWidth(rect); int height = RectHeight(rect); int i; DWORD *pdwBox, *pdwArrow; HBITMAP hbmBox, hbmArrow, hbm; HDC hdcBox, hdcArrow, hdcDIB, hdcSrc; HANDLE hOldBox, hOldArrow, hOldDIB; RECT *sprite = 0; POINT pos = { 0 }; int mask[] = { DWS_DOCKED_LEFT, DWS_DOCKED_RIGHT, DWS_DOCKED_TOP, DWS_DOCKED_BOTTOM, 0x1000000 }; int swidth, sheight; int sidx = type & DOCKRECT_TYPE_SHADED; // 32bpp bitmap BITMAPINFOHEADER bih = { sizeof(bih) }; bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; bih.biSizeImage = 0; hdcSrc = GetDC(0); hbmBox = LoadPNGImage(IDB_SELBOX, (void **)&pdwBox); hdcBox = CreateCompatibleDC(hdcSrc); hOldBox = SelectObject(hdcBox, hbmBox); hbm = CreateDIBSection(hdcSrc, (BITMAPINFO *)&bih, DIB_RGB_COLORS, (void**)&pdwBox, 0, 0); hdcDIB = CreateCompatibleDC(hdcSrc); hOldDIB = SelectObject(hdcDIB, hbm); if(type & DOCKRECT_TYPE_THICK) { // corners BitBlt(hdcDIB, 0, 0, 32, 32, hdcBox, 0, 0, SRCCOPY); BitBlt(hdcDIB, width - 32, 0, 32, 32, hdcBox, 32, 0, SRCCOPY); BitBlt(hdcDIB, 0, height-32, 32, 32, hdcBox, 0, 32, SRCCOPY); BitBlt(hdcDIB, width-32, height-32, 32, 32, hdcBox, 32, 32, SRCCOPY); // sides StretchBlt(hdcDIB, 0, 32, 32, height-64, hdcBox, 0,32,32,1,SRCCOPY); StretchBlt(hdcDIB, width-32, 32, 32, height-64, hdcBox, 32,32,32,1,SRCCOPY); StretchBlt(hdcDIB, 32, 0, width-64, 32, hdcBox, 32,0,1,32,SRCCOPY); StretchBlt(hdcDIB, 32, height-32, width-64, 32, hdcBox, 32,32,1,32,SRCCOPY); if(type & DOCKRECT_TYPE_SHADED) { // middle StretchBlt(hdcDIB, 32, 32, width-64, height-64, hdcBox, 32,32,1,1,SRCCOPY); } } else if(type & DOCKRECT_TYPE_SHADED) { StretchBlt(hdcDIB, 0, 0, width, height, hdcBox, 32,32,1,1,SRCCOPY); } if(side && (RectWidth(rect) < 64 || RectHeight(rect) < 64)) { side = 0; } hbmArrow = LoadPNGImage(IDB_SELARROW, (void **)&pdwArrow); hdcArrow = CreateCompatibleDC(hdcSrc); hOldArrow = SelectObject(hdcArrow, hbmArrow); // loop over the for(i = 0; i < 5; i++) { switch(side & mask[i]) { case DWS_DOCKED_LEFT: sprite = &spritemap[sidx][2]; pos.x = 0; pos.y = height/2 - RectHeight(sprite)/2; //StretchBlt(hdcDIB, 0, 100, 32, 45, hdcMem2, 257,80,32,45,SRCCOPY); break; case DWS_DOCKED_RIGHT: sprite = &spritemap[sidx][3]; pos.x = width- RectWidth(sprite); pos.y = height/2 - RectHeight(sprite)/2; //StretchBlt(hdcDIB, 0, 100, 32, 45, hdcMem2, 257,80,32,45,SRCCOPY); break; case DWS_DOCKED_TOP: sprite = &spritemap[sidx][1]; pos.x = width/2 - RectWidth(sprite)/2; pos.y = 0; //StretchBlt(hdcDIB, 0, 100, 32, 45, hdcMem2, 257,80,32,45,SRCCOPY); break; //case 0: case DWS_DOCKED_BOTTOM: sprite = &spritemap[sidx][0]; pos.x = width/2 - RectWidth(sprite)/2; pos.y = height-RectHeight(sprite); // break; case 0x1000000: sprite = &spritemap[sidx][4]; pos.x = 16; pos.y = height - RectHeight(sprite); break; default: continue; } swidth = RectWidth(sprite); sheight = RectHeight(sprite); /*if((type & DOCKRECT_TYPE_SHADED) == 0) { swidth = 56; sheight = 56; }*/ StretchBlt(hdcDIB, pos.x, pos.y, swidth, sheight, hdcArrow, sprite->left, sprite->top,// - ((type & DOCKRECT_TYPE_SHADED) == 0 ? 80 : 0), swidth,// + ((type & DOCKRECT_TYPE_SHADED) == 0 ? 30 : 0), sheight,//+ ((type & DOCKRECT_TYPE_SHADED) == 0 ? 30 : 0), SRCCOPY); } SelectObject(hdcDIB, hOldDIB); SelectObject(hdcBox, hOldBox); SelectObject(hdcArrow, hOldArrow); DeleteDC(hdcBox); DeleteDC(hdcDIB); DeleteDC(hdcArrow); ReleaseDC(0, hdcSrc); return hbm; }