summaryrefslogtreecommitdiff
blob: 8b62653cc0f497e4ee48574ffbc8fce346df157f (plain)
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
This patch is from netbsd pkgsrc

ftp://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/x11/fbdesk/patches

--- a/src/FbTk/ImagePNG.cc
+++ b/src/FbTk/ImagePNG.cc
@@ -76,6 +76,8 @@ ImagePNG::~ImagePNG() {
 }
 
 PixmapWithMask *ImagePNG::load(const std::string &filename, int screen_num) const {
+    int pixel_depth;
+    int rowbytes;
     if (filename.empty())
         return 0;
 #ifdef DEBUG
@@ -102,7 +104,7 @@ PixmapWithMask *ImagePNG::load(const std
         return 0;
     }
 
-    if (setjmp(png.png()->jmpbuf)) {
+    if (setjmp(png_jmpbuf(png.png()))) {
         fclose(fp);
         return 0;
     }
@@ -115,12 +117,14 @@ PixmapWithMask *ImagePNG::load(const std
     png_get_IHDR(png.png(), png.info(), &w, &h,
                  &bit_depth, &color_type,
                  &interlace_type, 0, 0);
+    pixel_depth = bit_depth * png_get_channels(png.png(), png.info());
+    rowbytes = png_get_rowbytes(png.png(), png.info());
 #ifdef DEBUG    
-    cerr<<png.info()->width<<", "<<png.info()->height<<endl;
-    cerr<<"bit_depth = "<<(int)png.info()->bit_depth<<endl;
-    cerr<<"bytes per pixel = "<<((int)png.info()->bit_depth>>3)<<endl;
-    cerr<<"pixel depth = "<<(int)png.info()->pixel_depth<<endl;
-    cerr<<"rowbytes = "<<png.info()->rowbytes<<endl;
+    cerr<<png_get_image_width(png.png(), png.info())<<", "<<png_get_image_height(png.png(), png.info())<<endl;
+    cerr<<"bit_depth = "<<(int)png_get_bit_depth(png.png(),png.info())<<endl;
+    cerr<<"bytes per pixel = "<<((int)png_get_bit_depth(png.png(), png.info())>>3)<<endl;
+    cerr<<"pixel depth = "<<pixel_depth<<endl;
+    cerr<<"rowbytes = "<<rowbytes<<endl;
     cerr<<"Color type = ";
     switch (color_type) {
     case PNG_COLOR_TYPE_GRAY:
@@ -146,7 +150,7 @@ PixmapWithMask *ImagePNG::load(const std
     // convert to rgb
     if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) {
         png_set_expand(png.png());
-        png.info()->pixel_depth = 8;
+        pixel_depth = 8;
     }
     // convert to rgb
     if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
@@ -158,7 +162,7 @@ PixmapWithMask *ImagePNG::load(const std
     if (color_type == PNG_COLOR_TYPE_GRAY ||
         color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
         png_set_gray_to_rgb(png.png());
-        png.info()->pixel_depth = 8;
+        pixel_depth = 8;
         color_type = PNG_COLOR_TYPE_RGB;
     }
 
@@ -170,23 +174,23 @@ PixmapWithMask *ImagePNG::load(const std
     // expand to 4 bytes
     if (bit_depth == 8 && color_type == PNG_COLOR_TYPE_RGB) {
         png_set_filler(png.png(), 0, PNG_FILLER_AFTER);
-        png.info()->rowbytes = png.info()->width * 4;
-        png.info()->pixel_depth = 32;
+        rowbytes = png_get_image_width(png.png(), png.info()) * 4;
+        pixel_depth = 32;
     }
     
-    if (png.info()->pixel_depth == 4 ||
-        png.info()->pixel_depth == 8)
+    if (pixel_depth == 4 ||
+        pixel_depth == 8)
         return 0;
 
     // create memory to hold rows
-    png_bytep *row_pointers = new (nothrow) png_bytep[png.info()->height];
+    png_bytep *row_pointers = new (nothrow) png_bytep[png_get_image_height(png.png(), png.info())];
     if (row_pointers == 0) {
         fclose(fp);
         return 0;
     }
 
-    for (unsigned int row = 0; row < png.info()->height; ++row) {
-        row_pointers[row] = new png_byte[png.info()->rowbytes];
+    for (unsigned int row = 0; row < png_get_image_height(png.png(), png.info()); ++row) {
+        row_pointers[row] = new png_byte[rowbytes];
     }
 
     // get transparent pixel
@@ -214,31 +218,31 @@ PixmapWithMask *ImagePNG::load(const std
     fclose(fp);
 
     // clear linear memory
-    char *data = new char[png.info()->rowbytes * png.info()->height];
-    for (int offset=0, y = 0; y < png.info()->height; y++) {
-        for (int x = 0; x < png.info()->rowbytes; x++, offset++) {
+    char *data = new char[rowbytes * png_get_image_height(png.png(), png.info())];
+    for (int offset=0, y = 0; y < png_get_image_height(png.png(), png.info()); y++) {
+        for (int x = 0; x < rowbytes; x++, offset++) {
             data[offset] = row_pointers[y][x];
         }
     }
 
-    FbTk::Surface *srf = new (nothrow) FbTk::Surface(png.info()->width, png.info()->height,
-                                                     png.info()->pixel_depth);
+    FbTk::Surface *srf = new (nothrow) FbTk::Surface(png_get_image_width(png.png(), png.info()), png_get_image_height(png.png(), png.info()),
+                                                     pixel_depth);
 
     if (srf == 0)
         return 0;
 
 
     // finaly copy data to surface
-    switch (png.info()->pixel_depth) {
+    switch (pixel_depth) {
     case 16:
         convert16to32(data, *srf);
         break;
     case 24:
     case 32:
-        memcpy(srf->data(), data, png.info()->height * png.info()->rowbytes);
+        memcpy(srf->data(), data, png_get_image_height(png.png(), png.info()) * rowbytes);
         break;
     default:
-        cerr<<"ImagePNG: Can't convert from "<<(int)png.info()->pixel_depth<<" to 32bpp."<<endl;
+        cerr<<"ImagePNG: Can't convert from "<<pixel_depth<<" to 32bpp."<<endl;
         break;
     }
     
@@ -264,9 +268,9 @@ PixmapWithMask *ImagePNG::load(const std
         long i = 0x44332211;
         unsigned char* a = (unsigned char*) &i;
         bool big_endian = (*a != 0x11);
-        int alphacolor = ((png.info()->channels != 4) ? 0xFF000000 : 0);
+        int alphacolor = ((png_get_channels(png.png(), png.info()) != 4) ? 0xFF000000 : 0);
         if (big_endian) {
-            int shift = ((png.info()->channels == 4) ? 0 : 8);
+            int shift = ((png_get_channels(png.png(), png.info()) == 4) ? 0 : 8);
             alphacolor = (0xFF >> shift);    
         }
         screen_surf.setColorKey(alphacolor, true);