int scanf_one(const char *fmt, void* val) { std::string buffer; char element = 0; bool bDone = false; if(substream) return substream->scanf_one(fmt,val); do { if(_io->read_proc(&element, 1, 1, _handle) == 1) { switch(element) { case '0': case '\n': case ' ': case '\t': bDone = true; break; default: break; } buffer.append(&element, 1); } else { return 0; } } while(!bDone); return sscanf(buffer.c_str(), fmt, val); }
/** Writes data to a memory stream. @param buffer Pointer to data to be written @param size Item size in bytes @param count Maximum number of items to be written @param stream Pointer to FIMEMORY structure @return Returns the number of full items actually written, which may be less than count if an error occurs */ unsigned DLL_CALLCONV FreeImage_WriteMemory(const void *buffer, unsigned size, unsigned count, FIMEMORY *stream) { if (stream != NULL) { FreeImageIO io; SetMemoryIO(&io); FIMEMORYHEADER *mem_header = (FIMEMORYHEADER*)(((FIMEMORY*)stream)->data); if(mem_header->delete_me == TRUE) { return io.write_proc((void *)buffer, size, count, stream); } else { // do not write in a user buffer FreeImage_OutputMessageProc(FIF_UNKNOWN, "Memory buffer is read only"); } } return 0; }
BOOL DLL_CALLCONV FreeImage_Validate(FREE_IMAGE_FORMAT fif, FreeImageIO &io, fi_handle handle) { if (s_plugins != NULL) { BOOL validated = FALSE; PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node) { long tell = io.tell_proc(handle); validated = (node != NULL) ? (node->m_enabled) ? (node->m_plugin->validate_proc != NULL) ? node->m_plugin->validate_proc(io, handle) : FALSE : FALSE : FALSE; io.seek_proc(handle, tell, SEEK_SET); } return validated; } return FALSE; }
virtual char* gets(char *buffer, int length) { if (substream) return substream->gets(buffer, length); memset(buffer, 0, length); for(int i = 0; i < length; i++) { if(!_io->read_proc(&buffer[i], 1, 1, _handle)) return NULL; if(buffer[i] == 0x0A) break; } return buffer; }
virtual INT64 tell() { if(substream) return substream->tell(); return _io->tell_proc(_handle); }
virtual int seek(INT64 offset, int origin) { if(substream) return substream->seek(offset, origin); return _io->seek_proc(_handle, (long)offset, origin); }
virtual int eof() { if(substream) return substream->eof(); return (_io->tell_proc(_handle) >= _eof); }
virtual int read(void *buffer, size_t size, size_t count) { if(substream) return substream->read(buffer, size, count); return _io->read_proc(buffer, (unsigned)size, (unsigned)count, _handle); }
void C_OStream::write (const char c[/*n*/], int n) { if((unsigned)n != _io->write_proc((void*)&c[0], 1, n, _handle)) { Iex::throwErrnoExc(); } }
void C_IStream::seekg (Imf::Int64 pos) { _io->seek_proc(_handle, (unsigned)pos, SEEK_SET); }
virtual Imath::Int64 tellg() { return _io->tell_proc(_handle); }
bool C_IStream::read (char c[/*n*/], int n) { return ((unsigned)n != _io->read_proc(c, 1, n, _handle)); }
static WORD readline(FreeImageIO &io, fi_handle handle, BYTE *buffer, WORD length, BOOL rle, BYTE * ReadBuf, int * ReadPos) { // -----------------------------------------------------------// // Read either run-length encoded or normal image data // // // // THIS IS HOW RUNTIME LENGTH ENCODING WORKS IN PCX: // // // // 1) If the upper 2 bits of a byte are set, // // the lower 6 bits specify the count for the next byte // // // // 2) If the upper 2 bits of the byte are clear, // // the byte is actual data with a count of 1 // // // // Note that a scanline always has an even number of bytes // // ------------------------------------------------------------- BYTE count = 0, value = 0; WORD written = 0; if (rle) { // run-length encoded read while (length--) { if (count == 0) { if (*ReadPos >= IO_BUF_SIZE - 1 ) { if (*ReadPos == IO_BUF_SIZE - 1) { // we still have one BYTE, copy it to the start pos *ReadBuf = ReadBuf[IO_BUF_SIZE - 1]; io.read_proc(ReadBuf + 1, 1, IO_BUF_SIZE - 1, handle); } else { // read the complete buffer io.read_proc(ReadBuf, 1, IO_BUF_SIZE, handle); } *ReadPos = 0; } value = *(ReadBuf + (*ReadPos)++); if ((value & 0xC0) == 0xC0) { count = value & 0x3F; value = *(ReadBuf + (*ReadPos)++); // $JR } else { count = 1; } } count--; *(buffer + written++) = value; } } else { // normal read written = (WORD)io.read_proc(buffer, length, 1, handle); } return written; }
virtual void seekg(Imath::Int64 pos) { _io->seek_proc(_handle, (unsigned)pos, SEEK_SET); }
virtual int get_char() { int c = 0; if(substream) return substream->get_char(); if(!_io->read_proc(&c, 1, 1, _handle)) return -1; return c; }
Imf::Int64 C_IStream::tellg () { return _io->tell_proc(_handle); }
virtual bool read (char c[/*n*/], int n) { return ((unsigned)n != _io->read_proc(c, 1, n, _handle)); }