bool Gui_LoadScreenAssignPic(const char* pic_name) { size_t pic_len = strlen(pic_name); size_t base_len = strlen(Engine_GetBasePath()); size_t buf_len = pic_len + base_len + 5; char image_name_buf[buf_len]; int image_format = 0; strncpy(image_name_buf, Engine_GetBasePath(), buf_len); strncat(image_name_buf, pic_name, buf_len); if(pic_len > 3) { char *ext = image_name_buf + pic_len + base_len; if(strncpy(ext, ".png", 5) && Sys_FileFound(image_name_buf, 0)) { image_format = IMAGE_FORMAT_PNG; }else if(strncpy(ext, ".pcx", 5) && Sys_FileFound(image_name_buf, 0)) { image_format = IMAGE_FORMAT_PCX; } } uint8_t *img_pixels = NULL; uint32_t img_w = 0; uint32_t img_h = 0; uint32_t img_bpp = 32; if(Image_Load(image_name_buf, image_format, &img_pixels, &img_w, &img_h, &img_bpp)) { bool ret = Gui_SetScreenTexture(img_pixels, img_w, img_h, img_bpp); free(img_pixels); return ret; } return false; }
HBITMAP BmpFilterLoadBitmap(BOOL *bIsTransparent, const wchar_t *ptszFilename) { FIBITMAP *dib = (FIBITMAP*)Image_Load(ptszFilename, IMGL_RETURNDIB); if (dib == nullptr) return nullptr; FIBITMAP *dib32 = nullptr; if (FreeImage_GetBPP(dib) != 32) { dib32 = FreeImage_ConvertTo32Bits(dib); FreeImage_Unload(dib); } else dib32 = dib; if (dib32 == nullptr) return nullptr; if (FreeImage_IsTransparent(dib32)) if (bIsTransparent) *bIsTransparent = TRUE; if (FreeImage_GetWidth(dib32) > 128 || FreeImage_GetHeight(dib32) > 128) { FIBITMAP *dib_new = FreeImage_MakeThumbnail(dib32, 128, FALSE); FreeImage_Unload(dib32); if (dib_new == nullptr) return nullptr; dib32 = dib_new; } HBITMAP bitmap = FreeImage_CreateHBITMAPFromDIB(dib32); FreeImage_Unload(dib32); FreeImage_CorrectBitmap32Alpha(bitmap, FALSE); return bitmap; }
Expr *MakeImageMapFunc(void (*fn)(Expr *)) { Expr *expr = NULL; TOKEN *fntoken = cur_token; Image *img = NULL; token = GetToken(); if(token == OP_LPAREN) { /* Get the quoted file name and first comma... */ if((token = GetToken()) == TK_QUOTESTRING) { FILE *fp; /* Open the file... */ if((fp = SCN_FindFile(token_buffer, READBIN, scn_include_paths, SCN_FINDFILE_CHK_CUR_FIRST)) != NULL) { /* Load the image... */ img = Image_Load(fp, token_buffer); fclose(fp); if(img == NULL) { LogError("Unable to load image file: %s", token_buffer); PrintFileAndLineNumber(); } } else { LogError("Unable to open image file: %s", token_buffer); PrintFileAndLineNumber(); } } else ErrUnknown(token, "expecting image file name", "expression syntax"); /* Eat the first comma... */ if((token = GetToken()) != OP_COMMA) ErrUnknown(token, ",", "expression syntax"); /* Get the U, V expressions and finish. */ token = GetToken(); expr = Term0(); if(token == OP_RPAREN) { CheckParamCount(expr, fntoken->name, 2); token = GetToken(); if(expr != NULL) { expr->data = img; expr->fn = fn; expr->isvec = 1; } } else ErrUnknown(token, ")", "expression syntax"); } else ErrUnknown(token, "(", "expression syntax"); return expr; }