HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfCompressor.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_COMPRESSOR_H
7 #define INCLUDED_IMF_COMPRESSOR_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // class Compressor
12 //
13 //-----------------------------------------------------------------------------
14 
15 #include "ImfForward.h"
16 
17 #include "ImfCompression.h"
18 
19 #include <ImathBox.h>
20 
21 #include <stdlib.h>
22 
24 
26 {
27 public:
28  //---------------------------------------------
29  // Constructor -- hdr is the header of the file
30  // that will be compressed or uncompressed
31  //---------------------------------------------
32 
34  Compressor (const Header& hdr);
35 
36  //-----------
37  // Destructor
38  //-----------
39 
41  virtual ~Compressor ();
42 
43  //----------------------------------------------
44  // Maximum number of scan lines processed by
45  // a single call to compress() and uncompress().
46  //----------------------------------------------
47 
49  virtual int numScanLines () const = 0;
50 
51  //--------------------------------------------
52  // Format of the pixel data read and written
53  // by the compress() and uncompress() methods.
54  // The default implementation of format()
55  // returns XDR.
56  //--------------------------------------------
57 
59  {
60  NATIVE, // the machine's native format
61  XDR // Xdr format
62  };
63 
65  virtual Format format () const;
66 
67  //----------------------------
68  // Access to the file's header
69  //----------------------------
70 
71  const Header& header () const { return _header; }
72 
73  //-------------------------------------------------------------------------
74  // Compress an array of bytes that represents the contents of up to
75  // numScanLines() scan lines:
76  //
77  // inPtr Input buffer (uncompressed data).
78  //
79  // inSize Number of bytes in the input buffer
80  //
81  // minY Minimum y coordinate of the scan lines to
82  // be compressed
83  //
84  // outPtr Pointer to output buffer
85  //
86  // return value Size of compressed data in output buffer
87  //
88  // Arrangement of uncompressed pixel data in the input buffer:
89  //
90  // Before calling
91  //
92  // compress (buf, size, minY, ...);
93  //
94  // the InputFile::writePixels() method gathers pixel data from the
95  // frame buffer, fb, and places them in buffer buf, like this:
96  //
97  // char *endOfBuf = buf;
98  //
99  // for (int y = minY;
100  // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
101  // ++y)
102  // {
103  // for (ChannelList::ConstIterator c = header().channels().begin();
104  // c != header().channels().end();
105  // ++c)
106  // {
107  // if (modp (y, c.channel().ySampling) != 0)
108  // continue;
109  //
110  // for (int x = header().dataWindow().min.x;
111  // x <= header().dataWindow().max.x;
112  // ++x)
113  // {
114  // if (modp (x, c.channel().xSampling) != 0)
115  // continue;
116  //
117  // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
118  // }
119  // }
120  // }
121  //
122  // int size = endOfBuf - buf;
123  //
124  //-------------------------------------------------------------------------
125 
126  virtual int
127  compress (const char* inPtr, int inSize, int minY, const char*& outPtr) = 0;
128 
129  IMF_EXPORT
130  virtual int compressTile (
131  const char* inPtr,
132  int inSize,
134  const char*& outPtr);
135 
136  //-------------------------------------------------------------------------
137  // Uncompress an array of bytes that has been compressed by compress():
138  //
139  // inPtr Input buffer (compressed data).
140  //
141  // inSize Number of bytes in the input buffer
142  //
143  // minY Minimum y coordinate of the scan lines to
144  // be uncompressed
145  //
146  // outPtr Pointer to output buffer
147  //
148  // return value Size of uncompressed data in output buffer
149  //
150  //-------------------------------------------------------------------------
151 
152  virtual int uncompress (
153  const char* inPtr, int inSize, int minY, const char*& outPtr) = 0;
154 
155  IMF_EXPORT
156  virtual int uncompressTile (
157  const char* inPtr,
158  int inSize,
160  const char*& outPtr);
161 
162 private:
163  const Header& _header;
164 };
165 
166 //--------------------------------------
167 // Test if c is a valid compression type
168 //--------------------------------------
169 
172 
173 //--------------------------------------
174 // Test if c is valid for deep data
175 //--------------------------------------
176 
179 
180 //---------------------------------------
181 // Return true for compression types which
182 // do not guarantee that HALF type values
183 // are preserved precisely
184 //---------------------------------------
187 
188 //-----------------------------------------------------------------
189 // Construct a Compressor for compression type c:
190 //
191 // maxScanLineSize Maximum number of bytes per uncompressed
192 // scan line.
193 //
194 // header Header of the input or output file whose
195 // pixels will be compressed or uncompressed.
196 //
197 // return value A pointer to a new Compressor object (it
198 // is the caller's responsibility to delete
199 // the object), or 0 (if c is NO_COMPRESSION).
200 //
201 //-----------------------------------------------------------------
202 
204 Compressor*
205 newCompressor (Compression c, size_t maxScanLineSize, const Header& hdr);
206 
207 //-----------------------------------------------------------------
208 // Construct a Compressor for compression type c for a tiled image:
209 //
210 // tileLineSize Maximum number of bytes per uncompressed
211 // line in a tile.
212 //
213 // numTileLines Maximum number of lines in a tile.
214 //
215 // header Header of the input or output file whose
216 // pixels will be compressed or uncompressed.
217 //
218 // return value A pointer to a new Compressor object (it
219 // is the caller's responsibility to delete
220 // the object), or 0 (if c is NO_COMPRESSION).
221 //
222 //-----------------------------------------------------------------
223 
226  Compression c, size_t tileLineSize, size_t numTileLines, const Header& hdr);
227 
228 //-----------------------------------------------------------------
229 // Return the maximum number of scanlines in each chunk
230 // of a scanline image using the given compression scheme
231 //-----------------------------------------------------------------
232 
234 int numLinesInBuffer (Compression comp);
235 
237 
238 #endif
NATIVE
Definition: ImfCompressor.h:60
#define IMF_EXPORT_ENUM
Definition: ImfExport.h:56
GLenum GLint * range
Definition: glcorearb.h:1925
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM Compression
IMF_EXPORT Compressor * newCompressor(Compression c, size_t maxScanLineSize, const Header &hdr)
IMF_EXPORT Compressor * newTileCompressor(Compression c, size_t tileLineSize, size_t numTileLines, const Header &hdr)
Format
Definition: oidn.hpp:118
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
#define IMF_EXPORT
Definition: ImfExport.h:54
IMF_EXPORT int numLinesInBuffer(Compression comp)
IMF_EXPORT bool isValidCompression(Compression c)
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
const Header & header() const
Definition: ImfCompressor.h:71
IMF_EXPORT bool isValidDeepCompression(Compression c)
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
IMF_EXPORT bool isLossyCompression(Compression c)