~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/LibRawLite/src/libraw_cxx.cpp

  • Committer: Stefano Rivera
  • Date: 2010-07-24 15:35:51 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: stefanor@ubuntu.com-20100724153551-6s3fth1653huk31a
Tags: upstream-3.13.1
ImportĀ upstreamĀ versionĀ 3.31.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- C++ -*-
 
2
 * File: libraw_cxx.cpp
 
3
 * Copyright 2008-2009 LibRaw LLC (info@libraw.org)
 
4
 * Created: Sat Mar  8 , 2008
 
5
 *
 
6
 * LibRaw (Lite) C++ interface (implementation)
 
7
 
 
8
    This library is free software; you can redistribute it and/or
 
9
    modify it under the terms of the GNU Lesser General Public
 
10
    License as published by the Free Software Foundation; either
 
11
    version 2.1 of the License, or (at your option) any later version.
 
12
 
 
13
    This library is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
    Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public
 
19
    License along with this library; if not, write to the Free Software
 
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 */
 
22
 
 
23
#include <errno.h>
 
24
#include <float.h>
 
25
#include <math.h>
 
26
#ifndef WIN32
 
27
#include <netinet/in.h>
 
28
#else
 
29
#include <winsock2.h>
 
30
#endif
 
31
#define LIBRAW_LIBRARY_BUILD
 
32
#include "libraw/libraw.h"
 
33
 
 
34
#ifdef __cplusplus
 
35
extern "C" 
 
36
{
 
37
#endif
 
38
    void default_memory_callback(void *,const char *file,const char *where)
 
39
    {
 
40
        fprintf (stderr,"%s: Out of memory in %s\n", file?file:"unknown file", where);
 
41
    }
 
42
 
 
43
    void default_data_callback(void*,const char *file, const int offset)
 
44
    {
 
45
        if(offset < 0)
 
46
            fprintf (stderr,"%s: Unexpected end of file\n", file?file:"unknown file");
 
47
        else
 
48
            fprintf (stderr,"%s: data corrupted at %d\n",file?file:"unknown file",offset); 
 
49
    }
 
50
    const char *libraw_strerror(int e)
 
51
    {
 
52
        enum LibRaw_errors errorcode = (LibRaw_errors)e;
 
53
        switch(errorcode)
 
54
            {
 
55
            case        LIBRAW_SUCCESS:
 
56
                return "No error";
 
57
            case        LIBRAW_UNSPECIFIED_ERROR:
 
58
                return "Unspecified error";
 
59
            case        LIBRAW_FILE_UNSUPPORTED:
 
60
                return "Unsupported file format or not RAW file";
 
61
            case        LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE:
 
62
                return "Request for nonexisting image number";
 
63
            case        LIBRAW_OUT_OF_ORDER_CALL:
 
64
                return "Out of order call of libraw function";
 
65
            case    LIBRAW_NO_THUMBNAIL:
 
66
                return "No thumbnail in file";
 
67
            case    LIBRAW_UNSUPPORTED_THUMBNAIL:
 
68
                return "Unsupported thumbnail format";
 
69
            case LIBRAW_CANNOT_ADDMASK:
 
70
                return "Cannot add masked pixels to resized image";
 
71
            case    LIBRAW_UNSUFFICIENT_MEMORY:
 
72
                return "Unsufficient memory";
 
73
            case    LIBRAW_DATA_ERROR:
 
74
                return "Corrupted data or unexpected EOF";
 
75
            case    LIBRAW_IO_ERROR:
 
76
                return "Input/output error";
 
77
            case LIBRAW_CANCELLED_BY_CALLBACK:
 
78
                return "Cancelled by user callback";
 
79
            default:
 
80
                return "Unknown error code";
 
81
        }
 
82
    }
 
83
 
 
84
#ifdef __cplusplus
 
85
}
 
86
#endif
 
87
 
 
88
 
 
89
const double LibRaw_constants::xyz_rgb[3][3] = 
 
90
{
 
91
    { 0.412453, 0.357580, 0.180423 },
 
92
    { 0.212671, 0.715160, 0.072169 },
 
93
    { 0.019334, 0.119193, 0.950227 } 
 
94
};
 
95
 
 
96
const float LibRaw_constants::d65_white[3] =  { 0.950456, 1, 1.088754 };
 
97
 
 
98
#define P1 imgdata.idata
 
99
#define S imgdata.sizes
 
100
#define O imgdata.params
 
101
#define C imgdata.color
 
102
#define T imgdata.thumbnail
 
103
#define IO libraw_internal_data.internal_output_params
 
104
#define ID libraw_internal_data.internal_data
 
105
 
 
106
#define EXCEPTION_HANDLER(e) do{                        \
 
107
        fprintf(stderr,"Exception %d caught\n",e);      \
 
108
        switch(e)                                       \
 
109
            {                                           \
 
110
            case LIBRAW_EXCEPTION_ALLOC:                \
 
111
                recycle();                              \
 
112
                return LIBRAW_UNSUFFICIENT_MEMORY;      \
 
113
            case LIBRAW_EXCEPTION_DECODE_RAW:           \
 
114
            case LIBRAW_EXCEPTION_DECODE_JPEG:          \
 
115
                recycle();                              \
 
116
                return LIBRAW_DATA_ERROR;               \
 
117
            case LIBRAW_EXCEPTION_IO_EOF:               \
 
118
            case LIBRAW_EXCEPTION_IO_CORRUPT:           \
 
119
                recycle();                              \
 
120
                return LIBRAW_IO_ERROR;                 \
 
121
            case LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK:\
 
122
                recycle();                              \
 
123
                return LIBRAW_CANCELLED_BY_CALLBACK;    \
 
124
            default:                                    \
 
125
                return LIBRAW_UNSPECIFIED_ERROR;        \
 
126
            } \
 
127
    }while(0)
 
128
 
 
129
void LibRaw::derror()
 
130
{
 
131
    if (!libraw_internal_data.unpacker_data.data_error && libraw_internal_data.internal_data.input) 
 
132
        {
 
133
            if (libraw_internal_data.internal_data.input->eof())
 
134
                {
 
135
                    if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data,
 
136
                                                              libraw_internal_data.internal_data.input->fname(),-1);
 
137
                    throw LIBRAW_EXCEPTION_IO_EOF;
 
138
                }
 
139
            else
 
140
                {
 
141
                    if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data,
 
142
                                                              libraw_internal_data.internal_data.input->fname(),
 
143
                                                              libraw_internal_data.internal_data.input->tell());
 
144
                    throw LIBRAW_EXCEPTION_IO_CORRUPT;
 
145
                }
 
146
        }
 
147
    libraw_internal_data.unpacker_data.data_error = 1;
 
148
}
 
149
LibRaw:: LibRaw(unsigned int flags)
 
150
{
 
151
    double aber[4] = {1,1,1,1};
 
152
    double gamm[5] = { 0.45,4.5,0,0,0 };
 
153
    unsigned greybox[4] =  { 0, 0, UINT_MAX, UINT_MAX };
 
154
#ifdef DCRAW_VERBOSE
 
155
    verbose = 1;
 
156
#else
 
157
    verbose = 0;
 
158
#endif
 
159
    bzero(&imgdata,sizeof(imgdata));
 
160
    bzero(&libraw_internal_data,sizeof(libraw_internal_data));
 
161
    bzero(&callbacks,sizeof(callbacks));
 
162
    callbacks.mem_cb = (flags & LIBRAW_OPIONS_NO_MEMERR_CALLBACK) ? NULL:  &default_memory_callback;
 
163
    callbacks.data_cb = (flags & LIBRAW_OPIONS_NO_DATAERR_CALLBACK)? NULL : &default_data_callback;
 
164
    memmove(&imgdata.params.aber,&aber,sizeof(aber));
 
165
    memmove(&imgdata.params.gamm,&gamm,sizeof(gamm));
 
166
    memmove(&imgdata.params.greybox,&greybox,sizeof(greybox));
 
167
    
 
168
    imgdata.params.bright=1;
 
169
    imgdata.params.use_camera_matrix=-1;
 
170
    imgdata.params.user_flip=-1;
 
171
    imgdata.params.user_black=-1;
 
172
    imgdata.params.user_sat=-1;
 
173
    imgdata.params.user_qual=-1;
 
174
    imgdata.params.output_color=1;
 
175
    imgdata.params.output_bps=8;
 
176
    imgdata.params.use_fuji_rotate=1;
 
177
    imgdata.params.auto_bright_thr = 0.01;
 
178
    imgdata.parent_class = this;
 
179
    imgdata.progress_flags = 0;
 
180
    tls = new LibRaw_TLS;
 
181
    tls->init();
 
182
}
 
183
 
 
184
 
 
185
void* LibRaw:: malloc(size_t t)
 
186
{
 
187
    void *p = memmgr.malloc(t);
 
188
    return p;
 
189
}
 
190
void* LibRaw::       calloc(size_t n,size_t t)
 
