1 //========================================================================
5 //========================================================================
10 #pragma implementation
15 #include "SplashErrorCodes.h"
16 #include "SplashBitmap.h"
18 //------------------------------------------------------------------------
20 //------------------------------------------------------------------------
22 SplashBitmap::SplashBitmap(int widthA, int heightA, SplashColorMode modeA) {
28 rowSize = (width + 7) >> 3;
29 data.mono1 = (SplashMono1P *)
30 gmalloc(rowSize * height * sizeof(SplashMono1P));
34 data.mono8 = (SplashMono8 *)
35 gmalloc(width * height * sizeof(SplashMono8));
39 data.rgb8 = (SplashRGB8 *)
40 gmalloc(width * height * sizeof(SplashRGB8));
42 case splashModeRGB8Packed:
43 rowSize = (width * 3 + 3) & ~3;
44 data.rgb8p = (SplashRGB8P *)
45 gmalloc(rowSize * height * sizeof(SplashRGB8P));
47 case splashModeBGR8Packed:
48 rowSize = (width * 3 + 3) & ~3;
49 data.bgr8 = (SplashBGR8P *)
50 gmalloc(rowSize * height * sizeof(SplashMono1P));
55 SplashBitmap::~SplashBitmap() {
66 case splashModeRGB8Packed:
69 case splashModeBGR8Packed:
74 SplashError SplashBitmap::writePNMFile(char *fileName) {
79 SplashRGB8P *rgb8pline, *rgb8p;
80 SplashBGR8P *bgr8line, *bgr8;
83 if (!(f = fopen(fileName, "wb"))) {
84 return splashErrOpenFile;
90 fprintf(f, "P4\n%d %d\n", width, height);
92 for (y = 0; y < height; ++y) {
93 for (x = 0; x < width; x += 8) {
94 fputc(*mono1 ^ 0xff, f);
100 case splashModeMono8:
101 fprintf(f, "P5\n%d %d\n255\n", width, height);
103 for (y = 0; y < height; ++y) {
104 for (x = 0; x < width; ++x) {
112 fprintf(f, "P6\n%d %d\n255\n", width, height);
114 for (y = 0; y < height; ++y) {
115 for (x = 0; x < width; ++x) {
116 fputc(splashRGB8R(*rgb8), f);
117 fputc(splashRGB8G(*rgb8), f);
118 fputc(splashRGB8B(*rgb8), f);
124 case splashModeRGB8Packed:
125 fprintf(f, "P6\n%d %d\n255\n", width, height);
126 rgb8pline = data.rgb8p;
127 for (y = 0; y < height; ++y) {
129 for (x = 0; x < width; ++x) {
135 rgb8pline += rowSize;
139 case splashModeBGR8Packed:
140 fprintf(f, "P6\n%d %d\n255\n", width, height);
141 bgr8line = data.bgr8;
142 for (y = 0; y < height; ++y) {
144 for (x = 0; x < width; ++x) {