int imFileFormatPFM::Open(const char* file_name) { unsigned char sig[2]; /* opens the binary file for reading */ handle = imBinFileOpen(file_name); if (!handle) return IM_ERR_OPEN; /* reads the PFM format identifier */ imBinFileRead(handle, sig, 2, 1); if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } if (sig[0] != 'P' || (sig[1] != 'f' && sig[1] != 'F')) { imBinFileClose(handle); return IM_ERR_FORMAT; } this->image_type = sig[1]; // 'F' means color, 'f' means grayscale this->image_count = 1; strcpy(this->compression, "NONE"); return IM_ERR_NONE; }
jas_stream_t *jas_binfile_open(const char *file_name, int is_new) { void* handle; jas_stream_t *stream; if (is_new) handle = (void*)imBinFileNew(file_name); else handle = (void*)imBinFileOpen(file_name); if (!handle) return 0; /* Allocate a stream object. */ stream = jas_stream_create(); if (is_new) stream->openmode_ = JAS_STREAM_WRITE | JAS_STREAM_CREATE | JAS_STREAM_BINARY; else stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_BINARY; /* Select the operations for a file stream object. */ stream->ops_ = &jas_stream_fileops; stream->obj_ = handle; /* By default, use full buffering for this type of stream. */ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); return stream; }
unsigned long FileSize(const char* file_name) { imBinFile* bfile = imBinFileOpen(file_name); if (!bfile) return 0; unsigned long file_size = imBinFileSize(bfile); imBinFileClose(bfile); return file_size; }
int imFileFormatLED::Open(const char* file_name) { char sig[4]; unsigned char byte_value; int found = 0; /* opens the binary file for reading */ handle = imBinFileOpen(file_name); if (!handle) return IM_ERR_OPEN; this->image_count = 1; strcpy(this->compression, "NONE"); imBinFileRead(handle, sig, 3, 1); sig[3] = 0; if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } if (!imStrEqual(sig, "LED")) { imBinFileClose(handle); return IM_ERR_FORMAT; } unsigned long offset = imBinFileTell(handle); /* count the number of colors */ this->pal_count = -1; // will count the first '=' that is not a color while (!found) { imBinFileRead(handle, &byte_value, 1, 1); if (byte_value == '(') found = 1; if (byte_value == '=') this->pal_count++; if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } } imBinFileSeekTo(handle, offset); return IM_ERR_NONE; }
int imFileFormatRAW::Open(const char* file_name) { this->handle = imBinFileOpen(file_name); if (this->handle == NULL) return IM_ERR_OPEN; strcpy(this->compression, "NONE"); this->image_count = 1; /* at least one image */ this->padding = 0; return IM_ERR_NONE; }
int imFileFormatJPEG::Open(const char* file_name) { this->handle = imBinFileOpen(file_name); if (this->handle == NULL) return IM_ERR_OPEN; unsigned char sig[2]; if (!imBinFileRead(this->handle, sig, 2, 1)) { imBinFileClose(this->handle); return IM_ERR_ACCESS; } if (sig[0] != 0xFF || sig[1] != 0xD8) { imBinFileClose(this->handle); return IM_ERR_FORMAT; } imBinFileSeekTo(this->handle, 0); strcpy(this->compression, "JPEG"); this->image_count = 1; this->dinfo.err = jpeg_std_error(&this->jerr.pub); this->jerr.pub.error_exit = JPEGerror_exit; this->jerr.pub.output_message = JPEGoutput_message; this->jerr.pub.emit_message = JPEGemit_message; /* Establish the setjmp return context for error_exit to use. */ if (setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ jpeg_destroy_decompress(&this->dinfo); imBinFileClose(this->handle); return IM_ERR_FORMAT; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress(&this->dinfo); /* Step 2: specify data source (eg, a file) */ jpeg_stdio_src(&this->dinfo, (FILE*)this->handle); return IM_ERR_NONE; }
int imFileFormatRAS::Open(const char* file_name) { unsigned int dword_value; /* opens the binary file for reading with motorola byte order */ handle = imBinFileOpen(file_name); if (!handle) return IM_ERR_OPEN; imBinFileByteOrder(handle, IM_BIGENDIAN); /* reads the RAS format identifier */ imBinFileRead(handle, &dword_value, 1, 4); if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } if (dword_value != RAS_ID) { imBinFileClose(handle); return IM_ERR_FORMAT; } /* reads the compression information */ imBinFileSeekOffset(handle, 16); imBinFileRead(handle, &this->comp_type, 1, 4); if (this->comp_type == RAS_BYTE_ENCODED) strcpy(this->compression, "RLE"); else if (this->comp_type == RAS_OLD || this->comp_type == RAS_STANDARD) strcpy(this->compression, "NONE"); else { imBinFileClose(handle); return IM_ERR_COMPRESS; } imBinFileSeekOffset(handle, -20); this->image_count = 1; return IM_ERR_NONE; }
int imFileFormatSGI::Open(const char* file_name) { unsigned short word_value; /* opens the binary file for reading with motorola byte order */ handle = imBinFileOpen(file_name); if (!handle) return IM_ERR_OPEN; imBinFileByteOrder(handle, IM_BIGENDIAN); /* reads the SGI format identifier */ imBinFileRead(handle, &word_value, 1, 2); if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } if (word_value != SGI_ID) { imBinFileClose(handle); return IM_ERR_FORMAT; } /* reads the compression information */ imBinFileRead(handle, &this->comp_type, 1, 1); if (this->comp_type == SGI_RLE) strcpy(this->compression, "RLE"); else if (this->comp_type == SGI_VERBATIM) strcpy(this->compression, "NONE"); else { imBinFileClose(handle); return IM_ERR_COMPRESS; } this->starttab = NULL; this->lengthtab = NULL; this->image_count = 1; return IM_ERR_NONE; }
int imFileFormatBMP::Open(const char* file_name) { unsigned short id; unsigned int dword; /* opens the binary file for reading with intel byte order */ handle = imBinFileOpen(file_name); if (!handle) return IM_ERR_OPEN; imBinFileByteOrder(handle, IM_LITTLEENDIAN); /* reads the BMP format identifier */ imBinFileRead(handle, &id, 1, 2); if (imBinFileError(handle)) { imBinFileClose(handle); return IM_ERR_ACCESS; } if (id != BMP_ID) { imBinFileClose(handle); return IM_ERR_FORMAT; } /* jump 8 bytes (file size,reserved) */ imBinFileSeekOffset(handle, 8); /* reads the image offset */ imBinFileRead(handle, &this->offset, 1, 4); /* reads the header size */ imBinFileRead(handle, &dword, 1, 4); if (dword == 40) this->is_os2 = 0; else if (dword == 12) this->is_os2 = 1; else { imBinFileClose(handle); return IM_ERR_FORMAT; } this->image_count = 1; /* reads the compression information */ if (this->is_os2) { this->comp_type = BMP_COMPRESS_RGB; strcpy(this->compression, "NONE"); } else { imBinFileSeekOffset(handle, 12); imBinFileRead(handle, &this->comp_type, 1, 4); switch (this->comp_type) { case BMP_COMPRESS_RGB: strcpy(this->compression, "NONE"); break; case BMP_COMPRESS_RLE8: strcpy(this->compression, "RLE"); break; case BMP_COMPRESS_RLE4: default: imBinFileClose(handle); return IM_ERR_COMPRESS; } imBinFileSeekOffset(handle, -16); } return IM_ERR_NONE; }