forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitives_fast.h
65 lines (49 loc) · 1.86 KB
/
primitives_fast.h
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
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_PRIMITIVES_FAST_H_INCLUDED
#define DOC_PRIMITIVES_FAST_H_INCLUDED
#pragma once
#include "doc/color.h"
namespace doc {
class Image;
template<typename ImageTraits> class ImageImpl;
template<class Traits>
inline typename Traits::address_t get_pixel_address_fast(const Image* image, int x, int y) {
ASSERT(x >= 0 && x < image->width());
ASSERT(y >= 0 && y < image->height());
return (((ImageImpl<Traits>*)image)->address(x, y));
}
template<class Traits>
inline typename Traits::pixel_t get_pixel_fast(const Image* image, int x, int y) {
ASSERT(x >= 0 && x < image->width());
ASSERT(y >= 0 && y < image->height());
return *(((ImageImpl<Traits>*)image)->address(x, y));
}
template<class Traits>
inline void put_pixel_fast(Image* image, int x, int y, typename Traits::pixel_t color) {
ASSERT(x >= 0 && x < image->width());
ASSERT(y >= 0 && y < image->height());
*(((ImageImpl<Traits>*)image)->address(x, y)) = color;
}
//////////////////////////////////////////////////////////////////////
// Bitmap specialization
template<>
inline BitmapTraits::pixel_t get_pixel_fast<BitmapTraits>(const Image* image, int x, int y) {
ASSERT(x >= 0 && x < image->width());
ASSERT(y >= 0 && y < image->height());
return (*image->getPixelAddress(x, y)) & (1 << (x % 8)) ? 1: 0;
}
template<>
inline void put_pixel_fast<BitmapTraits>(Image* image, int x, int y, BitmapTraits::pixel_t color) {
ASSERT(x >= 0 && x < image->width());
ASSERT(y >= 0 && y < image->height());
if (color)
*image->getPixelAddress(x, y) |= (1 << (x % 8));
else
*image->getPixelAddress(x, y) &= ~(1 << (x % 8));
}
} // namespace doc
#endif