w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bmp2png.c
Go to the documentation of this file.
1 /*
2 ** bmp2png --- conversion from (Windows or OS/2 style) BMP to PNG
3 **
4 ** Copyright (C) 1999-2005 MIYASAKA Masaru
5 **
6 ** For conditions of distribution and use,
7 ** see copyright notice in common.h.
8 */
9 
10 #include "common.h"
11 #include "bmphed.h"
12 
13 #define BMP2PNG_VERSION "1.62 (Sep 4, 2005)"
14 #define BMP2PNG_COPYRIGHT "Copyright (C) 1999-2005 MIYASAKA Masaru"
15 
16 char outnam[FILENAME_MAX];
17 char outdir[FILENAME_MAX];
18 int deletesrc = 0;
19 int copytime = 0;
20 int complevel = 6;
21 int interlace = 0;
22 int filters = 0;
23 int alpha_bmp = 0;
24 
25 #define B2P_TRANSPARENT_NONE 0
26 #define B2P_TRANSPARENT_RGB 1
27 #define B2P_TRANSPARENT_PALETTE 2
28 
31 
32 #if defined(WIN32) || defined(MSDOS)
33 const char errlogfile[] = ".\\B2PERROR.LOG";
34 #else
35 const char errlogfile[] = "./b2perror.log";
36 #endif
37 
38  /* error messages */
39 #ifdef JAPANESE /* ---------- */
40 const char wrn_invalidtrans[] =
41  "WARNING: 透明色指定の形式が正しくありません(無視されます) - '%s'\n";
42 const char wrn_notranscolor[] =
43  "WARNING: 指定された透明色に一致する色がありません - %s\n"
44  "WARNING: -> -P オプション での透明色指定は無視されます\n";
45 const char wrn_transtruecolor[] =
46  "WARNING: 画像はフルカラー形式です - %s\n"
47  "WARNING: -> -P オプション での透明色指定は無視されます\n";
48 const char wrn_imagehasalpha[] =
49  "WARNING: アルファチャネル付きの画像です - %s\n"
50  "WARNING: -> -P オプション での透明色指定は無視されます\n";
51 const char wrn_alphaallzero[] =
52  "WARNING: 4番目のチャネルはアルファチャネルではないようです(すべて0) - %s\n"
53  "WARNING: -> 4番目のチャネル(アルファチャネル)は破棄されます\n";
54 const char wrn_mkdirfail[] =
55  "WARNING: 出力先ディレクトリを作れません - %s\n"
56  "WARNING: -> -%c オプション での出力先指定は無視されます\n";
57 const char err_ropenfail[] = "SKIPPED: 該当するファイルがありません - %s\n";
58 const char err_wopenfail[] = "SKIPPED: 出力ファイルを作成できません - %s\n";
59 const char err_outofmemory[] = "SKIPPED: 作業用メモリが確保できません - %s\n";
60  /* -- */
61 const char err_readeof[] = "SKIPPED: ファイルが途中で切れています - %s\n";
62 const char err_readerr[] = "SKIPPED: 読み込みエラーが発生しました - %s\n";
63 const char err_not_a_bmp[] = "SKIPPED: BMP ファイルではありません - %s\n";
64 const char err_invalid_hed[] =
65  "SKIPPED: BMP ファイルのヘッダサイズが無効です - %s\n";
66 const char err_width_zero[] = "SKIPPED: 画像の幅が0(または負)です - %s\n";
67 const char err_height_zero[] = "SKIPPED: 画像の高さが0(または負)です - %s\n";
68 const char err_compression[] = "SKIPPED: 不明な圧縮タイプです - %s\n";
69 const char err_invalid_bpp[] = "SKIPPED: 画像の色数が無効です - %s\n";
70 const char err_no_palette[] = "SKIPPED: パレットが欠落しています - %s\n";
71 #else /* ------------------- */
72 const char wrn_invalidtrans[] =
73  "WARNING: Invalid transparent color specifier - '%s'. ignored.\n";
74 const char wrn_notranscolor[] =
75  "WARNING: Specified transparent color is not present in palette - %s\n"
76  "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
77 const char wrn_transtruecolor[] =
78  "WARNING: Image is truecolor format - %s\n"
79  "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
80 const char wrn_imagehasalpha[] =
81  "WARNING: Image has an alpha channel - %s\n"
82  "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
83 const char wrn_alphaallzero[] =
84  "WARNING: The 4th channel doesn't seem to be an alpha channel (all zero) - %s\n"
85  "WARNING: -> The 4th channel (alpha channel) will be discarded.\n";
86 const char wrn_mkdirfail[] =
87  "WARNING: Cannot create a directory - %s\n"
88  "WARNING: -> Output directory specified by '-%c' will be ignored.\n";
89 const char err_ropenfail[] = "SKIPPED: No such file or directory - %s\n";
90 const char err_wopenfail[] = "SKIPPED: Cannot create - %s\n";
91 const char err_outofmemory[] = "SKIPPED: Out of memory - %s\n";
92  /* -- */
93 const char err_readeof[] = "SKIPPED: Premature end of BMP file - %s\n";
94 const char err_readerr[] = "SKIPPED: Read operation failed - %s\n";
95 const char err_not_a_bmp[] = "SKIPPED: Not a BMP file - %s\n";
96 const char err_invalid_hed[] = "SKIPPED: Invalid header size in BMP file - %s\n";
97 const char err_width_zero[] = "SKIPPED: Invalid image width - %s\n";
98 const char err_height_zero[] = "SKIPPED: Invalid image height - %s\n";
99 const char err_compression[] = "SKIPPED: Unknown compression type - %s\n";
100 const char err_invalid_bpp[] = "SKIPPED: Invalid bit depth in BMP file - %s\n";
101 const char err_no_palette[] = "SKIPPED: Palette is missing - %s\n";
102 #endif /* ------------------- */
103 
104 static int transparent_color(png_color_16p, const char *);
105 static int png_filters(const char *);
106 static BOOL read_bmp(char *, IMAGE *);
107 static BOOL is_4th_alpha(IMAGE *);
108 static const char *read_rgb_bits(IMAGE *, FILE *);
109 static const char *read_bitfield_bits(IMAGE *, FILE *, DWORD *, UINT);
110 static const char *decompress_rle_bits(IMAGE *, FILE *);
111 static unsigned long mgetdwl(void *);
112 static unsigned int mgetwl(void *);
113 static BOOL write_png(char *, IMAGE *);
114 static void usage_exit(char *, int);
115 
116 
117 
118 /*
119 ** メイン
120 */
121 int main(int argc, char *argv[])
122 {
123  char outf[FILENAME_MAX];
124  IMAGE image;
125  int opt;
126  char *arg;
127  char *p, c;
128  int r_stdin, w_stdout;
129  int failure = 0, success = 0;
130 
131 #ifdef __LCC__ /* lcc-win32 */
132  char **envp;
133  void _GetMainArgs(int *, char ***, char ***, int);
134  _GetMainArgs(&argc, &argv, &envp, 1);
135 #endif
136 #ifdef __EMX__
137  _wildcard(&argc, &argv);
138 #endif
139  envargv(&argc, &argv, "B2P");
140 
141  r_stdin = !isatty(fileno(stdin));
142  w_stdout = !isatty(fileno(stdout));
143 
144  while (parsearg(&opt, &arg, argc, argv, "DdOoFfPp")) {
145  if (isdigit(opt)) { /* Zlib Compression Level (0-9) */
146  complevel = opt - '0';
147  continue;
148  }
149  switch (toupper(opt)) {
150  case 'I': interlace ^= 1; break;
151  case 'E': deletesrc ^= 1; break;
152  case 'T': copytime ^= 1; break;
153  case 'Q': quietmode ^= 1; break;
154  case 'L': errorlog ^= 1; break;
155 
156  case 'X':
157  r_stdin = 0;
158  w_stdout = 0;
159  break;
160 
161  case 'A':
162  alpha_bmp ^= 1;
163  break;
164 
165  case 'B':
166  alpha_bmp ^= 1;
167  break;
168 
169  case 'R':
170  /* '-R' option of png2bmp (ignored on bmp2png) */
171  break;
172 
173  case 'F': /* filter types to be used in libpng */
174  filters = png_filters(arg);
175  break;
176 
177  case 'P': /* transparent color */
179  break;
180 
181  case 'D': /* output directory */
182  if (*arg == '-') arg = NULL;
183  if (arg == NULL) {
184  outdir[0] = '\0';
185  } else {
186  strcpy(outdir, arg);
187  addslash(outdir);
188  if (makedir(outdir) != 0) {
190  outdir[0] = '\0';
191  }
192  }
193  break;
194 
195  case 'O': /* output filename */
196  if (arg == NULL) {
197  outnam[0] = '\0';
198  } else {
199  strcpy(outnam, arg);
200  p = basname(outnam);
201  c = *p; *p = '\0';
202  if (makedir(outnam) != 0) {
204  outnam[0] = '\0';
205  } else {
206  *p = c;
207  }
208  }
209  break;
210 
211  case 0x00: /* input file spec */
212  if (outnam[0] != '\0') {
213  strcpy(outf, outnam);
214  outnam[0] = '\0';
215  } else if (w_stdout) {
216  if (!read_bmp(arg, &image)) return 1;
217  if (!write_png(NULL, &image)) return 1;
218  if (deletesrc) remove(arg);
219  return 0;
220  } else {
221  if (outdir[0] != '\0') {
222  strcat(strcpy(outf, outdir), basname(arg));
223  } else {
224  strcpy(outf, arg);
225  }
226 #ifdef WIN32_LFN
227  strcpy(suffix(outf), is_dos_filename(outf) ? ".PNG" : ".png");
228 #else
229  strcpy(suffix(outf), ".png");
230 #endif
231  }
232  /* ---------------------- */
233  if (!read_bmp(arg, &image)) {
234  failure++;
235  break;
236  }
237  renbak(outf);
238  if (!write_png(outf, &image)) {
239  failure++;
240  break;
241  }
242  /* ---------------------- */
243  if (copytime) cpyftime(arg, outf);
244  if (deletesrc) remove(arg);
245  /* ---------------------- */
246  success++;
247  break;
248 
249  default:
250  ; /* Ignore unknown option */
251  }
252  }
253  if (failure == 0 && success == 0) {
254  if (!r_stdin) usage_exit(argv[0], 255);
255  if (!read_bmp(NULL, &image)) return 1;
256  if (outnam[0] != '\0') {
257  renbak(outnam);
258  return !write_png(outnam, &image);
259  } else if (w_stdout) {
260  return !write_png(NULL, &image);
261  } else {
262  strcat(strcpy(outf, outdir), "___stdin.png");
263  renbak(outf);
264  return !write_png(outf, &image);
265  }
266  }
267 
268  return (failure > 255) ? 255 : failure;
269 }
270 
271 
272 #define elemsof(a) (sizeof(a) / sizeof((a)[0]))
273 
274 /*
275 ** PNG のフィルタ種別指定を読む
276 */
277 static int png_filters(const char *arg)
278 {
279  static const struct { char name[8]; int flag; } filter[] = {
280  { "NONE", PNG_FILTER_NONE }, { "SUB" , PNG_FILTER_SUB },
281  { "UP" , PNG_FILTER_UP }, { "AVERAGE", PNG_FILTER_AVG },
282  { "AVG" , PNG_FILTER_AVG }, { "PAETH" , PNG_FILTER_PAETH },
283  { "ALL" , PNG_ALL_FILTERS },
284  { "AUTO", 0 }, { "DEFAULT", 0 }
285  };
286  char c, buf[64];
287  int i, flags = 0;
288 
289  if (arg == NULL) return 0; /* auto/default */
290 
291  do {
292  i = 0;
293  while (c = *(arg++), c != ',' && c != '\0')
294  if (i < sizeof(buf) - 1) buf[i++] = toupper(c);
295  buf[i] = '\0';
296 
297  for (i = 0; i < elemsof(filter); i++) {
298  if (strcmp(buf, filter[i].name) == 0) {
299  if (filter[i].flag == 0) flags = 0; /* auto/default */
300  else flags |= filter[i].flag;
301  }
302  }
303  } while (c != '\0');
304 
305  return flags;
306 }
307 
308 
309 /*
310 ** 透明色指定を読む
311 */
312 static int transparent_color(png_color_16p trans_values, const char *arg)
313 {
314  char c, buf[32];
315  int i, n;
316 
317  if (arg == NULL) return B2P_TRANSPARENT_NONE;
318 
319  for (i = 0; (c = arg[i]) != '\0' && i < sizeof(buf)-1; i++)
320  buf[i] = toupper(c);
321  buf[i] = '\0';
322 
323  if (strcmp(buf, "NONE") == 0) {
324  return B2P_TRANSPARENT_NONE;
325  }
326  if (buf[0] == '#') {
327  n = sscanf(buf, "#%2hx%2hx%2hx", &trans_values->red,
329  if (n == 3 && i >= 7) {
330  return B2P_TRANSPARENT_RGB;
331  }
332  } else {
333  n = sscanf(buf, "%hu,%hu,%hu", &trans_values->red,
335  if (n == 3 && trans_values->red <= 255 &&
336  trans_values->green <= 255 && trans_values->blue <= 255) {
337  return B2P_TRANSPARENT_RGB;
338  }
339  if (n == 1 && trans_values->red <= 255) {
342  }
343  }
344 
346 
347  return B2P_TRANSPARENT_NONE;
348 }
349 
350 
351 /* -----------------------------------------------------------------------
352 ** BMP ファイルの読み込み
353 */
354 
355 #define ERROR_ABORT(s) do { errmsg = (s); goto error_abort; } while (0)
356 
357 /*
358 ** .bmp ファイルの読み込み
359 */
360 static BOOL read_bmp(char *fn, IMAGE *img)
361 {
363  BYTE *const bih = bfh + FILEHED_SIZE;
364  BYTE rgbq[RGBQUAD_SIZE];
365  DWORD offbits, bihsize, skip;
366  DWORD compression, color_mask[4];
367  UINT palette_size, true_pixdepth;
368  BOOL alpha_check;
369  PALETTE *pal;
370  const char *errmsg;
371  FILE *fp;
372  int i;
373 
374  imgbuf_init(img);
375 
376  if (fn == NULL) { /* read from stdin */
377  fn = " (stdin)";
378  fp = binary_stdio(fileno(stdin));
379  } else {
380  fp = fopen(fn, "rb");
381  }
382  if (fp == NULL) ERROR_ABORT(err_ropenfail);
383 
384  set_status("Reading %.80s", basname(fn));
385 
386  /* ------------------------------------------------------ */
387 
388  for (i = 0; ; i++) { /* skip macbinary header */
389  if (fread(bfh, (FILEHED_SIZE + BIHSIZE_SIZE), 1, fp) != 1)
391  if (mgetwl(bfh + BFH_WTYPE) == BMP_SIGNATURE) break;
392  if (i != 0) ERROR_ABORT(err_not_a_bmp);
393  if (fread(bfh, (128 - FILEHED_SIZE - BIHSIZE_SIZE), 1, fp) != 1)
395  }
396  offbits = mgetdwl(bfh + BFH_DOFFBITS);
397  bihsize = mgetdwl(bfh + BFH_DBIHSIZE);
398  skip = offbits - bihsize - FILEHED_SIZE;
399  if (bihsize < COREHED_SIZE || bihsize > BMPV5HED_SIZE ||
400  offbits < (bihsize + FILEHED_SIZE)) ERROR_ABORT(err_invalid_hed);
401 
402  if (fread((bih + BIHSIZE_SIZE), (bihsize - BIHSIZE_SIZE), 1, fp) != 1)
404 
405  if (bihsize >= INFOHED_SIZE) { /* Windows-style BMP */
406  img->width = mgetdwl(bih + BIH_LWIDTH);
407  img->height = mgetdwl(bih + BIH_LHEIGHT);
408  img->pixdepth = mgetwl(bih + BIH_WBITCOUNT);
409  img->topdown = FALSE;
411  palette_size = RGBQUAD_SIZE;
412  if (img->height < 0) {
413  img->height = -img->height;
414  img->topdown = TRUE; /* top-down BMP */
415  }
416  } else { /* OS/2-style BMP */
417  img->width = mgetwl(bih + BCH_WWIDTH);
418  img->height = mgetwl(bih + BCH_WHEIGHT);
419  img->pixdepth = mgetwl(bih + BCH_WBITCOUNT);
420  img->topdown = FALSE;
422  palette_size = RGBTRIPLE_SIZE;
423  }
424  img->alpha = FALSE;
425  alpha_check = FALSE;
426  true_pixdepth = img->pixdepth;
427 
428  if (img->width <= 0) ERROR_ABORT(err_width_zero);
429  if (img->height <= 0) ERROR_ABORT(err_height_zero);
430 
431  switch (compression) {
432  case BI_RGB:
433  if (img->pixdepth != 1 && img->pixdepth != 4 &&
434  img->pixdepth != 8 && img->pixdepth != 16 &&
435  img->pixdepth != 24 && img->pixdepth != 32)
437 
438  if (img->pixdepth == 32 && alpha_bmp)
439  alpha_check = TRUE;
440 
441  if (img->pixdepth == 16) {
442  color_mask[3] = 0x0000; /* alpha */
443  color_mask[2] = 0x7C00; /* red */
444  color_mask[1] = 0x03E0; /* green */
445  color_mask[0] = 0x001F; /* blue */
447  }
448  break;
449 
450  case BI_BITFIELDS:
451  if (img->pixdepth != 16 && img->pixdepth != 32)
453 
454  if (bihsize < INFOHED_SIZE + 12) {
455  if (skip < (INFOHED_SIZE + 12 - bihsize))
457  if (fread((bih + bihsize), (INFOHED_SIZE + 12 - bihsize), 1, fp)
459  skip -= (INFOHED_SIZE + 12 - bihsize);
460  }
461  color_mask[3] = 0x00000000; /* alpha */
462  color_mask[2] = mgetdwl(bih + B4H_DREDMASK); /* red */
463  color_mask[1] = mgetdwl(bih + B4H_DGREENMASK); /* green */
464  color_mask[0] = mgetdwl(bih + B4H_DBLUEMASK); /* blue */
465 
466  if (img->pixdepth == 32 && alpha_bmp &&
467  bihsize >= INFOHED_SIZE + 16) {
468  color_mask[3] = mgetdwl(bih + B4H_DALPHAMASK); /* alpha */
469  if (color_mask[3] != 0x00000000)
470  img->alpha = TRUE;
471  }
472 
473  if (img->pixdepth == 32 && color_mask[0] == 0x000000FF &&
474  color_mask[1] == 0x0000FF00 && color_mask[2] == 0x00FF0000 &&
475  (color_mask[3] == 0xFF000000 || color_mask[3] == 0x00000000)) {
477  }
478  break;
479 
480  case BI_RLE8:
481  if (img->pixdepth != 8)
483  break;
484 
485  case BI_RLE4:
486  if (img->pixdepth != 4)
488  break;
489 
490  default:
492  }
493 
494  if (img->pixdepth == 16) img->pixdepth = 24;
495 
496  if (img->pixdepth <= 8) {
497  if (skip >= palette_size << img->pixdepth) {
498  img->palnum = 1 << img->pixdepth;
499  skip -= palette_size << img->pixdepth;
500  } else {
501  img->palnum = skip / palette_size;
502  skip = skip % palette_size;
503  }
504  if (img->palnum == 0)
506  } else {
507  img->palnum = 0;
508  }
510 
511  /* ------------------------------------------------------ */
512 
513  for (pal = img->palette, i = img->palnum; i > 0; pal++, i--) {
514  if (fread(rgbq, palette_size, 1, fp) != 1)
516  pal->red = rgbq[RGBQ_RED];
517  pal->green = rgbq[RGBQ_GREEN];
518  pal->blue = rgbq[RGBQ_BLUE];
519  }
520  for ( ; skip > 0; skip--) {
521  if (fgetc(fp) == EOF)
523  }
524 
525  /* ------------------------------------------------------ */
526 
527  img->sigbit.red = img->sigbit.green = img->sigbit.blue = 8;
528  img->sigbit.gray = img->sigbit.alpha = 8;
529 
530  switch (compression) {
531  case BI_RGB:
532  errmsg = read_rgb_bits(img, fp);
533  break;
534  case BI_BITFIELDS:
535  errmsg = read_bitfield_bits(img, fp, color_mask, true_pixdepth);
536  break;
537  case BI_RLE8:
538  case BI_RLE4:
539  errmsg = decompress_rle_bits(img, fp);
540  break;
541  default:
543  }
544  if (errmsg != NULL) ERROR_ABORT(errmsg);
545 
546  if (alpha_check) {
547  img->alpha = is_4th_alpha(img);
548  if (!img->alpha)
550  }
551 
552  /* ------------------------------------------------------ */
553 
554  set_status("Read OK %.80s", basname(fn));
555 
556  if (fp != stdin) fclose(fp);
557 
558  return TRUE;
559 
560 error_abort: /* error */
561  xxprintf(errmsg, fn);
562  if (fp != stdin && fp != NULL) fclose(fp);
563  imgbuf_free(img);
564 
565  return FALSE;
566 }
567 
568 
569 /*
570 ** 第4のチャネルがアルファチャネルかどうか調べる
571 */
572 static BOOL is_4th_alpha(IMAGE *img)
573 {
574  LONG w, h;
575  BYTE *p;
576 
577  if (img->pixdepth == 32) { /* failsafe */
578  for (h = img->height, p = img->bmpbits + 3; --h >= 0; )
579  for (w = img->width; --w >= 0; p += 4)
580  if (*p != 0) return TRUE;
581  }
582 
583  return FALSE;
584 }
585 
586 
587 /*
588 ** BI_RGB (無圧縮) 形式の画像データを読む
589 */
590 static const char *read_rgb_bits(IMAGE *img, FILE *fp)
591 {
592 #if 1
593  DWORD rd = 16*1024*1024;
594  DWORD num = img->imgbytes;
595  BYTE *ptr = img->bmpbits;
596 
597  while (num > 0) {
598  if (rd > num) rd = num;
599 
600  if (fread(ptr, rd, 1, fp) != 1)
601  return ferror(fp) ? err_readerr : err_readeof;
602 
603  ptr += rd; num -= rd;
604  }
605 #else
606  if (fread(img->bmpbits, img->imgbytes, 1, fp) != 1)
607  return ferror(fp) ? err_readerr : err_readeof;
608 #endif
609  return NULL;
610 }
611 
612 
613 /*
614 ** BI_BITFIELDS 形式の画像データを読む
615 */
616 static const char *read_bitfield_bits(IMAGE *img, FILE *fp, DWORD *color_mask,
617  UINT true_pixdepth)
618 {
619  int color_shift[4];
620  int color_sigbits[4];
621  BYTE color_tbl[4][1<<7];
622  DWORD true_rowbytes;
623  BYTE *row, *p, *q;
624  LONG w, h;
625  DWORD v, u;
626  int i, j, k;
627 
628  for (i = 0; i < 4; i++) {
629  v = color_mask[i];
630  if (v == 0) {
631  color_shift[i] = 0;
632  color_sigbits[i] = 8;
633  } else {
634  for (j = 0; (v & 1) == 0; v >>= 1, j++) ;
635  for (k = 0; (v) != 0; v >>= 1, k++) ;
636  color_shift[i] = j;
637  color_sigbits[i] = k;
638  }
639  if (color_sigbits[i] <= 7) {
640  k = (1 << color_sigbits[i]) - 1;
641  for (j = 0; j <= k; j++)
642  color_tbl[i][j] = (0xFF * j + k/2) / k;
643  }
644  }
645 
646  if (color_sigbits[3] < 8) img->sigbit.alpha = color_sigbits[3];
647  if (color_sigbits[2] < 8) img->sigbit.red = color_sigbits[2];
648  if (color_sigbits[1] < 8) img->sigbit.green = color_sigbits[1];
649  if (color_sigbits[0] < 8) img->sigbit.blue = color_sigbits[0];
650 
651  true_rowbytes = ((DWORD)img->width * (true_pixdepth/8) + 3) & (~3UL);
652 
653  for (h = img->height, row = img->bmpbits; --h >= 0;
654  row += img->rowbytes) {
655  if (fread(row, true_rowbytes, 1, fp) != 1)
656  return ferror(fp) ? err_readerr : err_readeof;
657 
658  switch (true_pixdepth) {
659  case 16:
660  for (w = img->width, p = row + (w-1)*2, q = row + (w-1)*3;
661  --w >= 0; p -= 2, q -= 3) {
662  v = ((UINT)p[0]) + ((UINT)p[1] << 8);
663  for (i = 0; i < 3; i++) {
664  u = (v & color_mask[i]) >> color_shift[i];
665  if (color_sigbits[i] <= 7)
666  u = color_tbl[i][u];
667  else if (color_sigbits[i] >= 9)
668  u >>= (color_sigbits[i] - 8);
669  q[i] = (BYTE) u;
670  }
671  }
672  break;
673 
674  case 32:
675  for (w = img->width, p = row; --w >= 0; p += 4) {
676  v = ((DWORD)p[0] ) + ((DWORD)p[1] << 8) +
677  ((DWORD)p[2] << 16) + ((DWORD)p[3] << 24);
678  for (i = 0; i < 4; i++) {
679  u = (v & color_mask[i]) >> color_shift[i];
680  if (color_sigbits[i] <= 7)
681  u = color_tbl[i][u];
682  else if (color_sigbits[i] >= 9)
683  u >>= (color_sigbits[i] - 8);
684  p[i] = (BYTE) u;
685  }
686  }
687  break;
688  }
689  }
690 
691  return NULL;
692 }
693 
694 
695 /*
696 ** BI_RLE8/BI_RLE4 形式の画像データを読む
697 */
698 static const char *decompress_rle_bits(IMAGE *img, FILE *fp)
699 {
700  BYTE buf[1024]; /* 258 or above */
701  BYTE *bfptr = buf;
702  UINT bfcnt = 0;
703  UINT rd, reclen;
704  BYTE *row = img->bmpbits;
705  LONG x = 0, y = 0;
706  BYTE *p, c;
707  int n;
708 
709  memset(img->bmpbits, 0, img->imgbytes);
710 
711  for (;;) {
712  while (bfcnt < (reclen = 2) ||
713  (bfptr[0] == 0 &&
714  ((bfptr[1] == 2 && bfcnt < (reclen += 2)) ||
715  (bfptr[1] >= 3 &&
716  bfcnt < (reclen += (bfptr[1] * img->pixdepth + 15) / 16 * 2)
717  )))) {
718  if (bfptr != buf && bfcnt != 0) memmove(buf, bfptr, bfcnt);
719  if ((rd = fread(buf+bfcnt, 1, sizeof(buf)-bfcnt, fp)) == 0) {
720  if (x >= img->width) { /*x = 0;*/ y += 1; }
721  if (y >= img->height) return NULL; /* missing EoB marker */
722  else return ferror(fp) ? err_readerr : err_readeof;
723  }
724  bfptr = buf;
725  bfcnt += rd;
726  }
727  if (y >= img->height) {
728  /* We simply discard the remaining records */
729  if (bfptr[0] == 0 && bfptr[1] == 1) break; /* EoB marker */
730  bfptr += reclen;
731  bfcnt -= reclen;
732  continue;
733  }
734  if (bfptr[0] != 0) { /* Encoded-mode record */
735  n = bfptr[0]; c = bfptr[1];
736  switch (img->pixdepth) {
737  case 8: /* BI_RLE8 */
738  while (n > 0 && x < img->width) {
739  row[x] = c;
740  n--; x++;
741  }
742  break;
743  case 4: /* BI_RLE4 */
744  if (x % 2 != 0 && x < img->width) {
745  c = (c >> 4) | (c << 4);
746  row[x/2] = (row[x/2] & 0xF0) | (c & 0x0F);
747  n--; x++;
748  }
749  while (n > 0 && x < img->width) {
750  row[x/2] = c;
751  n-=2; x+=2;
752  }
753  if (n < 0) x--;
754  break;
755  }
756  } else if (bfptr[1] >= 3) { /* Absolute-mode record */
757  n = bfptr[1]; p = bfptr + 2;
758  switch (img->pixdepth) {
759  case 8: /* BI_RLE8 */
760  while (n > 0 && x < img->width) {
761  row[x] = *p;
762  n--; x++; p++;
763  }
764  break;
765  case 4: /* BI_RLE4 */
766  if (x % 2 != 0) {
767  if (x < img->width) {
768  row[x/2] = (row[x/2] & 0xF0) | (*p >> 4);
769  n--; x++;
770  }
771  while (n > 0 && x < img->width) {
772  row[x/2] = (p[0] << 4) | (p[1] >> 4);
773  n-=2; x+=2; p++;
774  }
775  if (n < 0) x--;
776  } else {
777  while (n > 0 && x < img->width) {
778  row[x/2] = *p;
779  n-=2; x+=2; p++;
780  }
781  if (n < 0) x--;
782  }
783  break;
784  }
785  } else if (bfptr[1] == 2) { /* Delta record */
786  x += bfptr[2]; y += bfptr[3];
787  row += bfptr[3] * img->rowbytes;
788  } else if (bfptr[1] == 0) { /* End of line marker */
789  x = 0; y += 1;
790  row += img->rowbytes;
791  } else /*if (bfptr[1] == 1)*/ { /* End of bitmap marker */
792  break;
793  }
794  bfptr += reclen;
795  bfcnt -= reclen;
796  }
797 
798  return NULL;
799 }
800 
801 
802 /*
803 ** メモリから little-endien 形式 4バイト無符号整数を読む
804 */
805 static unsigned long mgetdwl(void *ptr)
806 {
807  unsigned char *p = ptr;
808 
809  return ((unsigned long)p[0] ) + ((unsigned long)p[1] << 8) +
810  ((unsigned long)p[2] << 16) + ((unsigned long)p[3] << 24);
811 }
812 
813 
814 /*
815 ** メモリから little-endien 形式 2バイト無符号整数を読む
816 */
817 static unsigned int mgetwl(void *ptr)
818 {
819  unsigned char *p = ptr;
820 
821  return ((unsigned int)p[0]) + ((unsigned int)p[1] << 8);
822 }
823 
824 
825 /* -----------------------------------------------------------------------
826 ** PNG ファイルの書き込み
827 */
828 
829 /*
830 ** .png ファイルの書き込み
831 */
832 static BOOL write_png(char *fn, IMAGE *img)
833 {
835  png_infop info_ptr;
836  int bit_depth;
837  int color_type;
838  int interlace_type;
839  png_byte trans[256];
840  unsigned i;
841  const char *errmsg;
842  FILE *fp;
843 
844  if (fn == NULL) {
845  fn = " (stdout)";
847  } else {
848  fp = fopen(fn, "wb");
849  }
850  if (fp == NULL) ERROR_ABORT(err_wopenfail);
851 
852  set_status("Writing %.80s", basname(fn));
853 
854  /* ------------------------------------------------------ */
855 
858  if (png_ptr == NULL) {
860  }
861  info_ptr = png_create_info_struct(png_ptr);
862  if (info_ptr == NULL) {
865  }
866  if (setjmp(png_jmpbuf(png_ptr))) {
867  /* If we get here, we had a problem reading the file */
868  png_destroy_write_struct(&png_ptr, &info_ptr);
869  ERROR_ABORT(NULL);
870  }
873  if (filters != 0)
875 
876  /* ------------------------------------------------------ */
877 
878  if (img->pixdepth == 24 || img->pixdepth == 32) {
879  bit_depth = 8;
880  color_type = (img->pixdepth == 32 && img->alpha) ?
883  } else {
884  bit_depth = img->pixdepth;
885  color_type = PNG_COLOR_TYPE_PALETTE;
886  png_set_PLTE(png_ptr, info_ptr, img->palette, img->palnum);
887  }
888  interlace_type = (interlace) ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
889 
890  png_set_IHDR(png_ptr, info_ptr, img->width, img->height, bit_depth,
891  color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT,
893 
894  if (img->sigbit.red != 8 || img->sigbit.green != 8 || img->sigbit.blue != 8
895  || (color_type == PNG_COLOR_TYPE_RGB_ALPHA && img->sigbit.alpha != 8))
896  png_set_sBIT(png_ptr, info_ptr, &img->sigbit);
897 
898  switch (trans_type) {
899  case B2P_TRANSPARENT_RGB:
900  switch (color_type) {
902  for (i = 0; i < img->palnum; i++) {
903  if (img->palette[i].red == trans_values.red &&
904  img->palette[i].green == trans_values.green &&
905  img->palette[i].blue == trans_values.blue) {
906  trans[i++] = 0x00;
907  break;
908  }
909  trans[i] = 0xFF;
910  }
911  if (trans[i-1] == 0x00) {
912  png_set_tRNS(png_ptr, info_ptr, trans, i, NULL);
913  } else {
915  }
916  break;
917  case PNG_COLOR_TYPE_RGB:
918  png_set_tRNS(png_ptr, info_ptr, NULL, 0, &trans_values);
919  break;
922  break;
923  }
924  break;
926  switch (color_type) {
928  if (trans_values.index < img->palnum) {
929  for (i = 0; i < trans_values.index; i++) trans[i] = 0xFF;
930  trans[i++] = 0x00;
931  png_set_tRNS(png_ptr, info_ptr, trans, i, NULL);
932  } else {
934  }
935  break;
936  case PNG_COLOR_TYPE_RGB:
938  break;
941  break;
942  }
943  break;
944  }
945 
946  png_write_info(png_ptr, info_ptr);
947 
948  /* ------------------------------------------------------ */
949 
950  if (img->pixdepth == 32 && !img->alpha)
952 
953  if (img->pixdepth == 24 || img->pixdepth == 32)
955 
956  /* ------------------------------------------------------ */
957 
960 
962 
963  png_write_end(png_ptr, info_ptr);
964  png_destroy_write_struct(&png_ptr, &info_ptr);
965 
966  /* ------------------------------------------------------ */
967 
968  set_status("OK %.80s", basname(fn));
969  feed_line();
970 
971  fflush(fp);
972  if (fp != stdout) fclose(fp);
973  imgbuf_free(img);
974 
975  return TRUE;
976 
977 error_abort: /* error */
978  if (errmsg != NULL) xxprintf(errmsg, fn);
979  if (fp != stdout && fp != NULL) fclose(fp);
980  imgbuf_free(img);
981 
982  return FALSE;
983 }
984 
985 
986 /* -----------------------------------------------------------------------
987 ** ヘルプスクリーンの表示
988 */
989 
990 /*
991 ** 使用法表示
992 */
993 static void usage_exit(char *argv0, int status)
994 {
995  static const char str_usage[] =
996 #ifdef JAPANESE /* -------------------------- */
997 #ifdef SJIS_ESCAPE
998 #define SJ_ESC(esc,raw) esc
999 #else
1000 #define SJ_ESC(esc,raw) raw
1001 #endif
1002  "bmp2png, BMP -> PNG コンバータ - version " BMP2PNG_VERSION "\n"
1003  " " BMP2PNG_COPYRIGHT "\n"
1004  " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
1005  "\n"
1006  "使い方 : %s [-スイッチ] 入力ファイル名 ...\n"
1007  " : ... | %s [-スイッチ] | ...\n"
1008  "\n"
1009  "入力ファイル名にはワイルドカードが使えます (* と ?)\n"
1010  "出力ファイル名は入力ファイル名の拡張子を .png に変えた名前になります\n"
1011  "\n"
1012  "スイッチオプション (小文字でも可) :\n"
1013  " -0..-9 圧縮レベル (デフォルトは -6)\n"
1014  " -I インターレース形式の PNG ファイルを作成する\n"
1015  " -P color 指定した色を透明色にする\n"
1016  " color: #RRGGBB(html式16進) / RR,GG,BB(10進RGB) / NN(パレット番号)\n"
1017  " -F type[,...] PNG の圧縮に使われるフィルタ・タイプを指定する\n"
1018  " type: none,sub,up,average(avg),paeth,all,auto(default)\n"
1019  " -A, -B アルファチャネルを保存する\n"
1020  " -O name 出力ファイル名を指定する\n"
1021  " -D dir ファイルを出力するディレクトリを指定する\n"
1022  " -E 変換が成功した場合には入力ファイルを削除する\n"
1023  " -T 入力ファイルのタイムスタンプを出力ファイルに設定する\n"
1024  " -Q 処理中, 一切の" SJ_ESC("表\示","表示") "をしない\n"
1025  " -L 処理中のエラーをログファイル(%s)に記録する\n"
1026  " -X 標準入力/標準出力を介した変換を無効にする\n";
1027 #else /* ----------------------------------- */
1028  "bmp2png, a BMP-to-PNG converter - version " BMP2PNG_VERSION "\n"
1029  " " BMP2PNG_COPYRIGHT "\n"
1030  " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
1031  "\n"
1032  "Usage: %s [-switches] inputfile(s) ...\n"
1033  " or: ... | %s [-switches] | ...\n"
1034  "\n"
1035  "List of input files may use wildcards (* and ?)\n"
1036  "Output filename is same as input filename, but extension .png\n"
1037  "\n"
1038  "Switches (case-insensitive) :\n"
1039  " -0..-9 Compression level (default: -6)\n"
1040  " -I Create interlaced PNG files\n"
1041  " -P color Mark the specified color as transparent\n"
1042  " color: #RRGGBB(html hex) / RR,GG,BB(decimal) / NN(palette index)\n"
1043  " -F type[,...] Specify filter type(s) used to create PNG files\n"
1044  " type: none,sub,up,average(avg),paeth,all,auto(default)\n"
1045  " -A, -B Preserve alpha channel\n"
1046  " -O name Specify name for output file\n"
1047  " -D dir Output files into dir\n"
1048  " -E Delete input files after successful conversion\n"
1049  " -T Set the timestamp of input file on output file\n"
1050  " -Q Quiet mode\n"
1051  " -L Log errors to %s file\n"
1052  " -X Disable conversion through standard input/output\n";
1053 #endif /* ----------------------------------- */
1054 #if defined(WIN32) || defined(MSDOS)
1055  char exename[FILENAME_MAX];
1056  char *p;
1057 
1058  argv0 = strcpy(exename, basname(argv0));
1059  for (p = argv0; *p != '\0'; p++) *p = tolower(*p);
1060 #endif
1061  fprintf(stdout, str_usage, argv0, argv0, errlogfile);
1062 
1063  exit(status);
1064 }
1065 
1066 #if 0
1067 #if (PNG_LIBPNG_VER >= 10007)
1068 /*
1069 ** dummy - see png_reset_zstream() in png.c
1070 */
1072 {
1073  return Z_OK;
1074 }
1075 #endif
1076 #endif
q
Definition: afm2pl.c:2287
#define width(a)
Definition: aptex-macros.h:198
#define name
#define BYTE
Definition: bioradtopgm.c:19
int filters
Definition: bmp2png.c:22
char wrn_notranscolor[]
Definition: bmp2png.c:74
int main(int argc, char *argv[])
Definition: bmp2png.c:121
char wrn_invalidtrans[]
Definition: bmp2png.c:72
static int png_filters(char *)
Definition: bmp2png.c:277
int interlace
Definition: bmp2png.c:21
char wrn_imagehasalpha[]
Definition: bmp2png.c:80
static unsigned int mgetwl(void *)
Definition: bmp2png.c:817
static char * read_rgb_bits(IMAGE *, FILE *)
Definition: bmp2png.c:590
static int transparent_color(png_color_16p, char *)
Definition: bmp2png.c:312
char err_readerr[]
Definition: bmp2png.c:94
static unsigned long mgetdwl(void *)
Definition: bmp2png.c:805
int alpha_bmp
Definition: bmp2png.c:23
char outdir[FILENAME_MAX]
Definition: bmp2png.c:17
char wrn_transtruecolor[]
Definition: bmp2png.c:77
static BOOL is_4th_alpha(IMAGE *)
Definition: bmp2png.c:572
char err_outofmemory[]
Definition: bmp2png.c:91
char err_width_zero[]
Definition: bmp2png.c:97
char err_wopenfail[]
Definition: bmp2png.c:90
#define elemsof(a)
Definition: bmp2png.c:272
char err_compression[]
Definition: bmp2png.c:99
char err_not_a_bmp[]
Definition: bmp2png.c:95
char err_invalid_bpp[]
Definition: bmp2png.c:100
#define BMP2PNG_VERSION
Definition: bmp2png.c:13
char err_ropenfail[]
Definition: bmp2png.c:89
char err_no_palette[]
Definition: bmp2png.c:101
#define B2P_TRANSPARENT_PALETTE
Definition: bmp2png.c:27
char wrn_alphaallzero[]
Definition: bmp2png.c:83
char err_invalid_hed[]
Definition: bmp2png.c:96
#define BMP2PNG_COPYRIGHT
Definition: bmp2png.c:14
static char * decompress_rle_bits(IMAGE *, FILE *)
Definition: bmp2png.c:698
char outnam[FILENAME_MAX]
Definition: bmp2png.c:16
static BOOL read_bmp(char *, IMAGE *)
Definition: bmp2png.c:360
int complevel
Definition: bmp2png.c:20
static char * read_bitfield_bits(IMAGE *, FILE *, DWORD *, UINT)
Definition: bmp2png.c:616
char err_readeof[]
Definition: bmp2png.c:93
int trans_type
Definition: bmp2png.c:29
char errlogfile[]
Definition: bmp2png.c:35
int deletesrc
Definition: bmp2png.c:18
static BOOL write_png(char *, IMAGE *)
Definition: bmp2png.c:832
#define B2P_TRANSPARENT_RGB
Definition: bmp2png.c:26
#define B2P_TRANSPARENT_NONE
Definition: bmp2png.c:25
static void usage_exit(char *, int)
Definition: bmp2png.c:993
png_color_16 trans_values
Definition: bmp2png.c:30
#define ERROR_ABORT(s)
Definition: bmp2png.c:355
char err_height_zero[]
Definition: bmp2png.c:98
int copytime
Definition: bmp2png.c:19
char wrn_mkdirfail[]
Definition: bmp2png.c:86
#define BI_RLE4
Definition: bmphed.h:78
#define BI_BITFIELDS
Definition: bmphed.h:79
#define BIH_WBITCOUNT
Definition: bmphed.h:29
#define RGBQUAD_SIZE
Definition: bmphed.h:66
#define RGBQ_RED
Definition: bmphed.h:64
#define BFH_DOFFBITS
Definition: bmphed.h:19
#define BFH_WTYPE
Definition: bmphed.h:15
#define BI_RGB
Definition: bmphed.h:76
#define B4H_DBLUEMASK
Definition: bmphed.h:38
#define FILEHED_SIZE
Definition: bmphed.h:21
#define BMPV5HED_SIZE
Definition: bmphed.h:51
#define BMP_SIGNATURE
Definition: bmphed.h:11
#define BIH_LWIDTH
Definition: bmphed.h:26
#define BIHSIZE_SIZE
Definition: bmphed.h:22
#define BFH_DBIHSIZE
Definition: bmphed.h:20
#define RGBQ_BLUE
Definition: bmphed.h:62
#define BIH_LHEIGHT
Definition: bmphed.h:27
#define BCH_WBITCOUNT
Definition: bmphed.h:58
#define B4H_DREDMASK
Definition: bmphed.h:36
#define BCH_WWIDTH
Definition: bmphed.h:55
#define BCH_WHEIGHT
Definition: bmphed.h:56
#define RGBQ_GREEN
Definition: bmphed.h:63
#define BIH_DCOMPRESSION
Definition: bmphed.h:30
#define B4H_DGREENMASK
Definition: bmphed.h:37
#define RGBTRIPLE_SIZE
Definition: bmphed.h:72
#define BI_RLE8
Definition: bmphed.h:77
#define INFOHED_SIZE
Definition: bmphed.h:49
#define B4H_DALPHAMASK
Definition: bmphed.h:39
#define n
Definition: t4ht.c:1290
BOOL
Definition: dd.h:100
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
int z
Definition: dviconv.c:26
int w
Definition: dviconv.c:26
int v
Definition: dviconv.c:10
int h
Definition: dviconv.c:9
#define fopen
Definition: xxstdio.h:21
#define fread
Definition: xxstdio.h:25
#define fflush
Definition: xxstdio.h:24
#define fgetc
Definition: xxstdio.h:26
#define skip(p, c)
Definition: ptexmac.h:70
int strcmp()
Definition: coll.cpp:143
int sscanf()
char * strcpy()
FILE * outf
Definition: dvibook.c:99
int compression
long int flag
Definition: f2c.h:53
#define c(n)
Definition: gpos-common.c:150
#define memmove(d, s, n)
Definition: gsftopk.c:65
pinfo pal
Definition: in_pcx.cpp:145
unsigned char * image
Definition: in_pcx.cpp:323
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific f u
Definition: afcover.h:88
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
#define MAX_MEM_LEVEL
Definition: ftzconf.h:114
static int inflateReset(z_streamp z)
Definition: inflate.c:54
#define ZLIB_VERSION
Definition: zlib.h:40
#define Z_OK
Definition: zlib.h:132
void exit()
#define EOF
Definition: afmparse.c:59
kerning y
Definition: ttdriver.c:212
static const char argv0[]
Definition: webpng.c:25
void png_init_io(png_structrp png_ptr, png_FILE_p fp)
Definition: png.c:703
png_infop png_create_info_struct(png_const_structrp png_ptr)
Definition: png.c:354
#define PNG_FILTER_SUB
Definition: png.h:1466
void() png_set_filter(png_structrp png_ptr, int method, int filters)
Definition: pngwrite.c:1000
#define PNG_FILTER_PAETH
Definition: png.h:1469
#define PNG_COLOR_TYPE_RGB
Definition: png.h:670
#define PNG_FILTER_NONE
Definition: png.h:1465
#define PNG_COMPRESSION_TYPE_DEFAULT
Definition: png.h:679
#define PNG_FILTER_AVG
Definition: png.h:1468
void() png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
Definition: pngwrite.c:979
void() png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
Definition: pngset.c:994
void() png_write_end(png_structrp png_ptr, png_inforp info_ptr)
Definition: pngwrite.c:358
png_structp() png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)
Definition: pngwrite.c:499
#define png_jmpbuf(png_ptr)
Definition: png.h:952
void() png_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn)
Definition: pngwrite.c:1317
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:671
void() png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
Definition: pngwrite.c:192
void() png_set_compression_level(png_structrp png_ptr, int level)
Definition: pngwrite.c:1158
void() png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_method, int compression_method, int filter_method)
Definition: pngset.c:254
#define PNG_ALL_FILTERS
Definition: png.h:1471
void() png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette)
Definition: pngset.c:572
#define PNG_FILTER_TYPE_BASE
Definition: png.h:682
#define PNG_FILLER_AFTER
Definition: png.h:1249
void() png_set_compression_mem_level(png_structrp png_ptr, int mem_level)
Definition: pngwrite.c:1169
#define PNG_INTERLACE_ADAM7
Definition: png.h:688
void() png_set_bgr(png_structrp png_ptr)
Definition: pngtrans.c:21
#define PNG_FILTER_UP
Definition: png.h:1467
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:669
#define PNG_LIBPNG_VER_STRING
Definition: png.h:281
#define PNG_FILTER_TYPE_DEFAULT
Definition: png.h:684
#define PNG_INTERLACE_NONE
Definition: png.h:687
void() png_set_filler(png_structrp png_ptr, png_uint_32 filler, int flags)
Definition: pngtrans.c:120
void() png_write_image(png_structrp png_ptr, png_bytepp image)
Definition: pngwrite.c:601
void() png_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, png_const_color_8p sig_bit)
Definition: pngset.c:638
unsigned char png_byte
Definition: pngconf.h:481
int num
Definition: disdvi.c:621
#define buf
unsigned char BYTE
Definition: sfnt.h:34
#define fclose
Definition: debug.h:100
#define fileno
Definition: win32lib.h:72
#define isatty
Definition: win32lib.h:80
#define fprintf
Definition: mendex.h:64
#define png_ptr(N)
Definition: image.h:99
int remove()
void xxprintf(char *fmt,...)
Definition: common.c:103
void feed_line(void)
Definition: common.c:135
char * addslash(char *path)
Definition: common.c:649
void row_callback(png_structp png_ptr, png_uint_32 row, int pass)
Definition: common.c:234
int renbak(char *path)
Definition: common.c:544
void imgbuf_free(IMAGE *img)
Definition: common.c:330
BOOL imgbuf_alloc(IMAGE *img)
Definition: common.c:283
char * basname(char *path)
Definition: common.c:633
char ** envargv(int *argcp, char ***argvp, char *envn)
Definition: common.c:404
void set_status(char *fmt,...)
Definition: common.c:122
void init_progress_meter(png_structp png_ptr, png_uint_32 width, png_uint_32 height)
Definition: common.c:211
int errorlog
Definition: common.c:44
void imgbuf_init(IMAGE *img)
Definition: common.c:341
int makedir(char *path)
Definition: common.c:516
void png_my_warning(png_structp png_ptr, png_const_charp message)
Definition: common.c:269
void png_my_error(png_structp png_ptr, png_const_charp message)
Definition: common.c:258
int quietmode
Definition: common.c:43
FILE * binary_stdio(int fd)
Definition: common.c:590
int parsearg(int *opt, char **arg, int argc, char **argv, char *aopts)
Definition: common.c:358
int cpyftime(char *srcf, char *dstf)
Definition: common.c:573
long LONG
Definition: common.h:146
unsigned int UINT
Definition: common.h:145
#define isdigit(c)
Definition: snprintf.c:177
unsigned int DWORD
Definition: mktexlib.h:49
float x
Definition: cordic.py:15
string fn
Definition: fc-lang.py:335
int k
Definition: otp-parser.c:70
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
#define fp
const char * suffix
Definition: pkg_icu.cpp:27
subroutine errmsg(lineq, iccount, ibarno, msgq)
Definition: pmx294.for:7804
static int filter
Definition: pnmtopng.c:113
type_C toupper(type_C)
bstring c int memset(void *s, int c, int length)
static int row
Definition: ps2pk.c:587
#define status
#define flags
#define tolower(ch)
Definition: utype.h:137
#define flag
Definition: round_prec.c:45
Definition: sd.h:76
png_uint_16 red
Definition: png.h:491
png_byte index
Definition: png.h:490
png_uint_16 green
Definition: png.h:492
png_uint_16 blue
Definition: png.h:493
png_byte green
Definition: png.h:503
png_byte gray
Definition: png.h:505
png_byte blue
Definition: png.h:504
png_byte red
Definition: png.h:502
png_byte alpha
Definition: png.h:506
png_byte blue
Definition: png.h:482
png_byte red
Definition: png.h:480
png_byte green
Definition: png.h:481
PALETTE * palette
Definition: common.h:161
BYTE ** rowptr
Definition: common.h:162
png_color_8 sigbit
Definition: common.h:165
BYTE * bmpbits
Definition: common.h:163
UINT palnum
Definition: common.h:155
UINT pixdepth
Definition: common.h:154
DWORD rowbytes
Definition: common.h:159
BOOL alpha
Definition: common.h:157
LONG height
Definition: common.h:153
BOOL topdown
Definition: common.h:156
LONG width
Definition: common.h:152
DWORD imgbytes
Definition: common.h:160
#define FILE
Definition: t1stdio.h:34
#define ferror(f)
Definition: t1stdio.h:110
int j
Definition: t4ht.c:1589
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
static zic_t trans[50]
Definition: zic.c:412