3 * Copyright 2009 Alex Tutubalin <lexa@lexa.ru>
4 * Created: Mon Feb 09, 2009
7 * Generates 4 TIFF file from RAW data, one file per channel
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include <netinet/in.h>
33 #include "libraw/libraw.h"
36 #define snprintf _snprintf
39 int main(int ac
, char *av
[])
42 int autoscale
=0,filtering_mode
=LIBRAW_FILTERING_DEFAULT
,black_subtraction
=1;
43 char outfn
[1024],thumbfn
[1024];
50 "4channeld - LibRaw %s sample. %d cameras supported\n"
51 "Usage: %s [-s N] [-g] [-A] [-B] [-N] raw-files....\n"
52 "\t-s N - select Nth image in file (default=0)\n"
53 "\t-g - use gamma correction with gamma 2.2 (not precise,use for visual inspection only)\n"
54 "\t-A - autoscaling (by integer factor)\n"
55 "\t-B - no black subtraction\n"
56 "\t-N - no raw curve\n"
58 LibRaw::cameraCount(),
63 #define P1 RawProcessor.imgdata.idata
64 #define S RawProcessor.imgdata.sizes
65 #define C RawProcessor.imgdata.color
66 #define T RawProcessor.imgdata.thumbnail
67 #define P2 RawProcessor.imgdata.other
68 #define OUT RawProcessor.imgdata.params
74 OUT
.no_auto_bright
= 1;
76 OUT
.filtering_mode
= LIBRAW_FILTERING_AUTOMATIC
;
82 if(av
[i
][1]=='s' && av
[i
][2]==0)
85 OUT
.shot_select
=atoi(av
[i
]);
87 else if(av
[i
][1]=='g' && av
[i
][2]==0)
89 else if(av
[i
][1]=='A' && av
[i
][2]==0)
91 else if(av
[i
][1]=='B' && av
[i
][2]==0)
93 filtering_mode
|= (LIBRAW_FILTERING_NOZEROES
| LIBRAW_FILTERING_NOBLACKS
);
96 else if(av
[i
][1]=='N' && av
[i
][2]==0)
97 filtering_mode
|= LIBRAW_FILTERING_NORAWCURVE
;
103 OUT
.filtering_mode
= (LibRaw_filtering
) filtering_mode
;
105 printf("Processing file %s\n",av
[i
]);
106 if( (ret
= RawProcessor
.open_file(av
[i
])) != LIBRAW_SUCCESS
)
108 fprintf(stderr
,"Cannot open %s: %s\n",av
[i
],libraw_strerror(ret
));
109 continue; // no recycle b/c open file will recycle itself
113 printf("Cannot process foveon image %s\n",av
[i
]);
116 if( (ret
= RawProcessor
.unpack() ) != LIBRAW_SUCCESS
)
118 fprintf(stderr
,"Cannot unpack %s: %s\n",av
[i
],libraw_strerror(ret
));
121 if(black_subtraction
&& C
.black
>0)
123 for(int j
=0; j
<S
.iheight
*S
.iwidth
; j
++)
124 for(int c
= 0; c
< 4; c
++)
125 if(RawProcessor
.imgdata
.image
[j
][c
]>C
.black
)
126 RawProcessor
.imgdata
.image
[j
][c
]-=C
.black
;
128 RawProcessor
.imgdata
.image
[j
][c
]=0;
133 unsigned max
=0,scale
;
134 for(int j
=0; j
<S
.iheight
*S
.iwidth
; j
++)
135 for(int c
= 0; c
< 4; c
++)
136 if(max
< RawProcessor
.imgdata
.image
[j
][c
])
137 max
= RawProcessor
.imgdata
.image
[j
][c
];
138 if (max
>0 && max
< 1<<15)
141 printf("Scaling with multiplier=%d (max=%d)\n",scale
,max
);
142 for(int j
=0; j
<S
.iheight
*S
.iwidth
; j
++)
144 RawProcessor
.imgdata
.image
[j
][c
] *= scale
;
146 printf("Black level (scaled)=%d\n",C
.black
*scale
);
149 printf("Black level (unscaled)=%d\n",C
.black
);
152 // hack to make dcraw tiff writer happy
153 int isrgb
=(P1
.colors
==4?0:1);
156 S
.height
= S
.iheight
;
158 for (int layer
=0;layer
<4;layer
++)
162 for (int rc
= 0; rc
< S
.iheight
*S
.iwidth
; rc
++)
163 RawProcessor
.imgdata
.image
[rc
][0] = RawProcessor
.imgdata
.image
[rc
][layer
];
168 snprintf(lname
,7,"%c",(char*)("RGBG")[layer
]);
173 snprintf(lname
,7,"%c",(char*)("GCMY")[layer
]);
176 snprintf(outfn
,sizeof(outfn
),"%s-%d.%s.tiff",av
[i
],OUT
.shot_select
,lname
);
178 snprintf(outfn
,sizeof(outfn
),"%s.%s.tiff",av
[i
],lname
);
180 printf("Writing file %s\n",outfn
);
181 if( LIBRAW_SUCCESS
!= (ret
= RawProcessor
.dcraw_ppm_tiff_writer(outfn
)))
182 fprintf(stderr
,"Cannot write %s: %s\n",outfn
,libraw_strerror(ret
));