2 GENERATED FILE, DO NOT EDIT
3 Generated from dcraw/dcraw.c at Sun Mar 15 13:33:57 2009
4 Look into original file (probably http://cybercom.net/~dcoffin/dcraw/dcraw.c)
5 for copyright information.
8 #line 4007 "dcraw/dcraw.c"
10 #include "libraw/libraw_types.h"
11 #define LIBRAW_LIBRARY_BUILD
12 #include "libraw/libraw.h"
13 #include "internal/defines.h"
14 #include "internal/var_defines.h"
15 #line 4017 "dcraw/dcraw.c"
18 Seach from the current directory up to the root looking for
19 a ".badpixels" file, and fix those pixels now.
21 void CLASS
bad_pixels (char *fname
)
25 int len
, time
, row
, col
, r
, c
, rad
, tot
, n
, fixed
=0;
28 #ifdef LIBRAW_LIBRARY_BUILD
29 RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS
,0,2);
32 fp
= fopen (fname
, "r");
33 #line 4060 "dcraw/dcraw.c"
36 #ifdef LIBRAW_LIBRARY_BUILD
37 imgdata
.process_warnings
|= LIBRAW_WARN_NO_BADPIXELMAP
;
41 while (fgets (line
, 128, fp
)) {
42 cp
= strchr (line
, '#');
44 if (sscanf (line
, "%d %d %d", &col
, &row
, &time
) != 3) continue;
45 if ((unsigned) col
>= width
|| (unsigned) row
>= height
) continue;
46 if (time
> timestamp
) continue;
47 for (tot
=n
=0, rad
=1; rad
< 3 && n
==0; rad
++)
48 for (r
= row
-rad
; r
<= row
+rad
; r
++)
49 for (c
= col
-rad
; c
<= col
+rad
; c
++)
50 if ((unsigned) r
< height
&& (unsigned) c
< width
&&
51 (r
!= row
|| c
!= col
) && fc(r
,c
) == fc(row
,col
)) {
55 BAYER2(row
,col
) = tot
/n
;
59 fprintf (stderr
,_("Fixed dead pixels at:"));
60 fprintf (stderr
, " %d,%d", col
, row
);
65 if (fixed
) fputc ('\n', stderr
);
68 #ifdef LIBRAW_LIBRARY_BUILD
69 RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS
,1,2);
73 void CLASS
subtract (char *fname
)
76 int dim
[3]={0,0,0}, comment
=0, number
=0, error
=0, nd
=0, c
, row
, col
;
78 #ifdef LIBRAW_LIBRARY_BUILD
79 RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME
,0,2);
82 if (!(fp
= fopen (fname
, "rb"))) {
86 #ifdef LIBRAW_LIBRARY_BUILD
87 imgdata
.process_warnings
|= LIBRAW_WARN_BAD_DARKFRAME_FILE
;
91 if (fgetc(fp
) != 'P' || fgetc(fp
) != '5') error
= 1;
92 while (!error
&& nd
< 3 && (c
= fgetc(fp
)) != EOF
) {
93 if (c
== '#') comment
= 1;
94 if (c
== '\n') comment
= 0;
95 if (comment
) continue;
96 if (isdigit(c
)) number
= 1;
98 if (isdigit(c
)) dim
[nd
] = dim
[nd
]*10 + c
-'0';
99 else if (isspace(c
)) {
104 if (error
|| nd
< 3) {
105 fprintf (stderr
,_("%s is not a valid PGM file!\n"), fname
);
107 } else if (dim
[0] != width
|| dim
[1] != height
|| dim
[2] != 65535) {
109 fprintf (stderr
,_("%s has the wrong dimensions!\n"), fname
);
111 #ifdef LIBRAW_LIBRARY_BUILD
112 imgdata
.process_warnings
|= LIBRAW_WARN_BAD_DARKFRAME_DIM
;
116 pixel
= (ushort
*) calloc (width
, sizeof *pixel
);
117 merror (pixel
, "subtract()");
118 for (row
=0; row
< height
; row
++) {
119 fread (pixel
, 2, width
, fp
);
120 for (col
=0; col
< width
; col
++)
121 BAYER(row
,col
) = MAX (BAYER(row
,col
) - ntohs(pixel
[col
]), 0);
125 #ifdef LIBRAW_LIBRARY_BUILD
126 RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME
,1,2);
129 #line 9134 "dcraw/dcraw.c"
132 void CLASS
apply_profile (char *input
, char *output
)
135 cmsHPROFILE hInProfile
=0, hOutProfile
=0;
136 cmsHTRANSFORM hTransform
;
140 cmsErrorAction (LCMS_ERROR_SHOW
);
141 if (strcmp (input
, "embed"))
142 hInProfile
= cmsOpenProfileFromFile (input
, "r");
143 else if (profile_length
) {
144 #ifndef LIBRAW_LIBRARY_BUILD
145 prof
= (char *) malloc (profile_length
);
146 merror (prof
, "apply_profile()");
147 fseek (ifp
, profile_offset
, SEEK_SET
);
148 fread (prof
, 1, profile_length
, ifp
);
149 hInProfile
= cmsOpenProfileFromMem (prof
, profile_length
);
152 hInProfile
= cmsOpenProfileFromMem (imgdata
.color
.profile
, profile_length
);
156 #ifdef LIBRAW_LIBRARY_BUILD
157 imgdata
.process_warnings
|= LIBRAW_WARN_NO_EMBEDDED_PROFILE
;
160 fprintf (stderr
,_("%s has no embedded profile.\n"), ifname
);
165 #ifdef LIBRAW_LIBRARY_BUILD
166 imgdata
.process_warnings
|= LIBRAW_WARN_NO_INPUT_PROFILE
;
171 hOutProfile
= cmsCreate_sRGBProfile();
172 else if ((fp
= fopen (output
, "rb"))) {
173 fread (&size
, 4, 1, fp
);
174 fseek (fp
, 0, SEEK_SET
);
175 oprof
= (unsigned *) malloc (size
= ntohl(size
));
176 merror (oprof
, "apply_profile()");
177 fread (oprof
, 1, size
, fp
);
179 if (!(hOutProfile
= cmsOpenProfileFromMem (oprof
, size
))) {
185 fprintf (stderr
,_("Cannot open file %s!\n"), output
);
191 #ifdef LIBRAW_LIBRARY_BUILD
192 imgdata
.process_warnings
|= LIBRAW_WARN_BAD_OUTPUT_PROFILE
;
198 fprintf (stderr
,_("Applying color profile...\n"));
200 #ifdef LIBRAW_LIBRARY_BUILD
201 RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE
,0,2);
203 hTransform
= cmsCreateTransform (hInProfile
, TYPE_RGBA_16
,
204 hOutProfile
, TYPE_RGBA_16
, INTENT_PERCEPTUAL
, 0);
205 cmsDoTransform (hTransform
, image
, image
, width
*height
);
206 raw_color
= 1; /* Don't use rgb_cam with a profile */
207 cmsDeleteTransform (hTransform
);
208 cmsCloseProfile (hOutProfile
);
210 cmsCloseProfile (hInProfile
);
211 #ifdef LIBRAW_LIBRARY_BUILD
212 RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE
,1,2);