inline void BuildMaterial(const HiresTextureCacheItem& item, ImageLoaderParams& ImgInfo, size_t level) { if (ImgInfo.resultTex != PC_TEX_FMT_RGBA32) { return; } bool bump = false; u8* bumpdata = ImgInfo.dst; if (item.maps[MapType::bump].size() > level) { auto& leveldata = item.maps[MapType::bump][level]; int image_width; int image_height; bumpdata = LoadImageFromFile(leveldata.path.c_str(), image_width, image_height); if (bumpdata != nullptr && static_cast<u32>(image_width) == ImgInfo.Width && static_cast<u32>(image_height) == ImgInfo.Height) { bump = true; } } bool specular = false; u8* speculardata = ImgInfo.dst; if (item.maps[MapType::specular].size() > level) { auto& leveldata = item.maps[MapType::specular][level]; int image_width; int image_height; speculardata = LoadImageFromFile(leveldata.path.c_str(), image_width, image_height); if (speculardata != nullptr && static_cast<u32>(image_width) == ImgInfo.Width && static_cast<u32>(image_height) == ImgInfo.Height) { specular = true; } } for (size_t i = 0; i < ImgInfo.Height; i++) { size_t idx = i * ImgInfo.Width * 4; for (size_t j = 0; j < ImgInfo.Width; j++) { ImgInfo.dst[idx + 3] = ImgInfo.dst[idx]; ImgInfo.dst[idx] = bump ? bumpdata[idx] : 127; ImgInfo.dst[idx] = specular ? speculardata[idx] : 51; idx += 4; } } if (bumpdata != nullptr && bumpdata != ImgInfo.dst) { SOIL_free_image_data(bumpdata); } if (speculardata != nullptr && speculardata != ImgInfo.dst) { SOIL_free_image_data(speculardata); } }
inline void ReadImageFile(ImageLoaderParams& ImgInfo) { // libpng path seems to fail with some png files using soil meanwhile /*if (ImageLoader::ReadImageFile(ImgInfo)) { ImgInfo.resultTex = PC_TEX_FMT_RGBA32; } */ int image_width; int image_height; ImgInfo.resultTex = PC_TEX_FMT_NONE; u8* decoded = LoadImageFromFile(ImgInfo.Path, image_width, image_height); if (decoded == nullptr) { return; } // Reallocate the memory so we can manage it ImgInfo.Width = image_width; ImgInfo.Height = image_height; ImgInfo.data_size = image_width * image_height * 4; ImgInfo.dst = ImgInfo.request_buffer_delegate(ImgInfo.data_size, false); if (ImgInfo.dst) { memcpy(ImgInfo.dst, decoded, ImgInfo.data_size); ImgInfo.resultTex = PC_TEX_FMT_RGBA32; } SOIL_free_image_data(decoded); }
void UIDirect3D9Window::DrawImage(UIEffect *Effect, QRectF *Dest, bool &PositionChanged, UIImage *Image) { if (!Image) return; if (Image->GetState() == UIImage::ImageReleasedFromGPU) { LOG(VB_GENERAL, LOG_INFO, QString("Image '%1' cache hit").arg(Image->GetName())); Image->SetState(UIImage::ImageNull); } if (Image->GetState() == UIImage::ImageLoading) return; if (Image->GetState() == UIImage::ImageNull) { LoadImageFromFile(Image); return; } if (!Dest) return; PositionChanged |= Image->IsShared(); D3D9Texture *texture = AllocateTexture(Image); if (texture) DrawTexture(texture, Dest, Image->GetSizeF(), PositionChanged); }
STDMETHODIMP CTaskbar7::SetTabsIcon(BSTR icon) { // Remove icon if icon path is empty if (CComBSTR(icon) == CComBSTR("")) { if (m_isWindows7) SetClassLong(m_hwnd, GCL_HICON, NULL); return S_OK; } USES_CONVERSION; Bitmap* bitmap = NULL; HRESULT hr = LoadImageFromFile(OLE2W(icon), &bitmap); // return a proper error if (!SUCCEEDED(hr)) return hr; // Do nothing on XP & Vista if (!m_isWindows7) { delete bitmap; return S_OK; } HICON hIcon; bitmap->GetHICON(&hIcon); SetClassLong(m_hwnd, GCL_HICON, (LONG)hIcon); // Cleanup the HICON & Bitmap DestroyIcon(hIcon); delete bitmap; return S_OK; }
CXlibToolkit::CXlibToolkit(void *parentWindow, CEditor *editor) { this->parentWindow = parentWindow; this->editor = editor; char *displayName = getenv("DISPLAY"); if (!displayName || !strlen(displayName)) { displayName = (char*)":0.0"; } if (!XInitThreads()) { fprintf(stderr, "Xlib threads support unavailable"); return; } this->display = XOpenDisplay(displayName); if (!parentWindow) { parentWindow = (void*)RootWindow(this->display, DefaultScreen(this->display)); } window = XCreateWindow(this->display, (Window)parentWindow, 0, 0, GUI_WIDTH, GUI_HEIGHT, 0, 24, InputOutput, CopyFromParent, 0, 0); gc = XCreateGC(this->display, window, 0, 0); XSelectInput(this->display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask); XMapWindow(this->display, window); XFlush(this->display); this->WM_TIMER = XInternAtom(this->display, "WM_TIMER" , false); this->WM_DELETE_WINDOW = XInternAtom(this->display, "WM_DELETE_WINDOW", false); XSetWMProtocols(this->display, window, &WM_DELETE_WINDOW, 1); offscreen = XCreatePixmap(this->display, window, GUI_WIDTH, GUI_HEIGHT, 24); memset(bmps, 0, sizeof(bmps)); bmps[BMP_CHARS ] = LoadImageFromFile(BMP_PATH"/chars.bmp" ); bmps[BMP_KNOB ] = LoadImageFromFile(BMP_PATH"/knob.bmp" ); bmps[BMP_KNOB2 ] = LoadImageFromFile(BMP_PATH"/knob2.bmp" ); bmps[BMP_KNOB3 ] = LoadImageFromFile(BMP_PATH"/knob3.bmp" ); bmps[BMP_KEY ] = LoadImageFromFile(BMP_PATH"/key.bmp" ); bmps[BMP_BG ] = LoadImageFromFile(BMP_PATH"/bg.bmp" ); bmps[BMP_BUTTONS] = LoadImageFromFile(BMP_PATH"/buttons.bmp"); bmps[BMP_OPS ] = LoadImageFromFile(BMP_PATH"/ops.bmp" ); if (!bmps[BMP_CHARS ]) bmps[BMP_CHARS ] = LoadImageFromBuffer(chars_bmp ); if (!bmps[BMP_KNOB ]) bmps[BMP_KNOB ] = LoadImageFromBuffer(knob_bmp ); if (!bmps[BMP_KNOB2 ]) bmps[BMP_KNOB2 ] = LoadImageFromBuffer(knob2_bmp ); if (!bmps[BMP_KNOB3 ]) bmps[BMP_KNOB3 ] = LoadImageFromBuffer(knob3_bmp ); if (!bmps[BMP_KEY ]) bmps[BMP_KEY ] = LoadImageFromBuffer(key_bmp ); if (!bmps[BMP_BG ]) bmps[BMP_BG ] = LoadImageFromBuffer(bg_bmp ); if (!bmps[BMP_BUTTONS]) bmps[BMP_BUTTONS] = LoadImageFromBuffer(buttons_bmp); if (!bmps[BMP_OPS ]) bmps[BMP_OPS ] = LoadImageFromBuffer(ops_bmp ); thread1Finished = true; thread2Finished = true; }
BOOL DrawBitmap(HDC hDC, LPCTSTR lpzBitmapFile, const RECT& dstRect, COLORREF clrTransColor) { HBITMAP hBitmap = (HBITMAP)LoadImageFromFile(lpzBitmapFile); if (hBitmap == NULL) return FALSE; CBitmap bmp; bmp.Attach(hBitmap); return DrawBitmap(hDC, hBitmap, dstRect, clrTransColor); }
HRESULT CTaskbar7::LoadButton(int id, wstring path, wstring tooltip, int flags, THUMBBUTTON* button) { Bitmap* bitmap = NULL; HRESULT hr = LoadImageFromFile(path, &bitmap); if (!SUCCEEDED(hr)) return hr; button->dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS; button->iId = id; bitmap->GetHICON(&button->hIcon); wcscpy_s((wchar_t *)&button->szTip, 260, tooltip.c_str()); button->dwFlags = (THUMBBUTTONFLAGS)flags; delete bitmap; return S_OK; }
/************************************* * Overlay *************************************/ STDMETHODIMP CTaskbar7::SetOverlayIcon(BSTR path, BSTR description) { if (!m_pTaskbarList || m_parentHwnd == NULL) return S_OK; USES_CONVERSION; wstring image(OLE2W(path)); wstring desc(OLE2W(description)); // if no path is given, we remove the overlay if (image.empty()) { if (m_isWindows7) return m_pTaskbarList->SetOverlayIcon(m_parentHwnd, NULL, L""); return S_OK; } Bitmap* bitmap = NULL; HRESULT hr = LoadImageFromFile(image, &bitmap); if (!SUCCEEDED(hr)) return hr; // Do nothing on XP & Vista if (!m_isWindows7) { delete bitmap; return S_OK; } HICON pIcon; bitmap->GetHICON(&pIcon); // Sets the overlay icon hr = m_pTaskbarList->SetOverlayIcon(m_parentHwnd, pIcon, desc.c_str()); DestroyIcon(pIcon); delete bitmap; return hr; }
void RectCutCMPT::OnLoadEditOP(wxCommandEvent& event) { wxFileDialog dlg(this, wxT("Open"), wxEmptyString, wxEmptyString, wxT("*_") + FILTER + wxT(".json"), wxFD_OPEN); if (dlg.ShowModal() == wxID_OK) { std::string filename = ee::FileHelper::GetFilenameAddTag(dlg.GetPath().ToStdString(), FILTER, "json"); Json::Value value; Json::Reader reader; std::locale::global(std::locale("")); std::ifstream fin(filename.c_str()); std::locale::global(std::locale("C")); reader.parse(fin, value); fin.close(); auto op = std::dynamic_pointer_cast<RectCutOP>(m_editop); sm::vec2 center; center.x = value["center"]["x"].asDouble(); center.y = value["center"]["y"].asDouble(); op->SetCenter(center); int i = 0; Json::Value val = value["part_rect"][i++]; while (!val.isNull()) { sm::rect r; r.xmin = static_cast<float>(val["xmin"].asDouble()); r.xmax = static_cast<float>(val["xmax"].asDouble()); r.ymin = static_cast<float>(val["ymin"].asDouble()); r.ymax = static_cast<float>(val["ymax"].asDouble()); m_part_rects.push_back(r); val = value["part_rect"][i++]; } std::string dlgpath = ee::FileHelper::GetFileDir(filename); std::string path = value["image filepath"].asString(); std::string absolutePath = ee::FileHelper::GetAbsolutePath(dlgpath, path); op->LoadImageFromFile(absolutePath); op->GetRectMgr().Load(value); } }
// Apple provides both stream and file loading functions in ImageIO. // Potentially, Apple can optimize for either case. SDL_Surface* IMG_Load(const char *file) { SDL_Surface* sdl_surface = NULL; sdl_surface = LoadImageFromFile(file); if(NULL == sdl_surface) { // Either the file doesn't exist or ImageIO doesn't understand the format. // For the latter case, fallback to the native SDL_image handlers. SDL_RWops *src = SDL_RWFromFile(file, "rb"); char *ext = strrchr(file, '.'); if(ext) { ext++; } if(!src) { /* The error message has been set in SDL_RWFromFile */ return NULL; } sdl_surface = IMG_LoadTyped_RW(src, 1, ext); } return sdl_surface; }
BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { const int INIT_ALPHA = 200;//窗口初始化alpha值 RECT rcDialog; HBITMAP hBitmap; static BITMAP s_bm; static HDC s_hdcMem; static HBRUSH s_hBitmapBrush;//位图画刷 static bool isReturnBrush = false; static bool needAlphaBlend = false; static bool isLayered = true; switch (message) { case WM_INITDIALOG: SetWindowText(hDlg, szDialogTitle); // 设置对话框大小可调节,需要设置MAXIZEBOX,MINSIZEBOX才有用 SetWindowLong(hDlg, GWL_STYLE, GetWindowLong(hDlg, GWL_STYLE) | WS_SIZEBOX); //SetWindowLong(hDlg, GWL_STYLE, GetWindowLong(hDlg, GWL_STYLE) & ~WS_CAPTION); // 加载背景图片 // LoadImage支持bmp,ico,cursor,LR_MONOCHROME会变为黑白 //hBitmap = (HBITMAP)LoadImage(NULL, L"test4.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); // 相对路径,调试时,当前目录是工程目录而不是debug目录,所以图片要放在工程所在目录下 hBitmap = LoadImageFromFile(L"0.png", needAlphaBlend); if (isLayered) { isReturnBrush = !(needAlphaBlend = false); // 注意是设置GWL_EXSTYLE而不是GWL_STYLE SetWindowLong(hDlg, GWL_EXSTYLE, GetWindowLong(hDlg, GWL_STYLE) | WS_EX_LAYERED); // 设置透明度 0 - completely transparent 255 - opaque,可设置半透明 SetLayeredWindowAttributes(hDlg, 0, INIT_ALPHA, LWA_ALPHA); // 设置透明底色,颜色为指定色的像素变成全透明,其他颜色不透明 //SetLayeredWindowAttributes(hDlg, RGB(0 , 0 , 0), 0, LWA_COLORKEY); // 设置滑块条变化范围 SendMessage(GetDlgItem(hDlg, IDC_SLIDER1), TBM_SETRANGE, (WPARAM)FALSE, MAKELONG(0, 255)); // 设置滑块条初始位置 SendMessage(GetDlgItem(hDlg, IDC_SLIDER1), TBM_SETPOS, (WPARAM)TRUE, INIT_ALPHA); } if (hBitmap == NULL) { MessageBox(hDlg, L"LoadImage failed", L"Error", MB_ICONERROR); exit(0); } else { if (!isReturnBrush) { // 将背景图片放入HDC HDC hdc; //获取当前对话框dc hdc = GetDC(hDlg); // 创建dc相关的内存dc s_hdcMem = CreateCompatibleDC(hdc); //把位图选择到兼容DC,之后这个兼容DC就拥有和hBitmap同样大小的绘图区域,超出位图返回的GDI输出都是无效的. //选择位图到内存dc,下一步再复制到窗口客户区dc SelectObject(s_hdcMem, hBitmap); ReleaseDC(hDlg, hdc); //通过位图句柄获取获取位图的大小等信息,位图大小事实上也是兼容DC绘图输出的范围 GetObject(hBitmap, sizeof(s_bm), &s_bm); } } if (isReturnBrush) { // 创建位图画刷 s_hBitmapBrush = CreatePatternBrush(hBitmap); } return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: DeleteDC(s_hdcMem); EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case WM_SIZE: InvalidateRect(hDlg, NULL, TRUE); return TRUE; case WM_HSCROLL: { int nTransparent = SendMessage(GetDlgItem(hDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0); SetLayeredWindowAttributes(hDlg, 0, nTransparent, LWA_ALPHA);//也会使颜色变暗 } break; case WM_QUERYNEWPALETTE: return FALSE; break; case WM_CTLCOLORDLG: //needAlphaBlend = false; if (needAlphaBlend)//对位图进行alpha操作然后显示,否则用bitBlt对于有alpha通道的位图来说只是透明度为0的部分只会是一片黑色 { static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) ::GetProcAddress(::GetModuleHandle(L"msimg32.dll"), "AlphaBlend"); if (lpAlphaBlend == NULL) lpAlphaBlend = AlphaBitBlt; static BLENDFUNCTION ftn = { 0 }; ftn.BlendOp = AC_SRC_OVER; ftn.AlphaFormat = AC_SRC_ALPHA; ftn.BlendFlags = 0; ftn.SourceConstantAlpha = 255;//整体透明度,与原位图进行alpha合成操作,使原本不透明的变为透明 GetClientRect(hDlg, &rcDialog); lpAlphaBlend((HDC)wParam, 0, 0, rcDialog.right, rcDialog.bottom, s_hdcMem, 0, 0, s_bm.bmWidth, s_bm.bmHeight, ftn); return (BOOL)((HBRUSH)GetStockObject(NULL_BRUSH)); } else { if (!isReturnBrush) { GetClientRect(hDlg, &rcDialog); //通过SetStretchBltMode的设置能使StrechBlt在缩放图像更加清晰 SetStretchBltMode((HDC)wParam, HALFTONE); //SetStretchBltMode((HDC)wParam, COLORONCOLOR); //复制内存dc到dc,StretchBlt会自动拉伸缩放 StretchBlt((HDC)wParam, 0, 0, rcDialog.right, rcDialog.bottom, s_hdcMem, 0, 0, s_bm.bmWidth, s_bm.bmHeight, SRCCOPY); return (BOOL)((HBRUSH)GetStockObject(NULL_BRUSH)); } if (isReturnBrush) return (BOOL)s_hBitmapBrush; } } return FALSE; }
cgID cgGdiplusRender::LoadImage( LPCTSTR path ) { return m_kImageStorage.Add( LoadImageFromFile(path)); }
void CTracer::RenderImage(Params & params) { // Reading input texture sample CImage* pImage = LoadImageFromFile("data/disk_32.png"); if (!pImage) { std::cout << "Received NULL pointer when loading texture. Probably wrong file." << std::endl; return; } saved_images.push_back(pImage); image_shapes.push_back(img_shape(0)); // Reading background (stars) texture CImage* stars = LoadImageFromFile("data/stars.jpg"); if (!stars) { std::cout << "Received NULL pointer when loading texture. Probably wrong file." << std::endl; return; } saved_images.push_back(stars); image_shapes.push_back(img_shape(1)); // Filling in properties m_camera.m_resolution = glm::uvec2(params.xRes, params.yRes); m_camera.m_pixels.resize(params.xRes * params.yRes); m_camera.m_pos = params.camera_pos; params.up /= glm::length(params.up); params.up *= params.yRes; m_camera.m_up = params.up; params.right /= glm::length(params.right); params.right *= params.xRes; m_camera.m_right = params.right; params.view_dir /= glm::length(params.view_dir); params.view_dir *= params.yRes / (2.0 * tan(params.view_angle.y / 2.0)); m_camera.m_forward = params.view_dir; m_camera.m_viewAngle = params.view_angle; double black_hole_radius = 2 * grav_const * params.black_hole_mass / light_speed / light_speed; black_hole.center = glm::dvec3(0, 0, 0); black_hole.radius = black_hole_radius; black_hole.mass = params.black_hole_mass; // setting disk params disk.center = glm::dvec3(0, 0, 0); disk.in_rad = black_hole_radius; disk.out_rad = black_hole_radius * params.disk_bh_rad_ratio; disk.normal = glm::vec3(0, 0, 1); for (int i = 0; i < 2; ++i) { planet_enable[i] = params.planet_enable[i]; planets[i].center = params.planet_center[i]; planets[i].radius = params.planet_rad[i]; planet_colors[i] = params.planet_color[i]; } alpha_blending_enable = params.alpha_blending_enable; antialiasing_rays = params.antialiasing_rays; // Rendering double gap, x_shift, y_shift; glm::vec3 rays_accum(0, 0, 0); SRay ray; for (int i = 0; i < params.yRes; i++) { for (int j = 0; j < params.xRes; j++) { rays_accum.r = rays_accum.b = rays_accum.g = 0; x_shift = y_shift = gap = 1.0 / (antialiasing_rays + 1); for (int x_rays = 0; x_rays < antialiasing_rays; ++x_rays, x_shift += gap) { for (int y_rays = 0; y_rays < antialiasing_rays; ++y_rays, y_shift += gap) { ray = MakeRay(glm::uvec2(j, i), x_shift, y_shift); rays_accum += TraceRay(ray); } } rays_accum /= (antialiasing_rays * antialiasing_rays); m_camera.m_pixels[i * params.xRes + j] = rays_accum; //m_camera.m_pixels[i * params.xRes + j] = rgb_cut(img_get_pxl_rgba(1, i, j)) / 255.0f; } } }
UIImage* UIDirect3D9Window::DrawText(UIEffect *Effect, QRectF *Dest, bool &PositionChanged, const QString &Text, UIFont *Font, int Flags, int Blur, UIImage *Fallback) { if (!Font->GetImageReady()) { // font is image backed QString file = Font->GetImageFileName(); UIImage *image = Font->GetImage(); // allocate an image if (!image) { QString name = Font->GetHash() + file; QSize size(Dest->size().width(), Dest->size().height()); image = AllocateImage(name, size, file); Font->SetImage(image); } if (!image) { LOG(VB_GENERAL, LOG_ERR, QString("Failed to load '%1' text image.") .arg(file)); // don't try again Font->SetImageReady(true); return NULL; } UIImage::ImageState state = image->GetState(); if (state == UIImage::ImageUploadedToGPU || state == UIImage::ImageReleasedFromGPU) { LOG(VB_GENERAL, LOG_ERR, "Font image cannot be unloaded from memory"); Font->SetImageReady(true); return NULL; } if (state == UIImage::ImageLoading) return NULL; // trigger loading if (state == UIImage::ImageNull) { LoadImageFromFile(image); return NULL; } // update the font's brush Font->UpdateTexture(); } UIImage* image = GetSimpleTextImage(Text, Dest, Font, Flags, Blur); if (!image) return NULL; if ((image->GetState() == UIImage::ImageLoading) && Fallback) image = Fallback; DrawImage(Effect, Dest, PositionChanged, image); return image; }
CTexture::CTexture(char* pNamePath, D3DCOLOR color, LPDIRECT3DDEVICE9 device) { this->_pNamePath = pNamePath; LoadImageFromFile(_pNamePath, color, device); }
CTexture::CTexture(char* pNamePath, D3DCOLOR color) { this->_pNamePath = pNamePath; LoadImageFromFile(_pNamePath, color); }