libopenraw
peffile.cpp
00001 /*
00002  * libopenraw - peffile.cpp
00003  *
00004  * Copyright (C) 2006-2008, 2010 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 License
00008  * as published by the Free Software Foundation, either version 3 of
00009  * 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, see
00018  * <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 
00022 #include <iostream>
00023 #include <libopenraw++/thumbnail.h>
00024 #include <libopenraw++/rawdata.h>
00025 
00026 #include "trace.h"
00027 #include "ifd.h"
00028 #include "ifdfilecontainer.h"
00029 #include "ifddir.h"
00030 #include "ifdentry.h"
00031 #include "io/file.h"
00032 #include "peffile.h"
00033 
00034 using namespace Debug;
00035 
00036 namespace OpenRaw {
00037 
00038 
00039     namespace Internals {
00040         const struct IFDFile::camera_ids_t PEFFile::s_def[] = {
00041             { "PENTAX *ist D      ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00042                                                          OR_TYPEID_PENTAX_IST_D) },
00043             { "PENTAX *ist DL     ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00044                                                          OR_TYPEID_PENTAX_IST_DL) },
00045             { "PENTAX K10D        ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00046                                                          OR_TYPEID_PENTAX_K10D_PEF) },
00047             { "PENTAX K100D       ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00048                                                          OR_TYPEID_PENTAX_K100D_PEF) },
00049             { "PENTAX K100D Super ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00050                                                          OR_TYPEID_PENTAX_K100D_PEF) },
00051             { "PENTAX K20D        ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 
00052                                                          OR_TYPEID_PENTAX_K20D_PEF) },
00053             { 0, 0 }
00054         };
00055 
00056 
00057         RawFile *PEFFile::factory(IO::Stream *s)
00058         {
00059             return new PEFFile(s);
00060         }
00061 
00062         PEFFile::PEFFile(IO::Stream *s)
00063             : IFDFile(s, OR_RAWFILE_TYPE_PEF)
00064         {
00065             _setIdMap(s_def);
00066         }
00067 
00068 
00069         PEFFile::~PEFFile()
00070         {
00071         }
00072 
00073         IFDDir::Ref  PEFFile::_locateCfaIfd()
00074         {
00075             // in PEF the CFA IFD is the main IFD
00076             if(!m_mainIfd) {
00077                 m_mainIfd = _locateMainIfd();
00078             }
00079             return m_mainIfd;
00080         }
00081 
00082 
00083         IFDDir::Ref  PEFFile::_locateMainIfd()
00084         {
00085             return m_container->setDirectory(0);
00086         }
00087 
00088         ::or_error PEFFile::_getRawData(RawData & data, uint32_t options)
00089         {
00090             ::or_error err;
00091             if(!m_cfaIfd) {
00092                 m_cfaIfd = _locateCfaIfd();
00093             }
00094             err = _getRawDataFromDir(data, m_cfaIfd);
00095             if(err == OR_ERROR_NONE) {
00096                 uint16_t compression = data.compression();
00097                 switch(compression) {
00098                 case 65535:
00099                     if((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) {
00100                         // TODO decompress
00101                     }
00102                     break;
00103                 default:
00104                     break;
00105                 }
00106             }
00107             return err;
00108         }
00109     }
00110 }
00111