~ubuntu-branches/debian/stretch/darktable/stretch

« back to all changes in this revision

Viewing changes to .pc/0001-fixed-error-handling-for-broken-full-color-images.patch/src/external/LibRaw/src/libraw_cxx.cpp

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-07-28 18:18:54 UTC
  • mfrom: (13.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130728181854-0ighzoz5nvq0zzoe
Tags: 1.2.2-1
* New upstream "hardware support release"
  - updated rawspeed r553. Support for Canon EOS 700D, Nikon Coolpix
    P330, New Olymbus base curve Updated Adobe Coeffs
  - Enhanced color matrices: Canon 700D (from Canon 650D), Canon 100D
    (from Canon 650D), Sony NEX-7
  - White balance presets: Some updates from UFRaw, Canon 100D, Canon
    700D, Sony SLT-A37 Nikon, Coolpix P330
  - Noise profiles: Canon EOS-M, Olympus E-600 (from: Olympus E-30),
    Olympus E-620 (from: Olympus E-30), Samsung WB2000, Sony A99v,
    Panasonic DMC-G10 iso 100, Nikon D60
  - Bug fixes: 0 star rating working again, LT: ctrl+d duplicates per
    default now, Some fixes concerning locale handling, double click on
    film strip jumps to image, remember position in collections, ctrl+k
    jumps to previous collection, Blending parameters are preserved when
    module is deactivated, In full-preview (alt-1) ratings and labels are
    only applied to image shown, libsquish compilation now optional, dr:
    deactivate interpolation at 200% zoom

Show diffs side-by-side

added added

removed removed

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