| 22 | namespace algorithm { |
| 23 | |
| 24 | void flip_image(Image* image, const gfx::Rect& bounds, FlipType flipType) |
| 25 | { |
| 26 | switch (flipType) { |
| 27 | |
| 28 | case FlipHorizontal: |
| 29 | for (int y=bounds.y; y<bounds.y+bounds.h; ++y) { |
| 30 | int u = bounds.x+bounds.w-1; |
| 31 | for (int x=bounds.x; x<bounds.x+bounds.w/2; ++x, --u) { |
| 32 | uint32_t c1 = get_pixel(image, x, y); |
| 33 | uint32_t c2 = get_pixel(image, u, y); |
| 34 | put_pixel(image, x, y, c2); |
| 35 | put_pixel(image, u, y, c1); |
| 36 | } |
| 37 | } |
| 38 | break; |
| 39 | |
| 40 | case FlipVertical: { |
| 41 | int v = bounds.y+bounds.h-1; |
| 42 | for (int y=bounds.y; y<bounds.y+bounds.h/2; ++y, --v) { |
| 43 | for (int x=bounds.x; x<bounds.x+bounds.w; ++x) { |
| 44 | uint32_t c1 = get_pixel(image, x, y); |
| 45 | uint32_t c2 = get_pixel(image, x, v); |
| 46 | put_pixel(image, x, y, c2); |
| 47 | put_pixel(image, x, v, c1); |
| 48 | } |
| 49 | } |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void flip_image_with_mask(Image* image, const Mask* mask, FlipType flipType, int bgcolor) |
| 56 | { |