191
{
 
192
    void *p = memmgr.calloc(n,t);
 
193
    return p;
 
194
}
 
195
void  LibRaw::      free(void *p)
 
196
{
 
197
    memmgr.free(p);
 
198
}
 
199
 
 
200
 
 
201
int LibRaw:: fc (int row, int col)
 
202
{
 
203
    static const char filter[16][16] =
 
204
        { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 },
 
205
          { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 },
 
206
          { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 },
 
207
          { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 },
 
208
          { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 },
 
209
          { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 },
 
210
          { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 },
 
211
          { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 },
 
212
          { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 },
 
213
          { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 },
 
214
          { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 },
 
215
          { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 },
 
216
          { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 },
 
217
          { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 },
 
218
          { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 },
 
219
          { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } };
 
220
    
 
221
    if (imgdata.idata.filters != 1) return FC(row,col);
 
222
    return filter[(row+imgdata.sizes.top_margin) & 15][(col+imgdata.sizes.left_margin) & 15];
 
223
}
 
224
 
 
225
void LibRaw:: recycle() 
 
226
{
 
227
    if(libraw_internal_data.internal_data.input && libraw_internal_data.internal_data.input_internal) 
 
228
        { 
 
229
            delete libraw_internal_data.internal_data.input; 
 
230
            libraw_internal_data.internal_data.input = NULL;
 
231
        }
 
232
    libraw_internal_data.internal_data.input_internal = 0;
 
233
#define FREE(a) do { if(a) { free(a); a = NULL;} }while(0)
 
234
            
 
235
    FREE(imgdata.image); 
 
236
    FREE(imgdata.thumbnail.thumb);
 
237
    FREE(libraw_internal_data.internal_data.meta_data);
 
238
    FREE(libraw_internal_data.output_data.histogram);
 
239
    FREE(libraw_internal_data.output_data.oprof);
 
240
    FREE(imgdata.color.profile);
 
241
#undef FREE
 
242
#define ZERO(a) bzero(&a,sizeof(a))
 
243
    ZERO(imgdata.sizes);
 
244
    ZERO(libraw_internal_data.internal_output_params);
 
245
#undef ZERO
 
246
    memmgr.cleanup();
 
247
    imgdata.thumbnail.tformat = LIBRAW_THUMBNAIL_UNKNOWN;
 
248
    imgdata.progress_flags = 0;
 
249
    
 
250
    tls->init();
 
251
}
 
252
 
 
253
const char * LibRaw::unpack_function_name()
 
254
{
 
255
    if(!load_raw) return "Function not set";
 
256
 
 
257
    // sorted names order
 
258
    if (load_raw == &LibRaw::adobe_dng_load_raw_lj)     return "adobe_dng_load_raw_lj()";
 
259
    if (load_raw == &LibRaw::adobe_dng_load_raw_nc)     return "adobe_dng_load_raw_nc()";
 
260
    if (load_raw == &LibRaw::canon_600_load_raw)        return "canon_600_load_raw()";
 
261
 
 
262
    if (load_raw == &LibRaw::canon_a5_load_raw)         return "canon_a5_load_raw()";
 
263
    if (load_raw == &LibRaw::canon_compressed_load_raw) return "canon_compressed_load_raw()";
 
264
    if (load_raw == &LibRaw::canon_sraw_load_raw)       return "canon_sraw_load_raw()";
 
265
 
 
266
    if (load_raw == &LibRaw::casio_qv5700_load_raw )    return "casio_qv5700_load_raw()";
 
267
    if (load_raw == &LibRaw::eight_bit_load_raw )       return "eight_bit_load_raw()";
 
268
    if (load_raw == &LibRaw::fuji_load_raw )            return "fuji_load_raw()";
 
269
    // 10
 
270
    if (load_raw == &LibRaw::hasselblad_load_raw )      return "hasselblad_load_raw()";
 
271
    if (load_raw == &LibRaw::imacon_full_load_raw )     return "imacon_full_load_raw()";
 
272
    if (load_raw == &LibRaw::kodak_262_load_raw )       return "kodak_262_load_raw()";
 
273
 
 
274
    if (load_raw == &LibRaw::kodak_65000_load_raw )     return "kodak_65000_load_raw()";
 
275
    if (load_raw == &LibRaw::kodak_dc120_load_raw )     return "kodak_dc120_load_raw()";
 
276
    if (load_raw == &LibRaw::kodak_jpeg_load_raw )      return "kodak_jpeg_load_raw()";
 
277
 
 
278
    if (load_raw == &LibRaw::kodak_radc_load_raw )      return "kodak_radc_load_raw()";
 
279
    if (load_raw == &LibRaw::kodak_rgb_load_raw )       return "kodak_rgb_load_raw()";
 
280
    if (load_raw == &LibRaw::kodak_yrgb_load_raw )      return "kodak_yrgb_load_raw()";
 
281
    if (load_raw == &LibRaw::kodak_ycbcr_load_raw )     return "kodak_ycbcr_load_raw()";
 
282
    // 20
 
283
    if (load_raw == &LibRaw::leaf_hdr_load_raw )        return "leaf_hdr_load_raw()";
 
284
    if (load_raw == &LibRaw::lossless_jpeg_load_raw)    return "lossless_jpeg_load_raw()";
 
285
    if (load_raw == &LibRaw::minolta_rd175_load_raw )   return "minolta_rd175_load_raw()";
 
286
 
 
287
    if (load_raw == &LibRaw::nikon_compressed_load_raw) return "nikon_compressed_load_raw()";
 
288
    if (load_raw == &LibRaw::nikon_e900_load_raw )      return "nikon_e900_load_raw()";
 
289
    if (load_raw == &LibRaw::nokia_load_raw )           return "nokia_load_raw()";
 
290
 
 
291
    if (load_raw == &LibRaw::olympus_e300_load_raw )    return "olympus_e300_load_raw()";
 
292
    if (load_raw == &LibRaw::olympus_e410_load_raw )    return "olympus_e410_load_raw()";
 
293
    if (load_raw == &LibRaw::packed_12_load_raw )       return "packed_12_load_raw()";
 
294
    if (load_raw == &LibRaw::panasonic_load_raw )       return "panasonic_load_raw()";
 
295
    // 30
 
296
    if (load_raw == &LibRaw::pentax_k10_load_raw )      return "pentax_k10_load_raw()";
 
297
    if (load_raw == &LibRaw::phase_one_load_raw )       return "phase_one_load_raw()";
 
298
    if (load_raw == &LibRaw::phase_one_load_raw_c )     return "phase_one_load_raw_c()";
 
299
 
 
300
    if (load_raw == &LibRaw::quicktake_100_load_raw )   return "quicktake_100_load_raw()";
 
301
    if (load_raw == &LibRaw::rollei_load_raw )          return "rollei_load_raw()";
 
302
    if (load_raw == &LibRaw::sinar_4shot_load_raw )     return "sinar_4shot_load_raw()";
 
303
 
 
304
    if (load_raw == &LibRaw::smal_v6_load_raw )         return "smal_v6_load_raw()";
 
305
    if (load_raw == &LibRaw::smal_v9_load_raw )         return "smal_v9_load_raw()";
 
306
    if (load_raw == &LibRaw::sony_load_raw )            return "sony_load_raw()";
 
307
    if (load_raw == &LibRaw::sony_arw_load_raw )        return "sony_arw_load_raw()";
 
308
    // 40
 
309
    if (load_raw == &LibRaw::sony_arw2_load_raw )       return "sony_arw2_load_raw()";
 
310
    if (load_raw == &LibRaw::unpacked_load_raw )        return "unpacked_load_raw()";
 
311
    // 42 total
 
312
        
 
313
    return "Unknown unpack function";
 
314
}
 
315
 
 
316
 
 
317
void LibRaw:: merror (void *ptr, const char *where)
 
318
{
 
319
    if (ptr) return;
 
320
    if(callbacks.mem_cb)(*callbacks.mem_cb)(callbacks.memcb_data,
 
321
                                            libraw_internal_data.internal_data.input
 
322
                                            ?libraw_internal_data.internal_data.input->fname()
 
323
                                            :NULL,
 
324
                                            where);
 
325
    throw LIBRAW_EXCEPTION_ALLOC;
 
326
}
 
327
 
 
328
 
 
329
int LibRaw::open_file(const char *fname)
 
330
{
 
331
    // this stream will close on recycle()
 
332
    LibRaw_file_datastream *stream = new LibRaw_file_datastream(fname);
 
333
    if(!stream->valid())
 
334
        {
 
335
            delete stream;
 
336
            return LIBRAW_IO_ERROR;
 
337
        }
 
338
    ID.input_internal = 0; // preserve from deletion on error
 
339
    int ret = open_datastream(stream);
 
340
    if (ret == LIBRAW_SUCCESS)
 
341
        {
 
342
            ID.input_internal =1 ; // flag to delete datastream on recycle
 
343
        }
 
344
    else
 
345
        {
 
346
            delete stream;
 
347
            ID.input_internal = 0;
 
348
        }
 
349
    return ret;
 
350
}
 
