1 module libraw; 2 3 public import libraw.datastream; 4 public import libraw.types; 5 public import libraw.const_; 6 public import libraw.internal; 7 public import libraw.alloc; 8 9 import core.stdc.limits; 10 //import core.stdc.memory; 11 import core.stdc.stdio; 12 import core.stdc.stdlib; 13 import core.stdc.config; 14 15 16 version (linux) { 17 enum _FILE_OFFSET_BITS = 64; 18 } 19 20 enum LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE = 250 * 1024L * 1024L; 21 22 23 extern (C) { 24 const(char)* libraw_strerror(int errorcode); 25 const(char)* libraw_strprogress(LibRaw_progress); 26 /* LibRaw C API */ 27 libraw_data_t *libraw_init(LibRaw_constructor_flags flags); 28 int libraw_open_file(libraw_data_t *, const(char)*); 29 int libraw_open_file_ex(libraw_data_t *, const(char)*, long max_buff_sz); 30 version (Windows) { 31 int libraw_open_wfile(libraw_data_t *, const(wchar_t)*); 32 int libraw_open_wfile_ex(libraw_data_t *, const(wchar_t)*, long max_buff_sz); 33 } 34 int libraw_open_buffer(libraw_data_t *, void *buffer, size_t size); 35 int libraw_open_datastream(libraw_data_t *lr, libraw_abstract_datastream_t *stream); 36 void libraw_wrap_ifp_stream(void *ifp, libraw_abstract_datastream_t *dst); 37 int libraw_unpack(libraw_data_t *); 38 int libraw_unpack_thumb(libraw_data_t *); 39 void libraw_recycle_datastream(libraw_data_t *); 40 void libraw_recycle(libraw_data_t *); 41 void libraw_close(libraw_data_t *); 42 void libraw_subtract_black(libraw_data_t *); 43 int libraw_raw2image(libraw_data_t *); 44 void libraw_free_image(libraw_data_t *); 45 /* version helpers */ 46 const(char)* libraw_version(); 47 int libraw_versionNumber(); 48 /* Camera list */ 49 const(char)** libraw_cameraList(); 50 int libraw_cameraCount(); 51 52 /* helpers */ 53 void libraw_set_memerror_handler(libraw_data_t *, memory_callback cb, void *datap); 54 void libraw_set_exifparser_handler(libraw_data_t *, exif_parser_callback cb, void *datap); 55 void libraw_set_dataerror_handler(libraw_data_t *, data_callback func, void *datap); 56 void libraw_set_progress_handler(libraw_data_t *, progress_callback cb, void *datap); 57 const(char)* libraw_unpack_function_name(libraw_data_t *lr); 58 int libraw_get_decoder_info(libraw_data_t *lr, libraw_decoder_info_t *d); 59 int libraw_COLOR(libraw_data_t *, int row, int col); 60 uint libraw_capabilities(); 61 62 /* DCRAW compatibility */ 63 int libraw_adjust_sizes_info_only(libraw_data_t *); 64 int libraw_dcraw_ppm_tiff_writer(libraw_data_t *lr, const(char)* filename); 65 int libraw_dcraw_thumb_writer(libraw_data_t *lr, const(char)* fname); 66 int libraw_dcraw_process(libraw_data_t *lr); 67 libraw_processed_image_t *libraw_dcraw_make_mem_image(libraw_data_t *lr, int *errc); 68 libraw_processed_image_t *libraw_dcraw_make_mem_thumb(libraw_data_t *lr, int *errc); 69 void libraw_dcraw_clear_mem(libraw_processed_image_t *); 70 /* getters/setters used by 3DLut Creator */ 71 void libraw_set_demosaic(libraw_data_t *lr, int value); 72 void libraw_set_output_color(libraw_data_t *lr, int value); 73 void libraw_set_user_mul(libraw_data_t *lr, int index, float val); 74 void libraw_set_output_bps(libraw_data_t *lr, int value); 75 void libraw_set_gamma(libraw_data_t *lr, int index, float value); 76 void libraw_set_no_auto_bright(libraw_data_t *lr, int value); 77 void libraw_set_bright(libraw_data_t *lr, float value); 78 void libraw_set_highlight(libraw_data_t *lr, int value); 79 void libraw_set_fbdd_noiserd(libraw_data_t *lr, int value); 80 int libraw_get_raw_height(libraw_data_t *lr); 81 int libraw_get_raw_width(libraw_data_t *lr); 82 int libraw_get_iheight(libraw_data_t *lr); 83 int libraw_get_iwidth(libraw_data_t *lr); 84 float libraw_get_cam_mul(libraw_data_t *lr, int index); 85 float libraw_get_pre_mul(libraw_data_t *lr, int index); 86 float libraw_get_rgb_cam(libraw_data_t *lr, int index1, int index2); 87 int libraw_get_color_maximum(libraw_data_t *lr); 88 void libraw_set_output_tif(libraw_data_t* lr, int value); 89 libraw_iparams_t *libraw_get_iparams(libraw_data_t *lr); 90 libraw_lensinfo_t *libraw_get_lensinfo(libraw_data_t *lr); 91 libraw_imgother_t *libraw_get_imgother(libraw_data_t *lr); 92 } 93 94 95 /+extern (C++) { 96 class LibRaw 97 { 98 libraw_data_t imgdata; 99 int verbose; 100 101 this(uint flags = LibRaw_constructor_flags.NONE); 102 final libraw_output_params_t *output_params_ptr() { return &imgdata.params; } 103 final int open_file(const(char)* fname, long max_buffered_sz = LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE); 104 version (Windows) { 105 final int open_file(const wchar_t *fname, long max_buffered_sz = LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE); 106 } 107 final int open_buffer(void *buffer, size_t size); 108 int open_datastream(LibRaw_abstract_datastream); 109 int open_bayer(ubyte *data, uint datalen, ushort _raw_width, ushort _raw_height, 110 ushort _left_margin, ushort _top_margin, ushort _right_margin, ushort _bottom_margin, 111 ubyte procflags, ubyte bayer_pattern, uint unused_bits, 112 uint otherflags, uint black_level); 113 final int error_count() { return libraw_internal_data.unpacker_data.data_error; } 114 final void recycle_datastream(); 115 final int unpack(); 116 final int unpack_thumb(); 117 final int thumbOK(long maxsz = -1); 118 final int adjust_sizes_info_only(); 119 final int subtract_black(); 120 final int subtract_black_internal(); 121 final int raw2image(); 122 final int raw2image_ex(int do_subtract_black); 123 final void raw2image_start(); 124 final void free_image(); 125 final int adjust_maximum(); 126 final void set_exifparser_handler(exif_parser_callback cb, void *data) 127 { 128 callbacks.exifparser_data = data; 129 callbacks.exif_cb = cb; 130 } 131 final void set_memerror_handler(memory_callback cb, void *data) 132 { 133 callbacks.memcb_data = data; 134 callbacks.mem_cb = cb; 135 } 136 final void set_dataerror_handler(data_callback func, void *data) 137 { 138 callbacks.datacb_data = data; 139 callbacks.data_cb = func; 140 } 141 final void set_progress_handler(progress_callback pcb, void *data) 142 { 143 callbacks.progresscb_data = data; 144 callbacks.progress_cb = pcb; 145 } 146 147 final void convertFloatToInt(float dmin = 4096.0f, float dmax = 32767.0f, float dtarget = 16383.0f); 148 /* helpers */ 149 static uint capabilities(); 150 static const(char)* version_(); 151 static int versionNumber(); 152 static const(char)** cameraList(); 153 static int cameraCount(); 154 static const(char)* strprogress(LibRaw_progress); 155 static const(char)* strerror(int p); 156 /* dcraw emulation */ 157 final int dcraw_ppm_tiff_writer(const(char)* filename); 158 final int dcraw_thumb_writer(const(char)* fname); 159 final int dcraw_process(); 160 /* information calls */ 161 final int is_fuji_rotated() { return libraw_internal_data.internal_output_params.fuji_width; } 162 final int is_sraw(); 163 final int sraw_midpoint(); 164 final int is_nikon_sraw(); 165 final int is_coolscan_nef(); 166 final int is_jpeg_thumb(); 167 final int is_floating_point(); 168 final int have_fpdata(); 169 /* memory writers */ 170 libraw_processed_image_t *dcraw_make_mem_image(int *errcode = null); 171 libraw_processed_image_t *dcraw_make_mem_thumb(int *errcode = null); 172 static void dcraw_clear_mem(libraw_processed_image_t *); 173 174 /* Additional calls for make_mem_image */ 175 final void get_mem_image_format(int *width, int *height, int *colors, int *bps) const; 176 final int copy_mem_image(void *scan0, int stride, int bgr); 177 178 /* free all internal data structures */ 179 final void recycle(); 180 ~this() {} 181 182 final int COLOR(int row, int col) 183 { 184 if (!imgdata.idata.filters) 185 return 6; /* Special value 0+1+2+3 */ 186 if (imgdata.idata.filters < 1000) 187 return fcol(row, col); 188 return libraw_internal_data.internal_output_params.fuji_width ? FCF(row, col) : FC(row, col); 189 } 190 191 final int FC(int row, int col) { return (imgdata.idata.filters >> (((row << 1 & 14) | (col & 1)) << 1) & 3); } 192 final int fcol(int row, int col); 193 194 final const(char)* unpack_function_name(); 195 int get_decoder_info(libraw_decoder_info_t *d_info); 196 final libraw_internal_data_t *get_internal_data_pointer() { return &libraw_internal_data; } 197 198 /* Debanding filter */ 199 final int wf_remove_banding(); 200 201 /* Phase one correction/subtractBL calls */ 202 /* Returns libraw error code */ 203 204 final int phase_one_subtract_black(ushort *src, ushort *dest); 205 final int phase_one_correct(); 206 207 final int set_rawspeed_camerafile(char *filename); 208 void setCancelFlag(); 209 void clearCancelFlag(); 210 void adobe_coeff(const(char)* , const(char)* , int internal_only = 0); 211 212 final void set_dng_host(void *); 213 214 protected: 215 final int is_curve_linear(); 216 final void checkCancel(); 217 final void cam_xyz_coeff(float[4]/*[3]*/* _rgb_cam, double[3]/*[4]*/* cam_xyz); 218 final void phase_one_allocate_tempbuffer(); 219 final void phase_one_free_tempbuffer(); 220 int is_phaseone_compressed(); 221 int is_canon_600(); 222 223 // NOTE: Static array parameters cannot currently be mapped to D properly, 224 // so all virtual methods starting from here are commented out 225 /+void copy_fuji_uncropped(ushort/*[4]*/* cblack, ushort *dmaxp); 226 void copy_bayer(ushort/*[4]*/* cblack, ushort *dmaxp); 227 void fuji_rotate(); 228 void convert_to_rgb_loop(float[4]/*[3]*/* out_cam); 229 void lin_interpolate_loop(int* code, int size); 230 void scale_colors_loop(float/*[4]*/* scale_mul); 231 void fuji_decode_loop(const(fuji_compressed_params)* common_info, int count, long *offsets, 232 uint *sizes);+/ 233 final void fuji_decode_strip(const(fuji_compressed_params)* info_common, int cur_block, long raw_offset, 234 uint size); 235 236 final int FCF(int row, int col) 237 { 238 int rr, cc; 239 if (libraw_internal_data.unpacker_data.fuji_layout) 240 { 241 rr = libraw_internal_data.internal_output_params.fuji_width - 1 - col + (row >> 1); 242 cc = col + ((row + 1) >> 1); 243 } 244 else 245 { 246 rr = libraw_internal_data.internal_output_params.fuji_width - 1 + row - (col >> 1); 247 cc = row + ((col + 1) >> 1); 248 } 249 return FC(rr, cc); 250 } 251 252 final void adjust_bl(); 253 final void *malloc(size_t t); 254 final void *calloc(size_t n, size_t t); 255 final void *realloc(void *p, size_t s); 256 final void free(void *p); 257 final void merror(void *ptr, const(char)* where); 258 final void derror(); 259 260 LibRaw_TLS tls; 261 libraw_internal_data_t libraw_internal_data; 262 decode[2048] first_decode; 263 decode* second_decode, free_decode; 264 tiff_ifd_t[LIBRAW_IFD_MAXCOUNT] tiff_ifd; 265 libraw_memmgr memmgr; 266 libraw_callbacks_t callbacks; 267 268 LibRaw_constants rgb_constants; 269 270 void function(LibRaw) write_thumb; 271 void function(LibRaw) write_fun; 272 void function(LibRaw) load_raw; 273 void function(LibRaw) thumb_load_raw; 274 void function(LibRaw) pentax_component_load_raw; 275 276 final void kodak_thumb_loader(); 277 final void write_thumb_ppm_tiff(/*FILE*/void *); 278 #ifdef USE_X3FTOOLS 279 final void x3f_thumb_loader(); 280 final long x3f_thumb_size(); 281 #endif 282 283 final int own_filtering_supported() { return 0; } 284 final void identify(); 285 final void initdata(); 286 final uint parse_custom_cameras(uint limit, libraw_custom_camera_t/*[]*/* table, char **list); 287 final void write_ppm_tiff(); 288 final void convert_to_rgb(); 289 final void remove_zeroes(); 290 final void crop_masked_pixels(); 291 version (NO_LCMS) {} 292 else { 293 final void apply_profile(const(char)* , const(char)* ); 294 } 295 final void pre_interpolate(); 296 final void border_interpolate(int border); 297 final void lin_interpolate(); 298 final void vng_interpolate(); 299 final void ppg_interpolate(); 300 final void cielab(ushort/*[3]*/* rgb, short/*[3]*/* lab); 301 final void xtrans_interpolate(int); 302 final void ahd_interpolate(); 303 final void dht_interpolate(); 304 final void aahd_interpolate(); 305 306 final void dcb(int iterations, int dcb_enhance); 307 final void fbdd(int noiserd); 308 final void exp_bef(float expos, float preser); 309 310 final void bad_pixels(const(char)* ); 311 final void subtract(const(char)* ); 312 final void hat_transform(float *temp, float *base, int st, int size, int sc); 313 final void wavelet_denoise(); 314 final void scale_colors(); 315 final void median_filter(); 316 final void blend_highlights(); 317 final void recover_highlights(); 318 final void green_matching(); 319 320 final void stretch(); 321 322 final void jpeg_thumb_writer(/*FILE*/void *tfp, char *thumb, int thumb_length); 323 final void jpeg_thumb(); 324 final void ppm_thumb(); 325 final void ppm16_thumb(); 326 final void layer_thumb(); 327 final void rollei_thumb(); 328 final void kodak_thumb_load_raw(); 329 330 final uint get4(); 331 332 final int flip_index(int row, int col); 333 final void gamma_curve(double pwr, double ts, int mode, int imax); 334 final void cubic_spline(const(int)*x_, const(int)*y_, const int len); 335 336 /* RawSpeed data */ 337 void *_rawspeed_camerameta; 338 void *_rawspeed_decoder; 339 final void fix_after_rawspeed(int bl); 340 final int try_rawspeed(); /* returns LIBRAW_SUCCESS on success */ 341 /* Fast cancel flag */ 342 c_long _exitflag; 343 344 /* DNG SDK data */ 345 void *dnghost; 346 final int valid_for_dngsdk(); 347 final int try_dngsdk(); 348 /* X3F data */ 349 void *_x3f_data; 350 351 final int raw_was_read() 352 { 353 return imgdata.rawdata.raw_image || imgdata.rawdata.color4_image || imgdata.rawdata.color3_image || 354 imgdata.rawdata.float_image || imgdata.rawdata.float3_image || imgdata.rawdata.float4_image; 355 } 356 357 /+#ifdef LIBRAW_LIBRARY_BUILD 358 #include "internal/libraw_internal_funcs.h" 359 #endif 360 #if LIBRAW_METADATA_LOOP_PREVENTION 361 uint metadata_blocks; /* This changes ABI, but offsets to prev.defined variables has not changed */ 362 #endif+/ 363 } 364 365 /+#ifdef LIBRAW_LIBRARY_BUILD 366 #define RUN_CALLBACK(stage, iter, expect) \ 367 if (callbacks.progress_cb) \ 368 { \ 369 int rr = (*callbacks.progress_cb)(callbacks.progresscb_data, stage, iter, expect); \ 370 if (rr != 0) \ 371 throw LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK; \ 372 } 373 #endif+/ 374 }+/