compile
[kdegraphics.git] / libs / libkdcraw / libraw / internal / dcraw_fileio.cpp
blobb2d26d612a14f4784cadbce991ee9bdd74cf909b
1 /*
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.
6 */
8 #line 4007 "dcraw/dcraw.c"
9 #define CLASS LibRaw::
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)
23 FILE *fp=0;
24 char *cp, line[128];
25 int len, time, row, col, r, c, rad, tot, n, fixed=0;
27 if (!filters) return;
28 #ifdef LIBRAW_LIBRARY_BUILD
29 RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,0,2);
30 #endif
31 if (fname)
32 fp = fopen (fname, "r");
33 #line 4060 "dcraw/dcraw.c"
34 if (!fp)
36 #ifdef LIBRAW_LIBRARY_BUILD
37 imgdata.process_warnings |= LIBRAW_WARN_NO_BADPIXELMAP;
38 #endif
39 return;
41 while (fgets (line, 128, fp)) {
42 cp = strchr (line, '#');
43 if (cp) *cp = 0;
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)) {
52 tot += BAYER2(r,c);
53 n++;
55 BAYER2(row,col) = tot/n;
56 #ifdef DCRAW_VERBOSE
57 if (verbose) {
58 if (!fixed++)
59 fprintf (stderr,_("Fixed dead pixels at:"));
60 fprintf (stderr, " %d,%d", col, row);
62 #endif
64 #ifdef DCRAW_VERBOSE
65 if (fixed) fputc ('\n', stderr);
66 #endif
67 fclose (fp);
68 #ifdef LIBRAW_LIBRARY_BUILD
69 RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,1,2);
70 #endif
73 void CLASS subtract (char *fname)
75 FILE *fp;
76 int dim[3]={0,0,0}, comment=0, number=0, error=0, nd=0, c, row, col;
77 ushort *pixel;
78 #ifdef LIBRAW_LIBRARY_BUILD
79 RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,0,2);
80 #endif
82 if (!(fp = fopen (fname, "rb"))) {
83 #ifdef DCRAW_VERBOSE
84 perror (fname);
85 #endif
86 #ifdef LIBRAW_LIBRARY_BUILD
87 imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_FILE;
88 #endif
89 return;
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;
97 if (number) {
98 if (isdigit(c)) dim[nd] = dim[nd]*10 + c -'0';
99 else if (isspace(c)) {
100 number = 0; nd++;
101 } else error = 1;
104 if (error || nd < 3) {
105 fprintf (stderr,_("%s is not a valid PGM file!\n"), fname);
106 fclose (fp); return;
107 } else if (dim[0] != width || dim[1] != height || dim[2] != 65535) {
108 #ifdef DCRAW_VERBOSE
109 fprintf (stderr,_("%s has the wrong dimensions!\n"), fname);
110 #endif
111 #ifdef LIBRAW_LIBRARY_BUILD
112 imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_DIM;
113 #endif
114 fclose (fp); return;
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);
123 free (pixel);
124 black = 0;
125 #ifdef LIBRAW_LIBRARY_BUILD
126 RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,1,2);
127 #endif
129 #line 9134 "dcraw/dcraw.c"
131 #ifndef NO_LCMS
132 void CLASS apply_profile (char *input, char *output)
134 char *prof;
135 cmsHPROFILE hInProfile=0, hOutProfile=0;
136 cmsHTRANSFORM hTransform;
137 FILE *fp;
138 unsigned size;
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);
150 free (prof);
151 #else
152 hInProfile = cmsOpenProfileFromMem (imgdata.color.profile, profile_length);
153 #endif
154 } else
156 #ifdef LIBRAW_LIBRARY_BUILD
157 imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE;
158 #endif
159 #ifdef DCRAW_VERBOSE
160 fprintf (stderr,_("%s has no embedded profile.\n"), ifname);
161 #endif
163 if (!hInProfile)
165 #ifdef LIBRAW_LIBRARY_BUILD
166 imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE;
167 #endif
168 return;
170 if (!output)
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);
178 fclose (fp);
179 if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) {
180 free (oprof);
181 oprof = 0;
183 #ifdef DCRAW_VERBOSE
184 } else
185 fprintf (stderr,_("Cannot open file %s!\n"), output);
186 #else
188 #endif
189 if (!hOutProfile)
191 #ifdef LIBRAW_LIBRARY_BUILD
192 imgdata.process_warnings |= LIBRAW_WARN_BAD_OUTPUT_PROFILE;
193 #endif
194 goto quit;
196 #ifdef DCRAW_VERBOSE
197 if (verbose)
198 fprintf (stderr,_("Applying color profile...\n"));
199 #endif
200 #ifdef LIBRAW_LIBRARY_BUILD
201 RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,0,2);
202 #endif
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);
209 quit:
210 cmsCloseProfile (hInProfile);
211 #ifdef LIBRAW_LIBRARY_BUILD
212 RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,1,2);
213 #endif
215 #endif