351
 
 
352
int LibRaw::open_buffer(void *buffer, size_t size)
 
353
{
 
354
    // this stream will close on recycle()
 
355
    if(!buffer  || buffer==(void*)-1)
 
356
        return LIBRAW_IO_ERROR;
 
357
 
 
358
    LibRaw_buffer_datastream *stream = new LibRaw_buffer_datastream(buffer,size);
 
359
    if(!stream->valid())
 
360
        {
 
361
            delete stream;
 
362
            return LIBRAW_IO_ERROR;
 
363
        }
 
364
    ID.input_internal = 0; // preserve from deletion on error
 
365
    int ret = open_datastream(stream);
 
366
    if (ret == LIBRAW_SUCCESS)
 
367
        {
 
368
            ID.input_internal =1 ; // flag to delete datastream on recycle
 
369
        }
 
370
    else
 
371
        {
 
372
            delete stream;
 
373
            ID.input_internal = 0;
 
374
        }
 
375
    return ret;
 
376
}
 
377
 
 
378
 
 
379
int LibRaw::open_datastream(LibRaw_abstract_datastream *stream)
 
380
{
 
381
 
 
382
    if(!stream)
 
383
        return ENOENT;
 
384
    if(!stream->valid())
 
385
        return LIBRAW_IO_ERROR;
 
386
    recycle();
 
387
 
 
388
    try {
 
389
        ID.input = stream;
 
390
        SET_PROC_FLAG(LIBRAW_PROGRESS_OPEN);
 
391
 
 
392
        if (O.use_camera_matrix < 0)
 
393
            O.use_camera_matrix = O.use_camera_wb;
 
394
 
 
395
        identify();
 
396
 
 
397
        int saved_raw_width = S.raw_width;
 
398
        int saved_width = S.width;
 
399
        // from packed_12_load_raw
 
400
        if ((load_raw == &LibRaw:: packed_12_load_raw) && (S.raw_width * 2 >= S.width * 3))
 
401
            {   
 
402
                // raw_width is in bytes!
 
403
                S.raw_width = S.raw_width * 2 / 3;      
 
404
            }
 
405
        else if (S.pixel_aspect < 0.95 || S.pixel_aspect > 1.05)
 
406
            {
 
407
                S.width*=S.pixel_aspect;
 
408
            }
 
409
 
 
410
        if(S.raw_width>S.width + S.left_margin)
 
411
            S.right_margin = S.raw_width - S.width - S.left_margin;
 
412
 
 
413
        if(S.raw_height > S.height + S.top_margin)
 
414
            S.bottom_margin = S.raw_height - S.height - S.top_margin;
 
415
 
 
416
        S.raw_width = saved_raw_width;
 
417
        S.width = saved_width;
 
418
 
 
419
        if(C.profile_length)
 
420
            {
 
421
                if(C.profile) free(C.profile);
 
422
                C.profile = malloc(C.profile_length);
 
423
                merror(C.profile,"LibRaw::open_file()");
 
424
                ID.input->seek(ID.profile_offset,SEEK_SET);
 
425
                ID.input->read(C.profile,C.profile_length,1);
 
426
            }
 
427
        
 
428
        SET_PROC_FLAG(LIBRAW_PROGRESS_IDENTIFY);
 
429
    }
 
430
    catch ( LibRaw_exceptions err) {
 
431
        EXCEPTION_HANDLER(err);
 
432
    }
 
433
 
 
434
    if(P1.raw_count < 1) 
 
435
        return LIBRAW_FILE_UNSUPPORTED;
 
436
 
 
437
    if (O.user_flip >= 0)
 
438
        S.flip = O.user_flip;
 
439
    
 
440
    switch ((S.flip+3600) % 360) 
 
441
        {
 
442
        case 270:  S.flip = 5;  break;
 
443
        case 180:  S.flip = 3;  break;
 
444
        case  90:  S.flip = 6;  break;
 
445
        }
 
446
    
 
447
    write_fun = &LibRaw::write_ppm_tiff;
 
448
    
 
449
    if (load_raw == &LibRaw::kodak_ycbcr_load_raw) 
 
450
        {
 
451
            S.height += S.height & 1;
 
452
            S.width  += S.width  & 1;
 
453
        }
 
454
 
 
455
    IO.shrink = P1.filters && (O.half_size || O.threshold || O.aber[0] != 1 || O.aber[2] != 1);
 
456
    S.iheight = (S.height + IO.shrink) >> IO.shrink;
 
457
    S.iwidth  = (S.width  + IO.shrink) >> IO.shrink;
 
458
    
 
459
    SET_PROC_FLAG(LIBRAW_PROGRESS_SIZE_ADJUST);
 
460
 
 
461
 
 
462
    return LIBRAW_SUCCESS;
 
463
}
 
464
 
 
465
int LibRaw::unpack(void)
 
466
{
 
467
    CHECK_ORDER_HIGH(LIBRAW_PROGRESS_LOAD_RAW);
 
468
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
 
469
    try {
 
470
 
 
471
        RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,0,2);
 
472
        if (O.shot_select >= P1.raw_count)
 
473
            return LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE;
 
474
        
 
475
        if(!load_raw)
 
476
            return LIBRAW_UNSPECIFIED_ERROR;
 
477
        
 
478
        if (O.use_camera_matrix && C.cmatrix[0][0] > 0.25) 
 
479
            {
 
480
                memcpy (C.rgb_cam, C.cmatrix, sizeof (C.cmatrix));
 
481
                IO.raw_color = 0;
 
482
            }
 
483
        // already allocated ?
 
484
        if(imgdata.image) free(imgdata.image);
 
485
        
 
486
        imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image));
 
487
        merror (imgdata.image, "unpack()");
 
488
 
 
489
        if (libraw_internal_data.unpacker_data.meta_length) 
 
490
            {
 
491
                libraw_internal_data.internal_data.meta_data = 
 
492
                    (char *) malloc (libraw_internal_data.unpacker_data.meta_length);
 
493
                merror (libraw_internal_data.internal_data.meta_data, "LibRaw::unpack()");
 
494
            }
 
495
        ID.input->seek(libraw_internal_data.unpacker_data.data_offset, SEEK_SET);
 
496
        // foveon_load_raw produces different data for document_mode, we'll
 
497
        // deal with it in dcraw_document_mode_processing
 
498
        int save_document_mode = O.document_mode;
 
499
        O.document_mode = 0;
 
500
 
 
501
        (this->*load_raw)();
 
502
        
 
503
        O.document_mode = save_document_mode;
 
504
 
 
505
        SET_PROC_FLAG(LIBRAW_PROGRESS_LOAD_RAW);
 
506
        RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,1,2);
 
507
        
 
508
        return 0;
 
509
    }
 
510
    catch ( LibRaw_exceptions err) {
 
511
        EXCEPTION_HANDLER(err);
 
512
    }
 
513
}
 
514
 
 
515
int LibRaw::dcraw_document_mode_processing(void)
 
516
{
 
517
    CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE);
 
518
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
 
519
 
 
520
    try {
 
521
 
 
522
        O.document_mode = 2;
 
523
 
 
524
        O.use_fuji_rotate = 0;
 
525
        if (IO.zero_is_bad)
 
526
            {
 
527
                remove_zeroes();
 
528
                SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES);
 
529
            }
 
530
        if(O.bad_pixels) 
 
531
            {
 
532
                bad_pixels(O.bad_pixels);
 
533
                SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS);
 
534
            }
 
535
        if (O.dark_frame)
 
536
            {
 
537
                subtract (O.dark_frame);
 
538
                SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME);
 
539
            }
 
540
 
 
541
        if (O.user_black >= 0) 
 
542
            C.black = O.user_black;
 
543
 
 
544
        if (O.user_sat > 0) 
 
545
            C.maximum = O.user_sat;
 
546
 
 
547
        pre_interpolate();
 
548
        SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE);
 
549
 
 
550
        if (libraw_internal_data.internal_output_params.mix_green)
 
551
            {
 
552
                int i;
 
553
                for (P1.colors=3, i=0; i < S.height*S.width; i++)
 
554
                    imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1;
 
555
            }
 
556
        SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN);
 
557
 
 
558
        if ( P1.colors == 3) 
 
559
            median_filter();
 
560
        SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER);
 
561
 
 
562
        if ( O.highlight == 2) 
 
563
            blend_highlights();
 
564
 
 
565
        if ( O.highlight > 2) 
 
566
            recover_highlights();
 
567
        SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
 
568
 
 
569
        if (O.use_fuji_rotate) 
 
570
            fuji_rotate();
 
571
        SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
 
572
#ifndef NO_LCMS
 
573
        if(O.camera_profile)
 
574
            {
 
575
                apply_profile(O.camera_profile,O.output_profile);
 
576
                SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE);
 
