| 164 | } |
| 165 | |
| 166 | void rotsprite_image(Image* bmp, const Image* spr, const Image* mask, |
| 167 | int x1, int y1, int x2, int y2, |
| 168 | int x3, int y3, int x4, int y4) |
| 169 | { |
| 170 | static ImageBufferPtr buf[3]; // TODO non-thread safe |
| 171 | |
| 172 | for (int i=0; i<3; ++i) |
| 173 | if (!buf[i]) |
| 174 | buf[i].reset(new ImageBuffer(1)); |
| 175 | |
| 176 | int xmin = MIN(x1, MIN(x2, MIN(x3, x4))); |
| 177 | int xmax = MAX(x1, MAX(x2, MAX(x3, x4))); |
| 178 | int ymin = MIN(y1, MIN(y2, MIN(y3, y4))); |
| 179 | int ymax = MAX(y1, MAX(y2, MAX(y3, y4))); |
| 180 | int rot_width = xmax - xmin; |
| 181 | int rot_height = ymax - ymin; |
| 182 | |
| 183 | if (rot_width == 0 || rot_height == 0) |
| 184 | return; |
| 185 | |
| 186 | int scale = 8; |
| 187 | std::unique_ptr<Image> bmp_copy(Image::create(bmp->pixelFormat(), rot_width*scale, rot_height*scale, buf[0])); |
| 188 | std::unique_ptr<Image> tmp_copy(Image::create(spr->pixelFormat(), spr->width()*scale, spr->height()*scale, buf[1])); |
| 189 | std::unique_ptr<Image> spr_copy(Image::create(spr->pixelFormat(), spr->width()*scale, spr->height()*scale, buf[2])); |
| 190 | std::unique_ptr<Image> msk_copy; |
| 191 | |
| 192 | color_t maskColor = spr->maskColor(); |
| 193 | |
| 194 | bmp_copy->setMaskColor(maskColor); |
| 195 | tmp_copy->setMaskColor(maskColor); |
| 196 | spr_copy->setMaskColor(maskColor); |
| 197 | |
| 198 | spr_copy->clear(maskColor); |
| 199 | spr_copy->copy(spr, gfx::Clip(spr->bounds())); |
| 200 | |
| 201 | for (int i=0; i<3; ++i) { |
| 202 | // clear_image(tmp_copy, maskColor); |
| 203 | image_scale2x(tmp_copy.get(), spr_copy.get(), spr->width()*(1<<i), spr->height()*(1<<i)); |
| 204 | spr_copy->copy(tmp_copy.get(), gfx::Clip(tmp_copy->bounds())); |
| 205 | } |
| 206 | |
| 207 | if (mask) { |
| 208 | // Same ImageBuffer than tmp_copy |
| 209 | msk_copy.reset(Image::create(IMAGE_BITMAP, mask->width()*scale, mask->height()*scale, buf[1])); |
| 210 | clear_image(msk_copy.get(), 0); |
| 211 | scale_image(msk_copy.get(), mask, |
| 212 | 0, 0, msk_copy->width(), msk_copy->height(), |
| 213 | 0, 0, mask->width(), mask->height()); |
| 214 | } |
| 215 | |
| 216 | clear_image(bmp_copy.get(), maskColor); |
| 217 | scale_image(bmp_copy.get(), bmp, |
| 218 | 0, 0, bmp_copy->width(), bmp_copy->height(), |
| 219 | xmin, ymin, rot_width, rot_height); |
| 220 | |
| 221 | parallelogram( |
| 222 | bmp_copy.get(), spr_copy.get(), msk_copy.get(), |
| 223 | (x1-xmin)*scale, (y1-ymin)*scale, (x2-xmin)*scale, (y2-ymin)*scale, |
no test coverage detected