crwfile.cpp

00001 /*
00002  * libopenraw - crwfile.cpp
00003  *
00004  * Copyright (C) 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 
00022 #include <libopenraw/libopenraw.h>
00023 #include <libopenraw++/thumbnail.h>
00024 
00025 #include "debug.h"
00026 #include "io/file.h"
00027 #include "io/streamclone.h"
00028 #include "crwfile.h"
00029 #include "ciffcontainer.h"
00030 #include "jfifcontainer.h"
00031 
00032 #include "rawfilefactory.h"
00033 
00034 using namespace Debug;
00035 
00036 namespace OpenRaw {
00037 
00038     namespace Internals {
00039 
00040         using namespace CIFF;
00041 
00042         RawFile *CRWFile::factory(const char* _filename)
00043         {
00044             return new CRWFile(_filename);
00045         }
00046 
00047         CRWFile::CRWFile(const char* _filename)
00048             : RawFile(_filename, OR_RAWFILE_TYPE_CRW),
00049                 m_io(new IO::File(_filename)),
00050                 m_container(new CIFFContainer(m_io)),
00051                 m_x(0), m_y(0)
00052         {
00053 
00054         }
00055 
00056         CRWFile::~CRWFile()
00057         {
00058             delete m_container;
00059             delete m_io;
00060         }
00061 
00062         ::or_error CRWFile::_enumThumbnailSizes(std::vector<uint32_t> &list)
00063         {
00064             ::or_error err = OR_ERROR_NOT_FOUND;
00065 
00066             Heap::Ref heap = m_container->heap();
00067 
00068             RecordEntry::List & records = heap->records();
00069             RecordEntry::List::iterator iter;
00070             for(iter = records.begin(); iter != records.end(); ++iter) {
00071                 if ((*iter).typeCode == (TAGCODE_MASK & TAG_JPEGIMAGE)) {
00072                     Trace(DEBUG2) << "JPEG @" << (*iter).offset << "\n";
00073                     m_x = m_y = 0;
00074 
00075                     IO::StreamClone *s = new IO::StreamClone(m_io, heap->offset()
00076                                                                                                      + (*iter).offset);
00077                     JFIFContainer *jfif = new JFIFContainer(s, 0);
00078                     jfif->getDimensions(m_x, m_y);
00079                     delete jfif;
00080                     delete s;
00081                     Trace(DEBUG1) << "JPEG dimensions x=" << m_x 
00082                                                             << " y=" << m_y << "\n";
00083                     list.push_back(std::max(m_x,m_y));
00084                     err = OR_ERROR_NONE;
00085                 }
00086             }
00087 
00088             return err;
00089         }
00090 
00091         ::or_error CRWFile::_getThumbnail(uint32_t size, Thumbnail & thumbnail)
00092         {
00093             ::or_error err = OR_ERROR_NOT_FOUND;
00094             Heap::Ref heap = m_container->heap();
00095 
00096             RecordEntry::List & records = heap->records();
00097 
00098             RecordEntry::List::iterator iter;
00099             for(iter = records.begin(); iter != records.end(); ++iter) {
00100                 if ((*iter).typeCode == (TAGCODE_MASK & TAG_JPEGIMAGE)) {
00101                     Trace(DEBUG2) << "JPEG @" << (*iter).offset << "\n";
00102                     size_t byte_size = (*iter).length;
00103                     void *buf = thumbnail.allocData(byte_size);
00104                     size_t real_size = (*iter).fetchData(heap.get(), buf, byte_size);
00105                     if (real_size != byte_size) {
00106                         Trace(WARNING) << "wrong size\n";
00107                     }
00108                     thumbnail.setDimensions(m_x, m_y);
00109                     thumbnail.setDataType(OR_DATA_TYPE_JPEG);
00110                     err = OR_ERROR_NONE;
00111                 }
00112             }
00113 
00114             return err;
00115         }
00116     }
00117 }

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