577
            }
 
578
#endif
 
579
        if(!libraw_internal_data.output_data.histogram)
 
580
            {
 
581
                libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
 
582
                merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_document_mode_processing()");
 
583
            }
 
584
        convert_to_rgb();
 
585
        SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB);
 
586
 
 
587
        if (O.use_fuji_rotate)
 
588
            stretch();
 
589
        SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH);
 
590
 
 
591
        return 0;
 
592
    }
 
593
    catch ( LibRaw_exceptions err) {
 
594
        EXCEPTION_HANDLER(err);
 
595
    }
 
596
 
 
597
}
 
598
 
 
599
#if 1
 
600
#define FORC(cnt) for (c=0; c < cnt; c++)
 
601
#define FORCC FORC(ret->colors)
 
602
#define SWAP(a,b) { a ^= b; a ^= (b ^= a); }
 
603
 
 
604
libraw_processed_image_t * LibRaw::dcraw_make_mem_thumb(int *errcode)
 
605
{
 
606
    if(!T.thumb)
 
607
        {
 
608
            if ( !ID.toffset) 
 
609
                {
 
610
                    if(errcode) *errcode= LIBRAW_NO_THUMBNAIL;
 
611
                }
 
612
            else
 
613
                {
 
614
                    if(errcode) *errcode= LIBRAW_OUT_OF_ORDER_CALL;
 
615
                }
 
616
            return NULL;
 
617
        }
 
618
 
 
619
    if (T.tformat == LIBRAW_THUMBNAIL_BITMAP)
 
620
        {
 
621
            libraw_processed_image_t * ret = 
 
622
                (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+T.tlength);
 
623
 
 
624
            if(!ret)
 
625
                {
 
626
                    if(errcode) *errcode= ENOMEM;
 
627
                    return NULL;
 
628
                }
 
629
 
 
630
            bzero(ret,sizeof(libraw_processed_image_t));
 
631
            ret->type   = LIBRAW_IMAGE_BITMAP;
 
632
            ret->height = T.theight;
 
633
            ret->width  = T.twidth;
 
634
            ret->colors = 3; 
 
635
            ret->bits   = 8;
 
636
            ret->gamma_corrected = 1;
 
637
            ret->data_size = T.tlength;
 
638
            memmove(ret->data,T.thumb,T.tlength);
 
639
            if(errcode) *errcode= 0;
 
640
            return ret;
 
641
        }
 
642
    else if (T.tformat == LIBRAW_THUMBNAIL_JPEG)
 
643
        {
 
644
            ushort exif[5];
 
645
            int mk_exif = 0;
 
646
            if(strcmp(T.thumb+6,"Exif")) mk_exif = 1;
 
647
            
 
648
            int dsize = T.tlength + mk_exif * (sizeof(exif)+sizeof(tiff_hdr));
 
649
 
 
650
            libraw_processed_image_t * ret = 
 
651
                (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+dsize);
 
652
 
 
653
            if(!ret)
 
654
                {
 
655
                    if(errcode) *errcode= ENOMEM;
 
656
                    return NULL;
 
657
                }
 
658
 
 
659
            bzero(ret,sizeof(libraw_processed_image_t));
 
660
 
 
661
            ret->type = LIBRAW_IMAGE_JPEG;
 
662
            ret->data_size = dsize;
 
663
            
 
664
            ret->data[0] = 0xff;
 
665
            ret->data[1] = 0xd8;
 
666
            if(mk_exif)
 
667
                {
 
668
                    struct tiff_hdr th;
 
669
                    memcpy (exif, "\xff\xe1  Exif\0\0", 10);
 
670
                    exif[1] = htons (8 + sizeof th);
 
671
                    memmove(ret->data+2,exif,sizeof(exif));
 
672
                    tiff_head (&th, 0);
 
673
                    memmove(ret->data+(2+sizeof(exif)),&th,sizeof(th));
 
674
                    memmove(ret->data+(2+sizeof(exif)+sizeof(th)),T.thumb+2,T.tlength-2);
 
675
                }
 
676
            else
 
677
                {
 
678
                    memmove(ret->data+2,T.thumb+2,T.tlength-2);
 
679
                }
 
680
            if(errcode) *errcode= 0;
 
681
            return ret;
 
682
            
 
683
        }
 
684
    else
 
685
        {
 
686
            if(errcode) *errcode= LIBRAW_UNSUPPORTED_THUMBNAIL;
 
687
            return NULL;
 
688
 
 
689
        }
 
690
}
 
691
 
 
692
 
 
693
 
 
694
libraw_processed_image_t *LibRaw::dcraw_make_mem_image(int *errcode)
 
695
{
 
696
    if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) < LIBRAW_PROGRESS_PRE_INTERPOLATE)
 
697
            {
 
698
                if(errcode) *errcode= LIBRAW_OUT_OF_ORDER_CALL;
 
699
                return NULL;
 
700
            }
 
701
 
 
702
    if(!libraw_internal_data.output_data.histogram)
 
703
        {
 
704
            libraw_internal_data.output_data.histogram = 
 
705
                (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
 
706
            merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_make_mem_image()");
 
707
        }
 
708
 
 
709
    unsigned ds = S.height * S.width * (O.output_bps/8) * P1.colors;
 
710
    libraw_processed_image_t *ret = (libraw_processed_image_t*)::malloc(sizeof(libraw_processed_image_t)+ds);
 
711
    if(!ret)
 
712
        {
 
713
                if(errcode) *errcode= ENOMEM;
 
714
                return NULL;
 
715
        }
 
716
    bzero(ret,sizeof(libraw_processed_image_t));
 
717
    // metadata init
 
718
 
 
719
    int s_iheight = S.iheight;
 
720
    int s_iwidth = S.iwidth;
 
721
    int s_width = S.width;
 
722
    int s_hwight = S.height;
 
723
 
 
724
    S.iheight = S.height;
 
725
    S.iwidth  = S.width;
 
726
 
 
727
 
 
728
    if (S.flip & 4) SWAP(S.height,S.width);
 
729
 
 
730
 
 
731
    ret->type   = LIBRAW_IMAGE_BITMAP;
 
732
    ret->height = S.height;
 
733
    ret->width  = S.width;
 
734
    ret->colors = P1.colors;
 
735
    ret->bits   = O.output_bps;
 
736
    ret->gamma_corrected = (O.output_bps == 8)?1:O.gamma_16bit;
 
737
 
 
738
    ret->data_size = ds;
 
739
 
 
740
    // Cut'n'paste from write_tiff_ppm, should be generalized later
 
741
    uchar *bufp = ret->data;
 
742
    uchar *ppm;
 
743
    ushort *ppm2,lut16[0x10000];
 
744
    int c, row, col, soff, rstep, cstep;
 
745
 
 
746
 
 
747
    if (ret->bits == 8 || ret->gamma_corrected ) gamma_lut (lut16);
 
748
    soff  = flip_index (0, 0);
 
749
    cstep = flip_index (0, 1) - soff;
 
750
    rstep = flip_index (1, 0) - flip_index (0, S.width);
 
751
 
 
752
 
 
753
    for (row=0; row < ret->height; row++, soff += rstep) 
 
754
        {
 
755
            ppm2 = (ushort*) (ppm = bufp);
 
756
            for (col=0; col < ret->width; col++, soff += cstep)
 
757
                if (ret->bits == 8)
 
758
                    FORCC ppm [col*ret->colors+c] = lut16[imgdata.image[soff][c]]/256;
 
759
                else if(ret->gamma_corrected) 
 
760
                    FORCC ppm2[col*ret->colors+c] =     lut16[imgdata.image[soff][c]];
 
761
                else 
 
762
                    FORCC ppm2[col*ret->colors+c] =     imgdata.image[soff][c];
 
763
            bufp+=ret->colors*(ret->bits/8)*ret->width;
 
764
        }
 
765
    if(errcode) *errcode= 0;
 
766
 
 
767
    S.iheight = s_iheight;
 
768
    S.iwidth = s_iwidth;
 
769
    S.width = s_width;
 
770
    S.height = s_hwight;
 
771
 
 
772
    return ret;
 
773
}
 
774
 
 
775
#undef FORC
 
776
#undef FORCC
 
777
#undef SWAP
 
778
#endif
 
779
 
 
780
 
 
781
int LibRaw::dcraw_ppm_tiff_writer(const char *filename)
 
782
{
 
783
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
 
784
 
 
785
    if(!imgdata.image) 
 
786
        return LIBRAW_OUT_OF_ORDER_CALL;
 
787
 
 
788
    if(!filename) 
 
789
        return ENOENT;
 
790
    FILE *f = fopen(filename,"wb");
 
791
 
 
792
    if(!f) 
 
793
        return errno;
 
794
        
 
795
    try {
 
796
        if(!libraw_internal_data.output_data.histogram)
 
797
            {
 
798
                libraw_internal_data.output_data.histogram = 
 
799
                    (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
 
800
                merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_ppm_tiff_writer()");
 
801
            }
 
802
        write_ppm_tiff(f);
 
803
        SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP);
 
804
        fclose(f);
 
805
        return 0;
 
806
    }
 
807
    catch ( LibRaw_exceptions err) {
 
808
        fclose(f);
 
809
        EXCEPTION_HANDLER(err);
 
810
    }
 
811
}
 
