Coverage Report

Created: 2023-06-07 08:11

/src/opencv/3rdparty/openexr/IlmImf/ImfCompressor.cpp
Line
Count
Source (jump to first uncovered line)
1
///////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
4
// Digital Ltd. LLC
5
// 
6
// All rights reserved.
7
// 
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
10
// met:
11
// *       Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// *       Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
16
// distribution.
17
// *       Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission. 
20
// 
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
//
33
///////////////////////////////////////////////////////////////////////////
34
35
36
37
//-----------------------------------------------------------------------------
38
//
39
//  class Compressor
40
//
41
//-----------------------------------------------------------------------------
42
43
#include "ImfCompressor.h"
44
#include "ImfRleCompressor.h"
45
#include "ImfZipCompressor.h"
46
#include "ImfPizCompressor.h"
47
#include "ImfPxr24Compressor.h"
48
#include "ImfB44Compressor.h"
49
#include "ImfDwaCompressor.h"
50
#include "ImfCheckedArithmetic.h"
51
#include "ImfNamespace.h"
52
53
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
54
55
using IMATH_NAMESPACE::Box2i;
56
57
58
0
Compressor::Compressor (const Header &hdr): _header (hdr) {}
59
60
61
0
Compressor::~Compressor () {}
62
63
64
Compressor::Format
65
Compressor::format () const
66
0
{
67
0
    return XDR;
68
0
}
69
70
71
int
72
Compressor::compressTile (const char *inPtr,
73
        int inSize,
74
        Box2i range,
75
        const char *&outPtr)
76
0
{
77
0
    return compress (inPtr, inSize, range.min.y, outPtr);
78
0
}
79
80
             
81
int
82
Compressor::uncompressTile (const char *inPtr,
83
          int inSize,
84
          Box2i range,
85
          const char *&outPtr)
86
0
{
87
0
    return uncompress (inPtr, inSize, range.min.y, outPtr);
88
0
}
89
90
91
bool  
92
isValidCompression (Compression c)
93
0
{
94
0
    switch (c)
95
0
    {
96
0
      case NO_COMPRESSION:
97
0
      case RLE_COMPRESSION:
98
0
      case ZIPS_COMPRESSION:
99
0
      case ZIP_COMPRESSION:
100
0
      case PIZ_COMPRESSION:
101
0
      case PXR24_COMPRESSION:
102
0
      case B44_COMPRESSION:
103
0
      case B44A_COMPRESSION:
104
0
      case DWAA_COMPRESSION:
105
0
      case DWAB_COMPRESSION:
106
107
0
  return true;
108
109
0
      default:
110
111
0
  return false;
112
0
    }
113
0
}
114
115
bool isValidDeepCompression(Compression c)
116
0
{
117
0
  switch(c)
118
0
  {
119
0
      case NO_COMPRESSION:
120
0
      case RLE_COMPRESSION:
121
0
      case ZIPS_COMPRESSION:
122
0
          return true;
123
0
      default :
124
0
          return false;
125
0
  }
126
0
}
127
128
129
Compressor *
130
newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)
131
0
{
132
0
    switch (c)
133
0
    {
134
0
      case RLE_COMPRESSION:
135
136
0
  return new RleCompressor (hdr, maxScanLineSize);
137
138
0
      case ZIPS_COMPRESSION:
139
140
0
  return new ZipCompressor (hdr, maxScanLineSize, 1);
141
142
0
      case ZIP_COMPRESSION:
143
144
0
  return new ZipCompressor (hdr, maxScanLineSize, 16);
145
146
0
      case PIZ_COMPRESSION:
147
148
0
  return new PizCompressor (hdr, maxScanLineSize, 32);
149
150
0
      case PXR24_COMPRESSION:
151
152
0
  return new Pxr24Compressor (hdr, maxScanLineSize, 16);
153
154
0
      case B44_COMPRESSION:
155
156
0
  return new B44Compressor (hdr, maxScanLineSize, 32, false);
157
158
0
      case B44A_COMPRESSION:
159
160
0
  return new B44Compressor (hdr, maxScanLineSize, 32, true);
161
162
0
      case DWAA_COMPRESSION:
163
164
0
  return new DwaCompressor (hdr, maxScanLineSize, 32, 
165
0
                               DwaCompressor::STATIC_HUFFMAN);
166
167
0
      case DWAB_COMPRESSION:
168
169
0
  return new DwaCompressor (hdr, maxScanLineSize, 256, 
170
0
                               DwaCompressor::STATIC_HUFFMAN);
171
172
0
      default:
173
174
0
  return 0;
175
0
    }
176
0
}
177
178
179
Compressor *
180
newTileCompressor (Compression c,
181
       size_t tileLineSize,
182
       size_t numTileLines,
183
       const Header &hdr)
184
0
{
185
0
    switch (c)
186
0
    {
187
0
      case RLE_COMPRESSION:
188
189
0
  return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));
190
191
0
      case ZIPS_COMPRESSION:
192
0
      case ZIP_COMPRESSION:
193
194
0
  return new ZipCompressor (hdr, tileLineSize, numTileLines);
195
196
0
      case PIZ_COMPRESSION:
197
198
0
  return new PizCompressor (hdr, tileLineSize, numTileLines);
199
200
0
      case PXR24_COMPRESSION:
201
202
0
  return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
203
204
0
      case B44_COMPRESSION:
205
206
0
  return new B44Compressor (hdr, tileLineSize, numTileLines, false);
207
208
0
      case B44A_COMPRESSION:
209
210
0
  return new B44Compressor (hdr, tileLineSize, numTileLines, true);
211
212
0
      case DWAA_COMPRESSION:
213
0
      case DWAB_COMPRESSION:
214
215
0
  return new DwaCompressor (hdr, tileLineSize, numTileLines, 
216
0
                               DwaCompressor::DEFLATE);
217
218
0
      default:
219
220
0
  return 0;
221
0
    }
222
0
}
223
224
225
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
226