PageRenderTime 71ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/FreeImage/Source/LibRawLite/src/libraw_cxx.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 2789 lines | 2394 code | 297 blank | 98 comment | 519 complexity | b4e1584f4136f83772c17d3d5c8a25df MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, CPL-1.0, Unlicense, GPL-2.0, GPL-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, BSD-2-Clause, LGPL-2.1
  1. /* -*- C++ -*-
  2. * File: libraw_cxx.cpp
  3. * Copyright 2008-2010 LibRaw LLC (info@libraw.org)
  4. * Created: Sat Mar 8 , 2008
  5. *
  6. * LibRaw C++ interface (implementation)
  7. LibRaw is free software; you can redistribute it and/or modify
  8. it under the terms of the one of three licenses as you choose:
  9. 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
  10. (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
  11. 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  12. (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
  13. 3. LibRaw Software License 27032010
  14. (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details).
  15. */
  16. #include <math.h>
  17. #include <errno.h>
  18. #include <float.h>
  19. #include <new>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #ifndef WIN32
  23. #include <netinet/in.h>
  24. #else
  25. #include <winsock2.h>
  26. #endif
  27. #define LIBRAW_LIBRARY_BUILD
  28. #include "libraw/libraw.h"
  29. #include "internal/defines.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. void default_memory_callback(void *,const char *file,const char *where)
  35. {
  36. fprintf (stderr,"%s: Out of memory in %s\n", file?file:"unknown file", where);
  37. }
  38. void default_data_callback(void*,const char *file, const int offset)
  39. {
  40. if(offset < 0)
  41. fprintf (stderr,"%s: Unexpected end of file\n", file?file:"unknown file");
  42. else
  43. fprintf (stderr,"%s: data corrupted at %d\n",file?file:"unknown file",offset);
  44. }
  45. const char *libraw_strerror(int e)
  46. {
  47. enum LibRaw_errors errorcode = (LibRaw_errors)e;
  48. switch(errorcode)
  49. {
  50. case LIBRAW_SUCCESS:
  51. return "No error";
  52. case LIBRAW_UNSPECIFIED_ERROR:
  53. return "Unspecified error";
  54. case LIBRAW_FILE_UNSUPPORTED:
  55. return "Unsupported file format or not RAW file";
  56. case LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE:
  57. return "Request for nonexisting image number";
  58. case LIBRAW_OUT_OF_ORDER_CALL:
  59. return "Out of order call of libraw function";
  60. case LIBRAW_NO_THUMBNAIL:
  61. return "No thumbnail in file";
  62. case LIBRAW_UNSUPPORTED_THUMBNAIL:
  63. return "Unsupported thumbnail format";
  64. case LIBRAW_UNSUFFICIENT_MEMORY:
  65. return "Unsufficient memory";
  66. case LIBRAW_DATA_ERROR:
  67. return "Corrupted data or unexpected EOF";
  68. case LIBRAW_IO_ERROR:
  69. return "Input/output error";
  70. case LIBRAW_CANCELLED_BY_CALLBACK:
  71. return "Cancelled by user callback";
  72. case LIBRAW_BAD_CROP:
  73. return "Bad crop box";
  74. default:
  75. return "Unknown error code";
  76. }
  77. }
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. const double LibRaw_constants::xyz_rgb[3][3] =
  82. {
  83. { 0.412453, 0.357580, 0.180423 },
  84. { 0.212671, 0.715160, 0.072169 },
  85. { 0.019334, 0.119193, 0.950227 }
  86. };
  87. const float LibRaw_constants::d65_white[3] = { 0.950456f, 1.0f, 1.088754f };
  88. #define P1 imgdata.idata
  89. #define S imgdata.sizes
  90. #define O imgdata.params
  91. #define C imgdata.color
  92. #define T imgdata.thumbnail
  93. #define IO libraw_internal_data.internal_output_params
  94. #define ID libraw_internal_data.internal_data
  95. #define EXCEPTION_HANDLER(e) do{ \
  96. /* fprintf(stderr,"Exception %d caught\n",e);*/ \
  97. switch(e) \
  98. { \
  99. case LIBRAW_EXCEPTION_ALLOC: \
  100. recycle(); \
  101. return LIBRAW_UNSUFFICIENT_MEMORY; \
  102. case LIBRAW_EXCEPTION_DECODE_RAW: \
  103. case LIBRAW_EXCEPTION_DECODE_JPEG: \
  104. recycle(); \
  105. return LIBRAW_DATA_ERROR; \
  106. case LIBRAW_EXCEPTION_DECODE_JPEG2000: \
  107. recycle(); \
  108. return LIBRAW_DATA_ERROR; \
  109. case LIBRAW_EXCEPTION_IO_EOF: \
  110. case LIBRAW_EXCEPTION_IO_CORRUPT: \
  111. recycle(); \
  112. return LIBRAW_IO_ERROR; \
  113. case LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK:\
  114. recycle(); \
  115. return LIBRAW_CANCELLED_BY_CALLBACK; \
  116. case LIBRAW_EXCEPTION_BAD_CROP: \
  117. recycle(); \
  118. return LIBRAW_BAD_CROP; \
  119. default: \
  120. return LIBRAW_UNSPECIFIED_ERROR; \
  121. } \
  122. }while(0)
  123. const char* LibRaw::version() { return LIBRAW_VERSION_STR;}
  124. int LibRaw::versionNumber() { return LIBRAW_VERSION; }
  125. const char* LibRaw::strerror(int p) { return libraw_strerror(p);}
  126. void LibRaw::derror()
  127. {
  128. if (!libraw_internal_data.unpacker_data.data_error && libraw_internal_data.internal_data.input)
  129. {
  130. if (libraw_internal_data.internal_data.input->eof())
  131. {
  132. if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data,
  133. libraw_internal_data.internal_data.input->fname(),-1);
  134. throw LIBRAW_EXCEPTION_IO_EOF;
  135. }
  136. else
  137. {
  138. if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data,
  139. libraw_internal_data.internal_data.input->fname(),
  140. libraw_internal_data.internal_data.input->tell());
  141. throw LIBRAW_EXCEPTION_IO_CORRUPT;
  142. }
  143. }
  144. libraw_internal_data.unpacker_data.data_error++;
  145. }
  146. void LibRaw::dcraw_clear_mem(libraw_processed_image_t* p)
  147. {
  148. if(p) ::free(p);
  149. }
  150. #define ZERO(a) memset(&a,0,sizeof(a))
  151. LibRaw:: LibRaw(unsigned int flags)
  152. {
  153. double aber[4] = {1,1,1,1};
  154. double gamm[6] = { 0.45,4.5,0,0,0,0 };
  155. unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX };
  156. unsigned cropbox[4] = { 0, 0, UINT_MAX, UINT_MAX };
  157. #ifdef DCRAW_VERBOSE
  158. verbose = 1;
  159. #else
  160. verbose = 0;
  161. #endif
  162. ZERO(imgdata);
  163. ZERO(libraw_internal_data);
  164. ZERO(callbacks);
  165. callbacks.mem_cb = (flags & LIBRAW_OPIONS_NO_MEMERR_CALLBACK) ? NULL: &default_memory_callback;
  166. callbacks.data_cb = (flags & LIBRAW_OPIONS_NO_DATAERR_CALLBACK)? NULL : &default_data_callback;
  167. memmove(&imgdata.params.aber,&aber,sizeof(aber));
  168. memmove(&imgdata.params.gamm,&gamm,sizeof(gamm));
  169. memmove(&imgdata.params.greybox,&greybox,sizeof(greybox));
  170. memmove(&imgdata.params.cropbox,&cropbox,sizeof(cropbox));
  171. imgdata.params.bright=1;
  172. imgdata.params.use_camera_matrix=-1;
  173. imgdata.params.user_flip=-1;
  174. imgdata.params.user_black=-1;
  175. imgdata.params.user_sat=-1;
  176. imgdata.params.user_qual=-1;
  177. imgdata.params.output_color=1;
  178. imgdata.params.output_bps=8;
  179. imgdata.params.use_fuji_rotate=1;
  180. imgdata.params.exp_shift = 1.0;
  181. imgdata.params.auto_bright_thr = LIBRAW_DEFAULT_AUTO_BRIGHTNESS_THRESHOLD;
  182. imgdata.params.adjust_maximum_thr= LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD;
  183. imgdata.params.green_matching = 0;
  184. imgdata.parent_class = this;
  185. imgdata.progress_flags = 0;
  186. tls = new LibRaw_TLS;
  187. tls->init();
  188. }
  189. void* LibRaw:: malloc(size_t t)
  190. {
  191. void *p = memmgr.malloc(t);
  192. return p;
  193. }
  194. void* LibRaw:: realloc(void *q,size_t t)
  195. {
  196. void *p = memmgr.realloc(q,t);
  197. return p;
  198. }
  199. void* LibRaw:: calloc(size_t n,size_t t)
  200. {
  201. void *p = memmgr.calloc(n,t);
  202. return p;
  203. }
  204. void LibRaw:: free(void *p)
  205. {
  206. memmgr.free(p);
  207. }
  208. int LibRaw:: fc (int row, int col)
  209. {
  210. static const char filter[16][16] =
  211. { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 },
  212. { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 },
  213. { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 },
  214. { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 },
  215. { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 },
  216. { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 },
  217. { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 },
  218. { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 },
  219. { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 },
  220. { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 },
  221. { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 },
  222. { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 },
  223. { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 },
  224. { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 },
  225. { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 },
  226. { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } };
  227. if (imgdata.idata.filters != 1) return FC(row,col);
  228. return filter[(row+imgdata.sizes.top_margin) & 15][(col+imgdata.sizes.left_margin) & 15];
  229. }
  230. void LibRaw:: recycle()
  231. {
  232. if(libraw_internal_data.internal_data.input && libraw_internal_data.internal_data.input_internal)
  233. {
  234. delete libraw_internal_data.internal_data.input;
  235. libraw_internal_data.internal_data.input = NULL;
  236. }
  237. libraw_internal_data.internal_data.input_internal = 0;
  238. #define FREE(a) do { if(a) { free(a); a = NULL;} }while(0)
  239. FREE(imgdata.image);
  240. FREE(imgdata.thumbnail.thumb);
  241. FREE(libraw_internal_data.internal_data.meta_data);
  242. FREE(libraw_internal_data.output_data.histogram);
  243. FREE(libraw_internal_data.output_data.oprof);
  244. FREE(imgdata.color.profile);
  245. FREE(imgdata.rawdata.ph1_black);
  246. FREE(imgdata.rawdata.raw_alloc);
  247. #undef FREE
  248. ZERO(imgdata.rawdata);
  249. ZERO(imgdata.sizes);
  250. ZERO(imgdata.color);
  251. ZERO(libraw_internal_data);
  252. memmgr.cleanup();
  253. imgdata.thumbnail.tformat = LIBRAW_THUMBNAIL_UNKNOWN;
  254. imgdata.progress_flags = 0;
  255. tls->init();
  256. }
  257. const char * LibRaw::unpack_function_name()
  258. {
  259. libraw_decoder_info_t decoder_info;
  260. get_decoder_info(&decoder_info);
  261. return decoder_info.decoder_name;
  262. }
  263. int LibRaw::get_decoder_info(libraw_decoder_info_t* d_info)
  264. {
  265. if(!d_info) return LIBRAW_UNSPECIFIED_ERROR;
  266. if(!load_raw) return LIBRAW_OUT_OF_ORDER_CALL;
  267. d_info->decoder_flags = LIBRAW_DECODER_NOTSET;
  268. // sorted names order
  269. if (load_raw == &LibRaw::adobe_dng_load_raw_lj)
  270. {
  271. // Check rbayer
  272. d_info->decoder_name = "adobe_dng_load_raw_lj()";
  273. d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT ;
  274. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  275. }
  276. else if (load_raw == &LibRaw::adobe_dng_load_raw_nc)
  277. {
  278. // Check rbayer
  279. d_info->decoder_name = "adobe_dng_load_raw_nc()";
  280. d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT;
  281. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  282. }
  283. else if (load_raw == &LibRaw::canon_600_load_raw)
  284. {
  285. d_info->decoder_name = "canon_600_load_raw()";
  286. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; // WB set within decoder, no need to load raw
  287. }
  288. else if (load_raw == &LibRaw::canon_compressed_load_raw)
  289. {
  290. d_info->decoder_name = "canon_compressed_load_raw()";
  291. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  292. }
  293. else if (load_raw == &LibRaw::canon_sraw_load_raw)
  294. {
  295. d_info->decoder_name = "canon_sraw_load_raw()";
  296. d_info->decoder_flags = LIBRAW_DECODER_LEGACY;
  297. }
  298. else if (load_raw == &LibRaw::eight_bit_load_raw )
  299. {
  300. d_info->decoder_name = "eight_bit_load_raw()";
  301. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  302. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  303. }
  304. else if (load_raw == &LibRaw::foveon_load_raw )
  305. {
  306. d_info->decoder_name = "foveon_load_raw()";
  307. d_info->decoder_flags = LIBRAW_DECODER_LEGACY;
  308. }
  309. else if (load_raw == &LibRaw::fuji_load_raw )
  310. {
  311. d_info->decoder_name = "fuji_load_raw()";
  312. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  313. }
  314. else if (load_raw == &LibRaw::hasselblad_load_raw )
  315. {
  316. d_info->decoder_name = "hasselblad_load_raw()";
  317. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  318. }
  319. else if (load_raw == &LibRaw::imacon_full_load_raw )
  320. {
  321. d_info->decoder_name = "imacon_full_load_raw()";
  322. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  323. }
  324. else if (load_raw == &LibRaw::kodak_262_load_raw )
  325. {
  326. d_info->decoder_name = "kodak_262_load_raw()"; // UNTESTED!
  327. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  328. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  329. }
  330. else if (load_raw == &LibRaw::kodak_65000_load_raw )
  331. {
  332. d_info->decoder_name = "kodak_65000_load_raw()";
  333. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  334. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  335. }
  336. else if (load_raw == &LibRaw::kodak_dc120_load_raw )
  337. {
  338. d_info->decoder_name = "kodak_dc120_load_raw()";
  339. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  340. }
  341. else if (load_raw == &LibRaw::kodak_jpeg_load_raw )
  342. {
  343. // UNTESTED + RBAYER
  344. d_info->decoder_name = "kodak_jpeg_load_raw()";
  345. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  346. }
  347. else if (load_raw == &LibRaw::kodak_radc_load_raw )
  348. {
  349. d_info->decoder_name = "kodak_radc_load_raw()";
  350. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  351. }
  352. else if (load_raw == &LibRaw::kodak_rgb_load_raw )
  353. {
  354. // UNTESTED
  355. d_info->decoder_name = "kodak_rgb_load_raw()";
  356. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  357. }
  358. else if (load_raw == &LibRaw::kodak_yrgb_load_raw )
  359. {
  360. d_info->decoder_name = "kodak_yrgb_load_raw()";
  361. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  362. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  363. }
  364. else if (load_raw == &LibRaw::kodak_ycbcr_load_raw )
  365. {
  366. // UNTESTED
  367. d_info->decoder_name = "kodak_ycbcr_load_raw()";
  368. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  369. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  370. }
  371. else if (load_raw == &LibRaw::leaf_hdr_load_raw )
  372. {
  373. d_info->decoder_name = "leaf_hdr_load_raw()";
  374. d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT;
  375. }
  376. else if (load_raw == &LibRaw::lossless_jpeg_load_raw)
  377. {
  378. // Check rbayer
  379. d_info->decoder_name = "lossless_jpeg_load_raw()";
  380. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_HASCURVE;
  381. }
  382. else if (load_raw == &LibRaw::minolta_rd175_load_raw )
  383. {
  384. // UNTESTED
  385. d_info->decoder_name = "minolta_rd175_load_raw()";
  386. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  387. }
  388. else if (load_raw == &LibRaw::nikon_compressed_load_raw)
  389. {
  390. // Check rbayer
  391. d_info->decoder_name = "nikon_compressed_load_raw()";
  392. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  393. }
  394. else if (load_raw == &LibRaw::nokia_load_raw )
  395. {
  396. // UNTESTED
  397. d_info->decoder_name = "nokia_load_raw()";
  398. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  399. }
  400. else if (load_raw == &LibRaw::olympus_load_raw )
  401. {
  402. d_info->decoder_name = "olympus_load_raw()";
  403. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  404. }
  405. else if (load_raw == &LibRaw::packed_load_raw )
  406. {
  407. d_info->decoder_name = "packed_load_raw()";
  408. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  409. }
  410. else if (load_raw == &LibRaw::panasonic_load_raw )
  411. {
  412. d_info->decoder_name = "panasonic_load_raw()";
  413. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  414. }
  415. else if (load_raw == &LibRaw::pentax_load_raw )
  416. {
  417. d_info->decoder_name = "pentax_load_raw()";
  418. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  419. }
  420. else if (load_raw == &LibRaw::phase_one_load_raw )
  421. {
  422. d_info->decoder_name = "phase_one_load_raw()";
  423. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  424. }
  425. else if (load_raw == &LibRaw::phase_one_load_raw_c )
  426. {
  427. d_info->decoder_name = "phase_one_load_raw_c()";
  428. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  429. }
  430. else if (load_raw == &LibRaw::quicktake_100_load_raw )
  431. {
  432. // UNTESTED
  433. d_info->decoder_name = "quicktake_100_load_raw()";
  434. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  435. }
  436. else if (load_raw == &LibRaw::rollei_load_raw )
  437. {
  438. // UNTESTED
  439. d_info->decoder_name = "rollei_load_raw()";
  440. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  441. }
  442. else if (load_raw == &LibRaw::sinar_4shot_load_raw )
  443. {
  444. // UNTESTED
  445. d_info->decoder_name = "sinar_4shot_load_raw()";
  446. d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT;
  447. }
  448. else if (load_raw == &LibRaw::smal_v6_load_raw )
  449. {
  450. // UNTESTED
  451. d_info->decoder_name = "smal_v6_load_raw()";
  452. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  453. }
  454. else if (load_raw == &LibRaw::smal_v9_load_raw )
  455. {
  456. // UNTESTED
  457. d_info->decoder_name = "smal_v9_load_raw()";
  458. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  459. }
  460. else if (load_raw == &LibRaw::sony_load_raw )
  461. {
  462. d_info->decoder_name = "sony_load_raw()";
  463. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  464. }
  465. else if (load_raw == &LibRaw::sony_arw_load_raw )
  466. {
  467. d_info->decoder_name = "sony_arw_load_raw()";
  468. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  469. }
  470. else if (load_raw == &LibRaw::sony_arw2_load_raw )
  471. {
  472. d_info->decoder_name = "sony_arw2_load_raw()";
  473. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  474. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  475. }
  476. else if (load_raw == &LibRaw::unpacked_load_raw )
  477. {
  478. d_info->decoder_name = "unpacked_load_raw()";
  479. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_USEBAYER2;
  480. }
  481. else if (load_raw == &LibRaw::redcine_load_raw)
  482. {
  483. d_info->decoder_name = "redcine_load_raw()";
  484. d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD;
  485. d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE;
  486. }
  487. else
  488. {
  489. d_info->decoder_name = "Unknown unpack function";
  490. d_info->decoder_flags = LIBRAW_DECODER_NOTSET;
  491. }
  492. return LIBRAW_SUCCESS;
  493. }
  494. int LibRaw::adjust_maximum()
  495. {
  496. int i;
  497. ushort real_max;
  498. float auto_threshold;
  499. if(O.adjust_maximum_thr < 0.00001)
  500. return LIBRAW_SUCCESS;
  501. else if (O.adjust_maximum_thr > 0.99999)
  502. auto_threshold = LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD;
  503. else
  504. auto_threshold = O.adjust_maximum_thr;
  505. real_max = C.channel_maximum[0];
  506. for(i = 1; i< 4; i++)
  507. if(real_max < C.channel_maximum[i])
  508. real_max = C.channel_maximum[i];
  509. if (real_max > 0 && real_max < C.maximum && real_max > C.maximum* auto_threshold)
  510. {
  511. C.maximum = real_max;
  512. }
  513. return LIBRAW_SUCCESS;
  514. }
  515. void LibRaw:: merror (void *ptr, const char *where)
  516. {
  517. if (ptr) return;
  518. if(callbacks.mem_cb)(*callbacks.mem_cb)(callbacks.memcb_data,
  519. libraw_internal_data.internal_data.input
  520. ?libraw_internal_data.internal_data.input->fname()
  521. :NULL,
  522. where);
  523. throw LIBRAW_EXCEPTION_ALLOC;
  524. }
  525. int LibRaw::open_file(const char *fname, INT64 max_buf_size)
  526. {
  527. #ifndef WIN32
  528. struct stat st;
  529. if(stat(fname,&st))
  530. return LIBRAW_IO_ERROR;
  531. int big = (st.st_size > max_buf_size)?1:0;
  532. #else
  533. struct _stati64 st;
  534. if(_stati64(fname,&st))
  535. return LIBRAW_IO_ERROR;
  536. int big = (st.st_size > max_buf_size)?1:0;
  537. #endif
  538. LibRaw_abstract_datastream *stream;
  539. try {
  540. if(big)
  541. stream = new LibRaw_bigfile_datastream(fname);
  542. else
  543. stream = new LibRaw_file_datastream(fname);
  544. }
  545. catch (std::bad_alloc)
  546. {
  547. recycle();
  548. return LIBRAW_UNSUFFICIENT_MEMORY;
  549. }
  550. if(!stream->valid())
  551. {
  552. delete stream;
  553. return LIBRAW_IO_ERROR;
  554. }
  555. ID.input_internal = 0; // preserve from deletion on error
  556. int ret = open_datastream(stream);
  557. if (ret == LIBRAW_SUCCESS)
  558. {
  559. ID.input_internal =1 ; // flag to delete datastream on recycle
  560. }
  561. else
  562. {
  563. delete stream;
  564. ID.input_internal = 0;
  565. }
  566. return ret;
  567. }
  568. int LibRaw::open_buffer(void *buffer, size_t size)
  569. {
  570. // this stream will close on recycle()
  571. if(!buffer || buffer==(void*)-1)
  572. return LIBRAW_IO_ERROR;
  573. LibRaw_buffer_datastream *stream;
  574. try {
  575. stream = new LibRaw_buffer_datastream(buffer,size);
  576. }
  577. catch (std::bad_alloc)
  578. {
  579. recycle();
  580. return LIBRAW_UNSUFFICIENT_MEMORY;
  581. }
  582. if(!stream->valid())
  583. {
  584. delete stream;
  585. return LIBRAW_IO_ERROR;
  586. }
  587. ID.input_internal = 0; // preserve from deletion on error
  588. int ret = open_datastream(stream);
  589. if (ret == LIBRAW_SUCCESS)
  590. {
  591. ID.input_internal =1 ; // flag to delete datastream on recycle
  592. }
  593. else
  594. {
  595. delete stream;
  596. ID.input_internal = 0;
  597. }
  598. return ret;
  599. }
  600. int LibRaw::open_datastream(LibRaw_abstract_datastream *stream)
  601. {
  602. if(!stream)
  603. return ENOENT;
  604. if(!stream->valid())
  605. return LIBRAW_IO_ERROR;
  606. recycle();
  607. try {
  608. ID.input = stream;
  609. SET_PROC_FLAG(LIBRAW_PROGRESS_OPEN);
  610. if (O.use_camera_matrix < 0)
  611. O.use_camera_matrix = O.use_camera_wb;
  612. identify();
  613. if(IO.fuji_width)
  614. {
  615. IO.fwidth = S.width;
  616. IO.fheight = S.height;
  617. S.iwidth = S.width = IO.fuji_width << (int)(!libraw_internal_data.unpacker_data.fuji_layout);
  618. S.iheight = S.height = S.raw_height;
  619. S.raw_height += 2*S.top_margin;
  620. }
  621. if(C.profile_length)
  622. {
  623. if(C.profile) free(C.profile);
  624. C.profile = malloc(C.profile_length);
  625. merror(C.profile,"LibRaw::open_file()");
  626. ID.input->seek(ID.profile_offset,SEEK_SET);
  627. ID.input->read(C.profile,C.profile_length,1);
  628. }
  629. SET_PROC_FLAG(LIBRAW_PROGRESS_IDENTIFY);
  630. }
  631. catch ( LibRaw_exceptions err) {
  632. EXCEPTION_HANDLER(err);
  633. }
  634. if(P1.raw_count < 1)
  635. return LIBRAW_FILE_UNSUPPORTED;
  636. write_fun = &LibRaw::write_ppm_tiff;
  637. if (load_raw == &LibRaw::kodak_ycbcr_load_raw)
  638. {
  639. S.height += S.height & 1;
  640. S.width += S.width & 1;
  641. }
  642. IO.shrink = P1.filters && (O.half_size ||
  643. ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) ));
  644. S.iheight = (S.height + IO.shrink) >> IO.shrink;
  645. S.iwidth = (S.width + IO.shrink) >> IO.shrink;
  646. // Save color,sizes and internal data into raw_image fields
  647. memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color));
  648. memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes));
  649. memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata));
  650. memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params));
  651. SET_PROC_FLAG(LIBRAW_PROGRESS_SIZE_ADJUST);
  652. return LIBRAW_SUCCESS;
  653. }
  654. int LibRaw::unpack(void)
  655. {
  656. CHECK_ORDER_HIGH(LIBRAW_PROGRESS_LOAD_RAW);
  657. CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
  658. try {
  659. RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,0,2);
  660. if (O.shot_select >= P1.raw_count)
  661. return LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE;
  662. if(!load_raw)
  663. return LIBRAW_UNSPECIFIED_ERROR;
  664. if (O.use_camera_matrix && C.cmatrix[0][0] > 0.25)
  665. {
  666. memcpy (C.rgb_cam, C.cmatrix, sizeof (C.cmatrix));
  667. IO.raw_color = 0;
  668. }
  669. // already allocated ?
  670. if(imgdata.image)
  671. {
  672. free(imgdata.image);
  673. imgdata.image = 0;
  674. }
  675. if (libraw_internal_data.unpacker_data.meta_length)
  676. {
  677. libraw_internal_data.internal_data.meta_data =
  678. (char *) malloc (libraw_internal_data.unpacker_data.meta_length);
  679. merror (libraw_internal_data.internal_data.meta_data, "LibRaw::unpack()");
  680. }
  681. ID.input->seek(libraw_internal_data.unpacker_data.data_offset, SEEK_SET);
  682. int save_document_mode = O.document_mode;
  683. O.document_mode = 0;
  684. libraw_decoder_info_t decoder_info;
  685. get_decoder_info(&decoder_info);
  686. int save_iwidth = S.iwidth, save_iheight = S.iheight, save_shrink = IO.shrink;
  687. int rwidth = S.raw_width, rheight = S.raw_height;
  688. if( !IO.fuji_width)
  689. {
  690. // adjust non-Fuji allocation
  691. if(rwidth < S.width + S.left_margin)
  692. rwidth = S.width + S.left_margin;
  693. if(rheight < S.height + S.top_margin)
  694. rheight = S.height + S.top_margin;
  695. }
  696. if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD)
  697. {
  698. imgdata.rawdata.raw_alloc = malloc(rwidth*rheight*sizeof(imgdata.rawdata.raw_image[0]));
  699. imgdata.rawdata.raw_image = (ushort*) imgdata.rawdata.raw_alloc;
  700. }
  701. else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT)
  702. {
  703. S.iwidth = S.width;
  704. S.iheight= S.height;
  705. IO.shrink = 0;
  706. imgdata.rawdata.raw_alloc = calloc(rwidth*rheight,sizeof(*imgdata.rawdata.color_image));
  707. imgdata.rawdata.color_image = (ushort(*)[4]) imgdata.rawdata.raw_alloc;
  708. }
  709. else if (decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY)
  710. {
  711. // sRAW and Foveon only, so extra buffer size is just 1/4
  712. // Legacy converters does not supports half mode!
  713. S.iwidth = S.width;
  714. S.iheight= S.height;
  715. IO.shrink = 0;
  716. // allocate image as temporary buffer, size
  717. imgdata.rawdata.raw_alloc = calloc(S.iwidth*S.iheight,sizeof(*imgdata.image));
  718. imgdata.image = (ushort (*)[4]) imgdata.rawdata.raw_alloc;
  719. }
  720. (this->*load_raw)();
  721. // recover saved
  722. if( decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY)
  723. {
  724. imgdata.image = 0;
  725. imgdata.rawdata.color_image = (ushort (*)[4]) imgdata.rawdata.raw_alloc;
  726. }
  727. // calculate channel maximum
  728. {
  729. for(int c=0;c<4;c++) C.channel_maximum[c] = 0;
  730. if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY)
  731. {
  732. for(int rc = 0; rc < S.iwidth*S.iheight; rc++)
  733. {
  734. if(C.channel_maximum[0]<imgdata.rawdata.color_image[rc][0])
  735. C.channel_maximum[0]=imgdata.rawdata.color_image[rc][0];
  736. if(C.channel_maximum[1]<imgdata.rawdata.color_image[rc][1])
  737. C.channel_maximum[1]=imgdata.rawdata.color_image[rc][1];
  738. if(C.channel_maximum[2]<imgdata.rawdata.color_image[rc][2])
  739. C.channel_maximum[2]=imgdata.rawdata.color_image[rc][2];
  740. if(C.channel_maximum[3]<imgdata.rawdata.color_image[rc][3])
  741. C.channel_maximum[3]=imgdata.rawdata.color_image[rc][3];
  742. }
  743. }
  744. else if(decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT)
  745. {
  746. for(int row = S.top_margin; row < S.height+S.top_margin; row++)
  747. for(int col = S.left_margin; col < S.width+S.left_margin; col++)
  748. {
  749. int rc = row*S.raw_width+col;
  750. if(C.channel_maximum[0]<imgdata.rawdata.color_image[rc][0])
  751. C.channel_maximum[0]=imgdata.rawdata.color_image[rc][0];
  752. if(C.channel_maximum[1]<imgdata.rawdata.color_image[rc][1])
  753. C.channel_maximum[1]=imgdata.rawdata.color_image[rc][1];
  754. if(C.channel_maximum[2]<imgdata.rawdata.color_image[rc][2])
  755. C.channel_maximum[2]=imgdata.rawdata.color_image[rc][2];
  756. if(C.channel_maximum[3]<imgdata.rawdata.color_image[rc][3])
  757. C.channel_maximum[3]=imgdata.rawdata.color_image[rc][4];
  758. }
  759. }
  760. else if (decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD)
  761. {
  762. for(int row = 0; row < S.height; row++)
  763. {
  764. int colors[4];
  765. for (int xx=0;xx<4;xx++)
  766. colors[xx] = COLOR(row,xx);
  767. for(int col = 0; col < S.width; col++)
  768. {
  769. int cc = colors[col&3];
  770. if(C.channel_maximum[cc]
  771. < imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  772. +(col+S.left_margin)])
  773. C.channel_maximum[cc] =
  774. imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  775. +(col+S.left_margin)];
  776. }
  777. }
  778. }
  779. }
  780. // recover image sizes
  781. S.iwidth = save_iwidth;
  782. S.iheight = save_iheight;
  783. IO.shrink = save_shrink;
  784. // phase-one black
  785. if(imgdata.rawdata.ph1_black)
  786. C.ph1_black = imgdata.rawdata.ph1_black;
  787. O.document_mode = save_document_mode;
  788. // adjust black to possible maximum
  789. unsigned int i = C.cblack[3];
  790. unsigned int c;
  791. for(c=0;c<3;c++)
  792. if (i > C.cblack[c]) i = C.cblack[c];
  793. for (c=0;c<4;c++)
  794. C.cblack[c] -= i;
  795. C.black += i;
  796. // Save color,sizes and internal data into raw_image fields
  797. memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color));
  798. memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes));
  799. memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata));
  800. memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params));
  801. SET_PROC_FLAG(LIBRAW_PROGRESS_LOAD_RAW);
  802. RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,1,2);
  803. return 0;
  804. }
  805. catch ( LibRaw_exceptions err) {
  806. EXCEPTION_HANDLER(err);
  807. }
  808. }
  809. void LibRaw::free_image(void)
  810. {
  811. if(imgdata.image)
  812. {
  813. free(imgdata.image);
  814. imgdata.image = 0;
  815. imgdata.progress_flags
  816. = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN
  817. |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW;
  818. }
  819. }
  820. void LibRaw::raw2image_start()
  821. {
  822. // restore color,sizes and internal data into raw_image fields
  823. memmove(&imgdata.color,&imgdata.rawdata.color,sizeof(imgdata.color));
  824. memmove(&imgdata.sizes,&imgdata.rawdata.sizes,sizeof(imgdata.sizes));
  825. memmove(&imgdata.idata,&imgdata.rawdata.iparams,sizeof(imgdata.idata));
  826. memmove(&libraw_internal_data.internal_output_params,&imgdata.rawdata.ioparams,sizeof(libraw_internal_data.internal_output_params));
  827. if (O.user_flip >= 0)
  828. S.flip = O.user_flip;
  829. switch ((S.flip+3600) % 360)
  830. {
  831. case 270: S.flip = 5; break;
  832. case 180: S.flip = 3; break;
  833. case 90: S.flip = 6; break;
  834. }
  835. // adjust for half mode!
  836. IO.shrink = P1.filters && (O.half_size ||
  837. ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) ));
  838. S.iheight = (S.height + IO.shrink) >> IO.shrink;
  839. S.iwidth = (S.width + IO.shrink) >> IO.shrink;
  840. if (O.user_black >= 0)
  841. C.black = O.user_black;
  842. }
  843. // Same as raw2image, but
  844. // 1) Do raw2image and rotate_fuji_raw in one pass
  845. // 2) Do raw2image and cropping in one pass
  846. #ifndef MIN
  847. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  848. #endif
  849. int LibRaw::raw2image_ex(void)
  850. {
  851. CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
  852. raw2image_start();
  853. // process cropping
  854. int do_crop = 0;
  855. unsigned save_filters = imgdata.idata.filters;
  856. unsigned save_width = S.width;
  857. if (~O.cropbox[2] && ~O.cropbox[3])
  858. {
  859. int crop[4],c,filt;
  860. for(int c=0;c<4;c++)
  861. {
  862. crop[c] = O.cropbox[c];
  863. if(crop[c]<0)
  864. crop[c]=0;
  865. }
  866. if(IO.fwidth)
  867. {
  868. crop[0] = (crop[0]/4)*4;
  869. crop[1] = (crop[1]/4)*4;
  870. }
  871. do_crop = 1;
  872. crop[2] = MIN (crop[2], (signed) S.width-crop[0]);
  873. crop[3] = MIN (crop[3], (signed) S.height-crop[1]);
  874. if (crop[2] <= 0 || crop[3] <= 0)
  875. throw LIBRAW_EXCEPTION_BAD_CROP;
  876. // adjust sizes!
  877. S.left_margin+=crop[0];
  878. S.top_margin+=crop[1];
  879. S.width=crop[2];
  880. S.height=crop[3];
  881. S.iheight = (S.height + IO.shrink) >> IO.shrink;
  882. S.iwidth = (S.width + IO.shrink) >> IO.shrink;
  883. if(!IO.fwidth && imgdata.idata.filters)
  884. {
  885. for (filt=c=0; c < 16; c++)
  886. filt |= FC((c >> 1)+(crop[1]),
  887. (c & 1)+(crop[0])) << c*2;
  888. imgdata.idata.filters = filt;
  889. }
  890. }
  891. if(IO.fwidth)
  892. {
  893. ushort fiwidth,fiheight;
  894. if(do_crop)
  895. {
  896. IO.fuji_width = S.width >> !libraw_internal_data.unpacker_data.fuji_layout;
  897. IO.fwidth = (S.height >> libraw_internal_data.unpacker_data.fuji_layout) + IO.fuji_width;
  898. IO.fheight = IO.fwidth - 1;
  899. }
  900. fiheight = (IO.fheight + IO.shrink) >> IO.shrink;
  901. fiwidth = (IO.fwidth + IO.shrink) >> IO.shrink;
  902. if(imgdata.image)
  903. {
  904. imgdata.image = (ushort (*)[4])realloc(imgdata.image,fiheight*fiwidth*sizeof (*imgdata.image));
  905. memset(imgdata.image,0,fiheight*fiwidth *sizeof (*imgdata.image));
  906. }
  907. else
  908. imgdata.image = (ushort (*)[4]) calloc (fiheight*fiwidth, sizeof (*imgdata.image));
  909. merror (imgdata.image, "raw2image_ex()");
  910. int cblk[4],i;
  911. for(i=0;i<4;i++)
  912. cblk[i] = C.cblack[i]+C.black;
  913. ZERO(C.channel_maximum);
  914. int row,col;
  915. for(row=0;row<S.height;row++)
  916. {
  917. for(col=0;col<S.width;col++)
  918. {
  919. int r,c;
  920. if (libraw_internal_data.unpacker_data.fuji_layout) {
  921. r = IO.fuji_width - 1 - col + (row >> 1);
  922. c = col + ((row+1) >> 1);
  923. } else {
  924. r = IO.fuji_width - 1 + row - (col >> 1);
  925. c = row + ((col+1) >> 1);
  926. }
  927. int val = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  928. +(col+S.left_margin)];
  929. int cc = FCF(row,col);
  930. if(val > cblk[cc])
  931. val -= cblk[cc];
  932. else
  933. val = 0;
  934. imgdata.image[((r) >> IO.shrink)*fiwidth + ((c) >> IO.shrink)][cc] = val;
  935. if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val;
  936. }
  937. }
  938. C.maximum -= C.black;
  939. ZERO(C.cblack);
  940. C.black = 0;
  941. // restore fuji sizes!
  942. S.height = IO.fheight;
  943. S.width = IO.fwidth;
  944. S.iheight = (S.height + IO.shrink) >> IO.shrink;
  945. S.iwidth = (S.width + IO.shrink) >> IO.shrink;
  946. S.raw_height -= 2*S.top_margin;
  947. }
  948. else
  949. {
  950. if(imgdata.image)
  951. {
  952. imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth
  953. *sizeof (*imgdata.image));
  954. memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image));
  955. }
  956. else
  957. imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image));
  958. merror (imgdata.image, "raw2image_ex()");
  959. libraw_decoder_info_t decoder_info;
  960. get_decoder_info(&decoder_info);
  961. if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD)
  962. {
  963. if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2)
  964. #if defined(LIBRAW_USE_OPENMP)
  965. #pragma omp parallel for default(shared)
  966. #endif
  967. for(int row = 0; row < S.height; row++)
  968. for(int col = 0; col < S.width; col++)
  969. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)]
  970. = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  971. +(col+S.left_margin)];
  972. else
  973. #if defined(LIBRAW_USE_OPENMP)
  974. #pragma omp parallel for default(shared)
  975. #endif
  976. for(int row = 0; row < S.height; row++)
  977. {
  978. int colors[2];
  979. for (int xx=0;xx<2;xx++)
  980. colors[xx] = COLOR(row,xx);
  981. for(int col = 0; col < S.width; col++)
  982. {
  983. int cc = colors[col&1];
  984. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] =
  985. imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  986. +(col+S.left_margin)];
  987. }
  988. }
  989. }
  990. else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT)
  991. {
  992. #define FC0(row,col) (save_filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3)
  993. if(IO.shrink)
  994. #if defined(LIBRAW_USE_OPENMP)
  995. #pragma omp parallel for default(shared)
  996. #endif
  997. for(int row = 0; row < S.height; row++)
  998. for(int col = 0; col < S.width; col++)
  999. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][FC(row,col)]
  1000. = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width
  1001. +S.left_margin+col]
  1002. [FC0(row+S.top_margin,col+S.left_margin)];
  1003. #undef FC0
  1004. else
  1005. #if defined(LIBRAW_USE_OPENMP)
  1006. #pragma omp parallel for default(shared)
  1007. #endif
  1008. for(int row = 0; row < S.height; row++)
  1009. memmove(&imgdata.image[row*S.width],
  1010. &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin],
  1011. S.width*sizeof(*imgdata.image));
  1012. }
  1013. else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY)
  1014. {
  1015. if(do_crop)
  1016. #if defined(LIBRAW_USE_OPENMP)
  1017. #pragma omp parallel for default(shared)
  1018. #endif
  1019. for(int row = 0; row < S.height; row++)
  1020. memmove(&imgdata.image[row*S.width],
  1021. &imgdata.rawdata.color_image[(row+S.top_margin)*save_width+S.left_margin],
  1022. S.width*sizeof(*imgdata.image));
  1023. else
  1024. memmove(imgdata.image,imgdata.rawdata.color_image,
  1025. S.width*S.height*sizeof(*imgdata.image));
  1026. }
  1027. if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked!
  1028. phase_one_correct();
  1029. }
  1030. return LIBRAW_SUCCESS;
  1031. }
  1032. #undef MIN
  1033. int LibRaw::raw2image(void)
  1034. {
  1035. CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
  1036. try {
  1037. raw2image_start();
  1038. // free and re-allocate image bitmap
  1039. if(imgdata.image)
  1040. {
  1041. imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth *sizeof (*imgdata.image));
  1042. memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image));
  1043. }
  1044. else
  1045. imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image));
  1046. merror (imgdata.image, "raw2image()");
  1047. libraw_decoder_info_t decoder_info;
  1048. get_decoder_info(&decoder_info);
  1049. // Move saved bitmap to imgdata.image
  1050. if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD)
  1051. {
  1052. if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2)
  1053. {
  1054. for(int row = 0; row < S.height; row++)
  1055. for(int col = 0; col < S.width; col++)
  1056. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)]
  1057. = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width
  1058. +(col+S.left_margin)];
  1059. }
  1060. else
  1061. {
  1062. for(int row = 0; row < S.height; row++)
  1063. {
  1064. int colors[4];
  1065. for (int xx=0;xx<4;xx++)
  1066. colors[xx] = COLOR(row,xx);
  1067. for(int col = 0; col < S.width; col++)
  1068. {
  1069. int cc = colors[col&3];
  1070. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] =
  1071. imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width+(col
  1072. +S.left_margin)];
  1073. }
  1074. }
  1075. }
  1076. }
  1077. else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT)
  1078. {
  1079. if(IO.shrink)
  1080. {
  1081. for(int row = 0; row < S.height; row++)
  1082. for(int col = 0; col < S.width; col++)
  1083. {
  1084. int cc = FC(row,col);
  1085. imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc]
  1086. = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width
  1087. +S.left_margin+col][cc];
  1088. }
  1089. }
  1090. else
  1091. for(int row = 0; row < S.height; row++)
  1092. memmove(&imgdata.image[row*S.width],
  1093. &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin],
  1094. S.width*sizeof(*imgdata.image));
  1095. }
  1096. else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY)
  1097. {
  1098. // legacy is always 4channel and not shrinked!
  1099. memmove(imgdata.image,imgdata.rawdata.color_image,S.width*S.height*sizeof(*imgdata.image));
  1100. }
  1101. if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked!
  1102. phase_one_correct();
  1103. // hack - clear later flags!
  1104. imgdata.progress_flags
  1105. = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN
  1106. |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW;
  1107. return 0;
  1108. }
  1109. catch ( LibRaw_exceptions err) {
  1110. EXCEPTION_HANDLER(err);
  1111. }
  1112. }
  1113. int LibRaw::dcraw_document_mode_processing(void)
  1114. {
  1115. // CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE);
  1116. CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
  1117. try {
  1118. int no_crop = 1;
  1119. if (~O.cropbox[2] && ~O.cropbox[3])
  1120. no_crop=0;
  1121. raw2image_ex(); // raw2image+crop+rotate_fuji_raw
  1122. if (IO.zero_is_bad)
  1123. {
  1124. remove_zeroes();
  1125. SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES);
  1126. }
  1127. if(!IO.fuji_width)
  1128. subtract_black();
  1129. O.document_mode = 2;
  1130. if(P1.is_foveon)
  1131. {
  1132. // filter image data for foveon document mode
  1133. short *iptr = (short *)imgdata.image;
  1134. for (int i=0; i < S.height*S.width*4; i++)
  1135. {
  1136. if ((short) iptr[i] < 0)
  1137. iptr[i] = 0;
  1138. }
  1139. SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE);
  1140. }
  1141. O.use_fuji_rotate = 0;
  1142. if(O.bad_pixels && no_crop)
  1143. {
  1144. bad_pixels(O.bad_pixels);
  1145. SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS);
  1146. }
  1147. if (O.dark_frame && no_crop)
  1148. {
  1149. subtract (O.dark_frame);
  1150. SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME);
  1151. }
  1152. adjust_maximum();
  1153. if (O.user_sat > 0)
  1154. C.maximum = O.user_sat;
  1155. pre_interpolate();
  1156. SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE);
  1157. if (libraw_internal_data.internal_output_params.mix_green)
  1158. {
  1159. int i;
  1160. for (P1.colors=3, i=0; i < S.height*S.width; i++)
  1161. imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1;
  1162. }
  1163. SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN);
  1164. if (!P1.is_foveon && P1.colors == 3)
  1165. median_filter();
  1166. SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER);
  1167. if (!P1.is_foveon && O.highlight == 2)
  1168. blend_highlights();
  1169. if (!P1.is_foveon && O.highlight > 2)
  1170. recover_highlights();
  1171. SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
  1172. if (O.use_fuji_rotate)
  1173. fuji_rotate();
  1174. SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
  1175. #ifndef NO_LCMS
  1176. if(O.camera_profile)
  1177. {
  1178. apply_profile(O.camera_profile,O.output_profile);
  1179. SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE);
  1180. }
  1181. #endif
  1182. if(!libraw_internal_data.output_data.histogram)
  1183. {
  1184. libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
  1185. merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_document_mode_processing()");
  1186. }
  1187. convert_to_rgb();
  1188. SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB);
  1189. if (O.use_fuji_rotate)
  1190. stretch();
  1191. SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH);
  1192. return 0;
  1193. }
  1194. catch ( LibRaw_exceptions err) {
  1195. EXCEPTION_HANDLER(err);
  1196. }
  1197. }
  1198. #if 1
  1199. libraw_processed_image_t * LibRaw::dcraw_make_mem_thumb(int *errcode)
  1200. {
  1201. if(!T.thumb)
  1202. {
  1203. if ( !ID.toffset)
  1204. {
  1205. if(errcode) *errcode= LIBRAW_NO_THUMBNAIL;
  1206. }
  1207. else
  1208. {
  1209. if(errcode) *errcode= LIBRAW_OUT_OF_ORDER_CALL;
  1210. }
  1211. return NULL;
  1212. }
  1213. if (T.tformat == LIBRAW_THUMBNAIL_BITMAP)
  1214. {
  1215. libraw_processed_image_t * ret =
  1216. (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+T.tlength);
  1217. if(!ret)
  1218. {
  1219. if(errcode) *errcode= ENOMEM;
  1220. return NULL;
  1221. }
  1222. memset(ret,0,sizeof(libraw_processed_image_t));
  1223. ret->type = LIBRAW_IMAGE_BITMAP;
  1224. ret->height = T.theight;
  1225. ret->width = T.twidth;
  1226. ret->colors = 3;
  1227. ret->bits = 8;
  1228. ret->data_size = T.tlength;
  1229. memmove(ret->data,T.thumb,T.tlength);
  1230. if(errcode) *errcode= 0;
  1231. return ret;
  1232. }
  1233. else if (T.tformat == LIBRAW_THUMBNAIL_JPEG)
  1234. {
  1235. ushort exif[5];
  1236. int mk_exif = 0;
  1237. if(strcmp(T.thumb+6,"Exif")) mk_exif = 1;
  1238. int dsize = T.tlength + mk_exif * (sizeof(exif)+sizeof(tiff_hdr));
  1239. libraw_processed_image_t * ret =
  1240. (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+dsize);
  1241. if(!ret)
  1242. {
  1243. if(errcode) *errcode= ENOMEM;
  1244. return NULL;
  1245. }
  1246. memset(ret,0,sizeof(libraw_processed_image_t));
  1247. ret->type = LIBRAW_IMAGE_JPEG;
  1248. ret->data_size = dsize;
  1249. ret->data[0] = 0xff;
  1250. ret->data[1] = 0xd8;
  1251. if(mk_exif)
  1252. {
  1253. struct tiff_hdr th;
  1254. memcpy (exif, "\xff\xe1 Exif\0\0", 10);
  1255. exif[1] = htons (8 + sizeof th);
  1256. memmove(ret->data+2,exif,sizeof(exif));
  1257. tiff_head (&th, 0);
  1258. memmove(ret->data+(2+sizeof(exif)),&th,sizeof(th));
  1259. memmove(ret->data+(2+sizeof(exif)+sizeof(th)),T.thumb+2,T.tlength-2);
  1260. }
  1261. else
  1262. {
  1263. memmove(ret->data+2,T.thumb+2,T.tlength-2);
  1264. }
  1265. if(errcode) *errcode= 0;
  1266. return ret;
  1267. }
  1268. else
  1269. {
  1270. if(errcode) *errcode= LIBRAW_UNSUPPORTED_THUMBNAIL;
  1271. return NULL;
  1272. }
  1273. }
  1274. // jlb
  1275. // macros for copying pixels to either BGR or RGB formats
  1276. #define FORBGR for(c=P1.colors-1; c >=0 ; c--)
  1277. #define FORRGB for(c=0; c < P1.colors ; c++)
  1278. void LibRaw::get_mem_image_format(int* width, int* height, int* colors, int* bps) const
  1279. {
  1280. if (S.flip & 4) {
  1281. *width = S.height;
  1282. *height = S.width;
  1283. }
  1284. else {
  1285. *width = S.width;
  1286. *height = S.height;
  1287. }
  1288. *colors = P1.colors;
  1289. *bps = O.output_bps;
  1290. }
  1291. int LibRaw::copy_mem_image(void* scan0, int stride, int bgr)
  1292. {
  1293. // the image memory pointed to by scan0 is assumed to be in the format returned by get_mem_image_format
  1294. if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) < LIBRAW_PROGRESS_PRE_INTERPOLATE)
  1295. return LIBRAW_OUT_OF_ORDER_CALL;
  1296. if(libraw_internal_data.output_data.histogram)
  1297. {
  1298. int perc, val, total, t_white=0x2000,c;
  1299. perc = S.width * S.height * 0.01; /* 99th percentile white level */
  1300. if (IO.fuji_width) perc /= 2;
  1301. if (!((O.highlight & ~2) || O.no_auto_bright))
  1302. for (t_white=c=0; c < P1.colors; c++) {
  1303. for (val=0x2000, total=0; --val > 32; )
  1304. if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break;
  1305. if (t_white < val) t_white = val;
  1306. }
  1307. gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright);
  1308. }
  1309. int s_iheight = S.iheight;
  1310. int s_iwidth = S.iwidth;
  1311. int s_width = S.width;
  1312. int s_hwight = S.height;
  1313. S.iheight = S.height;
  1314. S.iwidth = S.width;
  1315. if (S.flip & 4) SWAP(S.height,S.width);
  1316. uchar *ppm;
  1317. ushort *ppm2;
  1318. int c, row, col, soff, rstep, cstep;
  1319. soff = flip_index (0, 0);
  1320. cstep = flip_index (0, 1) - soff;
  1321. rstep = flip_index (1, 0) - flip_index (0, S.width);
  1322. for (row=0; row < S.height; row++, soff += rstep)
  1323. {
  1324. uchar *bufp = ((uchar*)scan0)+row*stride;
  1325. ppm2 = (ushort*) (ppm = bufp);
  1326. // keep trivial decisions in the outer loop for speed
  1327. if (bgr) {
  1328. if (O.output_bps == 8) {
  1329. for (col=0; col < S.width; col++, soff += cstep)
  1330. FORBGR *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8;
  1331. }
  1332. else {
  1333. for (col=0; col < S.width; col++, soff += cstep)
  1334. FORBGR *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]];
  1335. }
  1336. }
  1337. else {
  1338. if (O.output_bps == 8) {
  1339. for (col=0; col < S.width; col++, soff += cstep)
  1340. FORRGB *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8;
  1341. }
  1342. else {
  1343. for (col=0; col < S.width; col++, soff += cstep)
  1344. FORRGB *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]];
  1345. }
  1346. }
  1347. // bufp += stride; // go to the next line
  1348. }
  1349. S.iheight = s_iheight;
  1350. S.iwidth = s_iwidth;
  1351. S.width = s_width;
  1352. S.height = s_hwight;
  1353. return 0;
  1354. }
  1355. #undef FORBGR
  1356. #undef FORRGB
  1357. libraw_processed_image_t *LibRaw::dcraw_make_mem_image(int *errcode)
  1358. {
  1359. int width, height, colors, bps;
  1360. get_mem_image_format(&width, &height, &colors, &bps);
  1361. int stride = width * (bps/8) * colors;
  1362. unsigned ds = height * stride;
  1363. libraw_processed_image_t *ret = (libraw_processed_image_t*)::malloc(sizeof(libraw_processed_image_t)+ds);
  1364. if(!ret)
  1365. {
  1366. if(errcode) *errcode= ENOMEM;
  1367. return NULL;
  1368. }
  1369. memset(ret,0,sizeof(libraw_processed_image_t));
  1370. // metadata init
  1371. ret->type = LIBRAW_IMAGE_BITMAP;
  1372. ret->height = height;
  1373. ret->width = width;
  1374. ret->colors = colors;
  1375. ret->bits = bps;
  1376. ret->data_size = ds;
  1377. copy_mem_image(ret->data, stride, 0);
  1378. return ret;
  1379. }
  1380. #undef FORC
  1381. #undef FORCC
  1382. #undef SWAP
  1383. #endif
  1384. int LibRaw::dcraw_ppm_tiff_writer(const char *filename)
  1385. {
  1386. CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
  1387. if(!imgdata.image)
  1388. return LIBRAW_OUT_OF_ORDER_CALL;
  1389. if(!filename)
  1390. return ENOENT;
  1391. FILE *f = fopen(filename,"wb");
  1392. if(!f)
  1393. return errno;
  1394. try {
  1395. if(!libraw_internal_data.output_data.histogram)
  1396. {
  1397. libraw_internal_data.output_data.histogram =
  1398. (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
  1399. merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_ppm_tiff_writer()");
  1400. }
  1401. libraw_internal_data.internal_data.output = f;
  1402. write_ppm_tiff();
  1403. SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP);
  1404. libraw_internal_data.internal_data.output = NULL;
  1405. fclose(f);
  1406. return 0;
  1407. }
  1408. catch ( LibRaw_exceptions err) {
  1409. fclose(f);
  1410. EXCEPTION_HANDLER(err);
  1411. }
  1412. }
  1413. void LibRaw::kodak_thumb_loader()
  1414. {
  1415. // some kodak cameras
  1416. ushort s_height = S.height, s_width = S.width,s_iwidth = S.iwidth,s_iheight=S.iheight;
  1417. int s_colors = P1.colors;
  1418. unsigned s_filters = P1.filters;
  1419. ushort (*s_image)[4] = imgdata.image;
  1420. S.height = T.theight;
  1421. S.width = T.twidth;
  1422. P1.filters = 0;
  1423. if (thumb_load_raw == &CLASS kodak_ycbcr_load_thumb)
  1424. {
  1425. S.height += S.height & 1;
  1426. S.width += S.width & 1;
  1427. }
  1428. imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image));
  1429. merror (imgdata.image, "LibRaw::kodak_thumb_loader()");
  1430. ID.input->seek(ID.toffset, SEEK_SET);
  1431. // read kodak thumbnail into T.image[]
  1432. (this->*thumb_load_raw)();
  1433. // copy-n-paste from image pipe
  1434. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  1435. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  1436. #define LIM(x,min,max) MAX(min,MIN(x,max))
  1437. #define CLIP(x) LIM(x,0,65535)
  1438. #define SWAP(a,b) { a ^= b; a ^= (b ^= a); }
  1439. // from scale_colors
  1440. {
  1441. double dmax;
  1442. float scale_mul[4];
  1443. int c,val;
  1444. for (dmax=DBL_MAX, c=0; c < 3; c++)
  1445. if (dmax > C.pre_mul[c])
  1446. dmax = C.pre_mul[c];
  1447. for( c=0; c< 3; c++)
  1448. scale_mul[c] = (C.pre_mul[c] / dmax) * 65535.0 / C.maximum;
  1449. scale_mul[3] = scale_mul[1];
  1450. size_t size = S.height * S.width;
  1451. for (unsigned i=0; i < size*4 ; i++)
  1452. {
  1453. val = imgdata.image[0][i];
  1454. if(!val) continue;
  1455. val *= scale_mul[i & 3];
  1456. imgdata.image[0][i] = CLIP(val);
  1457. }
  1458. }
  1459. // from convert_to_rgb
  1460. ushort *img;
  1461. int row,col;
  1462. int (*t_hist)[LIBRAW_HISTOGRAM_SIZE] = (int (*)[LIBRAW_HISTOGRAM_SIZE]) calloc(sizeof(*t_hist),4);
  1463. merror (t_hist, "LibRaw::kodak_thumb_loader()");
  1464. float out[3],
  1465. out_cam[3][4] =
  1466. {
  1467. {2.81761312, -1.98369181, 0.166078627, 0},
  1468. {-0.111855984, 1.73688626, -0.625030339, 0},
  1469. {-0.0379119813, -0.891268849, 1.92918086, 0}
  1470. };
  1471. for (img=imgdata.image[0], row=0; row < S.height; row++)
  1472. for (col=0; col < S.width; col++, img+=4)
  1473. {
  1474. out[0] = out[1] = out[2] = 0;
  1475. int c;
  1476. for(c=0;c<3;c++)
  1477. {
  1478. out[0] += out_cam[0][c] * img[c];
  1479. out[1] += out_cam[1][c] * img[c];
  1480. out[2] += out_cam[2][c] * img[c];
  1481. }
  1482. for(c=0; c<3; c++)
  1483. img[c] = CLIP((int) out[c]);
  1484. for(c=0; c<P1.colors;c++)
  1485. t_hist[c][img[c] >> 3]++;
  1486. }
  1487. // from gamma_lut
  1488. int (*save_hist)[LIBRAW_HISTOGRAM_SIZE] = libraw_internal_data.output_data.histogram;
  1489. libraw_internal_data.output_data.histogram = t_hist;
  1490. // make curve output curve!
  1491. ushort (*t_curve) = (ushort*) calloc(sizeof(C.curve),1);
  1492. merror (t_curve, "LibRaw::kodak_thumb_loader()");
  1493. memmove(t_curve,C.curve,sizeof(C.curve));
  1494. memset(C.curve,0,sizeof(C.curve));
  1495. {
  1496. int perc, val, total, t_white=0x2000,c;
  1497. perc = S.width * S.height * 0.01; /* 99th percentile white level */
  1498. if (IO.fuji_width) perc /= 2;
  1499. if (!((O.highlight & ~2) || O.no_auto_bright))
  1500. for (t_white=c=0; c < P1.colors; c++) {
  1501. for (val=0x2000, total=0; --val > 32; )
  1502. if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break;
  1503. if (t_white < val) t_white = val;
  1504. }
  1505. gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright);
  1506. }
  1507. libraw_internal_data.output_data.histogram = save_hist;
  1508. free(t_hist);
  1509. // from write_ppm_tiff - copy pixels into bitmap
  1510. S.iheight = S.height;
  1511. S.iwidth = S.width;
  1512. if (S.flip & 4) SWAP(S.height,S.width);
  1513. if(T.thumb) free(T.thumb);
  1514. T.thumb = (char*) calloc (S.width * S.height, P1.colors);
  1515. merror (T.thumb, "LibRaw::kodak_thumb_loader()");
  1516. T.tlength = S.width * S.height * P1.colors;
  1517. // from write_tiff_ppm
  1518. {
  1519. int soff = flip_index (0, 0);
  1520. int cstep = flip_index (0, 1) - soff;
  1521. int rstep = flip_index (1, 0) - flip_index (0, S.width);
  1522. for (int row=0; row < S.height; row++, soff += rstep)
  1523. {
  1524. char *ppm = T.thumb + row*S.width*P1.colors;
  1525. for (int col=0; col < S.width; col++, soff += cstep)
  1526. for(int c = 0; c < P1.colors; c++)
  1527. ppm [col*P1.colors+c] = imgdata.color.curve[imgdata.image[soff][c]]>>8;
  1528. }
  1529. }
  1530. memmove(C.curve,t_curve,sizeof(C.curve));
  1531. free(t_curve);
  1532. // restore variables
  1533. free(imgdata.image);
  1534. imgdata.image = s_image;
  1535. T.twidth = S.width;
  1536. S.width = s_width;
  1537. S.iwidth = s_iwidth;
  1538. S.iheight = s_iheight;
  1539. T.theight = S.height;
  1540. S.height = s_height;
  1541. T.tcolors = P1.colors;
  1542. P1.colors = s_colors;
  1543. P1.filters = s_filters;
  1544. }
  1545. #undef MIN
  1546. #undef MAX
  1547. #undef LIM
  1548. #undef CLIP
  1549. #undef SWAP
  1550. // Достает thumbnail из файла, ставит thumb_format в соответствии с форматом
  1551. int LibRaw::unpack_thumb(void)
  1552. {
  1553. CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
  1554. CHECK_ORDER_BIT(LIBRAW_PROGRESS_THUMB_LOAD);
  1555. try {
  1556. if ( !ID.toffset)
  1557. {
  1558. return LIBRAW_NO_THUMBNAIL;
  1559. }
  1560. else if (thumb_load_raw)
  1561. {
  1562. kodak_thumb_loader();
  1563. T.tformat = LIBRAW_THUMBNAIL_BITMAP;
  1564. SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
  1565. return 0;
  1566. }
  1567. else
  1568. {
  1569. ID.input->seek(ID.toffset, SEEK_SET);
  1570. if ( write_thumb == &LibRaw::jpeg_thumb)
  1571. {
  1572. if(T.thumb) free(T.thumb);
  1573. T.thumb = (char *) malloc (T.tlength);
  1574. merror (T.thumb, "jpeg_thumb()");
  1575. ID.input->read (T.thumb, 1, T.tlength);
  1576. T.tcolors = 3;
  1577. T.tformat = LIBRAW_THUMBNAIL_JPEG;
  1578. SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
  1579. return 0;
  1580. }
  1581. else if (write_thumb == &LibRaw::ppm_thumb)
  1582. {
  1583. T.tlength = T.twidth * T.theight*3;
  1584. if(T.thumb) free(T.thumb);
  1585. T.thumb = (char *) malloc (T.tlength);
  1586. merror (T.thumb, "ppm_thumb()");
  1587. ID.input->read(T.thumb, 1, T.tlength);
  1588. T.tformat = LIBRAW_THUMBNAIL_BITMAP;
  1589. SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
  1590. return 0;
  1591. }
  1592. else if (write_thumb == &LibRaw::foveon_thumb)
  1593. {
  1594. foveon_thumb_loader();
  1595. // may return with error, so format is set in
  1596. // foveon thumb loader itself
  1597. SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
  1598. return 0;
  1599. }
  1600. // else if -- all other write_thumb cases!
  1601. else
  1602. {
  1603. return LIBRAW_UNSUPPORTED_THUMBNAIL;
  1604. }
  1605. }
  1606. // last resort
  1607. return LIBRAW_UNSUPPORTED_THUMBNAIL;
  1608. }
  1609. catch ( LibRaw_exceptions err) {
  1610. EXCEPTION_HANDLER(err);
  1611. }
  1612. }
  1613. int LibRaw::dcraw_thumb_writer(const char *fname)
  1614. {
  1615. // CHECK_ORDER_LOW(LIBRAW_PROGRESS_THUMB_LOAD);
  1616. if(!fname)
  1617. return ENOENT;
  1618. FILE *tfp = fopen(fname,"wb");
  1619. if(!tfp)
  1620. return errno;
  1621. if(!T.thumb)
  1622. {
  1623. fclose(tfp);
  1624. return LIBRAW_OUT_OF_ORDER_CALL;
  1625. }
  1626. try {
  1627. switch (T.tformat)
  1628. {
  1629. case LIBRAW_THUMBNAIL_JPEG:
  1630. jpeg_thumb_writer (tfp,T.thumb,T.tlength);
  1631. break;
  1632. case LIBRAW_THUMBNAIL_BITMAP:
  1633. fprintf (tfp, "P6\n%d %d\n255\n", T.twidth, T.theight);
  1634. fwrite (T.thumb, 1, T.tlength, tfp);
  1635. break;
  1636. default:
  1637. fclose(tfp);
  1638. return LIBRAW_UNSUPPORTED_THUMBNAIL;
  1639. }
  1640. fclose(tfp);
  1641. return 0;
  1642. }
  1643. catch ( LibRaw_exceptions err) {
  1644. fclose(tfp);
  1645. EXCEPTION_HANDLER(err);
  1646. }
  1647. }
  1648. int LibRaw::adjust_sizes_info_only(void)
  1649. {
  1650. CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
  1651. raw2image_start();
  1652. if (O.use_fuji_rotate)
  1653. {
  1654. if (IO.fuji_width)
  1655. {
  1656. // restore saved values
  1657. if(IO.fheight)
  1658. {
  1659. S.height = IO.fheight;
  1660. S.width = IO.fwidth;
  1661. S.iheight = (S.height + IO.shrink) >> IO.shrink;
  1662. S.iwidth = (S.width + IO.shrink) >> IO.shrink;
  1663. S.raw_height -= 2*S.top_margin;
  1664. IO.fheight = IO.fwidth = 0; // prevent repeated calls
  1665. }
  1666. // dcraw code
  1667. IO.fuji_width = (IO.fuji_width - 1 + IO.shrink) >> IO.shrink;
  1668. S.iwidth = (ushort)(IO.fuji_width / sqrt(0.5));
  1669. S.iheight = (ushort)( (S.iheight - IO.fuji_width) / sqrt(0.5));
  1670. }
  1671. else
  1672. {
  1673. if (S.pixel_aspect < 1) S.iheight = (ushort)( S.iheight / S.pixel_aspect + 0.5);
  1674. if (S.pixel_aspect > 1) S.iwidth = (ushort) (S.iwidth * S.pixel_aspect + 0.5);
  1675. }
  1676. }
  1677. SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
  1678. if ( S.flip & 4)
  1679. {
  1680. unsigned short t = S.iheight;
  1681. S.iheight=S.iwidth;
  1682. S.iwidth = t;
  1683. SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP);
  1684. }
  1685. return 0;
  1686. }
  1687. void LibRaw::subtract_black()
  1688. {
  1689. #define BAYERC(row,col,c) imgdata.image[((row) >> IO.shrink)*S.iwidth + ((col) >> IO.shrink)][c]
  1690. if(C.ph1_black)
  1691. {
  1692. // Phase One compressed format
  1693. int row,col,val,cc;
  1694. for(row=0;row<S.height;row++)
  1695. for(col=0;col<S.width;col++)
  1696. {
  1697. cc=FC(row,col);
  1698. val = BAYERC(row,col,cc)
  1699. - C.phase_one_data.t_black
  1700. + C.ph1_black[row+S.top_margin][(col + S.left_margin)
  1701. >=C.phase_one_data.split_col];
  1702. if(val<0) val = 0;
  1703. BAYERC(row,col,cc) = val;
  1704. }
  1705. C.maximum -= C.black;
  1706. phase_one_correct();
  1707. // recalculate channel maximum
  1708. ZERO(C.channel_maximum);
  1709. for(row=0;row<S.height;row++)
  1710. for(col=0;col<S.width;col++)
  1711. {
  1712. cc=FC(row,col);
  1713. val = BAYERC(row,col,cc);
  1714. if(C.channel_maximum[cc] > val) C.channel_maximum[cc] = val;
  1715. }
  1716. // clear P1 black level data
  1717. imgdata.color.phase_one_data.t_black = 0;
  1718. C.ph1_black = 0;
  1719. ZERO(C.cblack);
  1720. C.black = 0;
  1721. }
  1722. else if((C.black || C.cblack[0] || C.cblack[1] || C.cblack[2] || C.cblack[3]))
  1723. {
  1724. int cblk[4],i,row,col,val,cc;
  1725. for(i=0;i<4;i++)
  1726. cblk[i] = C.cblack[i]+C.black;
  1727. ZERO(C.channel_maximum);
  1728. for(row=0;row<S.height;row++)
  1729. for(col=0;col<S.width;col++)
  1730. {
  1731. cc=COLOR(row,col);
  1732. val = BAYERC(row,col,cc);
  1733. if(val > cblk[cc])
  1734. val -= cblk[cc];
  1735. else
  1736. val = 0;
  1737. if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val;
  1738. BAYERC(row,col,cc) = val;
  1739. }
  1740. C.maximum -= C.black;
  1741. ZERO(C.cblack);
  1742. C.black = 0;
  1743. }
  1744. else
  1745. {
  1746. // only calculate channel maximum;
  1747. int row,col,cc,val;
  1748. ZERO(C.channel_maximum);
  1749. for(row=0;row<S.height;row++)
  1750. for(col=0;col<S.width;col++)
  1751. for(cc = 0; cc< 4; cc++)
  1752. {
  1753. int val = BAYERC(row,col,cc);
  1754. if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val;
  1755. }
  1756. }
  1757. }
  1758. #define TBLN 65535
  1759. void LibRaw::exp_bef(float shift, float smooth)
  1760. {
  1761. // params limits
  1762. if(shift>8) shift = 8;
  1763. if(shift<0.25) shift = 0.25;
  1764. if(smooth < 0.0) smooth = 0.0;
  1765. if(smooth > 1.0) smooth = 1.0;
  1766. unsigned short *lut = (ushort*)malloc((TBLN+1)*sizeof(unsigned short));
  1767. if(shift <=1.0)
  1768. {
  1769. for(int i=0;i<=TBLN;i++)
  1770. lut[i] = (unsigned short)((float)i*shift);
  1771. }
  1772. else
  1773. {
  1774. float x1,x2,y1,y2;
  1775. float cstops = log(shift)/log(2.0f);
  1776. float room = cstops*2;
  1777. float roomlin = powf(2.0f,room);
  1778. x2 = (float)TBLN;
  1779. x1 = (x2+1)/roomlin-1;
  1780. y1 = x1*shift;
  1781. y2 = x2*(1+(1-smooth)*(shift-1));
  1782. float sq3x=powf(x1*x1*x2,1.0f/3.0f);
  1783. float B = (y2-y1+shift*(3*x1-3.0f*sq3x)) / (x2+2.0f*x1-3.0f*sq3x);
  1784. float A = (shift - B)*3.0f*powf(x1*x1,1.0f/3.0f);
  1785. float CC = y2 - A*powf(x2,1.0f/3.0f)-B*x2;
  1786. for(int i=0;i<=TBLN;i++)
  1787. {
  1788. float X = (float)i;
  1789. float Y = A*powf(X,1.0f/3.0f)+B*X+CC;
  1790. if(i<x1)
  1791. lut[i] = (unsigned short)((float)i*shift);
  1792. else
  1793. lut[i] = Y<0?0:(Y>TBLN?TBLN:(unsigned short)(Y));
  1794. }
  1795. }
  1796. for(int i=0; i< S.height*S.width; i++)
  1797. {
  1798. imgdata.image[i][0] = lut[imgdata.image[i][0]];
  1799. imgdata.image[i][1] = lut[imgdata.image[i][1]];
  1800. imgdata.image[i][2] = lut[imgdata.image[i][2]];
  1801. imgdata.image[i][3] = lut[imgdata.image[i][3]];
  1802. }
  1803. for(int i=0;i<4;i++)
  1804. C.channel_maximum[i] = lut[C.channel_maximum[i]];
  1805. C.maximum = lut[C.maximum];
  1806. // no need to adjust the minumum, black is already subtracted
  1807. free(lut);
  1808. }
  1809. int LibRaw::dcraw_process(void)
  1810. {
  1811. int quality,i;
  1812. int iterations=-1, dcb_enhance=1, noiserd=0;
  1813. int eeci_refine_fl=0, es_med_passes_fl=0;
  1814. float cared=0,cablue=0;
  1815. float linenoise=0;
  1816. float lclean=0,cclean=0;
  1817. float thresh=0;
  1818. float preser=0;
  1819. float expos=1.0;
  1820. CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
  1821. // CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE);
  1822. try {
  1823. int no_crop = 1;
  1824. if (~O.cropbox[2] && ~O.cropbox[3])
  1825. no_crop=0;
  1826. raw2image_ex(); // raw2image+crop+rotate_fuji_raw + subtract_black for fuji
  1827. int save_4color = O.four_color_rgb;
  1828. if (IO.zero_is_bad)
  1829. {
  1830. remove_zeroes();
  1831. SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES);
  1832. }
  1833. if(!IO.fuji_width) // PhaseOne only, all other cases handled at raw2image_ex()
  1834. subtract_black();
  1835. if(O.half_size)
  1836. O.four_color_rgb = 1;
  1837. if(O.bad_pixels && no_crop)
  1838. {
  1839. bad_pixels(O.bad_pixels);
  1840. SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS);
  1841. }
  1842. if (O.dark_frame && no_crop)
  1843. {
  1844. subtract (O.dark_frame);
  1845. SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME);
  1846. }
  1847. quality = 2 + !IO.fuji_width;
  1848. if (O.user_qual >= 0) quality = O.user_qual;
  1849. adjust_maximum();
  1850. if (O.user_sat > 0) C.maximum = O.user_sat;
  1851. if (P1.is_foveon && !O.document_mode)
  1852. {
  1853. foveon_interpolate();
  1854. SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE);
  1855. }
  1856. if (O.green_matching && !O.half_size)
  1857. {
  1858. green_matching();
  1859. }
  1860. if (!P1.is_foveon && O.document_mode < 2)
  1861. {
  1862. scale_colors();
  1863. SET_PROC_FLAG(LIBRAW_PROGRESS_SCALE_COLORS);
  1864. }
  1865. pre_interpolate();
  1866. SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE);
  1867. if (O.dcb_iterations >= 0) iterations = O.dcb_iterations;
  1868. if (O.dcb_enhance_fl >=0 ) dcb_enhance = O.dcb_enhance_fl;
  1869. if (O.fbdd_noiserd >=0 ) noiserd = O.fbdd_noiserd;
  1870. if (O.eeci_refine >=0 ) eeci_refine_fl = O.eeci_refine;
  1871. if (O.es_med_passes >0 ) es_med_passes_fl = O.es_med_passes;
  1872. // LIBRAW_DEMOSAIC_PACK_GPL3
  1873. if (!O.half_size && O.cfa_green >0) {thresh=O.green_thresh ;green_equilibrate(thresh);}
  1874. if (O.exp_correc >0) {expos=O.exp_shift ; preser=O.exp_preser; exp_bef(expos,preser);}
  1875. if (O.ca_correc >0 ) {cablue=O.cablue; cared=O.cared; CA_correct_RT(cablue, cared);}
  1876. if (O.cfaline >0 ) {linenoise=O.linenoise; cfa_linedn(linenoise);}
  1877. if (O.cfa_clean >0 ) {lclean=O.lclean; cclean=O.cclean; cfa_impulse_gauss(lclean,cclean);}
  1878. if (P1.filters && !O.document_mode)
  1879. {
  1880. if (noiserd>0 && P1.colors==3 && P1.filters) fbdd(noiserd);
  1881. if (quality == 0)
  1882. lin_interpolate();
  1883. else if (quality == 1 || P1.colors > 3)
  1884. vng_interpolate();
  1885. else if (quality == 2)
  1886. ppg_interpolate();
  1887. else if (quality == 3)
  1888. ahd_interpolate(); // really don't need it here due to fallback op
  1889. else if (quality == 4)
  1890. dcb(iterations, dcb_enhance);
  1891. // LIBRAW_DEMOSAIC_PACK_GPL2
  1892. else if (quality == 5)
  1893. ahd_interpolate_mod();
  1894. else if (quality == 6)
  1895. afd_interpolate_pl(2,1);
  1896. else if (quality == 7)
  1897. vcd_interpolate(0);
  1898. else if (quality == 8)
  1899. vcd_interpolate(12);
  1900. else if (quality == 9)
  1901. lmmse_interpolate(1);
  1902. // LIBRAW_DEMOSAIC_PACK_GPL3
  1903. else if (quality == 10)
  1904. amaze_demosaic_RT();
  1905. // fallback to AHD
  1906. else
  1907. ahd_interpolate();
  1908. SET_PROC_FLAG(LIBRAW_PROGRESS_INTERPOLATE);
  1909. }
  1910. if (IO.mix_green)
  1911. {
  1912. for (P1.colors=3, i=0; i < S.height * S.width; i++)
  1913. imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1;
  1914. SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN);
  1915. }
  1916. if(!P1.is_foveon)
  1917. {
  1918. if (P1.colors == 3)
  1919. {
  1920. if (quality == 8)
  1921. {
  1922. if (eeci_refine_fl == 1) refinement();
  1923. if (O.med_passes > 0) median_filter_new();
  1924. if (es_med_passes_fl > 0) es_median_filter();
  1925. }
  1926. else {
  1927. median_filter();
  1928. }
  1929. SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER);
  1930. }
  1931. }
  1932. if (O.highlight == 2)
  1933. {
  1934. blend_highlights();
  1935. SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
  1936. }
  1937. if (O.highlight > 2)
  1938. {
  1939. recover_highlights();
  1940. SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
  1941. }
  1942. if (O.use_fuji_rotate)
  1943. {
  1944. fuji_rotate();
  1945. SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
  1946. }
  1947. if(!libraw_internal_data.output_data.histogram)
  1948. {
  1949. libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
  1950. merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_process()");
  1951. }
  1952. #ifndef NO_LCMS
  1953. if(O.camera_profile)
  1954. {
  1955. apply_profile(O.camera_profile,O.output_profile);
  1956. SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE);
  1957. }
  1958. #endif
  1959. convert_to_rgb();
  1960. SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB);
  1961. if (O.use_fuji_rotate)
  1962. {
  1963. stretch();
  1964. SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH);
  1965. }
  1966. O.four_color_rgb = save_4color; // also, restore
  1967. return 0;
  1968. }
  1969. catch ( LibRaw_exceptions err) {
  1970. EXCEPTION_HANDLER(err);
  1971. }
  1972. }
  1973. // Supported cameras:
  1974. static const char *static_camera_list[] =
  1975. {
  1976. "Adobe Digital Negative (DNG)",
  1977. "AgfaPhoto DC-833m",
  1978. "Apple QuickTake 100",
  1979. "Apple QuickTake 150",
  1980. "Apple QuickTake 200",
  1981. "ARRIRAW format",
  1982. "AVT F-080C",
  1983. "AVT F-145C",
  1984. "AVT F-201C",
  1985. "AVT F-510C",
  1986. "AVT F-810C",
  1987. "Canon PowerShot 600",
  1988. "Canon PowerShot A5",
  1989. "Canon PowerShot A5 Zoom",
  1990. "Canon PowerShot A50",
  1991. "Canon PowerShot A460 (CHDK hack)",
  1992. "Canon PowerShot A470 (CHDK hack)",
  1993. "Canon PowerShot A530 (CHDK hack)",
  1994. "Canon PowerShot A570 (CHDK hack)",
  1995. "Canon PowerShot A590 (CHDK hack)",
  1996. "Canon PowerShot A610 (CHDK hack)",
  1997. "Canon PowerShot A620 (CHDK hack)",
  1998. "Canon PowerShot A630 (CHDK hack)",
  1999. "Canon PowerShot A640 (CHDK hack)",
  2000. "Canon PowerShot A650 (CHDK hack)",
  2001. "Canon PowerShot A710 IS (CHDK hack)",
  2002. "Canon PowerShot A720 IS (CHDK hack)",
  2003. "Canon PowerShot Pro70",
  2004. "Canon PowerShot Pro90 IS",
  2005. "Canon PowerShot Pro1",
  2006. "Canon PowerShot G1",
  2007. "Canon PowerShot G2",
  2008. "Canon PowerShot G3",
  2009. "Canon PowerShot G5",
  2010. "Canon PowerShot G6",
  2011. "Canon PowerShot G7 (CHDK hack)",
  2012. "Canon PowerShot G9",
  2013. "Canon PowerShot G10",
  2014. "Canon PowerShot G11",
  2015. "Canon PowerShot G12",
  2016. "Canon PowerShot S2 IS (CHDK hack)",
  2017. "Canon PowerShot S3 IS (CHDK hack)",
  2018. "Canon PowerShot S5 IS (CHDK hack)",
  2019. "Canon PowerShot SD300 (CHDK hack)",
  2020. "Canon PowerShot S30",
  2021. "Canon PowerShot S40",
  2022. "Canon PowerShot S45",
  2023. "Canon PowerShot S50",
  2024. "Canon PowerShot S60",
  2025. "Canon PowerShot S70",
  2026. "Canon PowerShot S90",
  2027. "Canon PowerShot S95",
  2028. "Canon PowerShot S100",
  2029. "Canon PowerShot SX1 IS",
  2030. "Canon PowerShot SX110 IS (CHDK hack)",
  2031. "Canon PowerShot SX120 IS (CHDK hack)",
  2032. "Canon PowerShot SX20 IS (CHDK hack)",
  2033. "Canon PowerShot SX30 IS (CHDK hack)",
  2034. "Canon EOS D30",
  2035. "Canon EOS D60",
  2036. "Canon EOS 5D",
  2037. "Canon EOS 5D Mark II",
  2038. "Canon EOS 7D",
  2039. "Canon EOS 10D",
  2040. "Canon EOS 20D",
  2041. "Canon EOS 30D",
  2042. "Canon EOS 40D",
  2043. "Canon EOS 50D",
  2044. "Canon EOS 60D",
  2045. "Canon EOS 300D / Digital Rebel / Kiss Digital",
  2046. "Canon EOS 350D / Digital Rebel XT / Kiss Digital N",
  2047. "Canon EOS 400D / Digital Rebel XTi / Kiss Digital X",
  2048. "Canon EOS 450D / Digital Rebel XSi / Kiss Digital X2",
  2049. "Canon EOS 500D / Digital Rebel T1i / Kiss Digital X3",
  2050. "Canon EOS 550D / Digital Rebel T2i / Kiss Digital X4",
  2051. "Canon EOS 600D / Digital Rebel T3i / Kiss Digital X5",
  2052. "Canon EOS 1000D / Digital Rebel XS / Kiss Digital F",
  2053. "Canon EOS 1100D / Digital Rebel T3 / Kiss Digital X50",
  2054. "Canon EOS D2000C",
  2055. "Canon EOS-1D",
  2056. "Canon EOS-1DS",
  2057. "Canon EOS-1D Mark II",
  2058. "Canon EOS-1D Mark II N",
  2059. "Canon EOS-1D Mark III",
  2060. "Canon EOS-1D Mark IV",
  2061. "Canon EOS-1Ds Mark II",
  2062. "Canon EOS-1Ds Mark III",
  2063. "Casio QV-2000UX",
  2064. "Casio QV-3000EX",
  2065. "Casio QV-3500EX",
  2066. "Casio QV-4000",
  2067. "Casio QV-5700",
  2068. "Casio QV-R41",
  2069. "Casio QV-R51",
  2070. "Casio QV-R61",
  2071. "Casio EX-S20",
  2072. "Casio EX-S100",
  2073. "Casio EX-Z4",
  2074. "Casio EX-Z50",
  2075. "Casio EX-Z55",
  2076. "Casio EX-Z60",
  2077. "Casio EX-Z75",
  2078. "Casio EX-Z750",
  2079. "Casio EX-Z850",
  2080. "Casio EX-Z1050",
  2081. "Casio EX-Z1080",
  2082. "Casio Exlim Pro 505",
  2083. "Casio Exlim Pro 600",
  2084. "Casio Exlim Pro 700",
  2085. "Contax N Digital",
  2086. "Creative PC-CAM 600",
  2087. "Epson R-D1",
  2088. "Foculus 531C",
  2089. "Fuji FinePix E550",
  2090. "Fuji FinePix E900",
  2091. "Fuji FinePix F700",
  2092. "Fuji FinePix F710",
  2093. "Fuji FinePix F800",
  2094. "Fuji FinePix F810",
  2095. "Fuji FinePix S2Pro",
  2096. "Fuji FinePix S3Pro",
  2097. "Fuji FinePix S5Pro",
  2098. "Fuji FinePix S20Pro",
  2099. "Fuji FinePix S100FS",
  2100. "Fuji FinePix S5000",
  2101. "Fuji FinePix S5100/S5500",
  2102. "Fuji FinePix S5200/S5600",
  2103. "Fuji FinePix S6000fd",
  2104. "Fuji FinePix S7000",
  2105. "Fuji FinePix S9000/S9500",
  2106. "Fuji FinePix S9100/S9600",
  2107. "Fuji FinePix S200EXR",
  2108. "Fuji FinePix HS10/HS11",
  2109. "Fuji FinePix HS20EXR",
  2110. "Fuji FinePix F550EXR",
  2111. "Fuji FinePix F600EXR",
  2112. "Fuji FinePix X100",
  2113. "Fuji FinePix X10",
  2114. "Fuji IS-1",
  2115. "Hasselblad CFV",
  2116. "Hasselblad H3D",
  2117. "Hasselblad H4D",
  2118. "Hasselblad V96C",
  2119. "Imacon Ixpress 16-megapixel",
  2120. "Imacon Ixpress 22-megapixel",
  2121. "Imacon Ixpress 39-megapixel",
  2122. "ISG 2020x1520",
  2123. "Kodak DC20",
  2124. "Kodak DC25",
  2125. "Kodak DC40",
  2126. "Kodak DC50",
  2127. "Kodak DC120 (also try kdc2tiff)",
  2128. "Kodak DCS200",
  2129. "Kodak DCS315C",
  2130. "Kodak DCS330C",
  2131. "Kodak DCS420",
  2132. "Kodak DCS460",
  2133. "Kodak DCS460A",
  2134. "Kodak DCS520C",
  2135. "Kodak DCS560C",
  2136. "Kodak DCS620C",
  2137. "Kodak DCS620X",
  2138. "Kodak DCS660C",
  2139. "Kodak DCS660M",
  2140. "Kodak DCS720X",
  2141. "Kodak DCS760C",
  2142. "Kodak DCS760M",
  2143. "Kodak EOSDCS1",
  2144. "Kodak EOSDCS3B",
  2145. "Kodak NC2000F",
  2146. "Kodak ProBack",
  2147. "Kodak PB645C",
  2148. "Kodak PB645H",
  2149. "Kodak PB645M",
  2150. "Kodak DCS Pro 14n",
  2151. "Kodak DCS Pro 14nx",
  2152. "Kodak DCS Pro SLR/c",
  2153. "Kodak DCS Pro SLR/n",
  2154. "Kodak C330",
  2155. "Kodak C603",
  2156. "Kodak P850",
  2157. "Kodak P880",
  2158. "Kodak Z980",
  2159. "Kodak Z981",
  2160. "Kodak Z990",
  2161. "Kodak Z1015",
  2162. "Kodak KAI-0340",
  2163. "Konica KD-400Z",
  2164. "Konica KD-510Z",
  2165. "Leaf AFi 7",
  2166. "Leaf AFi-II 5",
  2167. "Leaf AFi-II 6",
  2168. "Leaf AFi-II 7",
  2169. "Leaf AFi-II 8",
  2170. "Leaf AFi-II 10",
  2171. "Leaf AFi-II 10R",
  2172. "Leaf AFi-II 12",
  2173. "Leaf AFi-II 12R",
  2174. "Leaf Aptus 17",
  2175. "Leaf Aptus 22",
  2176. "Leaf Aptus 54S",
  2177. "Leaf Aptus 65",
  2178. "Leaf Aptus 75",
  2179. "Leaf Aptus 75S",
  2180. "Leaf Cantare",
  2181. "Leaf CatchLight",
  2182. "Leaf CMost",
  2183. "Leaf DCB2",
  2184. "Leaf Valeo 6",
  2185. "Leaf Valeo 11",
  2186. "Leaf Valeo 17",
  2187. "Leaf Valeo 22",
  2188. "Leaf Volare",
  2189. "Leica Digilux 2",
  2190. "Leica Digilux 3",
  2191. "Leica D-LUX2",
  2192. "Leica D-LUX3",
  2193. "Leica D-LUX4",
  2194. "Leica D-LUX5",
  2195. "Leica V-LUX1",
  2196. "Leica V-LUX2",
  2197. "Logitech Fotoman Pixtura",
  2198. "Mamiya ZD",
  2199. "Micron 2010",
  2200. "Minolta RD175",
  2201. "Minolta DiMAGE 5",
  2202. "Minolta DiMAGE 7",
  2203. "Minolta DiMAGE 7i",
  2204. "Minolta DiMAGE 7Hi",
  2205. "Minolta DiMAGE A1",
  2206. "Minolta DiMAGE A2",
  2207. "Minolta DiMAGE A200",
  2208. "Minolta DiMAGE G400",
  2209. "Minolta DiMAGE G500",
  2210. "Minolta DiMAGE G530",
  2211. "Minolta DiMAGE G600",
  2212. "Minolta DiMAGE Z2",
  2213. "Minolta Alpha/Dynax/Maxxum 5D",
  2214. "Minolta Alpha/Dynax/Maxxum 7D",
  2215. "Motorola PIXL",
  2216. "Nikon D1",
  2217. "Nikon D1H",
  2218. "Nikon D1X",
  2219. "Nikon D2H",
  2220. "Nikon D2Hs",
  2221. "Nikon D2X",
  2222. "Nikon D2Xs",
  2223. "Nikon D3",
  2224. "Nikon D3s",
  2225. "Nikon D3X",
  2226. "Nikon D40",
  2227. "Nikon D40X",
  2228. "Nikon D50",
  2229. "Nikon D60",
  2230. "Nikon D70",
  2231. "Nikon D70s",
  2232. "Nikon D80",
  2233. "Nikon D90",
  2234. "Nikon D100",
  2235. "Nikon D200",
  2236. "Nikon D300",
  2237. "Nikon D300s",
  2238. "Nikon D700",
  2239. "Nikon D3000",
  2240. "Nikon D3100",
  2241. "Nikon D5000",
  2242. "Nikon D5100",
  2243. "Nikon D7000",
  2244. "Nikon 1 J1",
  2245. "Nikon 1 V1",
  2246. "Nikon E700 (\"DIAG RAW\" hack)",
  2247. "Nikon E800 (\"DIAG RAW\" hack)",
  2248. "Nikon E880 (\"DIAG RAW\" hack)",
  2249. "Nikon E900 (\"DIAG RAW\" hack)",
  2250. "Nikon E950 (\"DIAG RAW\" hack)",
  2251. "Nikon E990 (\"DIAG RAW\" hack)",
  2252. "Nikon E995 (\"DIAG RAW\" hack)",
  2253. "Nikon E2100 (\"DIAG RAW\" hack)",
  2254. "Nikon E2500 (\"DIAG RAW\" hack)",
  2255. "Nikon E3200 (\"DIAG RAW\" hack)",
  2256. "Nikon E3700 (\"DIAG RAW\" hack)",
  2257. "Nikon E4300 (\"DIAG RAW\" hack)",
  2258. "Nikon E4500 (\"DIAG RAW\" hack)",
  2259. "Nikon E5000",
  2260. "Nikon E5400",
  2261. "Nikon E5700",
  2262. "Nikon E8400",
  2263. "Nikon E8700",
  2264. "Nikon E8800",
  2265. "Nikon Coolpix P6000",
  2266. "Nikon Coolpix P7000",
  2267. "Nikon Coolpix P7100",
  2268. "Nikon Coolpix S6 (\"DIAG RAW\" hack)",
  2269. "Nokia N95",
  2270. "Nokia X2",
  2271. "Olympus C3030Z",
  2272. "Olympus C5050Z",
  2273. "Olympus C5060WZ",
  2274. "Olympus C7070WZ",
  2275. "Olympus C70Z,C7000Z",
  2276. "Olympus C740UZ",
  2277. "Olympus C770UZ",
  2278. "Olympus C8080WZ",
  2279. "Olympus X200,D560Z,C350Z",
  2280. "Olympus E-1",
  2281. "Olympus E-3",
  2282. "Olympus E-5",
  2283. "Olympus E-10",
  2284. "Olympus E-20",
  2285. "Olympus E-30",
  2286. "Olympus E-300",
  2287. "Olympus E-330",
  2288. "Olympus E-400",
  2289. "Olympus E-410",
  2290. "Olympus E-420",
  2291. "Olympus E-500",
  2292. "Olympus E-510",
  2293. "Olympus E-520",
  2294. "Olympus E-620",
  2295. "Olympus E-P1",
  2296. "Olympus E-P2",
  2297. "Olympus E-P3",
  2298. "Olympus E-PL1",
  2299. "Olympus E-PL1s",
  2300. "Olympus E-PL2",
  2301. "Olympus E-PL3",
  2302. "Olympus E-PM1",
  2303. "Olympus SP310",
  2304. "Olympus SP320",
  2305. "Olympus SP350",
  2306. "Olympus SP500UZ",
  2307. "Olympus SP510UZ",
  2308. "Olympus SP550UZ",
  2309. "Olympus SP560UZ",
  2310. "Olympus SP570UZ",
  2311. "Olympus XZ-1",
  2312. "Panasonic DMC-FZ8",
  2313. "Panasonic DMC-FZ18",
  2314. "Panasonic DMC-FZ28",
  2315. "Panasonic DMC-FZ30",
  2316. "Panasonic DMC-FZ35/FZ38",
  2317. "Panasonic DMC-FZ40",
  2318. "Panasonic DMC-FZ50",
  2319. "Panasonic DMC-FZ100",
  2320. "Panasonic DMC-FZ150",
  2321. "Panasonic DMC-FX150",
  2322. "Panasonic DMC-G1",
  2323. "Panasonic DMC-G10",
  2324. "Panasonic DMC-G2",
  2325. "Panasonic DMC-G3",
  2326. "Panasonic DMC-GF1",
  2327. "Panasonic DMC-GF2",
  2328. "Panasonic DMC-GF3",
  2329. "Panasonic DMC-GH1",
  2330. "Panasonic DMC-GH2",
  2331. "Panasonic DMC-GX1",
  2332. "Panasonic DMC-L1",
  2333. "Panasonic DMC-L10",
  2334. "Panasonic DMC-LC1",
  2335. "Panasonic DMC-LX1",
  2336. "Panasonic DMC-LX2",
  2337. "Panasonic DMC-LX3",
  2338. "Panasonic DMC-LX5",
  2339. "Pentax *ist D",
  2340. "Pentax *ist DL",
  2341. "Pentax *ist DL2",
  2342. "Pentax *ist DS",
  2343. "Pentax *ist DS2",
  2344. "Pentax K10D",
  2345. "Pentax K20D",
  2346. "Pentax K100D",
  2347. "Pentax K100D Super",
  2348. "Pentax K200D",
  2349. "Pentax K2000/K-m",
  2350. "Pentax K-x",
  2351. "Pentax K-r",
  2352. "Pentax K-5",
  2353. "Pentax K-7",
  2354. "Pentax Optio S",
  2355. "Pentax Optio S4",
  2356. "Pentax Optio 33WR",
  2357. "Pentax Optio 750Z",
  2358. "Pentax 645D",
  2359. "Phase One LightPhase",
  2360. "Phase One H 10",
  2361. "Phase One H 20",
  2362. "Phase One H 25",
  2363. "Phase One P 20",
  2364. "Phase One P 25",
  2365. "Phase One P 30",
  2366. "Phase One P 45",
  2367. "Phase One P 45+",
  2368. "Phase One P 65",
  2369. "Pixelink A782",
  2370. #ifdef LIBRAW_DEMOSAIC_PACK_GPL2
  2371. "Polaroid x530",
  2372. #endif
  2373. #ifndef NO_JASPER
  2374. "Redcode R3D format",
  2375. #endif
  2376. "Rollei d530flex",
  2377. "RoverShot 3320af",
  2378. "Samsung EX1",
  2379. "Samsung GX-1S",
  2380. "Samsung GX10",
  2381. "Samsung GX20",
  2382. "Samsung NX10",
  2383. "Samsung NX11",
  2384. "Samsung NX100",
  2385. "Samsung NX200",
  2386. "Samsung WB550",
  2387. "Samsung WB2000",
  2388. "Samsung S85 (hacked)",
  2389. "Samsung S850 (hacked)",
  2390. "Sarnoff 4096x5440",
  2391. #ifdef LIBRAW_DEMOSAIC_PACK_GPL2
  2392. "Sigma SD9",
  2393. "Sigma SD10",
  2394. "Sigma SD14",
  2395. #endif
  2396. "Sinar 3072x2048",
  2397. "Sinar 4080x4080",
  2398. "Sinar 4080x5440",
  2399. "Sinar STI format",
  2400. "SMaL Ultra-Pocket 3",
  2401. "SMaL Ultra-Pocket 4",
  2402. "SMaL Ultra-Pocket 5",
  2403. "Sony DSC-F828",
  2404. "Sony DSC-R1",
  2405. "Sony DSC-V3",
  2406. "Sony DSLR-A100",
  2407. "Sony DSLR-A200",
  2408. "Sony DSLR-A230",
  2409. "Sony DSLR-A290",
  2410. "Sony DSLR-A300",
  2411. "Sony DSLR-A330",
  2412. "Sony DSLR-A350",
  2413. "Sony DSLR-A380",
  2414. "Sony DSLR-A390",
  2415. "Sony DSLR-A450",
  2416. "Sony DSLR-A500",
  2417. "Sony DSLR-A550",
  2418. "Sony DSLR-A580",
  2419. "Sony DSLR-A700",
  2420. "Sony DSLR-A850",
  2421. "Sony DSLR-A900",
  2422. "Sony NEX-3",
  2423. "Sony NEX-5",
  2424. "Sony NEX-5N",
  2425. "Sony NEX-7",
  2426. "Sony NEX-C3",
  2427. "Sony SLT-A33",
  2428. "Sony SLT-A35",
  2429. "Sony SLT-A55V",
  2430. "Sony SLT-A65V",
  2431. "Sony SLT-A77V",
  2432. "Sony XCD-SX910CR",
  2433. "STV680 VGA",
  2434. NULL
  2435. };
  2436. const char** LibRaw::cameraList() { return static_camera_list;}
  2437. int LibRaw::cameraCount() { return (sizeof(static_camera_list)/sizeof(static_camera_list[0]))-1; }
  2438. const char * LibRaw::strprogress(enum LibRaw_progress p)
  2439. {
  2440. switch(p)
  2441. {
  2442. case LIBRAW_PROGRESS_START:
  2443. return "Starting";
  2444. case LIBRAW_PROGRESS_OPEN :
  2445. return "Opening file";
  2446. case LIBRAW_PROGRESS_IDENTIFY :
  2447. return "Reading metadata";
  2448. case LIBRAW_PROGRESS_SIZE_ADJUST:
  2449. return "Adjusting size";
  2450. case LIBRAW_PROGRESS_LOAD_RAW:
  2451. return "Reading RAW data";
  2452. case LIBRAW_PROGRESS_REMOVE_ZEROES:
  2453. return "Clearing zero values";
  2454. case LIBRAW_PROGRESS_BAD_PIXELS :
  2455. return "Removing dead pixels";
  2456. case LIBRAW_PROGRESS_DARK_FRAME:
  2457. return "Subtracting dark frame data";
  2458. case LIBRAW_PROGRESS_FOVEON_INTERPOLATE:
  2459. return "Interpolating Foveon sensor data";
  2460. case LIBRAW_PROGRESS_SCALE_COLORS:
  2461. return "Scaling colors";
  2462. case LIBRAW_PROGRESS_PRE_INTERPOLATE:
  2463. return "Pre-interpolating";
  2464. case LIBRAW_PROGRESS_INTERPOLATE:
  2465. return "Interpolating";
  2466. case LIBRAW_PROGRESS_MIX_GREEN :
  2467. return "Mixing green channels";
  2468. case LIBRAW_PROGRESS_MEDIAN_FILTER :
  2469. return "Median filter";
  2470. case LIBRAW_PROGRESS_HIGHLIGHTS:
  2471. return "Highlight recovery";
  2472. case LIBRAW_PROGRESS_FUJI_ROTATE :
  2473. return "Rotating Fuji diagonal data";
  2474. case LIBRAW_PROGRESS_FLIP :
  2475. return "Flipping image";
  2476. case LIBRAW_PROGRESS_APPLY_PROFILE:
  2477. return "ICC conversion";
  2478. case LIBRAW_PROGRESS_CONVERT_RGB:
  2479. return "Converting to RGB";
  2480. case LIBRAW_PROGRESS_STRETCH:
  2481. return "Stretching image";
  2482. case LIBRAW_PROGRESS_THUMB_LOAD:
  2483. return "Loading thumbnail";
  2484. default:
  2485. return "Some strange things";
  2486. }
  2487. }