812
 
 
813
void LibRaw::kodak_thumb_loader()
 
814
{
 
815
    // some kodak cameras
 
816
    ushort s_height = S.height, s_width = S.width,s_iwidth = S.iwidth,s_iheight=S.iheight;
 
817
    int s_colors = P1.colors;
 
818
    unsigned s_filters = P1.filters;
 
819
    ushort (*s_image)[4] = imgdata.image;
 
820
 
 
821
    
 
822
    S.height = T.theight;
 
823
    S.width  = T.twidth;
 
824
    P1.filters = 0;
 
825
 
 
826
    if (thumb_load_raw == &CLASS kodak_ycbcr_load_raw) 
 
827
        {
 
828
            S.height += S.height & 1;
 
829
            S.width  += S.width  & 1;
 
830
        }
 
831
    
 
832
    imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image));
 
833
    merror (imgdata.image, "LibRaw::kodak_thumb_loader()");
 
834
 
 
835
    ID.input->seek(ID.toffset, SEEK_SET);
 
836
    // read kodak thumbnail into T.image[]
 
837
    (this->*thumb_load_raw)();
 
838
 
 
839
    // copy-n-paste from image pipe
 
840
#define MIN(a,b) ((a) < (b) ? (a) : (b))
 
841
#define MAX(a,b) ((a) > (b) ? (a) : (b))
 
842
#define LIM(x,min,max) MAX(min,MIN(x,max))
 
843
#define CLIP(x) LIM(x,0,65535)
 
844
#define SWAP(a,b) { a ^= b; a ^= (b ^= a); }
 
845
 
 
846
    // from scale_colors
 
847
    {
 
848
        double   dmax;
 
849
        float scale_mul[4];
 
850
        int c,val;
 
851
        for (dmax=DBL_MAX, c=0; c < 3; c++) 
 
852
                if (dmax > C.pre_mul[c])
 
853
                    dmax = C.pre_mul[c];
 
854
 
 
855
        for( c=0; c< 3; c++)
 
856
                scale_mul[c] = (C.pre_mul[c] / dmax) * 65535.0 / C.maximum;
 
857
        scale_mul[3] = scale_mul[1];
 
858
 
 
859
        size_t size = S.height * S.width;
 
860
        for (unsigned i=0; i < size*4 ; i++) 
 
861
            {
 
862
                val = imgdata.image[0][i];
 
863
                if(!val) continue;
 
864
                val *= scale_mul[i & 3];
 
865
                imgdata.image[0][i] = CLIP(val);
 
866
            }
 
867
    }
 
868
 
 
869
    // from convert_to_rgb
 
870
    ushort *img;
 
871
    int row,col;
 
872
    
 
873
    int  (*t_hist)[LIBRAW_HISTOGRAM_SIZE] =  (int (*)[LIBRAW_HISTOGRAM_SIZE]) calloc(sizeof(*t_hist),4);
 
874
    merror (t_hist, "LibRaw::kodak_thumb_loader()");
 
875
    
 
876
    float out[3], 
 
877
        out_cam[3][4] = 
 
878
        {
 
879
            {2.81761312, -1.98369181, 0.166078627, 0}, 
 
880
            {-0.111855984, 1.73688626, -0.625030339, 0}, 
 
881
            {-0.0379119813, -0.891268849, 1.92918086, 0}
 
882
        };
 
883
 
 
884
    for (img=imgdata.image[0], row=0; row < S.height; row++)
 
885
        for (col=0; col < S.width; col++, img+=4)
 
886
            {
 
887
                out[0] = out[1] = out[2] = 0;
 
888
                for(int c=0;c<3;c++) 
 
889
                    {
 
890
                        out[0] += out_cam[0][c] * img[c];
 
891
                        out[1] += out_cam[1][c] * img[c];
 
892
                        out[2] += out_cam[2][c] * img[c];
 
893
                    }
 
894
                for(int c=0; c<3; c++)
 
895
                    img[c] = CLIP((int) out[c]);
 
896
                for(int c=0; c<P1.colors;c++)
 
897
                    t_hist[c][img[c] >> 3]++;
 
898
                    
 
899
            }
 
900
 
 
901
    // from gamma_lut
 
902
    int  (*save_hist)[LIBRAW_HISTOGRAM_SIZE] = libraw_internal_data.output_data.histogram;
 
903
    libraw_internal_data.output_data.histogram = t_hist;
 
904
    
 
905
    ushort *lut16 = (ushort*)calloc(0x10000,sizeof(ushort));
 
906
    merror(lut16,"LibRaw::kodak_thumb_loader()");
 
907
    gamma_lut(lut16);
 
908
    
 
909
    libraw_internal_data.output_data.histogram = save_hist;
 
910
 
 
911
    free(t_hist);
 
912
    
 
913
    // from write_ppm_tiff - copy pixels into bitmap
 
914
    
 
915
    S.iheight = S.height;
 
916
    S.iwidth  = S.width;
 
917
    if (S.flip & 4) SWAP(S.height,S.width);
 
918
 
 
919
    if(T.thumb) free(T.thumb);
 
920
    T.thumb = (char*) calloc (S.width * S.height, P1.colors);
 
921
    merror (T.thumb, "LibRaw::kodak_thumb_loader()");
 
922
    T.tlength = S.width * S.height * P1.colors;
 
923
 
 
924
    // from write_tiff_ppm
 
925
    {
 
926
        int soff  = flip_index (0, 0);
 
927
        int cstep = flip_index (0, 1) - soff;
 
928
        int rstep = flip_index (1, 0) - flip_index (0, S.width);
 
929
        
 
930
        for (int row=0; row < S.height; row++, soff += rstep) 
 
931
            {
 
932
                char *ppm = T.thumb + row*S.width*P1.colors;
 
933
                for (int col=0; col < S.width; col++, soff += cstep)
 
934
                    for(int c = 0; c < P1.colors; c++)
 
935
                        ppm [col*P1.colors+c] = lut16[imgdata.image[soff][c]]/256;
 
936
            }
 
937
    }
 
938
    free(lut16);
 
939
    // restore variables
 
940
    free(imgdata.image);
 
941
    imgdata.image  = s_image;
 
942
    
 
943
    T.twidth = S.width;
 
944
    S.width = s_width;
 
945
 
 
946
    S.iwidth = s_iwidth;
 
947
    S.iheight = s_iheight;
 
948
 
 
949
    T.theight = S.height;
 
950
    S.height = s_height;
 
951
 
 
952
    T.tcolors = P1.colors;
 
953
    P1.colors = s_colors;
 
954
 
 
955
    P1.filters = s_filters;
 
956
}
 
957
#undef MIN
 
958
#undef MAX
 
959
#undef LIM
 
960
#undef CLIP
 
961
#undef SWAP
 
962
 
 
963
 
 
964
 
 
965
 
 
966
// ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ thumbnail ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ thumb_format ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
967
int LibRaw::unpack_thumb(void)
 
968
{
 
969
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
 
970
    CHECK_ORDER_BIT(LIBRAW_PROGRESS_THUMB_LOAD);
 
971
 
 
972
    try {
 
973
        if ( !ID.toffset) 
 
974
            {
 
975
                return LIBRAW_NO_THUMBNAIL;
 
976
            } 
 
977
        else if (thumb_load_raw) 
 
978
            {
 
979
                kodak_thumb_loader();
 
980
                T.tformat = LIBRAW_THUMBNAIL_BITMAP;
 
981
                SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
 
982
                return 0;
 
983
            } 
 
984
        else 
 
985
            {
 
986
                ID.input->seek(ID.toffset, SEEK_SET);
 
987
                if ( write_thumb == &LibRaw::jpeg_thumb)
 
988
                    {
 
989
                        if(T.thumb) free(T.thumb);
 
990
                        T.thumb = (char *) malloc (T.tlength);
 
991
                        merror (T.thumb, "jpeg_thumb()");
 
992
                        ID.input->read (T.thumb, 1, T.tlength);
 
993
                        T.tcolors = 3;
 
994
                        T.tformat = LIBRAW_THUMBNAIL_JPEG;
 
995
                        SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
 
996
                        return 0;
 
997
                    }
 
998
                else if (write_thumb == &LibRaw::ppm_thumb)
 
999
                    {
 
1000
                        T.tlength = T.twidth * T.theight*3;
 
1001
                        if(T.thumb) free(T.thumb);
 
1002
 
 
1003
                        T.thumb = (char *) malloc (T.tlength);
 
1004
                        merror (T.thumb, "ppm_thumb()");
 
1005
 
 
1006
                        ID.input->read(T.thumb, 1, T.tlength);
 
1007
 
 
1008
                        T.tformat = LIBRAW_THUMBNAIL_BITMAP;
 
1009
                        SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD);
 
1010
                        return 0;
 
1011
 
 
1012
                    }
 
1013
                // else if -- all other write_thumb cases!
 
1014
                else
 
1015
                    {
 
1016
                        return LIBRAW_UNSUPPORTED_THUMBNAIL;
 
1017
                    }
 
1018
            }
 
1019
        // last resort
 
1020
        return LIBRAW_UNSUPPORTED_THUMBNAIL;
 
1021
    }
 
