22
22
#include < algorithm>
23
23
#include < iostream>
24
24
25
- #include < boost/scope_exit.hpp>
26
- #include < png.h>
27
-
28
25
#include " system.h"
29
26
#include " utils.h"
30
27
#include " cache.h"
@@ -88,15 +85,6 @@ Color Bitmap::GetPixel(int x, int y) const {
88
85
return Color (r, g, b, a);
89
86
}
90
87
91
- static void write_data (png_structp out_ptr, png_bytep data, png_size_t len) {
92
- reinterpret_cast <std::ostream*>(png_get_io_ptr (out_ptr))->write (
93
- reinterpret_cast <char const *>(data), len);
94
- }
95
- static void flush_stream (png_structp out_ptr) {
96
- reinterpret_cast <std::ostream*>(png_get_io_ptr (out_ptr))->flush ();
97
- }
98
-
99
-
100
88
bool Bitmap::WritePNG (std::ostream& os) const {
101
89
size_t const width = GetWidth (), height = GetHeight ();
102
90
size_t const stride = width * 4 ;
@@ -109,50 +97,7 @@ bool Bitmap::WritePNG(std::ostream& os) const {
109
97
pixman_image_composite32 (PIXMAN_OP_SRC, bitmap, NULL , dst.get (),
110
98
0 , 0 , 0 , 0 , 0 , 0 , width, height);
111
99
112
- for (size_t i = 0 ; i < width * height; ++i) {
113
- uint32_t const p = data[i];
114
- uint8_t * out = reinterpret_cast <uint8_t *>(&data[i]);
115
- uint8_t
116
- a = (p >> 24 ) & 0xff , r = (p >> 16 ) & 0xff ,
117
- g = (p >> 8 ) & 0xff , b = (p >> 0 ) & 0xff ;
118
- if (a != 0 ) {
119
- r = (r * 255 ) / a;
120
- g = (g * 255 ) / a;
121
- b = (b * 255 ) / a;
122
- }
123
- *out++ = r; *out++ = g; *out++ = b; *out++ = a;
124
- }
125
-
126
- std::vector<png_bytep> ptrs (height);
127
- for (size_t i = 0 ; i < ptrs.size (); ++i) {
128
- ptrs[i] = reinterpret_cast <png_bytep>(&data[width*i]);
129
- }
130
-
131
- png_structp write = NULL ;
132
- if (!(write = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL , NULL , NULL ))) {
133
- Output::Warning (" Bitmap::WritePNG: error in png_create_write" );
134
- return false ;
135
- }
136
-
137
- png_infop info = NULL ;
138
- BOOST_SCOPE_EXIT ((&write )(&info)) {
139
- png_destroy_write_struct (&write , &info);
140
- } BOOST_SCOPE_EXIT_END do {} while (0 );
141
- if (!(info = png_create_info_struct (write ))) {
142
- Output::Warning (" Bitmap::WritePNG: error in png_create_info_struct" );
143
- return false ;
144
- }
145
-
146
- png_set_write_fn (write , &os, &write_data, &flush_stream);
147
-
148
- png_set_IHDR (write , info, width, height, 8 ,
149
- PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
150
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
151
- png_write_info (write , info);
152
- png_write_image (write , &ptrs.front ());
153
- png_write_end (write , NULL );
154
-
155
- return true ;
100
+ return ImagePNG::WritePNG (os, width, height, &data.front ());
156
101
}
157
102
158
103
void Bitmap::AttachBitmapScreen (BitmapScreen* bitmap) {
@@ -234,7 +179,7 @@ Bitmap::TileOpacity Bitmap::GetTileOpacity(int row, int col) {
234
179
return opacity? (*opacity)[row][col] : Partial;
235
180
}
236
181
237
- uint8_t Bitmap::bytes () const {
182
+ int Bitmap::bytes () const {
238
183
return format.bytes ;
239
184
}
240
185
@@ -717,7 +662,7 @@ void const* Bitmap::pixels() const {
717
662
return (void const *) pixman_image_get_data (bitmap);
718
663
}
719
664
720
- uint8_t Bitmap::bpp () const {
665
+ int Bitmap::bpp () const {
721
666
return (pixman_image_get_depth (bitmap) + 7 ) / 8 ;
722
667
}
723
668
@@ -729,7 +674,7 @@ int Bitmap::height() const {
729
674
return pixman_image_get_height (bitmap);
730
675
}
731
676
732
- uint16_t Bitmap::pitch () const {
677
+ int Bitmap::pitch () const {
733
678
return pixman_image_get_stride (bitmap);
734
679
}
735
680
0 commit comments