66
77namespace msdf_atlas {
88
9- #define BOUND_AREA () { \
9+ #define BOUND_SECTION () { \
1010 if (dx < 0 ) w += dx, sx -= dx, dx = 0 ; \
1111 if (dy < 0 ) h += dy, sy -= dy, dy = 0 ; \
1212 if (sx < 0 ) w += sx, dx -= sx, sx = 0 ; \
@@ -16,13 +16,23 @@ namespace msdf_atlas {
1616}
1717
1818template <typename T, int N>
19- void blitSameType (const msdfgen::BitmapRef<T, N> &dst, const msdfgen::BitmapConstRef<T, N> &src, int dx, int dy, int sx, int sy, int w, int h) {
20- BOUND_AREA ();
19+ static void blitSameType (const msdfgen::BitmapSection<T, N> &dst, const msdfgen::BitmapConstSection<T, N> &src) {
20+ int width = std::min (dst.width , src.width ), height = std::min (dst.height , src.height );
21+ size_t rowSize = sizeof (T)*N*width;
22+ for (int y = 0 ; y < height; ++y)
23+ memcpy (dst (0 , y), src (0 , y), rowSize);
24+ }
25+
26+ template <typename T, int N>
27+ static void blitSameType (const msdfgen::BitmapSection<T, N> &dst, const msdfgen::BitmapConstSection<T, N> &src, int dx, int dy, int sx, int sy, int w, int h) {
28+ BOUND_SECTION ();
29+ size_t rowSize = sizeof (T)*N*w;
2130 for (int y = 0 ; y < h; ++y)
22- memcpy (dst (dx, dy+y), src (sx, sy+y), sizeof (T)*N*w );
31+ memcpy (dst (dx, dy+y), src (sx, sy+y), rowSize );
2332}
2433
25- #define BLIT_SAME_TYPE_IMPL (T, N ) void blit (const msdfgen::BitmapRef<T, N> &dst, const msdfgen::BitmapConstRef<T, N> &src, int dx, int dy, int sx, int sy, int w, int h) { blitSameType (dst, src, dx, dy, sx, sy, w, h); }
34+ #define BLIT_SAME_TYPE_IMPL (T, N ) void blit (const msdfgen::BitmapSection<T, N> &dst, const msdfgen::BitmapConstSection<T, N> &src) { blitSameType (dst, src); }
35+ #define BLIT_SAME_TYPE_PART_IMPL (T, N ) void blit (const msdfgen::BitmapSection<T, N> &dst, const msdfgen::BitmapConstSection<T, N> &src, int dx, int dy, int sx, int sy, int w, int h) { blitSameType (dst, src, dx, dy, sx, sy, w, h); }
2636
2737BLIT_SAME_TYPE_IMPL (byte, 1 )
2838BLIT_SAME_TYPE_IMPL (byte, 3 )
@@ -31,40 +41,83 @@ BLIT_SAME_TYPE_IMPL(float, 1)
3141BLIT_SAME_TYPE_IMPL (float , 3 )
3242BLIT_SAME_TYPE_IMPL (float , 4 )
3343
34- void blit (const msdfgen::BitmapRef<byte, 1 > &dst, const msdfgen::BitmapConstRef<float , 1 > &src, int dx, int dy, int sx, int sy, int w, int h) {
35- BOUND_AREA ();
44+ void blit (const msdfgen::BitmapSection<byte, 1 > &dst, const msdfgen::BitmapConstSection<float , 1 > &src) {
45+ int width = std::min (dst.width , src.width ), height = std::min (dst.height , src.height );
46+ for (int y = 0 ; y < height; ++y) {
47+ byte *dstPixel = dst (0 , y);
48+ const float *srcPixel = src (0 , y);
49+ for (int x = 0 ; x < width; ++x)
50+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
51+ }
52+ }
53+
54+ void blit (const msdfgen::BitmapSection<byte, 3 > &dst, const msdfgen::BitmapConstSection<float , 3 > &src) {
55+ int width = std::min (dst.width , src.width ), height = std::min (dst.height , src.height );
56+ for (int y = 0 ; y < height; ++y) {
57+ byte *dstPixel = dst (0 , y);
58+ const float *srcPixel = src (0 , y);
59+ for (int x = 0 ; x < width; ++x) {
60+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
61+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
62+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
63+ }
64+ }
65+ }
66+
67+ void blit (const msdfgen::BitmapSection<byte, 4 > &dst, const msdfgen::BitmapConstSection<float , 4 > &src) {
68+ int width = std::min (dst.width , src.width ), height = std::min (dst.height , src.height );
69+ for (int y = 0 ; y < height; ++y) {
70+ byte *dstPixel = dst (0 , y);
71+ const float *srcPixel = src (0 , y);
72+ for (int x = 0 ; x < width; ++x) {
73+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
74+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
75+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
76+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
77+ }
78+ }
79+ }
80+
81+ BLIT_SAME_TYPE_PART_IMPL (byte, 1 )
82+ BLIT_SAME_TYPE_PART_IMPL (byte, 3 )
83+ BLIT_SAME_TYPE_PART_IMPL (byte, 4 )
84+ BLIT_SAME_TYPE_PART_IMPL (float , 1 )
85+ BLIT_SAME_TYPE_PART_IMPL (float , 3 )
86+ BLIT_SAME_TYPE_PART_IMPL (float , 4 )
87+
88+ void blit (const msdfgen::BitmapSection<byte, 1 > &dst, const msdfgen::BitmapConstSection<float , 1 > &src, int dx, int dy, int sx, int sy, int w, int h) {
89+ BOUND_SECTION ();
3690 for (int y = 0 ; y < h; ++y) {
3791 byte *dstPixel = dst (dx, dy+y);
38- for (int x = 0 ; x < w; ++x) {
39- const float *srcPixel = src (sx+x, sy+y);
40- *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel);
41- }
92+ const float *srcPixel = src (sx, sy+y);
93+ for (int x = 0 ; x < w; ++x)
94+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
4295 }
4396}
4497
45- void blit (const msdfgen::BitmapRef <byte, 3 > &dst, const msdfgen::BitmapConstRef <float , 3 > &src, int dx, int dy, int sx, int sy, int w, int h) {
46- BOUND_AREA ();
98+ void blit (const msdfgen::BitmapSection <byte, 3 > &dst, const msdfgen::BitmapConstSection <float , 3 > &src, int dx, int dy, int sx, int sy, int w, int h) {
99+ BOUND_SECTION ();
47100 for (int y = 0 ; y < h; ++y) {
48101 byte *dstPixel = dst (dx, dy+y);
102+ const float *srcPixel = src (sx, sy+y);
49103 for (int x = 0 ; x < w; ++x) {
50- const float *srcPixel = src (sx+x, sy+y);
51- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[0 ]);
52- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[1 ]);
53- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[2 ]);
104+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
105+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
106+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
54107 }
55108 }
56109}
57110
58- void blit (const msdfgen::BitmapRef <byte, 4 > &dst, const msdfgen::BitmapConstRef <float , 4 > &src, int dx, int dy, int sx, int sy, int w, int h) {
59- BOUND_AREA ();
111+ void blit (const msdfgen::BitmapSection <byte, 4 > &dst, const msdfgen::BitmapConstSection <float , 4 > &src, int dx, int dy, int sx, int sy, int w, int h) {
112+ BOUND_SECTION ();
60113 for (int y = 0 ; y < h; ++y) {
61114 byte *dstPixel = dst (dx, dy+y);
115+ const float *srcPixel = src (sx, sy+y);
62116 for (int x = 0 ; x < w; ++x) {
63- const float *srcPixel = src (sx+x, sy+y);
64- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[0 ]);
65- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[1 ]);
66- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[2 ]);
67- *dstPixel++ = msdfgen::pixelFloatToByte (srcPixel[3 ]);
117+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
118+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
119+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
120+ *dstPixel++ = msdfgen::pixelFloatToByte (*srcPixel++);
68121 }
69122 }
70123}
0 commit comments