1 /* -*- C++ -*-
2  * File: internal/libraw_cxx_defs.h
3  * Copyright 2008-2020 LibRaw LLC (info@libraw.org)
4  * Created: Sat Aug  17, 2020
5 
6 LibRaw is free software; you can redistribute it and/or modify
7 it under the terms of the one of two licenses as you choose:
8 
9 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
10    (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
11 
12 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
13    (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
14 
15  */
16 
17 #ifndef _LIBRAW_CXX_DEFS_H
18 #define _LIBRAW_CXX_DEFS_H
19 
20 #include <math.h>
21 #include <errno.h>
22 #include <float.h>
23 #include <new>
24 #include <exception>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #define LIBRAW_LIBRARY_BUILD
28 #include "libraw/libraw.h"
29 #include "internal/defines.h"
30 #ifdef USE_ZLIB
31 #include <zlib.h>
32 #endif
33 
34 #ifndef LIBRAW_WIN32_CALLS
35 #include <netinet/in.h>
36 #else
37 #ifndef LIBRAW_NO_WINSOCK2
38 #include <winsock2.h>
39 #endif
40 #include <io.h>
41 #endif
42 
43 #ifdef USE_RAWSPEED
44 #include <RawSpeed/StdAfx.h>
45 #include <RawSpeed/FileMap.h>
46 #include <RawSpeed/RawParser.h>
47 #include <RawSpeed/RawDecoder.h>
48 #include <RawSpeed/CameraMetaData.h>
49 #include <RawSpeed/ColorFilterArray.h>
50 extern const char *_rawspeed_data_xml[];
51 extern const int RAWSPEED_DATA_COUNT;
52 class CameraMetaDataLR : public RawSpeed::CameraMetaData
53 {
54 public:
CameraMetaDataLR()55   CameraMetaDataLR() : CameraMetaData() {}
CameraMetaDataLR(char * filename)56   CameraMetaDataLR(char *filename) : RawSpeed::CameraMetaData(filename) {}
57   CameraMetaDataLR(char *data, int sz);
58 };
59 
60 CameraMetaDataLR *make_camera_metadata();
61 
62 #endif
63 
64 #ifdef USE_DNGSDK
65 #include "dng_host.h"
66 #include "dng_negative.h"
67 #include "dng_simple_image.h"
68 #include "dng_info.h"
69 #endif
70 
71 #define P1 imgdata.idata
72 #define S  imgdata.sizes
73 #define O  imgdata.params
74 #define C  imgdata.color
75 #define T  imgdata.thumbnail
76 #define MN imgdata.makernotes
77 #define IO libraw_internal_data.internal_output_params
78 #define ID libraw_internal_data.internal_data
79 
80 #define makeIs(idx) (imgdata.idata.maker_index == idx)
81 #define mnCamID imgdata.lens.makernotes.CamID
82 
83 #define EXCEPTION_HANDLER(e)                                                   \
84   do                                                                           \
85   {                                                                            \
86     switch (e)                                                                 \
87     {                                                                          \
88     case LIBRAW_EXCEPTION_MEMPOOL:                                             \
89       recycle();                                                               \
90       return LIBRAW_MEMPOOL_OVERFLOW;                                          \
91     case LIBRAW_EXCEPTION_ALLOC:                                               \
92       recycle();                                                               \
93       return LIBRAW_UNSUFFICIENT_MEMORY;                                       \
94     case LIBRAW_EXCEPTION_TOOBIG:                                              \
95       recycle();                                                               \
96       return LIBRAW_TOO_BIG;                                                   \
97     case LIBRAW_EXCEPTION_DECODE_RAW:                                          \
98     case LIBRAW_EXCEPTION_DECODE_JPEG:                                         \
99       recycle();                                                               \
100       return LIBRAW_DATA_ERROR;                                                \
101     case LIBRAW_EXCEPTION_DECODE_JPEG2000:                                     \
102       recycle();                                                               \
103       return LIBRAW_DATA_ERROR;                                                \
104     case LIBRAW_EXCEPTION_IO_EOF:                                              \
105     case LIBRAW_EXCEPTION_IO_CORRUPT:                                          \
106       recycle();                                                               \
107       return LIBRAW_IO_ERROR;                                                  \
108     case LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK:                               \
109       recycle();                                                               \
110       return LIBRAW_CANCELLED_BY_CALLBACK;                                     \
111     case LIBRAW_EXCEPTION_BAD_CROP:                                            \
112       recycle();                                                               \
113       return LIBRAW_BAD_CROP;                                                  \
114     default:                                                                   \
115       return LIBRAW_UNSPECIFIED_ERROR;                                         \
116     }                                                                          \
117   } while (0)
118 
119 // copy-n-paste from image pipe
120 #define MIN(a, b) ((a) < (b) ? (a) : (b))
121 #define MAX(a, b) ((a) > (b) ? (a) : (b))
122 #define LIM(x, min, max) MAX(min, MIN(x, max))
123 #ifndef CLIP
124 #define CLIP(x) LIM(x, 0, 65535)
125 #endif
126 #define THUMB_READ_BEYOND 16384
127 
128 #define ZERO(a) memset(&a, 0, sizeof(a))
129 
130 #endif
131