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 "ImfContext.h"
20 
21 #include "openexr_compression.h"
22 
23 #include <ImathBox.h>
24 
25 #include <stdlib.h>
26 #include <memory>
27 
29 
31 {
32 public:
33  //---------------------------------------------
34  // Constructor -- hdr is the header of the file
35  // that will be compressed or uncompressed
36  //---------------------------------------------
37 
39  Compressor (const Header& hdr,
40  exr_compression_t compression_type,
41  size_t maxScanLineSize,
42  int scanlines = -1);
43 
44  //-----------
45  // Destructor
46  //-----------
47 
49  virtual ~Compressor ();
50 
51  Compressor (const Compressor& other) = delete;
52  Compressor& operator= (const Compressor& other) = delete;
53  Compressor (Compressor&& other) = delete;
54  Compressor& operator= (Compressor&& other) = delete;
55 
56  //----------------------------------------------
57  // Maximum number of scan lines processed by
58  // a single call to compress() and uncompress().
59  //----------------------------------------------
60 
62  virtual int numScanLines () const;
63 
64  //--------------------------------------------
65  // Format of the pixel data read and written
66  // by the compress() and uncompress() methods.
67  // The default implementation of format()
68  // returns XDR.
69  //--------------------------------------------
70 
72  {
73  NATIVE, // the machine's native format
74  XDR // Xdr format
75  };
76 
78  virtual Format format () const;
79 
80  //----------------------------
81  // Access to the file's header
82  //----------------------------
83 
84  const Header& header () const { return _header; }
85 
86  //-------------------------------------------------------------------------
87  // Compress an array of bytes that represents the contents of up to
88  // numScanLines() scan lines:
89  //
90  // inPtr Input buffer (uncompressed data).
91  //
92  // inSize Number of bytes in the input buffer
93  //
94  // minY Minimum y coordinate of the scan lines to
95  // be compressed
96  //
97  // outPtr Pointer to output buffer
98  //
99  // return value Size of compressed data in output buffer
100  //
101  // Arrangement of uncompressed pixel data in the input buffer:
102  //
103  // Before calling
104  //
105  // compress (buf, size, minY, ...);
106  //
107  // the InputFile::writePixels() method gathers pixel data from the
108  // frame buffer, fb, and places them in buffer buf, like this:
109  //
110  // char *endOfBuf = buf;
111  //
112  // for (int y = minY;
113  // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
114  // ++y)
115  // {
116  // for (ChannelList::ConstIterator c = header().channels().begin();
117  // c != header().channels().end();
118  // ++c)
119  // {
120  // if (modp (y, c.channel().ySampling) != 0)
121  // continue;
122  //
123  // for (int x = header().dataWindow().min.x;
124  // x <= header().dataWindow().max.x;
125  // ++x)
126  // {
127  // if (modp (x, c.channel().xSampling) != 0)
128  // continue;
129  //
130  // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
131  // }
132  // }
133  // }
134  //
135  // int size = endOfBuf - buf;
136  //
137  //-------------------------------------------------------------------------
138 
139  virtual int
140  compress (const char* inPtr, int inSize, int minY, const char*& outPtr);
141 
142  IMF_EXPORT
143  virtual int compressTile (
144  const char* inPtr,
145  int inSize,
147  const char*& outPtr);
148 
149  //-------------------------------------------------------------------------
150  // Uncompress an array of bytes that has been compressed by compress():
151  //
152  // inPtr Input buffer (compressed data).
153  //
154  // inSize Number of bytes in the input buffer
155  //
156  // minY Minimum y coordinate of the scan lines to
157  // be uncompressed
158  //
159  // outPtr Pointer to output buffer
160  //
161  // return value Size of uncompressed data in output buffer
162  //
163  //-------------------------------------------------------------------------
164 
165  virtual int uncompress (
166  const char* inPtr, int inSize, int minY, const char*& outPtr);
167 
168  IMF_EXPORT
169  virtual int uncompressTile (
170  const char* inPtr,
171  int inSize,
173  const char*& outPtr);
174 
175  void setExpectedSize (size_t sz) { _expectedSize = sz; }
176  void setTileLevel (int lx, int ly) { _levelX = lx; _levelY = ly; }
177 
178  exr_storage_t storageType () const { return _store_type; }
179  void setStorageType (exr_storage_t st) { _store_type = st; }
180 
181 protected:
183  const Header& _header;
184 
185  size_t _maxScanLineSize = 0;
186  int _numScanLines = -1;
187 
190 
193  bool _decoder_init = false;
194  bool _encoder_init = false;
195  std::unique_ptr<char[]> _memory_buffer;
196  uint64_t _buf_sz = 0;
197  size_t _expectedSize = 0;
198 
199  int _levelX = 0;
200  int _levelY = 0;
201 
202  uint64_t runEncodeStep (
203  const char* inPtr,
204  int inSize,
206  const char*& outPtr);
207  uint64_t runDecodeStep (
208  const char* inPtr,
209  int inSize,
211  const char*& outPtr);
212 };
213 
214 //-----------------------------------------------------------------
215 // Construct a Compressor for compression type c:
216 //
217 // maxScanLineSize Maximum number of bytes per uncompressed
218 // scan line.
219 //
220 // header Header of the input or output file whose
221 // pixels will be compressed or uncompressed.
222 //
223 // return value A pointer to a new Compressor object (it
224 // is the caller's responsibility to delete
225 // the object), or 0 (if c is NO_COMPRESSION).
226 //
227 //-----------------------------------------------------------------
228 
230 Compressor*
231 newCompressor (Compression c, size_t maxScanLineSize, const Header& hdr);
232 
233 //-----------------------------------------------------------------
234 // Construct a Compressor for compression type c for a tiled image:
235 //
236 // tileLineSize Maximum number of bytes per uncompressed
237 // line in a tile.
238 //
239 // numTileLines Maximum number of lines in a tile.
240 //
241 // header Header of the input or output file whose
242 // pixels will be compressed or uncompressed.
243 //
244 // return value A pointer to a new Compressor object (it
245 // is the caller's responsibility to delete
246 // the object), or 0 (if c is NO_COMPRESSION).
247 //
248 //-----------------------------------------------------------------
249 
252  Compression c, size_t tileLineSize, size_t numTileLines, const Header& hdr);
253 
254 //-----------------------------------------------------------------
255 // Return the maximum number of scanlines in each chunk
256 // of a scanline image using the given compression scheme
257 //-----------------------------------------------------------------
258 
260 int numLinesInBuffer (Compression comp);
261 
263 
264 #endif
NATIVE
Definition: ImfCompressor.h:73
#define IMF_EXPORT_ENUM
Definition: ImfExport.h:56
#define EXR_ENCODE_PIPELINE_INITIALIZER
Simple macro to initialize an empty decode pipeline.
GLenum GLint * range
Definition: glcorearb.h:1925
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
std::unique_ptr< char[]> _memory_buffer
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM Compression
IMF_EXPORT Compressor * newCompressor(Compression c, size_t maxScanLineSize, const Header &hdr)
void setStorageType(exr_storage_t st)
exr_compression_t _comp_type
Context _ctxt
exr_storage_t storageType() const
IMF_EXPORT Compressor * newTileCompressor(Compression c, size_t tileLineSize, size_t numTileLines, const Header &hdr)
Format
Definition: oidn.hpp:118
#define EXR_DECODE_PIPELINE_INITIALIZER
Simple macro to initialize an empty decode pipeline.
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
const Header & _header
void setTileLevel(int lx, int ly)
void setExpectedSize(size_t sz)
#define IMF_EXPORT
Definition: ImfExport.h:54
IMF_EXPORT int numLinesInBuffer(Compression comp)
exr_compression_t
Definition: openexr_attr.h:36
exr_storage_t _store_type
exr_storage_t
Definition: openexr_attr.h:69
GT_API const UT_StringHolder st
LeafData & operator=(const LeafData &)=delete
Context provides a wrapper around the Core library context object.
Definition: ImfContext.h:30
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
const Header & header() const
Definition: ImfCompressor.h:84
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57