libopenraw
jfifcontainer.h
00001 /*
00002  * libopenraw - jfifcontainer.h
00003  *
00004  * Copyright (C) 2006-2007 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 
00028 #ifndef _JFIFCONTAINER_H_
00029 #define _JFIFCONTAINER_H_
00030 
00031 #include <setjmp.h>
00032 #include <cstdio>
00033 
00034 namespace JPEG {
00035 #include <jpeglib.h>
00036 }
00037 
00038 #include <libopenraw/types.h>
00039 #include <libopenraw/consts.h>
00040 
00041 #include "exception.h"
00042 #include "rawcontainer.h"
00043 
00044 namespace OpenRaw {
00045 
00046     class BitmapData;
00047 
00048     namespace Internals {
00049 
00050         class JFIFContainer
00051             : public RawContainer
00052         {
00053         public:
00054             JFIFContainer(IO::Stream *file, off_t offset);
00056             virtual ~JFIFContainer();
00057 
00058             bool getDimensions(uint32_t &x, uint32_t &y);
00059             bool getDecompressedData(BitmapData &data);
00060 
00061             /* libjpeg callbacks j_ is the prefix for these callbacks */
00062             static void j_init_source(JPEG::j_decompress_ptr cinfo);
00063             static JPEG::boolean j_fill_input_buffer(JPEG::j_decompress_ptr cinfo);
00064             static void j_skip_input_data(JPEG::j_decompress_ptr cinfo, 
00065                                                                         long num_bytes);
00066 //          static void j_jpeg_resync_to_restart(JPEG::j_decompress_ptr cinfo);
00067             static void j_term_source(JPEG::j_decompress_ptr cinfo);
00068             static void j_error_exit(JPEG::j_common_ptr cinfo);
00069 
00070         private:
00071           int _loadHeader();
00072 
00073             struct JPEG::jpeg_decompress_struct m_cinfo;
00074             struct JPEG::jpeg_error_mgr m_jerr;
00075             jmp_buf m_jpegjmp;
00076             bool m_headerLoaded;
00077         };
00078 
00079     }
00080 }
00081 
00082 #endif