Added support to quick thumbnail code to load PPM embedded thumbnails.

This commit is contained in:
Steve Herrell
2010-12-01 20:04:29 -05:00
parent ecef42b4c1
commit ab777634db
6 changed files with 83 additions and 5 deletions

View File

@@ -476,6 +476,31 @@ int ImageIO::loadTIFF (Glib::ustring fname) {
return IMIO_SUCCESS;
}
int ImageIO::loadPPMFromMemory(const char* buffer, int width, int height, bool swap, int bps)
{
allocate (width, height);
int line_length(width * 3 * (bps/8));
if ( swap && bps > 8 )
{
char swapped[line_length];
for ( int row = 0; row < height; ++row )
{
::swab(((char*)buffer) + (row * line_length),swapped,line_length);
setScanline(row,(unsigned char*)&swapped[0],bps);
}
}
else
{
for ( int row = 0; row < height; ++row )
{
setScanline(row,((unsigned char*)buffer) + (row * line_length),bps);
}
}
return IMIO_SUCCESS;
}
int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {

View File

@@ -73,6 +73,7 @@ class ImageIO {
int loadTIFF (Glib::ustring fname);
int loadJPEGFromMemory (const char* buffer, int bufsize);
int loadPPMFromMemory(const char* buffer,int width,int height, bool swap, int bps);
int savePNG (Glib::ustring fname, int compression = -1, int bps = -1);
int saveJPEG (Glib::ustring fname, int quality = 100);

View File

@@ -8,6 +8,11 @@
#include <settings.h>
#include <colortemp.h>
#include <utils.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
namespace rtengine{
@@ -242,4 +247,19 @@ unsigned short** RawImage::compress_image()
return data;
}
bool
RawImage::is_supportedThumb() const
{
return ( (thumb_width * thumb_height) > 0 &&
( write_thumb == &rtengine::RawImage::jpeg_thumb ||
write_thumb == &rtengine::RawImage::ppm_thumb ||
thumb_load_raw == &rtengine::RawImage::kodak_thumb_load_raw ));
}
bool
RawImage::get_thumbSwap() const
{
return ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) ? true : false;
}
}; //namespace rtengine

View File

@@ -88,7 +88,12 @@ public:
int get_profileLen() const {return profile_length;}
char* get_profile() const { return profile_data;}
IMFILE *get_file() { return ifp; }
bool is_supportedThumb() const ;
int get_thumbOffset(){ return int(thumb_offset);}
int get_thumbWidth(){ return int(thumb_width);}
int get_thumbHeight(){ return int(thumb_height);}
int get_thumbBPS(){ return thumb_load_raw ? 16 : 8; }
bool get_thumbSwap() const;
unsigned get_thumbLength(){ return thumb_length;}
public:
// dcraw functions

View File

@@ -49,9 +49,20 @@ my_jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile);
namespace rtengine {
Thumbnail* Thumbnail::loadFromMemory (const char* image, int length, int &w, int &h, int fixwh) {
Thumbnail* Thumbnail::loadFromMemory (const char* image, int length, int &w, int &h, int fixwh,
bool swap_order, int bps) {
Image16* img = new Image16 ();
int err = img->loadJPEGFromMemory(image,length);
int err = 1;
if ( (unsigned char)image[1] == 0xd8 )
{
err = img->loadJPEGFromMemory(image,length);
}
else
{
err = img->loadPPMFromMemory(image,w,h,swap_order,bps);
}
if (err) {
printf("loadfromMemory: error\n");
delete img;
@@ -201,16 +212,31 @@ Thumbnail* Thumbnail::loadQuickFromRaw (const Glib::ustring& fname, RawMetaDataL
{
RawImage *ri= new RawImage(fname);
int r = ri->loadRaw(false,false);
if( r ) return NULL;
if( r )
{
delete ri;
return NULL;
}
rml.exifBase = ri->get_exifBase();
rml.ciffBase = ri->get_ciffBase();
rml.ciffLength = ri->get_ciffLen();
Thumbnail* tpp = Thumbnail::loadFromMemory((const char*)fdata(ri->get_thumbOffset(),ri->get_file()),ri->get_thumbLength(),w,h,fixwh);
rtengine::Thumbnail* tpp = 0;
// see if it is something we support
if ( ri->is_supportedThumb() )
{
w = ri->get_thumbWidth();
h = ri->get_thumbHeight();
tpp = rtengine::Thumbnail::loadFromMemory((const char*)fdata(ri->get_thumbOffset(),ri->get_file()),ri->get_thumbLength(),
w,h,fixwh,
ri->get_thumbSwap(),ri->get_thumbBPS());
}
if ( tpp == 0 )
{
delete ri;
printf("DCRAW: failed4\n");
return NULL;
}

View File

@@ -75,7 +75,8 @@ namespace rtengine {
void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h);
static Thumbnail* loadQuickFromRaw (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int &w, int &h, int fixwh);
static Thumbnail* loadFromMemory (const char* image, int length, int &w, int &h, int fixwh);
static Thumbnail* loadFromMemory (const char* image, int length, int &w, int &h, int fixwh,
bool swap_order, int bps);
static Thumbnail* loadFromRaw (const Glib::ustring& fname, RawMetaDataLocation& rml, int &w, int &h, int fixwh);
static Thumbnail* loadFromImage (const Glib::ustring& fname, int &w, int &h, int fixwh);