int getPallet(PALLET* pal, FILE* fp) { if (getHeader(&pal->header, fp) == 0) return 3; if (isBMP(&pal->header) == 0) return 4; if (getInfo(pal, fp) == 0) return 5; if (getColors(pal, fp) == 0) return 6; return 0; }
EXPORT BOOL WINAPI mhsp_SWFBitmap_buf(HSPEXINFO *hei, int p2, int p3, int p4) { unsigned char *buf, *buf2; int size, size2; SWFInput input; SWFBitmap *p1; lstrcpy(funcname, "SWFBitmap_buf"); p1 = (SWFBitmap *)hei->HspFunc_prm_getv(); buf = (unsigned char *)hei->HspFunc_prm_getv(); size = hei->HspFunc_prm_geti(); buf2 = (unsigned char *)hei->HspFunc_prm_getv(); size2 = hei->HspFunc_prm_getdi(0); input = newSWFInput_allocedBuffer(buf, size); if (size2 && isJPEG(input)) { SWFInput_seek(input, 0, SEEK_SET); *p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input, newSWFInput_allocedBuffer(buf2, size2)); } #ifdef JAMING else if (isDBL(input) || isJPEG(input)) #else else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input)) #endif { SWFInput_seek(input, 0, SEEK_SET); *p1 = newSWFBitmap_fromInput(newSWFInput_allocedBuffer(buf, size)); } else { return -1; } if (!mhsp_bitmap) { mhsp_bitmap = *p1; } return 0; }
Image::Image(unsigned char * _pixels, unsigned int w, unsigned int h, std::string extension) : pixels(_pixels), width(w), height(h), loaded(true){ std::string generateName = GENERATED_MANUALLY; generateName += "."; generateName += extension; path = generateName; ASSERT(isBMP() || isPNG(), "Invalid extension " << extension << "!"); }
ImageType getImageType(const std::string& FileName) { FILE *file_image = fopen(FileName.c_str(), "rb"); if (!file_image) { //file could not be opened for reading return itUnknown; } unsigned char header[8]; memset(header, 0, 8); //read first eight bytes if (fread(header, 1, 8, file_image)!=8) { //file is not long enough to be a proper image file fclose(file_image); return itUnknown; } fclose(file_image); if (isJPEG(header, 8)) { return itJPEG; } if (isPNG(header, 8)) { return itPNG; } if (isGIF(header, 8)) { return itGIF; } if (isPPM(header, 8)) { return itPPM; } if (isBMP(header, 8)) { return itBitmap; } return itUnknown; }
EXPORT BOOL WINAPI mhsp_SWFBitmap(HSPEXINFO *hei, int p2, int p3, int p4) { FILE *fp1, *fp2; char filename[MHSP_STRMAX], alpha[MHSP_STRMAX]; SWFInput input; SWFBitmap *p1; lstrcpy(funcname, "SWFBitmap"); p1 = (SWFBitmap *)hei->HspFunc_prm_getv(); lstrcpyn(filename, hei->HspFunc_prm_gets(), MHSP_STRMAX); lstrcpyn(alpha, hei->HspFunc_prm_getds(""), MHSP_STRMAX); fp1 = fopen(filename, "rb"); if (!fp1) { return 1; } input = newSWFInput_file(fp1); fp2 = fopen(alpha, "rb"); if (fp2 && isJPEG(input)) { SWFInput_seek(input, 0, SEEK_SET); *p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input, newSWFInput_file(fp2)); } #ifdef JAMING else if (isDBL(input) || isJPEG(input)) #else else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input)) #endif { SWFInput_seek(input, 0, SEEK_SET); *p1 = newSWFBitmap_fromInput(input); } else { return -1; /* 非対応フォーマット */ } if (!mhsp_bitmap) { mhsp_bitmap = *p1; } return 0; }
void Gosu::loadImageFile(Gosu::Bitmap& bitmap, Reader input) { bool needsColorKey = isBMP(input); stbi_io_callbacks callbacks; callbacks.read = readCallback; callbacks.skip = skipCallback; callbacks.eof = eofCallback; int x, y, n; stbi_uc* bytes = stbi_load_from_callbacks(&callbacks, &input, &x, &y, &n, STBI_rgb_alpha); if (bytes == 0) { // TODO - stbi_failure_reason is not thread safe. Everything here should be wrapped in a mutex. throw std::runtime_error("Cannot load image: " + std::string(stbi_failure_reason())); } bitmap.resize(x, y); std::memcpy(bitmap.data(), bytes, x * y * sizeof(Gosu::Color)); stbi_image_free(bytes); if (needsColorKey) applyColorKey(bitmap, Gosu::Color::FUCHSIA); }