thumbnail.cpp

00001 /*
00002  * libopenraw - thumbnail.cpp
00003  *
00004  * Copyright (C) 2005-2006 Hubert Figuiere
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #include <cstdlib>
00022 #include <cstring>
00023 #include <iostream>
00024 
00025 #include "debug.h"
00026 
00027 #include <libopenraw/libopenraw.h>
00028 #include <libopenraw++/rawfile.h>
00029 #include <libopenraw++/thumbnail.h>
00030 
00031 using namespace Debug;
00032 
00033 namespace OpenRaw {
00034 
00036     class Thumbnail::Private {
00037     public:
00039         void *data;
00041         size_t data_size;
00043         DataType data_type;
00045         uint32_t x;
00047         uint32_t y;
00048         
00049         Private()
00050             : data(NULL),
00051                 data_size(0),
00052                 data_type(OR_DATA_TYPE_NONE),
00053                 x(0), y(0)
00054             {
00055             }
00056         
00057         ~Private()
00058             {
00059                 if (NULL != data) {
00060                     free(data);
00061                 }
00062             }
00063     private:
00064         Private(const Private &);
00065         Private & operator=(const Private &);
00066     };
00067 
00068     Thumbnail::Thumbnail()
00069         : d(new Thumbnail::Private())
00070     {
00071     }
00072 
00073     Thumbnail::~Thumbnail()
00074     {
00075         delete d;
00076     }
00077 
00078     Thumbnail *
00079     Thumbnail::getAndExtractThumbnail(const char* _filename,
00080                                                                         uint32_t preferred_size, 
00081                                                                         or_error & err)
00082     {
00083         err = OR_ERROR_NONE;
00084         Thumbnail *thumb = NULL;
00085 
00086         RawFile *file = RawFile::newRawFile(_filename);
00087         if (file) {
00088             thumb = new Thumbnail();
00089             err = file->getThumbnail(preferred_size, *thumb);
00090             delete file;
00091         }
00092         else {
00093             err = OR_ERROR_CANT_OPEN; // file error
00094         }
00095         return thumb;
00096     }
00097 
00098     Thumbnail::DataType Thumbnail::dataType() const
00099     {
00100         return d->data_type;
00101     }
00102 
00103     void Thumbnail::setDataType(Thumbnail::DataType _type)
00104     {
00105         d->data_type = _type;
00106     }
00107 
00108     void * Thumbnail::allocData(const size_t s)
00109     {
00110         Trace(DEBUG1) << "allocate s=" << s << " data =" 
00111                             << d->data << "\n";
00112         d->data = malloc(s);
00113         Trace(DEBUG1) << " data =" << d->data << "\n";
00114         d->data_size = s;
00115         return d->data;
00116     }
00117 
00118     size_t Thumbnail::size() const
00119     {
00120         return d->data_size;
00121     }
00122 
00123     void * Thumbnail::data() const
00124     {
00125         return d->data;
00126     }
00127 
00128     uint32_t Thumbnail::x()
00129     {
00130         return d->x;
00131     }
00132 
00133     uint32_t Thumbnail::y()
00134     {
00135         return d->y;
00136     }
00137 
00138     void Thumbnail::setDimensions(uint32_t x, uint32_t y)
00139     {
00140         d->x = x;
00141         d->y = y;
00142     }
00143 
00144 }

Generated on Sat Jan 27 11:36:13 2007 for libopenraw by  doxygen 1.4.7