1022
    catch ( LibRaw_exceptions err) {
 
1023
        EXCEPTION_HANDLER(err);
 
1024
    }
 
1025
 
 
1026
}
 
1027
 
 
1028
int LibRaw::dcraw_thumb_writer(const char *fname)
 
1029
{
 
1030
//    CHECK_ORDER_LOW(LIBRAW_PROGRESS_THUMB_LOAD);
 
1031
 
 
1032
    if(!fname) 
 
1033
        return ENOENT;
 
1034
        
 
1035
    FILE *tfp = fopen(fname,"wb");
 
1036
    
 
1037
    if(!tfp) 
 
1038
        return errno;
 
1039
 
 
1040
    if(!T.thumb)
 
1041
        {
 
1042
                fclose(tfp);
 
1043
                return LIBRAW_OUT_OF_ORDER_CALL;
 
1044
        }
 
1045
 
 
1046
    try {
 
1047
        switch (T.tformat)
 
1048
            {
 
1049
            case LIBRAW_THUMBNAIL_JPEG:
 
1050
                jpeg_thumb_writer (tfp,T.thumb,T.tlength);
 
1051
                break;
 
1052
            case LIBRAW_THUMBNAIL_BITMAP:
 
1053
                fprintf (tfp, "P6\n%d %d\n255\n", T.twidth, T.theight);
 
1054
                fwrite (T.thumb, 1, T.tlength, tfp);
 
1055
                break;
 
1056
            default:
 
1057
                fclose(tfp);
 
1058
                return LIBRAW_UNSUPPORTED_THUMBNAIL;
 
1059
           }
 
1060
        fclose(tfp);
 
1061
        return 0;
 
1062
    }
 
1063
    catch ( LibRaw_exceptions err) {
 
1064
        fclose(tfp);
 
1065
        EXCEPTION_HANDLER(err);
 
1066
    }
 
1067
}
 
1068
 
 
1069
int LibRaw::adjust_sizes_info_only(void)
 
1070
{
 
1071
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY);
 
1072
    CHECK_ORDER_HIGH(LIBRAW_PROGRESS_FUJI_ROTATE);
 
1073
    if (O.use_fuji_rotate)
 
1074
        {
 
1075
            if (IO.fuji_width) 
 
1076
                {
 
1077
#if 0
 
1078
                    // restore saved values
 
1079
                    if(IO.fheight)
 
1080
                        {
 
1081
                            S.height = IO.fheight;
 
1082
                            S.width = IO.fwidth;
 
1083
                            S.iheight = (S.height + IO.shrink) >> IO.shrink;
 
1084
                            S.iwidth  = (S.width  + IO.shrink) >> IO.shrink;
 
1085
                            S.raw_height -= 2*S.top_margin;
 
1086
                            IO.fheight = IO.fwidth = 0; // prevent repeated calls
 
1087
                        }
 
1088
#endif
 
1089
                    // dcraw code
 
1090
                    IO.fuji_width = (IO.fuji_width - 1 + IO.shrink) >> IO.shrink;
 
1091
                    S.iwidth = (ushort)(IO.fuji_width / sqrt(0.5));
 
1092
                    S.iheight = (ushort)( (S.iheight - IO.fuji_width) / sqrt(0.5));
 
1093
                } 
 
1094
            else 
 
1095
                {
 
1096
                    if (S.pixel_aspect < 1) S.iheight = (ushort)( S.iheight / S.pixel_aspect + 0.5);
 
1097
                    if (S.pixel_aspect > 1) S.iwidth  = (ushort) (S.iwidth  * S.pixel_aspect + 0.5);
 
1098
                }
 
1099
        }
 
1100
    SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
 
1101
    if (S.flip & 4)
 
1102
        {
 
1103
            unsigned short t = S.iheight;
 
1104
            S.iheight=S.iwidth;
 
1105
            S.iwidth = t;
 
1106
            SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP);
 
1107
        }
 
1108
    return 0;
 
1109
}
 
1110
 
 
1111
 
 
1112
 
 
1113
int LibRaw::dcraw_process(void)
 
1114
{
 
1115
    int quality,i;
 
1116
 
 
1117
 
 
1118
    CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW);
 
1119
    CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE);
 
1120
 
 
1121
    try {
 
1122
 
 
1123
        if(O.half_size) 
 
1124
            O.four_color_rgb = 1;
 
1125
 
 
1126
        if (IO.zero_is_bad) 
 
1127
            {
 
1128
                remove_zeroes();
 
1129
                SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES);
 
1130
            }
 
1131
        if(O.bad_pixels) 
 
1132
            {
 
1133
                bad_pixels(O.bad_pixels);
 
1134
                SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS);
 
1135
            }
 
1136
        if (O.dark_frame)
 
1137
            {
 
1138
                subtract (O.dark_frame);
 
1139
                SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME);
 
1140
            }
 
1141
 
 
1142
        quality = 2 + !IO.fuji_width;
 
1143
 
 
1144
        if (O.user_qual >= 0) quality = O.user_qual;
 
1145
        if (O.user_black >= 0) C.black = O.user_black;
 
1146
        if (O.user_sat > 0) C.maximum = O.user_sat;
 
1147
 
 
1148
        if ( O.document_mode < 2)
 
1149
            {
 
1150
                scale_colors();
 
1151
                SET_PROC_FLAG(LIBRAW_PROGRESS_SCALE_COLORS);
 
1152
            }
 
1153
 
 
1154
        pre_interpolate();
 
1155
        SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE);
 
1156
 
 
1157
        if (P1.filters && !O.document_mode) 
 
1158
            {
 
1159
                if (quality == 0)
 
1160
                    lin_interpolate();
 
1161
                else if (quality == 1 || P1.colors > 3)
 
1162
                    vng_interpolate();
 
1163
                else if (quality == 2)
 
1164
                    ppg_interpolate();
 
1165
                else 
 
1166
                    ahd_interpolate();
 
1167
                SET_PROC_FLAG(LIBRAW_PROGRESS_INTERPOLATE);
 
1168
            }
 
1169
        if (IO.mix_green)
 
1170
            {
 
1171
                for (P1.colors=3, i=0; i < S.height * S.width; i++)
 
1172
                    imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1;
 
1173
                SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN);
 
1174
            }
 
1175
 
 
1176
        if(1)
 
1177
            {
 
1178
                if (P1.colors == 3) 
 
1179
                    {
 
1180
                        median_filter();
 
1181
                        SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER);
 
1182
                    }
 
1183
            
 
1184
                if (O.highlight == 2) 
 
1185
                    {
 
1186
                        blend_highlights();
 
1187
                        SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
 
1188
                    }
 
1189
            
 
1190
                if (O.highlight > 2) 
 
1191
                    {
 
1192
                        recover_highlights();
 
1193
                        SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS);
 
1194
                    }
 
1195
            }
 
1196
        if (O.use_fuji_rotate) 
 
1197
            {
 
1198
                fuji_rotate();
 
1199
                SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE);
 
1200
            }
 
1201
    
 
1202
        if(!libraw_internal_data.output_data.histogram)
 
1203
            {
 
1204
                libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4);
 
1205
                merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_process()");
 
1206
            }
 
1207
#ifndef NO_LCMS
 
1208
        if(O.camera_profile)
 
1209
            {
 
1210
                apply_profile(O.camera_profile,O.output_profile);
 
1211
                SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE);
 
1212
            }
 
1213
#endif
 
1214
 
 
1215
        convert_to_rgb();
 
1216
        SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB);
 
1217
 
 
1218
        if (O.use_fuji_rotate) 
 
1219
            {
 
1220
                stretch();
 
1221
                SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH);
 
1222
            }
 
1223
        return 0;
 
1224
    }
 
1225
    catch ( LibRaw_exceptions err) {
 
1226
        EXCEPTION_HANDLER(err);
 
1227
    }
 
1228
}
 
1229
 
 
1230
// Supported cameras:
 
1231
static const char  *static_camera_list[] = 
 
