]>
git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/SplashBitmap.cxx
1 //========================================================================
5 //========================================================================
10 #pragma implementation
15 #include "SplashErrorCodes.h"
16 #include "SplashBitmap.h"
18 //------------------------------------------------------------------------
20 //------------------------------------------------------------------------
22 SplashBitmap::SplashBitmap(int widthA
, int heightA
, int rowPad
,
23 SplashColorMode modeA
, GBool topDown
) {
29 rowSize
= (width
+ 7) >> 3;
34 case splashModeAMono8
:
49 case splashModeACMYK8
:
54 rowSize
+= rowPad
- 1;
55 rowSize
-= rowSize
% rowPad
;
56 data
= (SplashColorPtr
)gmalloc(rowSize
* height
);
58 data
+= (height
- 1) * rowSize
;
64 SplashBitmap::~SplashBitmap() {
66 gfree(data
+ (height
- 1) * rowSize
);
72 SplashError
SplashBitmap::writePNMFile(char *fileName
) {
74 SplashColorPtr row
, p
;
77 if (!(f
= fopen(fileName
, "wb"))) {
78 return splashErrOpenFile
;
84 fprintf(f
, "P4\n%d %d\n", width
, height
);
86 for (y
= 0; y
< height
; ++y
) {
88 for (x
= 0; x
< width
; x
+= 8) {
97 fprintf(f
, "P5\n%d %d\n255\n", width
, height
);
99 for (y
= 0; y
< height
; ++y
) {
101 for (x
= 0; x
< width
; ++x
) {
109 case splashModeAMono8
:
110 fprintf(f
, "P5\n%d %d\n255\n", width
, height
);
112 for (y
= 0; y
< height
; ++y
) {
114 for (x
= 0; x
< width
; ++x
) {
115 fputc(splashAMono8M(p
), f
);
123 fprintf(f
, "P6\n%d %d\n255\n", width
, height
);
125 for (y
= 0; y
< height
; ++y
) {
127 for (x
= 0; x
< width
; ++x
) {
128 fputc(splashRGB8R(p
), f
);
129 fputc(splashRGB8G(p
), f
);
130 fputc(splashRGB8B(p
), f
);
138 fprintf(f
, "P6\n%d %d\n255\n", width
, height
);
140 for (y
= 0; y
< height
; ++y
) {
142 for (x
= 0; x
< width
; ++x
) {
143 fputc(splashBGR8R(p
), f
);
144 fputc(splashBGR8G(p
), f
);
145 fputc(splashBGR8B(p
), f
);
152 case splashModeARGB8
:
153 fprintf(f
, "P6\n%d %d\n255\n", width
, height
);
155 for (y
= 0; y
< height
; ++y
) {
157 for (x
= 0; x
< width
; ++x
) {
158 fputc(splashARGB8R(p
), f
);
159 fputc(splashARGB8G(p
), f
);
160 fputc(splashARGB8B(p
), f
);
167 case splashModeBGRA8
:
168 fprintf(f
, "P6\n%d %d\n255\n", width
, height
);
170 for (y
= 0; y
< height
; ++y
) {
172 for (x
= 0; x
< width
; ++x
) {
173 fputc(splashBGRA8R(p
), f
);
174 fputc(splashBGRA8G(p
), f
);
175 fputc(splashBGRA8B(p
), f
);
183 case splashModeCMYK8
:
184 case splashModeACMYK8
:
185 // PNM doesn't support CMYK
194 void SplashBitmap::getPixel(int x
, int y
, SplashColorPtr pixel
) {
197 if (y
< 0 || y
>= height
|| x
< 0 || x
>= width
) {
201 case splashModeMono1
:
202 p
= &data
[y
* rowSize
+ (x
>> 3)];
203 pixel
[0] = (p
[0] >> (7 - (x
& 7))) & 1;
205 case splashModeMono8
:
206 p
= &data
[y
* rowSize
+ x
];
209 case splashModeAMono8
:
210 p
= &data
[y
* rowSize
+ 2 * x
];
216 p
= &data
[y
* rowSize
+ 3 * x
];
221 case splashModeARGB8
:
222 case splashModeBGRA8
:
224 case splashModeCMYK8
:
226 p
= &data
[y
* rowSize
+ 4 * x
];
233 case splashModeACMYK8
:
234 p
= &data
[y
* rowSize
+ 5 * x
];