Debian Codegraph @

sources/to_jpg.c

raw symbols SCIP
1 /*
2 Copyright (c) 2002 Martin Kroeker All rights reserved.
3
4 Distributed by Free Software Foundation, Inc.
5
6 This file is part of HP2xx.
7
8 HP2xx is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
10 to anyone for the consequences of using it or for whether it serves any
11 particular purpose or works at all, unless he says so in writing. Refer
12 to the GNU General Public License, Version 2 or later, for full details.
13
14 Everyone is granted permission to copy, modify and redistribute
15 HP2xx, but only under the conditions described in the GNU General Public
16 License. A copy of this license is supposed to have been
17 given to you along with HP2xx so you can know your rights and
18 responsibilities. It should be in a file named COPYING. Among other
19 things, the copyright notice and this notice must be preserved on all
20 copies.
21 --------------------------------------------------------------------
22
23 to_jpg.c - JPEG image converter part of hp2xx
24
25 2002/04/07 MK derived from to_tif.c based on libjpeg's example.c and
26 libjpeg.doc
27 *******************************************************************/
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include "bresnham.h"cxx . . $ `<file>/sources/bresnham.h`/
34 #include "pendef.h"cxx . . $ `<file>/sources/pendef.h`/
35 #include "hp2xx.h"cxx . . $ `<file>/sources/hp2xx.h`/
36 #include "jpeglib.h"
37
38 int PicBuf_to_JPGcxx . . $ PicBuf_to_JPG(e953c4e74cdc6780).(const GEN_PARcxx . . $ GEN_PAR# * pg, const OUT_PARcxx . . $ OUT_PAR# * po)
39 {
40 FILEcxx . . $ FILE# *w = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
41 RowBufcxx . . $ RowBuf# *row = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
42 int i, x, y, W, H, D, B, S;
43 JSAMPROWcxx . . $ JSAMPROW# row_pointer[1];
44 unsigned char *jpgbuf;
45 struct jpeg_compress_structcxx . . $ jpeg_compress_struct# cinfo;
46 struct jpeg_error_mgrcxx . . $ jpeg_error_mgr# jerr;
47
48 if (!pg->quietcxx . . $ $anonymous_type_61b3a55f7c267384_7#quiet.)
49 Eprintfcxx . . $ Eprintf(326aeb464d16410c).("\nWriting JPEG output\n");
50
51 W = po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->nrcxx . . $ $anonymous_type_61b3a55f7c267384_1#nr.;
52 H = po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->nccxx . . $ $anonymous_type_61b3a55f7c267384_1#nc.;
53 D = po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->depthcxx . . $ $anonymous_type_61b3a55f7c267384_1#depth.;
54 B = po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->nbcxx . . $ $anonymous_type_61b3a55f7c267384_1#nb.;
55
56
57 cinfo.errcxx . . $ jpeg_compress_struct#err. = jpeg_std_errorcxx . . $ jpeg_std_error(273a809c33617b39).(&jerr);
58 jpeg_create_compresscxx . . $ `<external>/1675768649605662117/jpeglib.h:968:9`!(&cinfo);
59 cinfo.image_widthcxx . . $ jpeg_compress_struct#image_width. = (JDIMENSIONcxx . . $ JDIMENSION#) H; /* image width and height, in pixels */
60 cinfo.image_heightcxx . . $ jpeg_compress_struct#image_height. = (JDIMENSIONcxx . . $ JDIMENSION#) W;
61 if (D == 1) {
62 cinfo.input_componentscxx . . $ jpeg_compress_struct#input_components. = 1;
63 cinfo.in_color_spacecxx . . $ jpeg_compress_struct#in_color_space. = JCS_GRAYSCALEcxx . . $ JCS_GRAYSCALE.;
64 } else {
65 cinfo.input_componentscxx . . $ jpeg_compress_struct#input_components. = 3; /* # of color components per pixel */
66 cinfo.in_color_spacecxx . . $ jpeg_compress_struct#in_color_space. = JCS_RGBcxx . . $ JCS_RGB.; /* colorspace of input image */
67 }
68 jpeg_set_defaultscxx . . $ jpeg_set_defaults(267d19bad4c1dcad).(&cinfo);
69
70 if (*po->outfilecxx . . $ $anonymous_type_61b3a55f7c267384_6#outfile. != '-') {
71 if ((w = fopencxx . . $ fopen(82ec0787cd37e0a3).(po->outfilecxx . . $ $anonymous_type_61b3a55f7c267384_6#outfile., "wb")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
72 PErrorcxx . . $ PError(85c52e162fed56f9).("hp2xx -- opening output file");
73 return ERRORcxx . . $ `sources/hp2xx.h:134:9`!;
74 }
75 jpeg_stdio_destcxx . . $ jpeg_stdio_dest(b7256bc87bd3260c).(&cinfo, w);
76 } else {
77 jpeg_stdio_destcxx . . $ jpeg_stdio_dest(b7256bc87bd3260c).(&cinfo, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
78 }
79
80 S = 3 * po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->nccxx . . $ $anonymous_type_61b3a55f7c267384_1#nc.;
81 if (D == 1)
82 S = po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.->nccxx . . $ $anonymous_type_61b3a55f7c267384_1#nc.;
83 if ((jpgbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(S * sizeof(unsigned char))) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
84 Eprintfcxx . . $ Eprintf(326aeb464d16410c).("malloc error!\n");
85 if (*po->outfilecxx . . $ $anonymous_type_61b3a55f7c267384_6#outfile. != '-')
86 fclosecxx . . $ fclose(89bc1efcdac0ca22).(w);
87 return 1;
88 }
89
90 jpeg_start_compresscxx . . $ jpeg_start_compress(e9a8a3aa27c15c90).(&cinfo, TRUEcxx . . $ `sources/hp2xx.h:117:9`!);
91
92
93 for (y = 0; y < W; ++y) {
94 if ((row = get_RowBufcxx . . $ get_RowBuf(c666a2728dabe176).(po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf., (W - 1) - y)) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
95 break;
96 memsetcxx . . $ memset(d1de1e4fb215f1c6).(jpgbuf, 0, (size_t) S);
97 i = 0;
98 for (x = 0; x < H; ++x) {
99 Bytecxx . . $ Byte# C =
100 (Bytecxx . . $ Byte#) index_from_RowBufcxx . . $ index_from_RowBuf(89b4a89edc67cdf8).(row, x, po->picbufcxx . . $ $anonymous_type_61b3a55f7c267384_6#picbuf.);
101 if (D == 1) {
102 switch (C) {
103 case xxBackgroundcxx . . $ `sources/pendef.h:33:9`!:
104 jpgbuf[i++] = 255;
105 break;
106 default:
107 jpgbuf[i++] = 0;
108 break;
109 }
110 } else {
111 jpgbuf[i++] = ptcxx . . $ pt..clutcxx . . $ $anonymous_type_7c055c5caba4536d_0#clut.[C][0];
112 jpgbuf[i++] = ptcxx . . $ pt..clutcxx . . $ $anonymous_type_7c055c5caba4536d_0#clut.[C][1];
113 jpgbuf[i++] = ptcxx . . $ pt..clutcxx . . $ $anonymous_type_7c055c5caba4536d_0#clut.[C][2];
114 }
115 }
116 row_pointer[0] = &jpgbuf[0];
117 (void) jpeg_write_scanlinescxx . . $ jpeg_write_scanlines(eed4da272f4daa84).(&cinfo, row_pointer, 1);
118 }
119
120 freecxx . . $ free(5d22bdacc48458e8).(jpgbuf);
121 jpeg_finish_compresscxx . . $ jpeg_finish_compress(267d19bad4c1dcad).(&cinfo);
122 jpeg_destroy_compresscxx . . $ jpeg_destroy_compress(267d19bad4c1dcad).(&cinfo);
123 if (*po->outfilecxx . . $ $anonymous_type_61b3a55f7c267384_6#outfile. != '-')
124 fclosecxx . . $ fclose(89bc1efcdac0ca22).(w);
125
126 return 0;
127 }