~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/rawspeed/RawSpeed/RawDecoder.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-08-02 21:32:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110802213231-r9v63trgyk1e822j
Tags: 0.9.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef RAW_DECODER_H
2
 
#define RAW_DECODER_H
3
 
 
4
 
#include "RawDecoderException.h"
5
 
#include "FileMap.h"
6
 
#include "BitPumpJPEG.h" // Includes bytestream
7
 
#include "RawImage.h"
8
 
#include "BitPumpMSB.h"
9
 
#include "BitPumpPlain.h"
10
 
#include "CameraMetaData.h"
11
 
#include "TiffIFD.h"
12
 
 
13
 
/* 
14
 
    RawSpeed - RAW file decoder.
15
 
 
16
 
    Copyright (C) 2009 Klaus Post
17
 
 
18
 
    This library is free software; you can redistribute it and/or
19
 
    modify it under the terms of the GNU Lesser General Public
20
 
    License as published by the Free Software Foundation; either
21
 
    version 2 of the License, or (at your option) any later version.
22
 
 
23
 
    This library is distributed in the hope that it will be useful,
24
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26
 
    Lesser General Public License for more details.
27
 
 
28
 
    You should have received a copy of the GNU Lesser General Public
29
 
    License along with this library; if not, write to the Free Software
30
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31
 
 
32
 
    http://www.klauspost.com
33
 
*/
34
 
 
35
 
