2 * File: docmode_withmask.cpp
3 * Copyright 2009 Alex Tutubalin <lexa@lexa.ru>
4 * Created: Fri Jan 02, 2009
7 * Generates RAW .pgm file with masked pixels included
8 * and all processing turned off
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 #include <netinet/in.h>
34 #include "libraw/libraw.h"
37 #define snprintf _snprintf
40 int main(int ac
, char *av
[])
43 int verbose
=1,autoscale
=0;
44 char outfn
[1024],thumbfn
[1024];
51 "unprocessed_raw - LibRaw %s sample. %d cameras supported\n"
52 "Usage: %s [-q] [-A] [-g] [-s N] [-N] raw-files....\n"
54 "\t-s N - select Nth image in file (default=0)\n"
55 "\t-g - use gamma correction with gamma 2.2 (not precise,use for visual inspection only)\n"
56 "\t-A - autoscaling (by integer factor)\n"
57 "\t-N - no raw curve\n"
59 LibRaw::cameraCount(),
64 #define P1 RawProcessor.imgdata.idata
65 #define S RawProcessor.imgdata.sizes
66 #define C RawProcessor.imgdata.color
67 #define T RawProcessor.imgdata.thumbnail
68 #define P2 RawProcessor.imgdata.other
69 #define OUT RawProcessor.imgdata.params
75 OUT
.no_auto_bright
= 1;
76 OUT
.filtering_mode
=(LibRaw_filtering
)( LIBRAW_FILTERING_NOBLACKS
|LIBRAW_FILTERING_NOZEROES
);
81 if(av
[i
][1]=='q' && av
[i
][2]==0)
83 else if(av
[i
][1]=='A' && av
[i
][2]==0)
85 else if(av
[i
][1]=='g' && av
[i
][2]==0)
87 else if(av
[i
][1]=='N' && av
[i
][2]==0)
88 OUT
.filtering_mode
=LIBRAW_FILTERING_NONE
;
89 else if(av
[i
][1]=='s' && av
[i
][2]==0)
92 OUT
.shot_select
=atoi(av
[i
]);
99 if(verbose
) printf("Processing file %s\n",av
[i
]);
100 if( (ret
= RawProcessor
.open_file(av
[i
])) != LIBRAW_SUCCESS
)
102 fprintf(stderr
,"Cannot open %s: %s\n",av
[i
],libraw_strerror(ret
));
103 continue; // no recycle b/c open file will recycle itself
107 printf("Image size: %dx%d\nRaw size: %dx%d\n",S
.width
,S
.height
,S
.raw_width
,S
.raw_height
);
108 printf("Margins: top=%d, left=%d, right=%d, bottom=%d\n",
109 S
.top_margin
,S
.left_margin
,S
.right_margin
,S
.bottom_margin
);
112 if( (ret
= RawProcessor
.unpack() ) != LIBRAW_SUCCESS
)
114 fprintf(stderr
,"Cannot unpack %s: %s\n",av
[i
],libraw_strerror(ret
));
118 printf("Unpacked....\n");
120 if( (ret
= RawProcessor
.add_masked_borders_to_bitmap() ) != LIBRAW_SUCCESS
)
122 fprintf(stderr
,"Cannot add mask data to bitmap %s\n",av
[i
]);
124 for(int r
=0;r
<S
.iheight
;r
++)
125 for(c
=0;c
<S
.iwidth
;c
++)
126 RawProcessor
.imgdata
.image
[r
*S
.iwidth
+c
][0]
127 = RawProcessor
.imgdata
.image
[r
*S
.iwidth
+c
][RawProcessor
.FC(r
,c
)];
132 unsigned max
=0,scale
;
133 for(int j
=0; j
<S
.iheight
*S
.iwidth
; j
++)
134 if(max
< RawProcessor
.imgdata
.image
[j
][0])
135 max
= RawProcessor
.imgdata
.image
[j
][0];
136 if (max
>0 && max
< 1<<15)
140 printf("Scaling with multiplier=%d (max=%d)\n",scale
,max
);
142 for(int j
=0; j
<S
.iheight
*S
.iwidth
; j
++)
143 RawProcessor
.imgdata
.image
[j
][0] *= scale
;
148 snprintf(outfn
,sizeof(outfn
),"%s-%d.tiff",av
[i
],OUT
.shot_select
);
150 snprintf(outfn
,sizeof(outfn
),"%s.tiff",av
[i
]);
152 if(verbose
) printf("Writing file %s\n",outfn
);
153 if( LIBRAW_SUCCESS
!= (ret
= RawProcessor
.dcraw_ppm_tiff_writer(outfn
)))
154 fprintf(stderr
,"Cannot write %s: %s\n",outfn
,libraw_strerror(ret
));