bool Image::loadFromBuffer(uint8_t* buf, size_t len) { clearData(); size_t pixelsByteLen = 0; if (isPNG(buf)) { pixels = pixels_from_png(buf, len, pixelsByteLen, width, height); __BGRA = true; } else if (isJPEG(buf)) { pixels = pixels_from_jpeg(buf, len, pixelsByteLen, width, height); __BGRA = false; } if (pixels && pixelsByteLen) { _surface = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32, width, height, 4 * width); cairo_surface_flush(_surface); } cairo_status_t status = cairo_surface_status(_surface); if (status == CAIRO_STATUS_SUCCESS) { naturalWidth = width = cairo_image_surface_get_width(_surface); naturalHeight = height = cairo_image_surface_get_height(_surface); } return (status == CAIRO_STATUS_SUCCESS); }
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; }
BitmapData::Format BitmapData::checkImageFormat(const unsigned char *data, ssize_t size) { if (isPNG(data, size)) { return Format::PNG; } else if (isJPG(data, size)) { return Format::JPG; } else { return Format::UNKOWN; } return Format::UNKOWN; }
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 << "!"); }
int ReadDir(const char *dir) { int file_count = 0; int temp = 0; struct dirent* ptr; DIR* srcdir = opendir(dir); if (srcdir == NULL) { perror("opendir"); return -1; } while((ptr = readdir(srcdir)) != NULL) // traverse done { char* d_name; d_name = ptr -> d_name; printf("\n/////////////////////////START SCANNING//////////////////////////\n"); // Open catlog.csv file FILE* fp; char html_path[100] = {}; sprintf(html_path, "%s/%s/%s", getcwd(NULL, 0), inputdir, "catlog.csv"); fp = fopen(html_path, "w"); // Open directory if (ptr -> d_type & DT_DIR) // check whether it is a directory { if(strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { char path[100]; sprintf(path, "%s/%s", dir, d_name); temp = ReadDir(path); file_count += temp; } }else{ // Check if the type matchs if (isPNG(d_name) || isGIF(d_name) || isTIFF(d_name)){ fseek(fp, 0L, SEEK_END); int sz = ftell(fp); fseek(fp, 0L, SEEK_SET); fprintf(fp, }else{ printf("The file is not png/gif/tiff file, skipped it.\n"); } }
bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf) { #ifdef USE_PNG if (isPNG(vf)) { return _loadPNGState(gba, vf); } #endif if (vf->size(vf) < (ssize_t) sizeof(struct GBASerializedState)) { return false; } struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); if (!state) { return false; } bool success = GBADeserialize(gba, state); vf->unmap(vf, state, sizeof(struct GBASerializedState)); return success; }
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; }
bool Image::loadSupportedFormat(const char* path_) { const char *verifiedPath = MediaPathManager::lookUpMediaPath(path_); if (!verifiedPath) return false; path = verifiedPath; if (isPNG(verifiedPath)) return loadPNG(verifiedPath, this); if (isJPEG(verifiedPath)) return loadJPG(verifiedPath); if (isTGA(verifiedPath)) return loadTGA(verifiedPath); if (isDDS(verifiedPath)) return loadDDS(verifiedPath); return false; }
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; }