namespace RawSpeed {
36
 
 
37
 
class RawDecoder;
38
 
 
39
 
/* Class with information delivered to RawDecoder::decodeThreaded() */
40
 
class RawDecoderThread
41
 
{
42
 
  public:
43
 
    RawDecoderThread() {error = 0;};
44
 
    uint32 start_y;
45
 
    uint32 end_y;
46
 
    const char* error;
47
 
    pthread_t threadid;
48
 
    RawDecoder* parent;
49
 
};
50
 
 
51
 
class RawDecoder 
52
 
{
53
 
public:
54
 
  /* Construct decoder instance - FileMap is a filemap of the file to be decoded */
55
 
  /* The FileMap is not owned by this class, will not be deleted, and must remain */
56
 
  /* valid while this object exists */
57
 
  RawDecoder(FileMap* file);
58
 
  virtual ~RawDecoder(void);
59
 
 
60
 
  /* Check if the decoder can decode the image from this camera */
61
 
  /* A RawDecoderException will be thrown if the camera isn't supported */
62
 
  /* Unknown cameras does NOT generate any specific feedback */
63
 
  /* This function must be overridden by actual decoders */
64
 
  virtual void checkSupport(CameraMetaData *meta) = 0;
65
 
 
66
 
  /* Attempt to decode the image */
67
 
  /* A RawDecoderException will be thrown if the image cannot be decoded, */
68
 
  /* and there will not be any data in the mRaw image. */
69
 
  /* This function must be overridden by actual decoders. */
70
 
  virtual RawImage decodeRaw() = 0;
71
 
 
72
 
  /* This will apply metadata information from the camera database, */
73
 
  /* such as crop, black+white level, etc. */
74
 
  /* This function is expected to use the protected "setMetaData" */
75
 
  /* after retrieving make, model and mode if applicate. */
76
 
  /* If meta-data is set during load, this function can be empty. */
77
 
  /* The image is expected to be cropped after this, but black/whitelevel */
78
 
  /* compensation is not expected to be applied to the image */
79
 
  virtual void decodeMetaData(CameraMetaData *meta) = 0;
80
 
 
81
 
  /* Called function for filters that are capable of doing simple multi-threaded decode */
82
 
  /* The delivered class gives information on what part of the image should be decoded. */
83
 
  virtual void decodeThreaded(RawDecoderThread* t);
84
 
 
85
 
  /* The decoded image - undefined if image has not or could not be decoded. */
86
 
  /* Remember this is automatically refcounted, so a reference is retained until this class is destroyed */
87
 
  RawImage mRaw; 
88
 
 
89
 
  /* You can set this if you do not want Rawspeed to attempt to decode images, */
90
 
  /* where it does not have reliable information about CFA, cropping, black and white point */
91
 
  /* It is pretty safe to leave this disabled (default behaviour), but if you do not want to */
92
 
  /* support unknown cameras, you can enable this */
93
 
  /* DNGs are always attempted to be decoded, so this variable has no effect on DNGs */
94
 
  bool failOnUnknown;
95
 
 
96
 
  /* Vector containing silent errors that occurred doing decoding, that may have lead to */
97
 
  /* an incomplete image. */
98
 
  vector<const char*> errors;
99
 
 
100
 
 
101
 
protected:
102
 
  /* Helper function for decoders - splits the image vertically and starts of decoder threads */
103
 
  /* The function returns when all threads are done */
104
 
  /* All errors are silently pushed into the "errors" array.*/
105
 
  /* If all threads report an error an exception will be thrown*/
106
 
  void startThreads();
107
 
 
108
 
  /* Check the camera and mode against the camera database. */
109
 
  /* A RawDecoderException will be thrown if the camera isn't supported */
110
 
  /* Unknown cameras does NOT generate any errors, but returns false */
111
 
  bool checkCameraSupported(CameraMetaData *meta, string make, string model, string mode);
112
 
 
113
 
  /* Helper function for decodeMetaData(), that find the camera in the CameraMetaData DB */
114
 
  /* and sets common settings such as crop, black- white level, and sets CFA information */
115
 
  virtual void setMetaData(CameraMetaData *meta, string make, string model, string mode);
116
 
 
117
 
  /* Helper function for decoders, that will unpack uncompressed image data */
118
 
  /* input: Input image, positioned at first pixel */
119
 
  /* size: Size of the image to decode in pixels */
120
 
  /* offset: offset to write the data into the final image */
121
 
  /* inputPitch: Number of bytes between each line in the input image */
122
 
  /* bitPerPixel: Number of bits to read for each input pixel. */
123
 
  /* MSBOrder: true -  bits are read from MSB (JPEG style) False: Read from LSB. */
124
 
  void readUncompressedRaw(ByteStream &input, iPoint2D& size, iPoint2D& offset, int inputPitch, int bitPerPixel, bool MSBOrder);
125
 
 
126
 
  /* Faster version for unpacking 12 bit LSB data */
127
 
  void Decode12BitRaw(ByteStream &input, uint32 w, uint32 h);
128
 
 
129
 
  /* Generic decompressor for uncompressed images */
130
 
  /* MSBOrder: true -  bits are read from MSB (JPEG style) False: Read from LSB. */
131
 
  void decodeUncompressed(TiffIFD *rawIFD, bool MSBOrder);
132
 
 
133
 
  /* The Raw input file to be decoded */
134
 
  FileMap *mFile; 
135
 
 
136
 
  /* Decoder version - defaults to 0, but can be overridden by decoders */
137
 
  /* This can be used to avoid newer version of an xml file to indicate that a file */
138
 
  /* can be decoded, when a specific version of the code is needed */
139
 
  /* Higher number in camera xml file: Files for this camera will not be decoded */
140
 
  /* Higher number in code than xml: Image will be decoded. */
141
 
  int decoderVersion;
142
 
 
143
 
  /* Hints set for the camera after checkCameraSupported has been called from the implementation*/
144
 
   map<string,string> hints;
145
 
};
146
 
 
147
 
class RawSlice {
148
 
public:
149
 
  RawSlice() { h = offset = count = 0;};
150
 
  ~RawSlice() {};
151
 
  uint32 h;
152
 
  uint32 offset;
153
 
  uint32 count;
154
 
};
155
 
 
156
 
} // namespace RawSpeed
157
 
 
158
 
#endif