1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
diff -ur ps2eps-1.68.orig/src/C/bbox.c ps2eps-1.68/src/C/bbox.c
--- ps2eps-1.68.orig/src/C/bbox.c 2010-08-31 10:58:37.000000000 +0200
+++ ps2eps-1.68/src/C/bbox.c 2010-12-15 13:39:27.000000000 +0100
@@ -4,25 +4,25 @@
/** Author: Roland Bless <roland -at- bless.de> **/
/** Copyright (C) 1998-2009 Roland Bless **/
/** To compile simply use: **/
-/** "cc bbox.c -o bbox" or "make bbox" **/
+/** "cc bbox.c -o bbox" or "make bbox" **/
/********************************************************************/
/*
* $Id: bbox.c,v 1.18 2009-10-13 15:03:49 bless Exp $
*/
/**
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**/
@@ -69,12 +69,14 @@
1
};
-unsigned int minus_one(const unsigned x)
+static
+unsigned int minus_one(const unsigned x)
{
return (x == 0) ? x : x-1;
}
-unsigned int plus_one(const unsigned x)
+static
+unsigned int plus_one(const unsigned x)
{
return (x == (unsigned int) ~0U) ? x : x+1;
}
@@ -95,8 +97,9 @@
* and printed to stdout *
************************************************************************/
/* calculate the bounding box in postscript points, given a resolution in dpi */
-void readppm_and_calcbb(const char *name,
- const unsigned int resolution,
+static
+void readppm_and_calcbb(const char *name,
+ const unsigned int resolution,
const unsigned char tight)
{
FILE *inputfile;
@@ -109,29 +112,29 @@
double hllx, hlly, hurx, hury; /* hires bounding box */
unsigned char *image_row, /* ImageRow */
*tmpcolumnbytep;
- unsigned int width,height; /* Image Size */
+ unsigned int width,height; /* Image Size */
unsigned int byte_width;
unsigned char stepsize;
unsigned char colormax= 0; /* max color value */
unsigned int ui_colormax= 0; /* max color value */
-
- if ( name == NULL )
+
+ if ( name == NULL )
{
inputfile = stdin;
name = "- STDIN -";
}
- else
+ else
{
inputfile = fopen(name,"r");
if ( inputfile == NULL )
{
- fprintf(stderr,"%s: ERROR -- could not open file %s\n",
+ fprintf(stderr,"%s: ERROR -- could not open file %s\n",
prgname, name);
return;
}
}
/** check for magic number **/
- do
+ do
{
fgets(inputline, 1024, inputfile);
#ifdef DEBUG
@@ -150,7 +153,7 @@
}
}
while ( !feof(inputfile) && !magic_found );
-
+
if ( !magic_found )
{
fprintf(stderr,"%s: ERROR -- %s is not in ppmraw or pbmraw format\n",
@@ -158,7 +161,7 @@
return;
}
/** skip comments **/
- do
+ do
{
fgets(inputline, 1024, inputfile);
#ifdef DEBUG
@@ -175,15 +178,16 @@
if ( magic_found == 6 ) /* PPM file has maximum color-component value */
{
fgets(inputline, 1024, inputfile);
- sscanf(inputline,"%u",&ui_colormax);
+ sscanf(inputline,"%u",&ui_colormax);
colormax = (unsigned char) ui_colormax; /* this is safer */
}
#ifdef DEBUG
fprintf(stderr,"\nreading picture: %s size X: %u Y: %u\n",name,width,height);
#endif
+ x = 0; /* avoid uninitialized warning */
x_min= width>0 ? width-1 : 0;
- x_max= 0;
- y_min= height>0 ? height-1 : 0;
+ x_max= 0;
+ y_min= height>0 ? height-1 : 0;
y_max= 0;
if ( magic_found == 4 ) /* PBMRAW = Bitmap */
{ /** read raw pbmfile **/
@@ -192,12 +196,12 @@
byte_width++;
}
else /** assume ppm raw **/
- {
+ {
byte_width= width * 3; /* we have RGB, i.e. three bytes for each pixel */
}
- /*
+ /*
* Now read a raster of Width * Height pixels, proceeding through the image in normal English reading order,
- * i.e., starting from top left then moving right
+ * i.e., starting from top left then moving right
*/
/* we allocate only one line */
image_row= malloc(byte_width);
@@ -258,8 +262,8 @@
{ /* there was a pixel with no background color */
tmpcolumnbytep= image_row+byte_width-1;
/* inspect this line from the right */
- for (byte_x= byte_width-1;
- byte_x >= 0;
+ for (byte_x= byte_width-1;
+ byte_x >= 0;
byte_x--,tmpcolumnbytep--)
{
if ( *tmpcolumnbytep != colormax ) /* there are pixels not white */
@@ -292,7 +296,7 @@
y_min,y_max,x_min,x_max);
#endif
break;
- } /* if there are pixels not white */
+ } /* if there are pixels not white */
} /* end for byte_x */
} /* if line contained not only background color */
} /* end for y */
@@ -303,7 +307,7 @@
hllx= (x_min*pt_dpi_dbl)/resolution;
/* distance from the bottom edge to the bottommost point */
hlly= ((minus_one(height)-y_max)*pt_dpi_dbl)/resolution;
- /* distance from the left edge to the righmost point */
+ /* distance from the left edge to the righmost point */
hurx= (plus_one(x_max)*pt_dpi_dbl)/resolution;
/* distance from the bottom edge to the uppermost point */
hury= ((height-y_min)*pt_dpi_dbl)/resolution;
@@ -315,7 +319,7 @@
llx= minus_one((unsigned int) ((unsigned long) x_min*72UL)/resolution);
/* distance from the bottom edge to the bottommost point */
lly= minus_one((unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution);
- /* distance from the left edge to the righmost point */
+ /* distance from the left edge to the righmost point */
urx= plus_one((unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution);
/* distance from the bottom edge to the uppermost point */
ury= plus_one((unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution);
@@ -335,7 +339,7 @@
llx= (unsigned int) ((unsigned long) x_min*72UL)/resolution;
/* distance from the bottom edge to the bottommost point */
lly= (unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution;
- /* distance from the left edge to the righmost point */
+ /* distance from the left edge to the righmost point */
urx= (unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution;
/* round up if we got a remainder */
if ( (((unsigned long) plus_one(x_max)*72UL) % resolution) != 0 )
@@ -357,15 +361,15 @@
}
else
fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n",prgname);
-
+
fclose(inputfile);
free(image_row);
}
-int
+int
main(int argc, char **argv)
-{
+{
int i;
char *filename= NULL;
unsigned int resolution= 72; /* use 72 dpi as default resolution */
|