Coverage Report

Created: 2025-06-22 08:04

/src/LibRaw/libraw/libraw_internal.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- C++ -*-
2
 * File: libraw_internal.h
3
 * Copyright 2008-2024 LibRaw LLC (info@libraw.org)
4
 * Created: Sat Mar  8 , 2008
5
 *
6
 * LibRaw internal data structures (not visible outside)
7
8
LibRaw is free software; you can redistribute it and/or modify
9
it under the terms of the one of two licenses as you choose:
10
11
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
12
   (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
13
14
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
15
   (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
16
17
 */
18
19
#ifndef _LIBRAW_INTERNAL_TYPES_H
20
#define _LIBRAW_INTERNAL_TYPES_H
21
22
#include <stdio.h>
23
24
#ifdef __cplusplus
25
26
#include "libraw_datastream.h"
27
#include "libraw_types.h"
28
29
class LibRaw_TLS
30
{
31
public:
32
  struct
33
  {
34
    unsigned bitbuf;
35
    int vbits, reset;
36
  } getbits;
37
  struct
38
  {
39
    UINT64 bitbuf;
40
    int vbits;
41
42
  } ph1_bits;
43
  struct
44
  {
45
    unsigned pad[128], p;
46
  } sony_decrypt;
47
  struct
48
  {
49
    uchar buf[0x4002];
50
    int vpos, padding;
51
  } pana_data;
52
  uchar jpeg_buffer[4096];
53
  struct
54
  {
55
    float cbrt[0x10000], xyz_cam[3][4];
56
  } ahd_data;
57
  void init()
58
89.4k
  {
59
89.4k
    getbits.bitbuf = 0;
60
89.4k
    getbits.vbits = getbits.reset = 0;
61
89.4k
    ph1_bits.bitbuf = 0;
62
89.4k
    ph1_bits.vbits = 0;
63
89.4k
    pana_data.vpos = 0;
64
89.4k
    ahd_data.cbrt[0] = -2.0f;
65
89.4k
  }
66
};
67
68
class LibRaw_constants
69
{
70
public:
71
  static const float d65_white[3];
72
  static const double xyz_rgb[3][3];
73
  static const double xyzd50_srgb[3][3];
74
  static const double rgb_rgb[3][3];
75
  static const double adobe_rgb[3][3];
76
  static const double wide_rgb[3][3];
77
  static const double prophoto_rgb[3][3];
78
  static const double aces_rgb[3][3];
79
  static const double dcip3d65_rgb[3][3];
80
  static const double rec2020_rgb[3][3];
81
};
82
#endif /* __cplusplus */
83
84
typedef struct
85
{
86
#ifndef __cplusplus
87
  struct
88
#endif
89
      LibRaw_abstract_datastream *input;
90
  FILE *output;
91
  int input_internal;
92
  char *meta_data;
93
  INT64 profile_offset;
94
  INT64 toffset;
95
  unsigned pana_black[4];
96
97
} internal_data_t;
98
99
1.31k
#define LIBRAW_HISTOGRAM_SIZE 0x2000
100
typedef struct
101
{
102
  int (*histogram)[LIBRAW_HISTOGRAM_SIZE];
103
  unsigned *oprof;
104
} output_data_t;
105
106
typedef struct
107
{
108
  unsigned olympus_exif_cfa;
109
  unsigned long long unique_id;
110
  unsigned long long OlyID;
111
  unsigned tiff_nifds;
112
  int tiff_flip;
113
  int metadata_blocks;
114
} identify_data_t;
115
116
typedef struct
117
{
118
  uint32_t first;
119
  uint32_t count;
120
  uint32_t id;
121
} crx_sample_to_chunk_t;
122
123
// contents of tag CMP1 for relevant track in CR3 file
124
typedef struct
125
{
126
  int32_t version;
127
  int32_t f_width;
128
  int32_t f_height;
129
  int32_t tileWidth;
130
  int32_t tileHeight;
131
  int32_t nBits;
132
  int32_t nPlanes;
133
  int32_t cfaLayout;
134
  int32_t encType;
135
  int32_t imageLevels;
136
  int32_t hasTileCols;
137
  int32_t hasTileRows;
138
  int32_t mdatHdrSize;
139
  int32_t medianBits;
140
  // Not from header, but from datastream
141
  uint32_t MediaSize;
142
  INT64 MediaOffset;
143
  uint32_t MediaType; /* 1 -> /C/RAW, 2-> JPEG, 3-> CTMD metadata*/
144
  crx_sample_to_chunk_t * stsc_data; /* samples to chunk */
145
  uint32_t stsc_count;
146
  uint32_t sample_count;
147
  uint32_t sample_size; /* zero if not fixed sample size */
148
  int32_t *sample_sizes;
149
  uint32_t chunk_count;
150
  INT64  *chunk_offsets;
151
} crx_data_header_t;
152
153
typedef struct 
154
{
155
  uint32_t tag39[6];
156
  uint16_t tag3A[6];
157
  uint16_t tag3B;
158
  uint16_t initial[4];
159
  uint16_t tag40a[17], tag40b[17], tag41[17];
160
  uint16_t stripe_count; // 0x42
161
  uint16_t tag43;
162
  INT64  stripe_offsets[5]; //0x44
163
  uint16_t stripe_left[5]; // 0x45
164
  uint32_t stripe_compressed_size[5]; //0x46
165
  uint16_t stripe_width[5]; //0x47
166
  uint16_t stripe_height[5];
167
} pana8_tags_t;
168
169
typedef struct
170
{
171
  short order;
172
  ushort sraw_mul[4], cr2_slice[3];
173
  unsigned kodak_cbpp;
174
  INT64 strip_offset, data_offset;
175
  INT64 meta_offset;
176
  INT64 exif_offset, exif_subdir_offset, ifd0_offset;
177
  INT64 data_size;
178
  unsigned meta_length;
179
  unsigned cr3_exif_length, cr3_ifd0_length;
180
  unsigned thumb_misc;
181
  enum LibRaw_internal_thumbnail_formats thumb_format;
182
  unsigned fuji_layout;
183
  unsigned tiff_samples;
184
  unsigned tiff_bps;
185
  unsigned tiff_compress;
186
  unsigned tiff_sampleformat;
187
  unsigned zero_after_ff;
188
  unsigned tile_width, tile_length, load_flags;
189
  unsigned data_error;
190
  int hasselblad_parser_flag;
191
  long long posRAFData;
192
  unsigned lenRAFData;
193
  int fuji_total_lines, fuji_total_blocks, fuji_block_width, fuji_bits,
194
      fuji_raw_type, fuji_lossless;
195
  int pana_encoding, pana_bpp;
196
  pana8_tags_t pana8;
197
  crx_data_header_t crx_header[LIBRAW_CRXTRACKS_MAXCOUNT];
198
  int crx_track_selected;
199
  int crx_track_count;
200
  short CR3_CTMDtag;
201
  short CR3_Version;
202
  int CM_found;
203
  unsigned is_NikonTransfer;
204
  unsigned is_Olympus;
205
  int OlympusDNG_SubDirOffsetValid;
206
  unsigned is_Sony;
207
  unsigned is_pana_raw;
208
  unsigned is_PentaxRicohMakernotes; /* =1 for Ricoh software by Pentax, Camera DNG */
209
210
  unsigned dng_frames[LIBRAW_IFD_MAXCOUNT*2]; /* bits: 0-7: shot_select, 8-15: IFD#, 16-31: low 16 bit of newsubfile type */
211
  unsigned short raw_stride;
212
} unpacker_data_t;
213
214
typedef struct
215
{
216
  internal_data_t internal_data;
217
  libraw_internal_output_params_t internal_output_params;
218
  output_data_t output_data;
219
  identify_data_t identify_data;
220
  unpacker_data_t unpacker_data;
221
} libraw_internal_data_t;
222
223
struct decode
224
{
225
  struct decode *branch[2];
226
  int leaf;
227
};
228
229
struct tiff_ifd_t
230
{
231
  int t_width, t_height, bps, comp, phint, t_flip, samples, extrasamples;
232
  INT64 offset, bytes;
233
  int t_tile_width, t_tile_length, sample_format, predictor;
234
  int rows_per_strip;
235
  INT64 *strip_offsets;
236
  int strip_offsets_count;
237
  INT64 *strip_byte_counts;
238
  int strip_byte_counts_count;
239
  unsigned t_filters;
240
  int t_vwidth, t_vheight, t_lm,t_tm;
241
  int t_fuji_width;
242
  float t_shutter;
243
  /* Per-IFD DNG fields */
244
  INT64 opcode2_offset;
245
  INT64 lineartable_offset;
246
  int lineartable_len;
247
  libraw_dng_color_t dng_color[2];
248
  libraw_dng_levels_t dng_levels;
249
  int newsubfiletype;
250
};
251
252
struct jhead
253
{
254
  int algo, bits, high, wide, clrs, sraw, psv, restart, vpred[6];
255
  ushort quant[64], idct[64], *huff[20], *free[20], *row;
256
};
257
258
struct libraw_tiff_tag
259
{
260
  ushort tag, type;
261
  int count;
262
  union {
263
    char c[4];
264
    short s[2];
265
    int i;
266
  } val;
267
};
268
269
struct tiff_hdr
270
{
271
  ushort t_order, magic;
272
  int ifd;
273
  ushort pad, ntag;
274
  struct libraw_tiff_tag tag[23];
275
  int nextifd;
276
  ushort pad2, nexif;
277
  struct libraw_tiff_tag exif[4];
278
  ushort pad3, ngps;
279
  struct libraw_tiff_tag gpst[10];
280
  short bps[4];
281
  int rat[10];
282
  unsigned gps[26];
283
  char t_desc[512], t_make[64], t_model[64], soft[32], date[20], t_artist[64];
284
};
285
286
#ifdef DEBUG_STAGE_CHECKS
287
#define CHECK_ORDER_HIGH(expected_stage)                                       \
288
  do                                                                           \
289
  {                                                                            \
290
    if ((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) >=               \
291
        expected_stage)                                                        \
292
    {                                                                          \
293
      fprintf(stderr, "CHECK_HIGH: check %d >=  %d\n",                         \
294
              imgdata.progress_flags &LIBRAW_PROGRESS_THUMB_MASK,              \
295
              expected_stage);                                                 \
296
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
297
    }                                                                          \
298
  } while (0)
299
300
#define CHECK_ORDER_LOW(expected_stage)                                        \
301
  do                                                                           \
302
  {                                                                            \
303
    printf("Checking LOW %d/%d : %d\n", imgdata.progress_flags,                \
304
           expected_stage, imgdata.progress_flags < expected_stage);           \
305
    if ((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) <                \
306
        expected_stage)                                                        \
307
    {                                                                          \
308
      printf("failed!\n");                                                     \
309
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
310
    }                                                                          \
311
  } while (0)
312
#define CHECK_ORDER_BIT(expected_stage)                                        \
313
  do                                                                           \
314
  {                                                                            \
315
    if (imgdata.progress_flags & expected_stage)                               \
316
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
317
  } while (0)
318
319
#define SET_PROC_FLAG(stage)                                                   \
320
  do                                                                           \
321
  {                                                                            \
322
    imgdata.progress_flags |= stage;                                           \
323
    fprintf(stderr, "SET_FLAG: %d\n", stage);                                  \
324
  } while (0)
325
326
#else
327
328
#define CHECK_ORDER_HIGH(expected_stage)                                       \
329
3.09k
  do                                                                           \
330
3.09k
  {                                                                            \
331
3.09k
    if ((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) >=               \
332
3.09k
        expected_stage)                                                        \
333
3.09k
    {                                                                          \
334
0
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
335
0
    }                                                                          \
336
3.09k
  } while (0)
337
338
#define CHECK_ORDER_LOW(expected_stage)                                        \
339
6.17k
  do                                                                           \
340
6.17k
  {                                                                            \
341
6.17k
    if ((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) <                \
342
6.17k
        expected_stage)                                                        \
343
6.17k
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
344
6.17k
  } while (0)
345
346
#define CHECK_ORDER_BIT(expected_stage)                                        \
347
0
  do                                                                           \
348
0
  {                                                                            \
349
0
    if (imgdata.progress_flags & expected_stage)                               \
350
0
      return LIBRAW_OUT_OF_ORDER_CALL;                                         \
351
0
  } while (0)
352
353
#define SET_PROC_FLAG(stage)                                                   \
354
68.3k
  do                                                                           \
355
68.3k
  {                                                                            \
356
68.3k
    imgdata.progress_flags |= stage;                                           \
357
68.3k
  } while (0)
358
359
#endif
360
361
#endif