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 splashModeBGR8Packed:
43 rowSize = (width * 3 + 3) & ~3;
44 data.bgr8 = (SplashBGR8P *)
45 gmalloc(rowSize * height * sizeof(SplashMono1P));
50 SplashBitmap::~SplashBitmap() {
61 case splashModeBGR8Packed:
67 SplashError SplashBitmap::writePNMFile(char *fileName) {
72 SplashBGR8P *bgr8line, *bgr8;
75 if (!(f = fopen(fileName, "wb"))) {
76 return splashErrOpenFile;
82 fprintf(f, "P4\n%d %d\n", width, height);
84 for (y = 0; y < height; ++y) {
85 for (x = 0; x < width; x += 8) {
86 fputc(*mono1 ^ 0xff, f);
93 fprintf(f, "P5\n%d %d\n255\n", width, height);
95 for (y = 0; y < height; ++y) {
96 for (x = 0; x < width; ++x) {
104 fprintf(f, "P6\n%d %d\n255\n", width, height);
106 for (y = 0; y < height; ++y) {
107 for (x = 0; x < width; ++x) {
108 fputc(splashRGB8R(*rgb8), f);
109 fputc(splashRGB8G(*rgb8), f);
110 fputc(splashRGB8B(*rgb8), f);
116 case splashModeBGR8Packed:
117 fprintf(f, "P6\n%d %d\n255\n", width, height);
118 bgr8line = data.bgr8;
119 for (y = 0; y < height; ++y) {
121 for (x = 0; x < width; ++x) {