1232
{
 
1233
"Adobe Digital Negative (DNG)",
 
1234
"Apple QuickTake 100",
 
1235
"Apple QuickTake 150",
 
1236
"Apple QuickTake 200",
 
1237
"AVT F-080C",
 
1238
"AVT F-145C",
 
1239
"AVT F-201C",
 
1240
"AVT F-510C",
 
1241
"AVT F-810C",
 
1242
"Canon PowerShot 600",
 
1243
"Canon PowerShot A5",
 
1244
"Canon PowerShot A5 Zoom",
 
1245
"Canon PowerShot A50",
 
1246
"Canon PowerShot A460 (CHDK hack)",
 
1247
"Canon PowerShot A530 (CHDK hack)",
 
1248
"Canon PowerShot A610 (CHDK hack)",
 
1249
"Canon PowerShot A620 (CHDK hack)",
 
1250
"Canon PowerShot A630 (CHDK hack)",
 
1251
"Canon PowerShot A640 (CHDK hack)",
 
1252
"Canon PowerShot A650 (CHDK hack)",
 
1253
"Canon PowerShot A710 IS (CHDK hack)",
 
1254
"Canon PowerShot A720 IS (CHDK hack)",
 
1255
"Canon PowerShot Pro70",
 
1256
"Canon PowerShot Pro90 IS",
 
1257
"Canon PowerShot G1",
 
1258
"Canon PowerShot G2",
 
1259
"Canon PowerShot G3",
 
1260
"Canon PowerShot G5",
 
1261
"Canon PowerShot G6",
 
1262
"Canon PowerShot G7 (CHDK hack)",
 
1263
"Canon PowerShot G9",
 
1264
"Canon PowerShot G10",
 
1265
"Canon PowerShot S2 IS (CHDK hack)",
 
1266
"Canon PowerShot S3 IS (CHDK hack)",
 
1267
"Canon PowerShot S5 IS (CHDK hack)",
 
1268
"Canon PowerShot SD300 (CHDK hack)",
 
1269
"Canon PowerShot S30",
 
1270
"Canon PowerShot S40",
 
1271
"Canon PowerShot S45",
 
1272
"Canon PowerShot S50",
 
1273
"Canon PowerShot S60",
 
1274
"Canon PowerShot S70",
 
1275
"Canon PowerShot Pro1",
 
1276
"Canon EOS D30",
 
1277
"Canon EOS D60",
 
1278
"Canon EOS 5D",
 
1279
"Canon EOS 5D Mark II",
 
1280
"Canon EOS 10D",
 
1281
"Canon EOS 20D",
 
1282
"Canon EOS 30D",
 
1283
"Canon EOS 40D",
 
1284
"Canon EOS 50D",
 
1285
"Canon EOS 300D / Digital Rebel / Kiss Digital",
 
1286
"Canon EOS 350D / Digital Rebel XT / Kiss Digital N",
 
1287
"Canon EOS 400D / Digital Rebel XTi / Kiss Digital X",
 
1288
"Canon EOS 450D / Digital Rebel XSi / Kiss Digital X2",
 
1289
"Canon EOS 1000D / Digital Rebel XS / Kiss Digital F",
 
1290
"Canon EOS D2000C",
 
1291
"Canon EOS-1D",
 
1292
"Canon EOS-1DS",
 
1293
"Canon EOS-1D Mark II",
 
1294
"Canon EOS-1D Mark III",
 
1295
"Canon EOS-1D Mark II N",
 
1296
"Canon EOS-1Ds Mark II",
 
1297
"Canon EOS-1Ds Mark III",
 
1298
"Casio QV-2000UX",
 
1299
"Casio QV-3000EX",
 
1300
"Casio QV-3500EX",
 
1301
"Casio QV-4000",
 
1302
"Casio QV-5700",
 
1303
"Casio QV-R41",
 
1304
"Casio QV-R51",
 
1305
"Casio QV-R61",
 
1306
"Casio EX-S100",
 
1307
"Casio EX-Z4",
 
1308
"Casio EX-Z50",
 
1309
"Casio EX-Z55",
 
1310
"Casio Exlim Pro 505",
 
1311
"Casio Exlim Pro 600",
 
1312
"Casio Exlim Pro 700",
 
1313
"Contax N Digital",
 
1314
"Creative PC-CAM 600",
 
1315
"Epson R-D1",
 
1316
"Foculus 531C",
 
1317
"Fuji FinePix E550",
 
1318
"Fuji FinePix E900",
 
1319
"Fuji FinePix F700",
 
1320
"Fuji FinePix F710",
 
1321
"Fuji FinePix F800",
 
1322
"Fuji FinePix F810",
 
1323
"Fuji FinePix S2Pro",
 
1324
"Fuji FinePix S3Pro",
 
1325
"Fuji FinePix S5Pro",
 
1326
"Fuji FinePix S20Pro",
 
1327
"Fuji FinePix S100FS",
 
1328
"Fuji FinePix S5000",
 
1329
"Fuji FinePix S5100/S5500",
 
1330
"Fuji FinePix S5200/S5600",
 
1331
"Fuji FinePix S6000fd",
 
1332
"Fuji FinePix S7000",
 
1333
"Fuji FinePix S9000/S9500",
 
1334
"Fuji FinePix S9100/S9600",
 
1335
"Fuji IS-1",
 
1336
"Hasselblad CFV",
 
1337
"Hasselblad H3D",
 
1338
"Hasselblad V96C",
 
1339
"Imacon Ixpress 16-megapixel",
 
1340
"Imacon Ixpress 22-megapixel",
 
1341
"Imacon Ixpress 39-megapixel",
 
1342
"ISG 2020x1520",
 
1343
"Kodak DC20 (see Oliver Hartman's page)",
 
1344
"Kodak DC25 (see Jun-ichiro Itoh's page)",
 
1345
"Kodak DC40",
 
1346
"Kodak DC50",
 
1347
"Kodak DC120 (also try kdc2tiff)",
 
1348
"Kodak DCS200",
 
1349
"Kodak DCS315C",
 
1350
"Kodak DCS330C",
 
1351
"Kodak DCS420",
 
1352
"Kodak DCS460",
 
1353
"Kodak DCS460A",
 
1354
"Kodak DCS520C",
 
1355
"Kodak DCS560C",
 
1356
"Kodak DCS620C",
 
1357
"Kodak DCS620X",
 
1358
"Kodak DCS660C",
 
1359
"Kodak DCS660M",
 
1360
"Kodak DCS720X",
 
1361
"Kodak DCS760C",
 
1362
"Kodak DCS760M",
 
1363
"Kodak EOSDCS1",
 
1364
"Kodak EOSDCS3B",
 
1365
"Kodak NC2000F",
 
1366
"Kodak ProBack",
 
1367
"Kodak PB645C",
 
1368
"Kodak PB645H",
 
1369
"Kodak PB645M",
 
1370
"Kodak DCS Pro 14n",
 
1371
"Kodak DCS Pro 14nx",
 
1372
"Kodak DCS Pro SLR/c",
 
1373
"Kodak DCS Pro SLR/n",
 
1374
"Kodak C330",
 
1375
"Kodak C603",
 
1376
"Kodak P850",
 
1377
"Kodak P880",
 
1378
"Kodak KAI-0340",
 
1379
"Konica KD-400Z",
 
1380
"Konica KD-510Z",
 
1381
"Leaf AFi 7",
 
1382
"Leaf Aptus 17",
 
1383
"Leaf Aptus 22",
 
1384
"Leaf Aptus 54S",
 
1385
"Leaf Aptus 65",
 
1386
"Leaf Aptus 75",
 
1387
"Leaf Aptus 75S",
 
1388
"Leaf Cantare",
 
1389
"Leaf CatchLight",
 
1390
"Leaf CMost",
 
1391
"Leaf DCB2",
 
1392
"Leaf Valeo 6",
 
1393
"Leaf Valeo 11",
 
1394
"Leaf Valeo 17",
 
1395
"Leaf Valeo 22",
 
1396
"Leaf Volare",
 
1397
"Leica Digilux 2",
 
1398
"Leica Digilux 3",
 
1399
"Leica D-LUX2",
 
1400
"Leica D-LUX3",
 
1401
"Leica D-LUX4",
 
1402
"Leica V-LUX1",
 
1403
"Logitech Fotoman Pixtura",
 
1404
"Mamiya ZD",
 
1405
"Micron 2010",
 
1406
"Minolta RD175",
 
1407
"Minolta DiMAGE 5",
 
1408
"Minolta DiMAGE 7",
 
1409
"Minolta DiMAGE 7i",
 
1410
"Minolta DiMAGE 7Hi",
 
1411
"Minolta DiMAGE A1",
 
1412
"Minolta DiMAGE A2",
 
1413
"Minolta DiMAGE A200",
 
1414
"Minolta DiMAGE G400",
 
1415
"Minolta DiMAGE G500",
 
1416
"Minolta DiMAGE G530",
 
1417
"Minolta DiMAGE G600",
 
1418
"Minolta DiMAGE Z2",
 
1419
"Minolta Alpha/Dynax/Maxxum 5D",
 
1420
"Minolta Alpha/Dynax/Maxxum 7D",
 
1421
"Nikon D1",
 
1422
"Nikon D1H",
 
1423
"Nikon D1X",
 
1424
"Nikon D2H",
 
1425
"Nikon D2Hs",
 
1426
"Nikon D2X",
 
1427
"Nikon D2Xs",
 
1428
"Nikon D3",
 
1429
"Nikon D3X",
 
1430
"Nikon D40",
 
1431
"Nikon D40X",
 
1432
"Nikon D50",
 
1433
"Nikon D60",
 
1434
"Nikon D70",
 
1435
"Nikon D70s",
 
1436
"Nikon D80",
 
1437
"Nikon D90",
 
1438
"Nikon D100",
 
1439
"Nikon D200",
 
1440
"Nikon D300",
 
1441
"Nikon D700",
 
1442
"Nikon E700 (\"DIAG RAW\" hack)",
 
1443
"Nikon E800 (\"DIAG RAW\" hack)",
 
1444
"Nikon E880 (\"DIAG RAW\" hack)",
 
1445
"Nikon E900 (\"DIAG RAW\" hack)",
 
1446
"Nikon E950 (\"DIAG RAW\" hack)",
 
1447
"Nikon E990 (\"DIAG RAW\" hack)",
 
1448
"Nikon E995 (\"DIAG RAW\" hack)",
 
1449
"Nikon E2100 (\"DIAG RAW\" hack)",
 
1450
"Nikon E2500 (\"DIAG RAW\" hack)",
 
1451
"Nikon E3200 (\"DIAG RAW\" hack)",
 
1452
"Nikon E3700 (\"DIAG RAW\" hack)",
 
1453
"Nikon E4300 (\"DIAG RAW\" hack)",
 
1454
"Nikon E4500 (\"DIAG RAW\" hack)",
 
1455
"Nikon E5000",
 
1456
"Nikon E5400",
 
1457
"Nikon E5700",
 
1458
"Nikon E8400",
 
1459
"Nikon E8700",
 
1460
"Nikon E8800",
 
1461
"Nikon Coolpix P6000",
 
1462
"Nikon Coolpix S6 (\"DIAG RAW\" hack)",
 
1463
"Nokia N95",
 
1464
"Olympus C3030Z",
 
1465
"Olympus C5050Z",
 
1466
"Olympus C5060WZ",
 
1467
"Olympus C7070WZ",
 
1468
"Olympus C70Z,C7000Z",
 
1469
"Olympus C740UZ",
 
1470
"Olympus C770UZ",
 
1471
"Olympus C8080WZ",
 
1472
"Olympus E-1",
 
1473
"Olympus E-3",
 
1474
"Olympus E-10",
 
1475
"Olympus E-20",
 
1476
"Olympus E-300",
 
1477
"Olympus E-330",
 
1478
"Olympus E-400",
 
1479
"Olympus E-410",
 
1480
"Olympus E-420",
 
1481
"Olympus E-500",
 
1482
"Olympus E-510",
 
1483
"Olympus E-520",
 
1484
"Olympus SP310",
 
1485
"Olympus SP320",
 
1486
"Olympus SP350",
 
1487
"Olympus SP500UZ",
 
1488
"Olympus SP510UZ",
 
1489
"Olympus SP550UZ",
 
1490
"Olympus SP560UZ",
 
1491
"Olympus SP570UZ",
 
1492
"Panasonic DMC-FZ8",
 
1493
"Panasonic DMC-FZ18",
 
1494
"Panasonic DMC-FZ28",
 
1495
"Panasonic DMC-FZ30",
 
1496
"Panasonic DMC-FZ50",
 
1497
"Panasonic DMC-FX150",
 
1498
"Panasonic DMC-G1",
 
1499
"Panasonic DMC-L1",
 
1500
"Panasonic DMC-L10",
 
1501
"Panasonic DMC-LC1",
 
1502
"Panasonic DMC-LX1",
 
1503
"Panasonic DMC-LX2",
 
1504
"Panasonic DMC-LX3",
 
1505
"Pentax *ist D",
 
1506
"Pentax *ist DL",
 
1507
"Pentax *ist DL2",
 
1508
"Pentax *ist DS",
 
1509
"Pentax *ist DS2",
 
1510
"Pentax K10D",
 
1511
"Pentax K20D",
 
1512
"Pentax K100D",
 
1513
"Pentax K100D Super",
 
1514
"Pentax K200D",
 
1515
"Pentax K2000/K-m",
 
1516
"Pentax Optio S",
 
1517
"Pentax Optio S4",
 
1518
"Pentax Optio 33WR",
 
1519
"Pentax Optio 750Z",
 
1520
"Phase One LightPhase",
 
1521
"Phase One H 10",
 
1522
"Phase One H 20",
 
1523
"Phase One H 25",
 
1524
"Phase One P 20",
 
1525
"Phase One P 25",
 
1526
"Phase One P 30",
 
1527
"Phase One P 45",
 
1528
"Pixelink A782",
 
1529
"Rollei d530flex",
 
1530
"RoverShot 3320af",
 
1531
"Samsung GX-1S",
 
1532
"Samsung GX-10",
 
1533
"Samsung S85 (hacked)",
 
1534
"Sarnoff 4096x5440",
 
1535
"Sinar 3072x2048",
 
1536
"Sinar 4080x4080",
 
1537
"Sinar 4080x5440",
 
1538
"Sinar STI format",
 
1539
"SMaL Ultra-Pocket 3",
 
1540
"SMaL Ultra-Pocket 4",
 
1541
"SMaL Ultra-Pocket 5",
 
1542
"Sony DSC-F828",
 
1543
"Sony DSC-R1",
 
1544
"Sony DSC-V3",
 
1545
"Sony DSLR-A100",
 
1546
"Sony DSLR-A200",
 
1547
"Sony DSLR-A300",
 
1548
"Sony DSLR-A350",
 
1549
"Sony DSLR-A700",
 
1550
"Sony DSLR-A900",
 
1551
"Sony XCD-SX910CR",
 
1552
"STV680 VGA",
 
1553
   NULL
 
1554
};
 
