libopenraw
jfifcontainer.h
1 /*
2  * libopenraw - jfifcontainer.h
3  *
4  * Copyright (C) 2006-2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 
28 #ifndef _JFIFCONTAINER_H_
29 #define _JFIFCONTAINER_H_
30 
31 #include <setjmp.h>
32 #include <cstdio>
33 
34 namespace JPEG {
35 #include <jpeglib.h>
36 }
37 
38 #include <libopenraw/types.h>
39 #include <libopenraw/consts.h>
40 
41 #include "exception.h"
42 #include "rawcontainer.h"
43 
44 namespace OpenRaw {
45 
46  class BitmapData;
47 
48  namespace Internals {
49 
51  : public RawContainer
52  {
53  public:
54  JFIFContainer(IO::Stream *file, off_t offset);
56  virtual ~JFIFContainer();
57 
58  bool getDimensions(uint32_t &x, uint32_t &y);
59  bool getDecompressedData(BitmapData &data);
60 
61  /* libjpeg callbacks j_ is the prefix for these callbacks */
62  static void j_init_source(JPEG::j_decompress_ptr cinfo);
63  static JPEG::boolean j_fill_input_buffer(JPEG::j_decompress_ptr cinfo);
64  static void j_skip_input_data(JPEG::j_decompress_ptr cinfo,
65  long num_bytes);
66 // static void j_jpeg_resync_to_restart(JPEG::j_decompress_ptr cinfo);
67  static void j_term_source(JPEG::j_decompress_ptr cinfo);
68  static void j_error_exit(JPEG::j_common_ptr cinfo);
69 
70  private:
71  int _loadHeader();
72 
73  struct JPEG::jpeg_decompress_struct m_cinfo;
74  struct JPEG::jpeg_error_mgr m_jerr;
75  jmp_buf m_jpegjmp;
76  bool m_headerLoaded;
77  };
78 
79  }
80 }
81 
82 #endif