Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginRAW.cpp view on Meta::CPAN
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "../LibRawLite/libraw/libraw.h"
#include "FreeImage.h"
#include "Utilities.h"
#include "../Metadata/FreeImageTag.h"
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ==========================================================
// Internal functions
// ==========================================================
// ----------------------------------------------------------
// FreeImage datastream wrapper
// ----------------------------------------------------------
class LibRaw_freeimage_datastream : public LibRaw_abstract_datastream {
private:
FreeImageIO *_io;
fi_handle _handle;
long _eof;
INT64 _fsize;
public:
LibRaw_freeimage_datastream(FreeImageIO *io, fi_handle handle) : _io(io), _handle(handle) {
long start_pos = io->tell_proc(handle);
io->seek_proc(handle, 0, SEEK_END);
_eof = io->tell_proc(handle);
_fsize = _eof - start_pos;
io->seek_proc(handle, start_pos, SEEK_SET);
}
~LibRaw_freeimage_datastream() {
}
int valid() {
return (_io && _handle);
}
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);
}
int seek(INT64 offset, int origin) {
if(substream) return substream->seek(offset, origin);
return _io->seek_proc(_handle, (long)offset, origin);
}
INT64 tell() {
if(substream) return substream->tell();
return _io->tell_proc(_handle);
}
INT64 size() {
return _fsize;
}
int get_char() {
int c = 0;
if(substream) return substream->get_char();
if(!_io->read_proc(&c, 1, 1, _handle)) return -1;
return c;
}
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;
}
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);
}
int eof() {
if(substream) return substream->eof();
return (_io->tell_proc(_handle) >= _eof);
}
( run in 0.678 second using v1.01-cache-2.11-cpan-5623c5533a1 )