libkdcraw from trunk : update internal LibRaw to 0.7.0-alpha4
[kdegraphics.git] / libs / libkdcraw / libraw / samples / identify.cpp
bloba1e0f203f99a05239b8ec7a7950cc14bce2022a0
1 /* -*- C++ -*-
2 * File: identify.cpp
3 * Copyright 2008-2009 Alex Tutubalin <lexa@lexa.ru>
4 * Created: Sat Mar 8 , 2008
6 * LibRaw C++ demo (emulates dcraw -i [-v])
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
24 #include <stdio.h>
25 #include <string.h>
26 #include <math.h>
27 #include <time.h>
29 #include "libraw/libraw.h"
31 #ifdef WIN32
32 #define snprintf _snprintf
33 #endif
36 int main(int ac, char *av[])
38 int verbose = 0, ret,print_unpack=0,print_frame=0;
39 LibRaw MyCoolRawProcessor;
41 for (int i=1;i<ac;i++) {
42 if(av[i][0]=='-')
44 if(av[i][1]=='v' && av[i][2]==0) verbose++;
45 if(av[i][1]=='u' && av[i][2]==0) print_unpack++;
46 if(av[i][1]=='f' && av[i][2]==0) print_frame++;
47 continue;
49 if( (ret = MyCoolRawProcessor.open_file(av[i])) != LIBRAW_SUCCESS)
51 printf("Cannot decode %s: %s\n",av[i],libraw_strerror(ret));
52 continue; // no recycle, open_file will recycle
54 if(verbose) {
56 #define P1 MyCoolRawProcessor.imgdata.idata
57 #define P2 MyCoolRawProcessor.imgdata.other
59 #define S MyCoolRawProcessor.imgdata.sizes
60 #define O MyCoolRawProcessor.imgdata.params
61 #define C MyCoolRawProcessor.imgdata.color
62 #define T MyCoolRawProcessor.imgdata.thumbnail
65 if( (ret = MyCoolRawProcessor.adjust_sizes_info_only()))
67 printf("Cannot decode %s: %s\n",av[i],libraw_strerror(ret));
68 continue; // no recycle, open_file will recycle
71 printf ("\nFilename: %s\n", av[i]);
72 printf ("Timestamp: %s", ctime(&(P2.timestamp)));
73 printf ("Camera: %s %s\n", P1.make, P1.model);
74 if (P2.artist[0])
75 printf ("Owner: %s\n", P2.artist);
76 if (P1.dng_version) {
77 printf ("DNG Version: ");
78 for (int i=24; i >= 0; i -= 8)
79 printf ("%d%c", P1.dng_version >> i & 255, i ? '.':'\n');
81 printf ("ISO speed: %d\n", (int) P2.iso_speed);
82 printf ("Shutter: ");
83 if (P2.shutter > 0 && P2.shutter < 1)
84 P2.shutter = (printf ("1/"), 1 / P2.shutter);
85 printf ("%0.1f sec\n", P2.shutter);
86 printf ("Aperture: f/%0.1f\n", P2.aperture);
87 printf ("Focal length: %0.1f mm\n", P2.focal_len);
88 if(C.profile)
89 printf ("Embedded ICC profile: yes, %d bytes\n", C.profile_length);
90 else
91 printf ("Embedded ICC profile: no\n", C.profile_length);
93 printf ("Number of raw images: %d\n", P1.raw_count);
94 if (S.pixel_aspect != 1)
95 printf ("Pixel Aspect Ratio: %0.6f\n", S.pixel_aspect);
96 if (T.tlength)
97 printf ("Thumb size: %4d x %d\n", T.twidth, T.theight);
98 printf ("Full size: %4d x %d\n", S.raw_width, S.raw_height);
100 printf ("Image size: %4d x %d\n", S.width, S.height);
101 printf ("Output size: %4d x %d\n", S.iwidth, S.iheight);
102 printf ("Raw colors: %d", P1.colors);
103 if (P1.filters)
105 printf ("\nFilter pattern: ");
106 if (!P1.cdesc[3]) P1.cdesc[3] = 'G';
107 for (int i=0; i < 16; i++)
108 putchar (P1.cdesc[MyCoolRawProcessor.fc(i >> 1,i & 1)]);
110 printf ("\nDaylight multipliers:");
111 for(int c=0;c<P1.colors;c++) printf (" %f", C.pre_mul[c]);
112 if (C.cam_mul[0] > 0)
114 printf ("\nCamera multipliers:");
115 for(int c=0;c<4;c++) printf (" %f", C.cam_mul[c]);
117 char *csl[] = {"U","I","CO","L","CA"};
118 printf("\nColor sources /Legend: (U)nknown, (I)nit, (CO)nstant, (L)oaded, (CA)lculated/:\n");
119 printf("\tcurve=%s; rgb_cam=%s; cmatrix=%s, pre_mul=%s, cam_mul=%s",
120 csl[C.color_flags.curve_state],csl[C.color_flags.rgb_cam_state],
121 csl[C.color_flags.cmatrix_state],csl[C.color_flags.pre_mul_state],
122 csl[C.color_flags.cam_mul_state]);
123 putchar ('\n');
124 printf("Cam->XYZ matrix:\n");
125 for(int i=0; i< 4; i++)
126 printf("%6.4f\t%6.4f\t%6.4f\n",C.cam_xyz[i][0],C.cam_xyz[i][1],C.cam_xyz[i][2]);
128 else
130 if(print_unpack)
132 char frame[32]="";
133 if(print_frame)
134 snprintf(frame,32,"%dx%dx%dx%d",S.left_margin,S.top_margin,S.right_margin,S.bottom_margin);
135 printf ("%s\t%s\t%s\t%s/%s\n",
136 av[i],
137 MyCoolRawProcessor.unpack_function_name(),
138 frame,
139 P1.make, P1.model);
141 else
142 printf ("%s is a %s %s image.\n", av[i],P1.make, P1.model);
144 MyCoolRawProcessor.recycle();
145 }// endfor
146 return 0;