1 /* CINELERRA dcraw.c */
13 #define uchar unsigned char
16 #define ushort unsigned short
24 // ZEROd by DCRaw reset
29 char *meta_data, xtrans[6][6], xtrans_abs[6][6];
30 char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64];
31 float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len;
33 off_t strip_offset, data_offset;
34 off_t thumb_offset, meta_offset, profile_offset;
35 unsigned shot_order, kodak_cbpp, exif_cfa, unique_id;
36 unsigned thumb_length, meta_length, profile_length;
37 unsigned thumb_misc, *oprof, fuji_layout;
38 unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress;
39 unsigned black, maximum, mix_green, raw_color, zero_is_bad;
40 unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error;
41 unsigned tile_width, tile_length, gpsdata[32], load_flags;
42 unsigned flip, tiff_flip, filters, colors;
43 ushort raw_height, raw_width, height, width, top_margin, left_margin;
44 ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height;
45 ushort *raw_image, (*image)[4], cblack[4102];
46 ushort white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4];
48 unsigned shot_select, multi_out;
49 double pixel_aspect, aber[4], gamm[6];
50 float bright, user_mul[4], threshold;
52 int half_size, four_color_rgb, document_mode, highlight;
53 int verbose, use_auto_wb, use_camera_wb, use_camera_matrix;
54 int output_color, output_bps, output_tiff, med_passes;
57 float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4];
58 int histogram[4][0x2000];
59 void (CLASS *write_thumb)(), (CLASS *write_fun)();
60 void (CLASS *load_raw)(), (CLASS *thumb_load_raw)();
64 struct decode *branch[2];
66 } first_decode[2048], /* *second_decode, CINELERRA */ *free_decode;
69 int width, height, bps, comp, phint, offset, flip, samples, bytes;
70 int tile_width, tile_length;
75 int format, key_off, tag_21a;
76 int black, split_col, black_col, split_row, black_row;
82 int gbh_vbits, gbh_reset;
86 unsigned sony_pad[128], sony_p;
87 unsigned fov_huff[1024];
88 float clb_cbrt[0x10000], clb_xyz_cam[3][4];
89 uchar pana_buf[0x4000]; int pana_vbits;
91 static const double xyz_rgb[3][3];
92 static const float d65_white[3];
96 class DCRaw : public DCRaw_data {
98 int fcol(int row,int col);
100 char *my_memmem(char *haystack,size_t haystacklen,char *needle,size_t needlelen);
101 char *my_strcasestr(char *haystack,const char *needle);
103 void merror(void *ptr,const char *where);
105 ushort sget2(uchar *s);
107 unsigned sget4(uchar *s);
109 unsigned getint(int type);
110 float int_to_float(int i);
111 double getreal(int type);
112 void read_shorts(ushort *pixel,int count);
113 void cubic_spline(const int *x_,const int *y_,const int len);
114 void canon_600_fixed_wb(int temp);
115 int canon_600_color(int ratio[2],int mar);
116 void canon_600_auto_wb(void);
117 void canon_600_coeff(void);
118 void canon_600_load_raw(void);
119 void canon_600_correct(void);
120 int canon_s2is(void);
121 unsigned getbithuff(int nbits,ushort *huff);
122 ushort *make_decoder_ref(const uchar **source);
123 ushort *make_decoder(const uchar *source);
124 void crw_init_tables(unsigned table,ushort *huff[2]);
125 int canon_has_lowbits(void);
126 void canon_load_raw(void);
127 int ljpeg_start(struct jhead *jh,int info_only);
128 void ljpeg_end(struct jhead *jh);
129 int ljpeg_diff(ushort *huff);
130 ushort *ljpeg_row(int jrow,struct jhead *jh);
131 void lossless_jpeg_load_raw(void);
132 void canon_sraw_load_raw(void);
133 void adobe_copy_pixel(unsigned row,unsigned col,ushort **rp);
134 void ljpeg_idct(struct jhead *jh);
135 void lossless_dng_load_raw(void);
136 void packed_dng_load_raw(void);
137 void pentax_load_raw(void);
138 void nikon_load_raw(void);
139 void nikon_yuv_load_raw(void);
140 int nikon_e995(void);
141 int nikon_e2100(void);
142 void nikon_3700(void);
143 int minolta_z2(void);
144 void ppm_thumb(void);
145 void ppm16_thumb(void);
146 void layer_thumb(void);
147 void rollei_thumb(void);
148 void rollei_load_raw(void);
149 int raw(unsigned row,unsigned col);
150 void phase_one_flat_field(int is_float,int nc);
151 void phase_one_correct(void);
152 void phase_one_load_raw(void);
153 unsigned ph1_bithuff(int nbits,ushort *huff);
154 void phase_one_load_raw_c(void);
155 void hasselblad_load_raw(void);
156 void leaf_hdr_load_raw(void);
157 void unpacked_load_raw(void);
158 void sinar_4shot_load_raw(void);
159 void imacon_full_load_raw(void);
160 void packed_load_raw(void);
161 void nokia_load_raw(void);
162 void canon_rmf_load_raw(void);
163 unsigned pana_bits(int nbits);
164 void panasonic_load_raw(void);
165 void olympus_load_raw(void);
166 void canon_crx_load_raw();
167 void fuji_xtrans_load_raw();
168 void minolta_rd175_load_raw(void);
169 void quicktake_100_load_raw(void);
170 void kodak_radc_load_raw(void);
171 void kodak_jpeg_load_raw(void);
172 void lossy_dng_load_raw(void);
174 boolean fill_input_buffer(j_decompress_ptr cinfo);
176 void kodak_dc120_load_raw(void);
177 void eight_bit_load_raw(void);
178 void kodak_c330_load_raw(void);
179 void kodak_c603_load_raw(void);
180 void kodak_262_load_raw(void);
181 int kodak_65000_decode(short *out,int bsize);
182 void kodak_65000_load_raw(void);
183 void kodak_ycbcr_load_raw(void);
184 void kodak_rgb_load_raw(void);
185 void kodak_thumb_load_raw(void);
186 void sony_decrypt(unsigned *data,int len,int start,int key);
187 void sony_load_raw(void);
188 void sony_arw_load_raw(void);
189 void sony_arw2_load_raw(void);
190 void samsung_load_raw(void);
191 void samsung2_load_raw(void);
192 void samsung3_load_raw(void);
193 void smal_decode_segment(unsigned seg[2][2],int holes);
194 void smal_v6_load_raw(void);
196 void fill_holes(int holes);
197 void smal_v9_load_raw(void);
198 void redcine_load_raw(void);
199 void foveon_decoder(unsigned size,unsigned code);
200 void foveon_thumb(void);
201 void foveon_sd_load_raw(void);
202 void foveon_huff(ushort *huff);
203 void foveon_dp_load_raw(void);
204 void foveon_load_camf(void);
205 const char *foveon_camf_param(const char *block,const char *param);
206 void *foveon_camf_matrix(unsigned dim[3],const char *name);
207 int foveon_fixed(void *ptr,int size,const char *name);
208 float foveon_avg(short *pix,int range[2],float cfilt);
209 short *foveon_make_curve(double max,double mul,double filt);
210 void foveon_make_curves(short **curvep,float dq[3],float div[3],float filt);
211 int foveon_apply_curve(short *curve,int i);
212 void foveon_interpolate(void);
213 void crop_masked_pixels(void);
214 void remove_zeroes(void);
215 void bad_pixels(const char *cfname);
216 void subtract(const char *fname);
217 void gamma_curve(double pwr,double ts,int mode,int imax);
218 void pseudoinverse (double (*in)[3],double (*out)[3],int size);
219 void cam_xyz_coeff(float rgb_cam[3][4],double cam_xyz[4][3]);
221 void colorcheck(void);
223 void hat_transform(float *temp,float *base,int st,int size,int sc);
224 void wavelet_denoise(void);
225 void scale_colors(void);
226 void pre_interpolate(void);
227 void border_interpolate(int border);
228 void lin_interpolate(void);
229 void vng_interpolate(void);
230 void ppg_interpolate(void);
231 void cielab(ushort rgb[3],short lab[3]);
232 void xtrans_interpolate(int passes);
233 void ahd_interpolate(void);
234 void median_filter(void);
235 void blend_highlights(void);
236 void recover_highlights(void);
237 void tiff_get(unsigned base,unsigned *tag,unsigned *type,unsigned *len,unsigned *save);
238 void parse_thumb_note(int base,unsigned toff,unsigned tlen);
239 void parse_makernote(int base,int uptag);
240 void get_timestamp(int reversed);
241 void parse_exif(int base);
242 void parse_gps(int base);
243 void romm_coeff(float romm_cam[3][3]);
244 void parse_mos(int offset);
245 void linear_table(unsigned len);
246 void parse_kodak_ifd(int base);
247 int parse_tiff_ifd(int base);
248 int parse_tiff(int base);
249 void apply_tiff(void);
250 void parse_minolta(int base);
251 void parse_external_jpeg(void);
252 void ciff_block_1030(void);
253 void parse_ciff(int offset,int length,int depth);
254 void parse_rollei(void);
255 void parse_sinar_ia(void);
256 void parse_phase_one(int base);
257 void parse_fuji(int offset);
258 int parse_jpeg(int offset);
259 void parse_riff(void);
260 void parse_crx(int end);
261 void parse_qt(int end);
262 void parse_smal(int offset,int fsize);
263 void parse_cine(void);
264 void parse_redcine(void);
265 char *foveon_gets(int offset,char *str,int len);
266 void parse_foveon(void);
267 void adobe_coeff(const char *make,const char *model);
268 void simple_coeff(int index);
269 short guess_byte_order(int words);
270 float find_green(int bps,int bite,int off0,int off1);
273 void apply_profile(const char *input,const char *output);
275 void convert_to_rgb(void);
276 void fuji_rotate(void);
278 int flip_index(int row, int col);
279 void tiff_set(struct tiff_hdr *th,ushort *ntag,ushort tag,ushort type,int count,int val);
280 void tiff_head(struct tiff_hdr *th,int full);
281 void jpeg_thumb(void);
282 void write_ppm_tiff(void);
283 void write_cinelerra(void);
293 int main(int argc, const char **argv);