1555
 
 
1556
const char** LibRaw::cameraList() { return static_camera_list;}
 
1557
int LibRaw::cameraCount() { return (sizeof(static_camera_list)/sizeof(static_camera_list[0]))-1; }
 
1558
 
 
1559
 
 
1560
const char * LibRaw::strprogress(enum LibRaw_progress p)
 
1561
{
 
1562
    switch(p)
 
1563
        {
 
1564
        case LIBRAW_PROGRESS_START:
 
1565
            return "Starting";
 
1566
        case LIBRAW_PROGRESS_OPEN :
 
1567
            return "Opening file";
 
1568
        case LIBRAW_PROGRESS_IDENTIFY :
 
1569
            return "Reading metadata";
 
1570
        case LIBRAW_PROGRESS_SIZE_ADJUST:
 
1571
            return "Adjusting size";
 
1572
        case LIBRAW_PROGRESS_LOAD_RAW:
 
1573
            return "Reading RAW data";
 
1574
        case LIBRAW_PROGRESS_REMOVE_ZEROES:
 
1575
            return "Clearing zero values";
 
1576
        case LIBRAW_PROGRESS_BAD_PIXELS :
 
1577
            return "Removing dead pixels";
 
1578
        case LIBRAW_PROGRESS_DARK_FRAME:
 
1579
            return "Subtracting dark frame data";
 
1580
        case LIBRAW_PROGRESS_SCALE_COLORS:
 
1581
            return "Scaling colors";
 
1582
        case LIBRAW_PROGRESS_PRE_INTERPOLATE:
 
1583
            return "Pre-interpolating";
 
1584
        case LIBRAW_PROGRESS_INTERPOLATE:
 
1585
            return "Interpolating";
 
1586
        case LIBRAW_PROGRESS_MIX_GREEN :
 
1587
            return "Mixing green channels";
 
1588
        case LIBRAW_PROGRESS_MEDIAN_FILTER   :
 
1589
            return "Median filter";
 
1590
        case LIBRAW_PROGRESS_HIGHLIGHTS:
 
1591
            return "Highlight recovery";
 
1592
        case LIBRAW_PROGRESS_FUJI_ROTATE :
 
1593
            return "Rotating Fuji diagonal data";
 
1594
        case LIBRAW_PROGRESS_FLIP :
 
1595
            return "Flipping image";
 
1596
        case LIBRAW_PROGRESS_APPLY_PROFILE:
 
1597
            return "ICC conversion";
 
1598
        case LIBRAW_PROGRESS_CONVERT_RGB:
 
1599
            return "Converting to RGB";
 
1600
        case LIBRAW_PROGRESS_STRETCH:
 
1601
            return "Stretching image";
 
1602
        case LIBRAW_PROGRESS_THUMB_LOAD:
 
1603
            return "Loading thumbnail";
 
1604
        default:
 
1605
            return "Some strange things";
 
1606
        }
 
1607
}