26 if(items.size() == 2) {
27 x = atoi(items[0].c_str());
28 y = atoi(items[1].c_str());
39 if(items.size() == 4) {
40 x = atoi(items[0].c_str());
41 y = atoi(items[1].c_str());
42 w = atoi(items[2].c_str());
43 h = atoi(items[3].c_str());
68 Uint32* dest_beg = dest_lock.
pixels();
69 Uint32* src_beg = src_lock.
pixels();
70 Uint32* mask_beg = mask_lock.
pixels();
72 size_t small_shift_before;
73 size_t small_shift_after;
75 size_t src_width = src->w;
76 size_t src_height = src->h;
79 small_shift_before = -
x;
80 if (src_width < small_shift_before)
82 src_width -= small_shift_before;
85 small_shift_before = 0;
88 if(x + src_width <=
unsigned(dest->w)) {
89 small_shift_after = 0;
91 small_shift_after = src_width - (dest->w -
x);
92 src_width = dest->w -
x;
96 dest_beg += dest->w * y +
x;
98 src_beg += (-
y) * src->w;
99 mask_beg += (-y) * mask->w;
101 if (src_height < static_cast<size_t>(-y))
107 if(y + src_height >
unsigned(dest->h)) {
108 src_height = dest->h -
y;
111 dest_shift = dest->w - src_width;
113 for(
size_t j = 0; j < src_height; ++j) {
114 src_beg += small_shift_before;
115 mask_beg += small_shift_before;
117 for(
size_t i = 0;
i < src_width; ++
i) {
119 if((*mask_beg & 0x00ffffff) != 0x00ffffff) {
120 *dest_beg = *src_beg;
127 src_beg += small_shift_after;
128 mask_beg += small_shift_after;
129 dest_beg += dest_shift;
144 Uint32* beg = lock.
pixels();
145 Uint32*
end = beg + surf->w*surf->h;
150 if((*beg & 0xff000000) != 0 && (*beg != color))
177 png_struct* png_ptr = png_create_write_struct
178 (PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
182 png_info* info_ptr = png_create_info_struct(png_ptr);
184 png_destroy_write_struct(&png_ptr,
nullptr);
189 png_init_io(png_ptr, file);
192 png_set_compression_level(png_ptr,
196 png_set_IHDR(png_ptr, info_ptr, surf->w, surf->h,
197 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
198 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
201 png_byte **row_pointers =
new png_byte *[surf->h];
209 Uint32 *surf_data = lock.
pixels();
211 for(
int y = 0;
y < surf->h; ++
y) {
212 row_pointers[
y] =
reinterpret_cast<png_byte*
>(rgba_data +
pos);
213 for(
int x = 0;
x < surf->w; ++
x) {
215 SDL_GetRGBA(*surf_data, surf->format, &red, &green, &blue, &alpha);
216 rgba_data[
pos].r = red;
224 png_set_rows(png_ptr, info_ptr, row_pointers);
227 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY,
nullptr);
230 png_write_end(png_ptr, info_ptr);
231 png_destroy_write_struct(&png_ptr, &info_ptr);
232 delete [] row_pointers;
GLint GLint GLint GLint GLint GLint y
const std::vector< std::string > items
GLdouble GLdouble GLdouble b
This class has identical behavior to scoped_ptr, except it manages heap-allocated arrays instead of h...
std::string get_exploder_dir()
void masked_overwrite_surface(surface dest, surface src, surface mask, int x, int y)
GLubyte GLubyte GLubyte GLubyte w
GLboolean GLboolean GLboolean GLboolean a
A class template, scoped_resource, designed to implement the Resource Acquisition Is Initialization (...
GLclampf GLclampf GLclampf alpha
void save_image(surface surf, const std::string &filename)
Helper class for pinning SDL surfaces into memory.
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
GLdouble GLdouble GLdouble r
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::string get_mask_dir()
GLsizei const GLcharARB ** string
bool image_empty(surface surf)