diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-08-05 04:01:01 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2010-08-05 04:01:01 +0000 |
| commit | 13e643c744ca21ea6f5a50d404bec8aac886a808 (patch) | |
| tree | 94f0ad849ad7f2ad60fb442848a46f31a89fe1a0 /src/libnr | |
| parent | Fix mask rendering to use luminance-to-alpha (diff) | |
| download | inkscape-13e643c744ca21ea6f5a50d404bec8aac886a808.tar.gz inkscape-13e643c744ca21ea6f5a50d404bec8aac886a808.zip | |
Wholesale cruft removal part 5; completely remove RasterFont
(bzr r9508.1.50)
Diffstat (limited to 'src/libnr')
| -rw-r--r-- | src/libnr/Makefile_insert | 19 | ||||
| -rw-r--r-- | src/libnr/nr-blit.cpp | 300 | ||||
| -rw-r--r-- | src/libnr/nr-blit.h | 32 | ||||
| -rw-r--r-- | src/libnr/nr-compose-reference.cpp | 266 | ||||
| -rw-r--r-- | src/libnr/nr-compose-reference.h | 69 | ||||
| -rw-r--r-- | src/libnr/nr-compose-test.h | 457 | ||||
| -rw-r--r-- | src/libnr/nr-compose.cpp | 1197 | ||||
| -rw-r--r-- | src/libnr/nr-compose.h | 69 | ||||
| -rw-r--r-- | src/libnr/testnr.cpp | 92 |
9 files changed, 1 insertions, 2500 deletions
diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index 0a9b99e1e..2da8e36fb 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -2,11 +2,6 @@ ink_common_sources += \ libnr/in-svg-plane.h \ - libnr/nr-blit.cpp \ - libnr/nr-blit.h \ - libnr/nr-compose-reference.h \ - libnr/nr-compose.cpp \ - libnr/nr-compose.h \ libnr/nr-convert2geom.h \ libnr/nr-coord.h \ libnr/nr-dim2.h \ @@ -30,27 +25,15 @@ ink_common_sources += \ libnr/nr-rect.cpp \ libnr/nr-rect.h \ libnr/nr-rect-ops.h \ - libnr/nr-render.h \ libnr/nr-types.cpp \ libnr/nr-types.h \ libnr/nr-values.cpp \ - libnr/nr-values.h \ - $(libnr_mmx_sources) - -# Ancient performance test (?) -# Won't work anymore. -#libnr_testnr_SOURCES = \ -# libnr/testnr.cpp - -#libnr_testnr_LDADD = \ -# libnr/libnr.a \ -# -lglib-2.0 + libnr/nr-values.h # ###################### # ### CxxTest stuff #### # ###################### CXXTEST_TESTSUITES += \ $(srcdir)/libnr/in-svg-plane-test.h \ - $(srcdir)/libnr/nr-compose-test.h \ $(srcdir)/libnr/nr-point-fns-test.h \ $(srcdir)/libnr/nr-types-test.h diff --git a/src/libnr/nr-blit.cpp b/src/libnr/nr-blit.cpp deleted file mode 100644 index 144caa597..000000000 --- a/src/libnr/nr-blit.cpp +++ /dev/null @@ -1,300 +0,0 @@ -#define __NR_BLIT_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include "nr-pixops.h" -#include "nr-compose.h" -#include "nr-blit.h" - -void -nr_blit_pixblock_pixblock_alpha (NRPixBlock *d, NRPixBlock *s, unsigned int alpha) -{ - NRRectL clip; - unsigned char *dpx, *spx; - int dbpp, sbpp; - int w, h; - - if (alpha == 0) return; - if (s->empty) return; - /* fixme: */ - if (s->mode == NR_PIXBLOCK_MODE_A8) return; - /* fixme: */ - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8) return; - - /* - * Possible variants as of now: - * - * 0. SRC EP - DST EP * - * 1. SRC EP - DST EN * - * 2. SRC EP - DST P * - * 3. SRC EP - DST N * - * 4. SRC EN - DST EP * - * 5. SRC EN - DST EN * - * 6. SRC EN - DST P * - * 7. SRC EN - DST N * - * 8. SRC P - DST EP * - * 9. SRC P - DST EN * - * A. SRC P - DST P * - * B. SRC P - DST N * - * C. SRC N - DST EP * - * D. SRC N - DST EN * - * E. SRC N - DST P * - * F. SRC N - DST N * - * - */ - - nr_rect_l_intersect (&clip, &d->area, &s->area); - - if (nr_rect_l_test_empty(clip)) return; - - /* Pointers */ - dbpp = NR_PIXBLOCK_BPP (d); - dpx = NR_PIXBLOCK_PX (d) + (clip.y0 - d->area.y0) * d->rs + dbpp * (clip.x0 - d->area.x0); - sbpp = NR_PIXBLOCK_BPP (s); - spx = NR_PIXBLOCK_PX (s) + (clip.y0 - s->area.y0) * s->rs + sbpp * (clip.x0 - s->area.x0); - w = clip.x1 - clip.x0; - h = clip.y1 - clip.y0; - - switch (d->mode) { - case NR_PIXBLOCK_MODE_A8: - /* No rendering into alpha at moment */ - break; - case NR_PIXBLOCK_MODE_R8G8B8: - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - nr_R8G8B8_R8G8B8_R8G8B8A8_P (dpx, w, h, d->rs, spx, s->rs, alpha); - } else { - nr_R8G8B8_R8G8B8_R8G8B8A8_N (dpx, w, h, d->rs, spx, s->rs, alpha); - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8P: - if (d->empty) { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* Case 8 */ - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P (dpx, w, h, d->rs, spx, s->rs, alpha); - } else { - /* Case C */ - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N (dpx, w, h, d->rs, spx, s->rs, alpha); - } - } else { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* case A */ - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P (dpx, w, h, d->rs, spx, s->rs, alpha); - } else { - /* case E */ - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N (dpx, w, h, d->rs, spx, s->rs, alpha); - } - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - if (d->empty) { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* Case 9 */ - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P (dpx, w, h, d->rs, spx, s->rs, alpha); - } else { - /* Case D */ - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N (dpx, w, h, d->rs, spx, s->rs, alpha); - } - } else { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* case B */ - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P (dpx, w, h, d->rs, spx, s->rs, alpha); - } else { - /* case F */ - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N (dpx, w, h, d->rs, spx, s->rs, alpha); - } - } - break; - } -} - -void -nr_blit_pixblock_pixblock_mask (NRPixBlock *d, NRPixBlock *s, NRPixBlock *m) -{ - NRRectL clip; - unsigned char *dpx, *spx, *mpx; - int dbpp, sbpp; - int w, h; - - if (s->empty) return; - /* fixme: */ - if (s->mode == NR_PIXBLOCK_MODE_A8) return; - /* fixme: */ - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8) return; - - /* - * Possible variants as of now: - * - * 0. SRC EP - DST EP * - * 1. SRC EP - DST EN * - * 2. SRC EP - DST P * - * 3. SRC EP - DST N * - * 4. SRC EN - DST EP * - * 5. SRC EN - DST EN * - * 6. SRC EN - DST P * - * 7. SRC EN - DST N * - * 8. SRC P - DST EP * - * 9. SRC P - DST EN * - * A. SRC P - DST P * - * B. SRC P - DST N * - * C. SRC N - DST EP * - * D. SRC N - DST EN * - * E. SRC N - DST P * - * F. SRC N - DST N * - * - */ - - nr_rect_l_intersect (&clip, &d->area, &s->area); - nr_rect_l_intersect (&clip, &clip, &m->area); - - if (nr_rect_l_test_empty(clip)) return; - - /* Pointers */ - dbpp = NR_PIXBLOCK_BPP (d); - dpx = NR_PIXBLOCK_PX (d) + (clip.y0 - d->area.y0) * d->rs + dbpp * (clip.x0 - d->area.x0); - sbpp = NR_PIXBLOCK_BPP (s); - spx = NR_PIXBLOCK_PX (s) + (clip.y0 - s->area.y0) * s->rs + sbpp * (clip.x0 - s->area.x0); - mpx = NR_PIXBLOCK_PX (m) + (clip.y0 - m->area.y0) * m->rs + 1 * (clip.x0 - m->area.x0); - w = clip.x1 - clip.x0; - h = clip.y1 - clip.y0; - - switch (d->mode) { - case NR_PIXBLOCK_MODE_A8: - /* No rendering into alpha at moment */ - break; - case NR_PIXBLOCK_MODE_R8G8B8: - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } else { - nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8P: - if (d->empty) { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* Case 8 */ - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } else { - /* Case C */ - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } - } else { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* case A */ - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } else { - /* case E */ - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - if (d->empty) { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* Case 9 */ - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } else { - /* Case D */ - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } - } else { - if (s->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - /* case B */ - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } else { - /* case F */ - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8 (dpx, w, h, d->rs, spx, s->rs, mpx, m->rs); - } - } - break; - } -} - -void -nr_blit_pixblock_mask_rgba32 (NRPixBlock *d, NRPixBlock *m, unsigned long rgba) -{ - if (!(rgba & 0xff)) return; - - if (m) { - NRRectL clip; - unsigned char *dpx, *mpx; - int w, h; - - if (m->mode != NR_PIXBLOCK_MODE_A8) return; - - if (!nr_rect_l_test_intersect(d->area, m->area)) return; - - nr_rect_l_intersect (&clip, &d->area, &m->area); - - /* Pointers */ - dpx = NR_PIXBLOCK_PX (d) + (clip.y0 - d->area.y0) * d->rs + NR_PIXBLOCK_BPP (d) * (clip.x0 - d->area.x0); - mpx = NR_PIXBLOCK_PX (m) + (clip.y0 - m->area.y0) * m->rs + (clip.x0 - m->area.x0); - w = clip.x1 - clip.x0; - h = clip.y1 - clip.y0; - - if (d->empty) { - if (d->mode == NR_PIXBLOCK_MODE_R8G8B8) { - nr_R8G8B8_R8G8B8_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } else if (d->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - nr_R8G8B8A8_P_EMPTY_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } else { - nr_R8G8B8A8_N_EMPTY_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } - d->empty = 0; - } else { - if (d->mode == NR_PIXBLOCK_MODE_R8G8B8) { - nr_R8G8B8_R8G8B8_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } else if (d->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } else { - nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32 (dpx, w, h, d->rs, mpx, m->rs, rgba); - } - } - } else { - unsigned int r, g, b, a; - int x, y; - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - for (y = d->area.y0; y < d->area.y1; y++) { - unsigned char *p; - p = NR_PIXBLOCK_PX (d) + (y - d->area.y0) * d->rs; - for (x = d->area.x0; x < d->area.x1; x++) { - unsigned int da; - switch (d->mode) { - case NR_PIXBLOCK_MODE_R8G8B8: - p[0] = NR_COMPOSEN11_1111 (r, a, p[0]); - p[1] = NR_COMPOSEN11_1111 (g, a, p[1]); - p[2] = NR_COMPOSEN11_1111 (b, a, p[2]); - p += 3; - break; - case NR_PIXBLOCK_MODE_R8G8B8A8P: - p[0] = NR_COMPOSENPP_1111 (r, a, p[0]); - p[1] = NR_COMPOSENPP_1111 (g, a, p[1]); - p[2] = NR_COMPOSENPP_1111 (b, a, p[2]); - p[3] = NR_COMPOSEA_111(a, p[3]); - p += 4; - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - da = NR_COMPOSEA_112(a, p[3]); - p[0] = NR_COMPOSENNN_111121 (r, a, p[0], p[3], da); - p[1] = NR_COMPOSENNN_111121 (g, a, p[1], p[3], da); - p[2] = NR_COMPOSENNN_111121 (b, a, p[2], p[3], da); - p[3] = NR_NORMALIZE_21(da); - p += 4; - break; - default: - break; - } - } - } - } -} - diff --git a/src/libnr/nr-blit.h b/src/libnr/nr-blit.h deleted file mode 100644 index 3221c8187..000000000 --- a/src/libnr/nr-blit.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __NR_BLIT_H__ -#define __NR_BLIT_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <libnr/nr-pixblock.h> - -#define nr_blit_pixblock_pixblock(d,s) nr_blit_pixblock_pixblock_alpha (d, s, 255) - -void nr_blit_pixblock_pixblock_alpha (NRPixBlock *d, NRPixBlock *s, unsigned int alpha); -void nr_blit_pixblock_pixblock_mask (NRPixBlock *d, NRPixBlock *s, NRPixBlock *m); -void nr_blit_pixblock_mask_rgba32 (NRPixBlock *d, NRPixBlock *m, unsigned long rgba32); - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-compose-reference.cpp b/src/libnr/nr-compose-reference.cpp deleted file mode 100644 index b4ff5851a..000000000 --- a/src/libnr/nr-compose-reference.cpp +++ /dev/null @@ -1,266 +0,0 @@ - -// This is a reference implementation of the compositing functions in nr-compose.cpp. - -#include "nr-compose-reference.h" - -#define NR_RGBA32_R(v) (unsigned char) (((v) >> 24) & 0xff) -#define NR_RGBA32_G(v) (unsigned char) (((v) >> 16) & 0xff) -#define NR_RGBA32_B(v) (unsigned char) (((v) >> 8) & 0xff) -#define NR_RGBA32_A(v) (unsigned char) ((v) & 0xff) - -static inline unsigned int DIV_ROUND(unsigned int v, unsigned int divisor) { return (v+divisor/2)/divisor; } - -static unsigned int pixelSize[] = { 1, 3, 4, 4 }; - -// Computes : -// dc' = (1 - alpha*sa) * dc + alpha*sc -// da' = 1 - (1 - alpha*sa) * (1 - da) -// Assuming premultiplied color values -template<PIXEL_FORMAT resultFormat, PIXEL_FORMAT backgroundFormat, PIXEL_FORMAT foregroundFormat> -static void composePixel(unsigned char *d, const unsigned char *s, unsigned int alpha); - -template<> void composePixel<R8G8B8, R8G8B8, R8G8B8A8N>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[0] + alpha*s[3]*s[0], 255*255); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[1] + alpha*s[3]*s[1], 255*255); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[2] + alpha*s[3]*s[2], 255*255); -} - -template<> void composePixel<R8G8B8, R8G8B8, R8G8B8A8P>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[0] + 255*alpha*s[0], 255*255); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[1] + 255*alpha*s[1], 255*255); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[2] + 255*alpha*s[2], 255*255); -} - -template<> void composePixel<R8G8B8A8N, EMPTY, R8G8B8A8N>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - unsigned int newa = 255*255 - (255*255 - alpha*s[3]); - d[0] = s[0];//newa == 0 ? 0 : DIV_ROUND(alpha*s[3]*s[0], newa); - d[1] = s[1];//newa == 0 ? 0 : DIV_ROUND(alpha*s[3]*s[1], newa); - d[2] = s[2];//newa == 0 ? 0 : DIV_ROUND(alpha*s[3]*s[2], newa); - d[3] = DIV_ROUND(newa, 255); -} - -template<> void composePixel<R8G8B8A8N, EMPTY, R8G8B8A8P>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - unsigned int newa = 255*255 - (255*255 - alpha*s[3]); - d[0] = s[3] == 0 ? 0 : DIV_ROUND(255*s[0], s[3]);//newa == 0 ? 0 : DIV_ROUND(255*alpha*s[0], newa); - d[1] = s[3] == 0 ? 0 : DIV_ROUND(255*s[1], s[3]);//newa == 0 ? 0 : DIV_ROUND(255*alpha*s[1], newa); - d[2] = s[3] == 0 ? 0 : DIV_ROUND(255*s[2], s[3]);//newa == 0 ? 0 : DIV_ROUND(255*alpha*s[2], newa); - d[3] = DIV_ROUND(newa, 255); -} - -template<> void composePixel<R8G8B8A8N, R8G8B8A8N, R8G8B8A8N>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - if ( d[3] == 0 ) { - composePixel<R8G8B8A8N, EMPTY, R8G8B8A8N>(d, s, alpha); - } else if ( alpha*s[3] == 0 ) { - /* NOP */ - } else { - unsigned int newa = 255*255*255 - (255*255 - alpha*s[3]) * (255 - d[3]); - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[0] + 255 * alpha*s[3]*s[0], newa); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[1] + 255 * alpha*s[3]*s[1], newa); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[2] + 255 * alpha*s[3]*s[2], newa); - d[3] = DIV_ROUND(newa, 255*255); - } -} - -template<> void composePixel<R8G8B8A8N, R8G8B8A8N, R8G8B8A8P>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - if ( d[3] == 0 ) { - composePixel<R8G8B8A8N, EMPTY, R8G8B8A8P>(d, s, alpha); - } else if ( alpha*s[3] == 0 ) { - /* NOP */ - } else { - unsigned int newa = 255*255*255 - (255*255 - alpha*s[3]) * (255 - d[3]); - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[0] + 255*255 * alpha*s[0], newa); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[1] + 255*255 * alpha*s[1], newa); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[3]*d[2] + 255*255 * alpha*s[2], newa); - d[3] = DIV_ROUND(newa, 255*255); - } -} - -template<> void composePixel<R8G8B8A8P, EMPTY, R8G8B8A8N>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND(alpha*s[3]*s[0], 255*255); - d[1] = DIV_ROUND(alpha*s[3]*s[1], 255*255); - d[2] = DIV_ROUND(alpha*s[3]*s[2], 255*255); - d[3] = DIV_ROUND(255*255 - (255*255 - alpha*s[3]), 255); -} - -template<> void composePixel<R8G8B8A8P, EMPTY, R8G8B8A8P>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND(alpha*s[0], 255); - d[1] = DIV_ROUND(alpha*s[1], 255); - d[2] = DIV_ROUND(alpha*s[2], 255); - d[3] = DIV_ROUND(255*255 - (255*255 - alpha*s[3]), 255); -} - -template<> void composePixel<R8G8B8A8P, R8G8B8A8P, R8G8B8A8N>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[0] + alpha*s[3]*s[0], 255*255); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[1] + alpha*s[3]*s[1], 255*255); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[2] + alpha*s[3]*s[2], 255*255); - d[3] = DIV_ROUND(255*255*255 - (255*255 - alpha*s[3]) * (255 - d[3]), 255*255); -} - -template<> void composePixel<R8G8B8A8P, R8G8B8A8P, R8G8B8A8P>(unsigned char *d, const unsigned char *s, unsigned int alpha) { - d[0] = DIV_ROUND((255*255 - alpha*s[3]) * d[0] + 255 * alpha*s[0], 255*255); - d[1] = DIV_ROUND((255*255 - alpha*s[3]) * d[1] + 255 * alpha*s[1], 255*255); - d[2] = DIV_ROUND((255*255 - alpha*s[3]) * d[2] + 255 * alpha*s[2], 255*255); - d[3] = DIV_ROUND(255*255*255 - (255*255 - alpha*s[3]) * (255 - d[3]), 255*255); -} - - -// composeAlpha, iterates over all pixels and applies composePixel to each of them -template<PIXEL_FORMAT resultFormat, PIXEL_FORMAT backgroundFormat, PIXEL_FORMAT foregroundFormat> -static void composeAlpha(unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - for(int y=0; y<h; y++) { - unsigned char* d = px; - const unsigned char* s = spx; - for(int x=0; x<w; x++) { - composePixel<resultFormat, backgroundFormat, foregroundFormat>(d, s, alpha); - d += pixelSize[resultFormat]; - s += pixelSize[foregroundFormat]; - } - px += rs; - spx += srs; - } -} - -template<PIXEL_FORMAT resultFormat, PIXEL_FORMAT backgroundFormat, PIXEL_FORMAT foregroundFormat> -static void composeMask(unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - for(int y=0; y<h; y++) { - unsigned char* d = px; - const unsigned char* s = spx; - const unsigned char* m = mpx; - for(int x=0; x<w; x++) { - composePixel<resultFormat, backgroundFormat, foregroundFormat>(d, s, *m); - d += pixelSize[resultFormat]; - s += pixelSize[foregroundFormat]; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -template<PIXEL_FORMAT resultFormat, PIXEL_FORMAT backgroundFormat> -static void composeColor(unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) { - const unsigned char rgba_array[4] = {NR_RGBA32_R(rgba), NR_RGBA32_G(rgba), NR_RGBA32_B(rgba), NR_RGBA32_A(rgba)}; - for(int y=0; y<h; y++) { - unsigned char* d = px; - const unsigned char* m = mpx; - for(int x=0; x<w; x++) { - composePixel<resultFormat, backgroundFormat, R8G8B8A8N>(d, rgba_array, *m); - d += pixelSize[resultFormat]; - m += 1; - } - px += rs; - mpx += mrs; - } -} - -/* FINAL DST SRC */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8N, EMPTY, R8G8B8A8N>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8N, EMPTY, R8G8B8A8P>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8P, EMPTY, R8G8B8A8N>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8P, EMPTY, R8G8B8A8P>(px, w, h, rs, spx, srs, alpha); -} - - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8N, R8G8B8A8N, R8G8B8A8N>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8N, R8G8B8A8N, R8G8B8A8P>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8P, R8G8B8A8P, R8G8B8A8N>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8A8P, R8G8B8A8P, R8G8B8A8P>(px, w, h, rs, spx, srs, alpha); -} - -/* FINAL DST SRC MASK */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8A8N, EMPTY, R8G8B8A8N>(px, w, h, rs, spx, srs, mpx, mrs); -} - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8A8N, EMPTY, R8G8B8A8P>(px, w, h, rs, spx, srs, mpx, mrs); -} - -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8A8P, EMPTY, R8G8B8A8N>(px, w, h, rs, spx, srs, mpx, mrs); -} - -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8A8P, EMPTY, R8G8B8A8P>(px, w, h, rs, spx, srs, mpx, mrs); -} - - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8_ref (unsigned char *p, int w, int h, int rs, const unsigned char *s, int srs, const unsigned char *m, int mrs) { - composeMask<R8G8B8A8N, R8G8B8A8N, R8G8B8A8N>(p, w, h, rs, s, srs, m, mrs); -} - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8_ref (unsigned char *p, int w, int h, int rs, const unsigned char *s, int srs, const unsigned char *m, int mrs) { - composeMask<R8G8B8A8N, R8G8B8A8N, R8G8B8A8P>(p, w, h, rs, s, srs, m, mrs); -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8_ref (unsigned char *p, int w, int h, int rs, const unsigned char *s, int srs, const unsigned char *m, int mrs) { - composeMask<R8G8B8A8P, R8G8B8A8P, R8G8B8A8N>(p, w, h, rs, s, srs, m, mrs); -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8_ref (unsigned char *p, int w, int h, int rs, const unsigned char *s, int srs, const unsigned char *m, int mrs) { - composeMask<R8G8B8A8P, R8G8B8A8P, R8G8B8A8P>(p, w, h, rs, s, srs, m, mrs); -} - -/* FINAL DST MASK COLOR */ - -void nr_R8G8B8A8_N_EMPTY_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) { - composeColor<R8G8B8A8N, EMPTY>(px, w, h, rs, mpx, mrs, rgba); -} - -void nr_R8G8B8A8_P_EMPTY_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) { - composeColor<R8G8B8A8P, EMPTY>(px, w, h, rs, mpx, mrs, rgba); -} - - -void nr_R8G8B8_R8G8B8_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba) { - composeColor<R8G8B8, R8G8B8>(px, w, h, rs, spx, srs, rgba); -} - -void nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba) { - composeColor<R8G8B8A8N, R8G8B8A8N>(px, w, h, rs, spx, srs, rgba); -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba) { - composeColor<R8G8B8A8P, R8G8B8A8P>(px, w, h, rs, spx, srs, rgba); -} - -/* RGB */ - -void nr_R8G8B8_R8G8B8_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8, R8G8B8, R8G8B8A8P>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8_R8G8B8_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) { - composeAlpha<R8G8B8, R8G8B8, R8G8B8A8N>(px, w, h, rs, spx, srs, alpha); -} - -void nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8, R8G8B8, R8G8B8A8P>(px, w, h, rs, spx, srs, mpx, mrs); -} - -void nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) { - composeMask<R8G8B8, R8G8B8, R8G8B8A8N>(px, w, h, rs, spx, srs, mpx, mrs); -} diff --git a/src/libnr/nr-compose-reference.h b/src/libnr/nr-compose-reference.h deleted file mode 100644 index 8d004a135..000000000 --- a/src/libnr/nr-compose-reference.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __NR_COMPOSE_REFERENCE_H__ -#define __NR_COMPOSE_REFERENCE_H__ - -// Based on nr-pixblock.h -typedef enum { - A8 = 0, - R8G8B8, - R8G8B8A8N, - R8G8B8A8P, - EMPTY = -1 -} PIXEL_FORMAT; - -/* FINAL DST SRC */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); - -/* FINAL DST SRC MASK */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8_ref (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8_ref (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8_ref (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8_ref (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); - -/* FINAL DST MASK COLOR */ - -void nr_R8G8B8A8_N_EMPTY_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); -void nr_R8G8B8A8_P_EMPTY_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); - -void nr_R8G8B8_R8G8B8_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba); -void nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba); -void nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba); - -/* RGB */ - -void nr_R8G8B8_R8G8B8_R8G8B8A8_P_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8_R8G8B8_R8G8B8A8_N_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs); -void nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8_ref (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs); - -#endif//__NR_COMPOSE_REFERENCE_H__ diff --git a/src/libnr/nr-compose-test.h b/src/libnr/nr-compose-test.h deleted file mode 100644 index fe3ccd61f..000000000 --- a/src/libnr/nr-compose-test.h +++ /dev/null @@ -1,457 +0,0 @@ - -#include <cxxtest/TestSuite.h> - -#include "nr-compose.h" -#include "nr-compose-reference.h" -#include <glib.h> -#include <memory.h> -#include <stdio.h> -#include <stdlib.h> - -static inline unsigned int DIV_ROUND(unsigned int v, unsigned int divisor) { return (v+divisor/2)/divisor; } -static inline unsigned char NR_PREMUL_111(unsigned int c, unsigned int a) { return static_cast<unsigned char>(DIV_ROUND(c*a, 255)); } - -template<PIXEL_FORMAT format> -int IMGCMP(const unsigned char* a, const unsigned char* b, size_t n) { return memcmp(a, b, n); } - -template<> -int IMGCMP<R8G8B8A8N>(const unsigned char* a, const unsigned char* b, size_t n) -{ - // If two pixels each have their alpha channel set to zero they're equivalent - // Note that this doesn't work for premultiplied values, as their color values should - // be zero when alpha is zero. - int cr = 0; - while(n && cr == 0) { - if ( a[3] != 0 || b[3] != 0 ) { - cr = memcmp(a, b, 4); - } - a+=4; - b+=4; - n-=4; - } - return cr; -} - -class NrComposeTest : public CxxTest::TestSuite { -private: - int const w, h; - - unsigned char* const dst_rgba_n_org; - unsigned char* const dst_rgba_p_org; - unsigned char* const dst_rgb_org; - - unsigned char* const dst1_rgba; - unsigned char* const dst2_rgba; - unsigned char* const src_rgba_n; - unsigned char* const src_rgba_p; - unsigned char* const dst1_rgb; - unsigned char* const dst2_rgb; - unsigned char* const src_rgb; - unsigned char* const mask; - - static unsigned int const alpha_vals[7]; - static unsigned int const rgb_vals[3]; - -public: - NrComposeTest() : - w(13), - h(5), - - dst_rgba_n_org(new unsigned char[w*h*4]), - dst_rgba_p_org(new unsigned char[w*h*4]), - dst_rgb_org(new unsigned char[w*h*3]), - - dst1_rgba(new unsigned char[w*h*4]), - dst2_rgba(new unsigned char[w*h*4]), - src_rgba_n(new unsigned char[w*h*4]), - src_rgba_p(new unsigned char[w*h*4]), - dst1_rgb(new unsigned char[w*h*3]), - dst2_rgb(new unsigned char[w*h*3]), - src_rgb(new unsigned char[w*h*3]), - mask(new unsigned char[w*h]) - { - srand(23874683); // It shouldn't really matter what this is, as long as it's always the same (to be reproducible) - - for(int y=0; y<h; y++) { - for(int x=0; x<w; x++) { - dst_rgba_n_org[(x+y*w)*4+3] = 255*rand()/RAND_MAX; - dst_rgba_p_org[(x+y*w)*4+3] = 255*rand()/RAND_MAX; - src_rgba_n[(x+y*w)*4+3] = 255*rand()/RAND_MAX; - src_rgba_p[(x+y*w)*4+3] = 255*rand()/RAND_MAX; - for(int i=0; i<3; i++) { - dst_rgba_n_org[(x+y*w)*4+i] = 255*rand()/RAND_MAX; - dst_rgba_p_org[(x+y*w)*4+i] = NR_PREMUL_111(255*rand()/RAND_MAX, dst_rgba_p_org[(x+y*w)*4+3]); - src_rgba_n[(x+y*w)*4+i] = 255*rand()/RAND_MAX; - src_rgba_p[(x+y*w)*4+i] = NR_PREMUL_111(255*rand()/RAND_MAX, src_rgba_p[(x+y*w)*4+3]); - dst_rgb_org[(x+y*w)*3+i] = 255*rand()/RAND_MAX; - } - mask[x+y*w] = 255*rand()/RAND_MAX; - } - } - } - virtual ~NrComposeTest() - { - delete[] dst_rgba_n_org; - delete[] dst_rgba_p_org; - delete[] dst_rgb_org; - - delete[] dst1_rgba; - delete[] dst2_rgba; - delete[] src_rgba_n; - delete[] src_rgba_p; - delete[] dst1_rgb; - delete[] dst2_rgb; - delete[] src_rgb; - delete[] mask; - } - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrComposeTest *createSuite() { return new NrComposeTest(); } - static void destroySuite( NrComposeTest *suite ) { delete suite; } - - // FINAL DST SRC - - void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - - // FINAL DST SRC MASK - - void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8() - { - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8() - { - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8() - { - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8() - { - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8() - { - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8() - { - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8() - { - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8() - { - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w); - TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - - // FINAL DST MASK COLOR - - void testnr_R8G8B8A8_N_EMPTY_A8_RGBA32() - { - for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int rgba = rgb_vals[j]+alpha_vals[i]; - char msg[100]; - sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba); - nr_R8G8B8A8_N_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - } - - void testnr_R8G8B8A8_P_EMPTY_A8_RGBA32() - { - for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int rgba = rgb_vals[j]+alpha_vals[i]; - char msg[100]; - sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba); - nr_R8G8B8A8_P_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - } - - void testnr_R8G8B8_R8G8B8_A8_RGBA32() - { - for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int rgba = rgb_vals[j]+alpha_vals[i]; - char msg[100]; - sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff); - memcpy(dst1_rgb, dst_rgb_org, w*h*3); - memcpy(dst2_rgb, dst_rgb_org, w*h*3); - nr_R8G8B8_R8G8B8_A8_RGBA32(dst1_rgb, w, h, w*3, mask, w, rgba); - nr_R8G8B8_R8G8B8_A8_RGBA32_ref(dst2_rgb, w, h, w*3, mask, w, rgba); - TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 ); - } - } - } - - void testnr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32() - { - for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int rgba = rgb_vals[j]+alpha_vals[i]; - char msg[100]; - sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff); - memcpy(dst1_rgba, dst_rgba_n_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_n_org, w*h*4); - nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba); - nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - } - - void testnr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32() - { - for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int rgba = rgb_vals[j]+alpha_vals[i]; - char msg[100]; - sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff); - memcpy(dst1_rgba, dst_rgba_p_org, w*h*4); - memcpy(dst2_rgba, dst_rgba_p_org, w*h*4); - nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba); - nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba); - TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 ); - } - } - } - - // RGB - - void testnr_R8G8B8_R8G8B8_R8G8B8A8_N() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgb, dst_rgb_org, w*h*3); - memcpy(dst2_rgb, dst_rgb_org, w*h*3); - nr_R8G8B8_R8G8B8_R8G8B8A8_N(dst1_rgb, w, h, w*3, src_rgba_n, w*4, alpha); - nr_R8G8B8_R8G8B8_R8G8B8A8_N_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 ); - } - } - - void testnr_R8G8B8_R8G8B8_R8G8B8A8_P() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgb, dst_rgb_org, w*h*3); - memcpy(dst2_rgb, dst_rgb_org, w*h*3); - nr_R8G8B8_R8G8B8_R8G8B8A8_P(dst1_rgb, w, h, w*3, src_rgba_p, w*4, alpha); - nr_R8G8B8_R8G8B8_R8G8B8A8_P_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, alpha); - TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 ); - } - } - - void testnr_R8G8B8_R8G8B8_R8G8B8A8_N_A8() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgb, dst_rgb_org, w*h*3); - memcpy(dst2_rgb, dst_rgb_org, w*h*3); - nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8(dst1_rgb, w, h, w*3, src_rgba_n, w*4, mask, w); - nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, mask, w); - TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 ); - } - } - - void testnr_R8G8B8_R8G8B8_R8G8B8A8_P_A8() - { - for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) { - unsigned int alpha = alpha_vals[i]; - char msg[40]; - sprintf(msg, "alpha = %u", alpha); - memcpy(dst1_rgb, dst_rgb_org, w*h*3); - memcpy(dst2_rgb, dst_rgb_org, w*h*3); - nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8(dst1_rgb, w, h, w*3, src_rgba_p, w*4, mask, w); - nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, mask, w); - TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 ); - } - } -}; - -unsigned int const NrComposeTest::alpha_vals[7] = {0, 1, 127, 128, 129, 254, 255}; -unsigned int const NrComposeTest::rgb_vals[3] = { - ( 0u<<24u)+( 1u<<16u)+( 92u<<8u), - (127u<<24u)+(128u<<16u)+(129u<<8u), - (163u<<24u)+(254u<<16u)+(255u<<8u)}; - -/* -Local Variables: -mode:c++ -c-file-style:"stroustrup" -c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) -indent-tabs-mode:nil -fill-column:99 -End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-compose.cpp b/src/libnr/nr-compose.cpp deleted file mode 100644 index 74f9d036b..000000000 --- a/src/libnr/nr-compose.cpp +++ /dev/null @@ -1,1197 +0,0 @@ -#define __NR_COMPOSE_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <string.h> -#include "nr-pixops.h" - -#ifdef WITH_MMX -/* fixme: */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ -int nr_have_mmx (void); -void nr_mmx_R8G8B8A8_P_EMPTY_A8_RGBAP (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned char *c); -void nr_mmx_R8G8B8A8_P_R8G8B8A8_P_A8_RGBAP (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned char *c); -void nr_mmx_R8G8B8_R8G8B8_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -#define NR_PIXOPS_MMX nr_have_mmx () -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif - -// Naming: nr_RESULT_BACKGROUND_FOREGROUND_extra - -void -nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - if (alpha == 0) { - memset(px, 0x0, 4 * w); - } else if (alpha == 255) { - memcpy(px, spx, 4 * w); - } else { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - *d++ = *s++; - *d++ = *s++; - *d++ = *s++; - *d++ = NR_PREMUL_111(*s, alpha); - s++; - } - } - px += rs; - spx += srs; - } -} - -void -nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - if (alpha == 0) { - memset(px, 0x0, 4 * w); - } else { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - d[3] = 0; - } else if (s[3] == 255) { - memcpy(d, s, 4); - } else { - d[0] = NR_DEMUL_111(s[0], s[3]); - d[1] = NR_DEMUL_111(s[1], s[3]); - d[2] = NR_DEMUL_111(s[2], s[3]); - d[3] = NR_PREMUL_111(s[3], alpha); - } - d += 4; - s += 4; - } - } - px += rs; - spx += srs; - } -} - -void -nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - if (alpha == 0) { - memset(px, 0x0, 4 * w); - } else if (alpha == 255) { - for (c = w; c > 0; c--) { - d[0] = NR_PREMUL_111(s[0], s[3]); - d[1] = NR_PREMUL_111(s[1], s[3]); - d[2] = NR_PREMUL_111(s[2], s[3]); - d[3] = s[3]; - d += 4; - s += 4; - } - } else { - for (c = w; c > 0; c--) { - if (s[3] == 0) { - memset(d, 0, 4); - } else { - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - d[0] = NR_PREMUL_121(s[0], a); - d[1] = NR_PREMUL_121(s[1], a); - d[2] = NR_PREMUL_121(s[2], a); - d[3] = NR_NORMALIZE_21(a); - } - d += 4; - s += 4; - } - } - px += rs; - spx += srs; - } -} - -void -nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - if (alpha == 0) { - memset(px, 0x0, 4 * w); - } else if (alpha == 255) { - memcpy(px, spx, 4 * w); - } else { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - d[0] = NR_PREMUL_111(s[0], alpha); - d[1] = NR_PREMUL_111(s[1], alpha); - d[2] = NR_PREMUL_111(s[2], alpha); - d[3] = NR_PREMUL_111(s[3], alpha); - d += 4; - s += 4; - } - } - px += rs; - spx += srs; - } -} - -void -nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - if (alpha == 0) { - /* NOP */ - } else if (alpha == 255) { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - /* Transparent FG, NOP */ - } else if ((s[3] == 255) || (d[3] == 0)) { - /* Full coverage, COPY */ - memcpy(d, s, 4); - } else { - /* Full composition */ - unsigned int ca; - ca = NR_COMPOSEA_112(s[3], d[3]); - d[0] = NR_COMPOSENNN_111121(s[0], s[3], d[0], d[3], ca); - d[1] = NR_COMPOSENNN_111121(s[1], s[3], d[1], d[3], ca); - d[2] = NR_COMPOSENNN_111121(s[2], s[3], d[2], d[3], ca); - d[3] = NR_NORMALIZE_21(ca); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - if (a == 0) { - /* Transparent FG, NOP */ - } else if ((a == 255*255) || (d[3] == 0)) { - /* Full coverage, COPY */ - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - d[3] = NR_NORMALIZE_21(a); - } else { - /* Full composition */ - unsigned int ca; - ca = NR_COMPOSEA_213(a, d[3]); - d[0] = NR_COMPOSENNN_121131(s[0], a, d[0], d[3], ca); - d[1] = NR_COMPOSENNN_121131(s[1], a, d[1], d[3], ca); - d[2] = NR_COMPOSENNN_121131(s[2], a, d[2], d[3], ca); - d[3] = NR_NORMALIZE_31(ca); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -void -nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - if (alpha == 0) { - /* NOP */ - } else if (alpha == 255) { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - /* Transparent FG, NOP */ - } else if (s[3] == 255) { - /* Full coverage, demul src */ - // dc' = ((1 - sa) * da*dc + sc)/da' = sc/da' = sc - // da' = 1 - (1 - sa) * (1 - da) = 1 - 0 * (1 - da) = 1 - memcpy(d, s, 4); - } else if (d[3] == 0) { - /* Full coverage, demul src */ - // dc' = ((1 - sa) * da*dc + sc)/da' = sc/da' = sc/sa = sc/sa - // da' = 1 - (1 - sa) * (1 - da) = 1 - (1 - sa) = sa - d[0] = NR_DEMUL_111(s[0], s[3]); - d[1] = NR_DEMUL_111(s[1], s[3]); - d[2] = NR_DEMUL_111(s[2], s[3]); - d[3] = s[3]; - } else { - /* Full composition */ - // dc' = ((1 - sa) * da*dc + sc)/da' = ((1 - sa) * da*dc + sc)/da' - // da' = 1 - (1 - sa) * (1 - da) = 1 - (1 - sa) * (1 - da) - unsigned int da = NR_COMPOSEA_112(s[3], d[3]); - d[0] = NR_COMPOSEPNN_111121(s[0], s[3], d[0], d[3], da); - d[1] = NR_COMPOSEPNN_111121(s[1], s[3], d[1], d[3], da); - d[2] = NR_COMPOSEPNN_111121(s[2], s[3], d[2], d[3], da); - d[3] = NR_NORMALIZE_21(da); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - if (a == 0) { - /* Transparent FG, NOP */ - } else if (d[3] == 0) { - /* Full coverage, demul src */ - // dc' = ((1 - alpha*sa) * da*dc + alpha*sc)/da' = alpha*sc/da' = alpha*sc/(alpha*sa) = sc/sa - // da' = 1 - (1 - alpha*sa) * (1 - da) = 1 - (1 - alpha*sa) = alpha*sa - d[0] = NR_DEMUL_111(s[0], s[3]); - d[1] = NR_DEMUL_111(s[1], s[3]); - d[2] = NR_DEMUL_111(s[2], s[3]); - d[3] = NR_NORMALIZE_21(a); - } else { - // dc' = ((1 - alpha*sa) * da*dc + alpha*sc)/da' - // da' = 1 - (1 - alpha*sa) * (1 - da) - unsigned int da = NR_COMPOSEA_213(a, d[3]); - d[0] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[0], alpha), a, d[0], d[3], da); - d[1] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[1], alpha), a, d[1], d[3], da); - d[2] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[2], alpha), a, d[2], d[3], da); - d[3] = NR_NORMALIZE_31(da); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - if (alpha == 0) { - /* NOP */ - } else if (alpha == 255) { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - /* Transparent FG, NOP */ - } else if (s[3] == 255) { - /* Opaque FG, COPY */ - // dc' = (1 - sa) * dc + sa*sc = sa*sc = sc - // da' = 1 - (1 - sa) * (1 - da) = 1 - 0 * (1 - da) = 1 (= sa) - memcpy(d, s, 4); - } else if (d[3] == 0) { - /* Transparent BG, premul src */ - // dc' = (1 - sa) * dc + sa*sc = sa*sc - // da' = 1 - (1 - sa) * (1 - da) = 1 - (1 - sa) = sa - d[0] = NR_PREMUL_111(s[0], s[3]); - d[1] = NR_PREMUL_111(s[1], s[3]); - d[2] = NR_PREMUL_111(s[2], s[3]); - d[3] = s[3]; - } else { - // dc' = (1 - sa) * dc + sa*sc - // da' = 1 - (1 - sa) * (1 - da) - d[0] = NR_COMPOSENPP_1111(s[0], s[3], d[0]); - d[1] = NR_COMPOSENPP_1111(s[1], s[3], d[1]); - d[2] = NR_COMPOSENPP_1111(s[2], s[3], d[2]); - d[3] = NR_COMPOSEA_111(s[3], d[3]); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112 (s[3], alpha); - if (a == 0) { - /* Transparent FG, NOP */ - } else if (d[3] == 0) { - /* Transparent BG, premul src */ - // dc' = (1 - alpha*sa) * dc + alpha*sa*sc = alpha*sa*sc - // da' = 1 - (1 - alpha*sa) * (1 - da) = 1 - (1 - alpha*sa) = alpha*sa - d[0] = NR_PREMUL_121(s[0], a); - d[1] = NR_PREMUL_121(s[1], a); - d[2] = NR_PREMUL_121(s[2], a); - d[3] = NR_NORMALIZE_21(a); - } else { - // dc' = (1 - alpha*sa) * dc + alpha*sa*sc - // da' = 1 - (1 - alpha*sa) * (1 - da) - d[0] = NR_COMPOSENPP_1211(s[0], a, d[0]); - d[1] = NR_COMPOSENPP_1211(s[1], a, d[1]); - d[2] = NR_COMPOSENPP_1211(s[2], a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - if (alpha == 0) { - /* Transparent FG, NOP */ - } else if (alpha == 255) { - /* Simple */ - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - /* Transparent FG, NOP */ - } else if ((s[3] == 255) || (d[3] == 0)) { - /* Transparent BG, COPY */ - memcpy(d, s, 4); - } else { - d[0] = NR_COMPOSEPPP_1111(s[0], s[3], d[0]); - d[1] = NR_COMPOSEPPP_1111(s[1], s[3], d[1]); - d[2] = NR_COMPOSEPPP_1111(s[2], s[3], d[2]); - d[3] = NR_COMPOSEA_111(s[3], d[3]); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - if (s[3] == 0) { - /* Transparent FG, NOP */ - } else if (d[3] == 0) { - /* Transparent BG, COPY */ - d[0] = NR_PREMUL_111(s[0], alpha); - d[1] = NR_PREMUL_111(s[1], alpha); - d[2] = NR_PREMUL_111(s[2], alpha); - d[3] = NR_PREMUL_111(s[3], alpha); - } else { - // dc' = (1 - alpha*sa) * dc + alpha*sc - // da' = 1 - (1 - alpha*sa) * (1 - da) - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - d[0] = NR_COMPOSEPPP_2211(NR_PREMUL_112(alpha, s[0]), a, d[0]); - d[1] = NR_COMPOSEPPP_2211(NR_PREMUL_112(alpha, s[1]), a, d[1]); - d[2] = NR_COMPOSEPPP_2211(NR_PREMUL_112(alpha, s[2]), a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - d += 4; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -/* Masked operations */ - -void -nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - d[3] = NR_PREMUL_111(s[3], m[0]); - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112 (s[3], m[0]); - if (a == 0) { - d[3] = 0; - } else if (a == 255*255) { - memcpy(d, s, 4); - } else { - // dc' = ((1 - m*sa) * da*dc + m*sc)/da' = m*sc/da' = m*sc/(m*sa) = sc/sa - // da' = 1 - (1 - m*sa) * (1 - da) = 1 - (1 - m*sa) = m*sa - d[0] = NR_DEMUL_111(s[0], s[3]); - d[1] = NR_DEMUL_111(s[1], s[3]); - d[2] = NR_DEMUL_111(s[2], s[3]); - d[3] = NR_NORMALIZE_21(a); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - memset(d, 0, 4); - } else if (a == 255*255) { - memcpy(d, s, 4); - } else { - d[0] = NR_PREMUL_121(s[0], a); - d[1] = NR_PREMUL_121(s[1], a); - d[2] = NR_PREMUL_121(s[2], a); - d[3] = NR_NORMALIZE_21(a); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - d[0] = NR_PREMUL_111(s[0], m[0]); - d[1] = NR_PREMUL_111(s[1], m[0]); - d[2] = NR_PREMUL_111(s[2], m[0]); - d[3] = NR_PREMUL_111(s[3], m[0]); - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - /* Transparent FG, NOP */ - } else if ((a == 255*255) || (d[3] == 0)) { - /* Full coverage, COPY */ - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - d[3] = NR_NORMALIZE_21(a); - } else { - /* Full composition */ - unsigned int ca; - ca = NR_COMPOSEA_213(a, d[3]); - d[0] = NR_COMPOSENNN_121131(s[0], a, d[0], d[3], ca); - d[1] = NR_COMPOSENNN_121131(s[1], a, d[1], d[3], ca); - d[2] = NR_COMPOSENNN_121131(s[2], a, d[2], d[3], ca); - d[3] = NR_NORMALIZE_31(ca); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - /* Transparent FG, NOP */ - } else if (a == 255*255) { - /* Opaque FG, COPY */ - memcpy(d, s, 4); - } else if (d[3] == 0) { - /* Full coverage, demul src */ - // dc' = ((1 - m*sa) * da*dc + m*sc)/da' = m*sc/da' = m*sc/(m*sa) = sc/sa - // da' = 1 - (1 - m*sa) * (1 - da) = 1 - (1 - m*sa) = m*sa - d[0] = NR_DEMUL_111(s[0], s[3]); - d[1] = NR_DEMUL_111(s[1], s[3]); - d[2] = NR_DEMUL_111(s[2], s[3]); - d[3] = NR_NORMALIZE_21(a); - } else if (m[0] == 255) { - /* Full composition */ - // dc' = ((1 - m*sa) * da*dc + m*sc)/da' = ((1 - sa) * da*dc + sc)/da' - // da' = 1 - (1 - m*sa) * (1 - da) = 1 - (1 - sa) * (1 - da) - unsigned int da = NR_COMPOSEA_112(s[3], d[3]); - d[0] = NR_COMPOSEPNN_111121(s[0], s[3], d[0], d[3], da); - d[1] = NR_COMPOSEPNN_111121(s[1], s[3], d[1], d[3], da); - d[2] = NR_COMPOSEPNN_111121(s[2], s[3], d[2], d[3], da); - d[3] = NR_NORMALIZE_21(da); - } else { - // dc' = ((1 - m*sa) * da*dc + m*sc)/da' - // da' = 1 - (1 - m*sa) * (1 - da) - unsigned int da = NR_COMPOSEA_213(a, d[3]); - d[0] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[0], m[0]), a, d[0], d[3], da); - d[1] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[1], m[0]), a, d[1], d[3], da); - d[2] = NR_COMPOSEPNN_221131(NR_PREMUL_112(s[2], m[0]), a, d[2], d[3], da); - d[3] = NR_NORMALIZE_31(da); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r>0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c>0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - /* Transparent FG, NOP */ - } else if (a == 255*255) { - memcpy(d, s, 4); - } else { - d[0] = NR_COMPOSENPP_1211(s[0], a, d[0]); - d[1] = NR_COMPOSENPP_1211(s[1], a, d[1]); - d[2] = NR_COMPOSENPP_1211(s[2], a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int r, c; - - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - const unsigned char *m = mpx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112 (s[3], m[0]); - if (a == 0) { - /* Transparent FG, NOP */ - } else if (a == 255*255) { - /* Opaque FG, COPY */ - memcpy(d, s, 4); - } else if (d[3] == 0) { - /* Transparent BG, COPY */ - // dc' = (1 - m*sa) * dc + m*sc = m*sc - // da' = 1 - (1 - m*sa) * (1 - da) = 1 - (1 - m*sa) = m*sa - d[0] = NR_PREMUL_111 (s[0], m[0]); - d[1] = NR_PREMUL_111 (s[1], m[0]); - d[2] = NR_PREMUL_111 (s[2], m[0]); - d[3] = NR_NORMALIZE_21(a); - } else { - // dc' = (1 - m*sa) * dc + m*sc - // da' = 1 - (1 - m*sa) * (1 - da) - d[0] = NR_COMPOSEPPP_2211 (NR_PREMUL_112 (s[0], m[0]), a, d[0]); - d[1] = NR_COMPOSEPPP_2211 (NR_PREMUL_112 (s[1], m[0]), a, d[1]); - d[2] = NR_COMPOSEPPP_2211 (NR_PREMUL_112 (s[2], m[0]), a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - d += 4; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -/* FINAL DST MASK COLOR */ - -void -nr_R8G8B8A8_N_EMPTY_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) -{ - unsigned int r, g, b, a; - unsigned int x, y; - - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - - for (y = h; y > 0; y--) { - if (a == 0) { - memset(px, 0, w*4); - } else { - unsigned char *d = px; - const unsigned char *m = mpx; - for (x = w; x > 0; x--) { - d[0] = r; - d[1] = g; - d[2] = b; - d[3] = NR_PREMUL_111 (m[0], a); - d += 4; - m += 1; - } - } - px += rs; - mpx += mrs; - } -} - -void -nr_R8G8B8A8_P_EMPTY_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) -{ - unsigned int r, g, b, a; - unsigned int x, y; - - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - -#ifdef WITH_MMX - if (NR_PIXOPS_MMX) { - unsigned char c[4]; - c[0] = NR_PREMUL_111 (r, a); - c[1] = NR_PREMUL_111 (g, a); - c[2] = NR_PREMUL_111 (b, a); - c[3] = a; - /* WARNING: MMX composer REQUIRES w > 0 and h > 0 */ - nr_mmx_R8G8B8A8_P_EMPTY_A8_RGBAP (px, w, h, rs, mpx, mrs, c); - // This mmx optimized code is approx. 2x faster than the non-optimized code below (Measured by Diederik van Lierop, 2009-12-17) - return; - } -#endif - - if ( a != 255 ){ - // Pre-premultiply color values - r *= a; - g *= a; - b *= a; - } - - for (y = h; y > 0; y--) { - unsigned char *d = px; - const unsigned char *m = mpx; - if (a == 0) { - memset(px, 0, w*4); - } else if (a == 255) { - for (x = w; x > 0; x--) { - d[0] = NR_PREMUL_111(m[0], r); - d[1] = NR_PREMUL_111(m[0], g); - d[2] = NR_PREMUL_111(m[0], b); - d[3] = m[0]; - d += 4; - m += 1; - } - } else { - for (x = w; x > 0; x--) { - // Color values are already premultiplied with a - d[0] = NR_PREMUL_121(m[0], r); - d[1] = NR_PREMUL_121(m[0], g); - d[2] = NR_PREMUL_121(m[0], b); - d[3] = NR_PREMUL_111(m[0], a); - d += 4; - m += 1; - } - } - px += rs; - mpx += mrs; - } -} - -void -nr_R8G8B8_R8G8B8_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) -{ - unsigned int r, g, b, a; - unsigned int x, y; - - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - - if (a == 0) { - /* NOP */ - } else if (a == 255) { - for (y = h; y > 0; y--) { - unsigned char *d = px; - const unsigned char *m = mpx; - for (x = w; x > 0; x--) { - d[0] = NR_COMPOSEN11_1111 (r, m[0], d[0]); - d[1] = NR_COMPOSEN11_1111 (g, m[0], d[1]); - d[2] = NR_COMPOSEN11_1111 (b, m[0], d[2]); - d += 3; - m += 1; - } - px += rs; - mpx += mrs; - } - } else { - for (y = h; y > 0; y--) { - unsigned char *d = px; - const unsigned char *m = mpx; - for (x = w; x > 0; x--) { - // dc' = (1 - m*sa) * dc + m*sa*sc - unsigned int alpha; - alpha = NR_PREMUL_112 (a, m[0]); - d[0] = NR_COMPOSEN11_1211 (r, alpha, d[0]); - d[1] = NR_COMPOSEN11_1211 (g, alpha, d[1]); - d[2] = NR_COMPOSEN11_1211 (b, alpha, d[2]); - d += 3; - m += 1; - } - px += rs; - mpx += mrs; - } - } -} - -void -nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba) -{ - unsigned int r, g, b, a; - unsigned int x, y; - - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - - if (a == 0) { - /* NOP */ - } else if (a == 255) { - for (y = h; y > 0; y--) { - unsigned char *d = px; - const unsigned char *m = mpx; - for (x = w; x > 0; x--) { - if (m[0] == 0) { - /* Transparent FG, NOP */ - } else if (m[0] == 255 || d[3] == 0) { - /* Full coverage, COPY */ - d[0] = r; - d[1] = g; - d[2] = b; - d[3] = m[0]; - } else { - /* Full composition */ - unsigned int da = NR_COMPOSEA_112(m[0], d[3]); - d[0] = NR_COMPOSENNN_111121(r, m[0], d[0], d[3], da); - d[1] = NR_COMPOSENNN_111121(g, m[0], d[1], d[3], da); - d[2] = NR_COMPOSENNN_111121(b, m[0], d[2], d[3], da); - d[3] = NR_NORMALIZE_21(da); - } - d += 4; - m += 1; - } - px += rs; - mpx += mrs; - } - } else { - for (y = h; y > 0; y--) { - unsigned char *d = px; - const unsigned char *m = mpx; - for (x = w; x > 0; x--) { - unsigned int ca; - ca = NR_PREMUL_112 (m[0], a); - if (ca == 0) { - /* Transparent FG, NOP */ - } else if (d[3] == 0) { - /* Full coverage, COPY */ - d[0] = r; - d[1] = g; - d[2] = b; - d[3] = NR_NORMALIZE_21(ca); - } else { - /* Full composition */ - unsigned int da = NR_COMPOSEA_213(ca, d[3]); - d[0] = NR_COMPOSENNN_121131(r, ca, d[0], d[3], da); - d[1] = NR_COMPOSENNN_121131(g, ca, d[1], d[3], da); - d[2] = NR_COMPOSENNN_121131(b, ca, d[2], d[3], da); - d[3] = NR_NORMALIZE_31(da); - } - d += 4; - m += 1; - } - px += rs; - mpx += mrs; - } - } -} - -void -nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned long rgba) -{ - unsigned int r, g, b, a; - unsigned int x, y; - - r = NR_RGBA32_R (rgba); - g = NR_RGBA32_G (rgba); - b = NR_RGBA32_B (rgba); - a = NR_RGBA32_A (rgba); - -#ifdef WITH_MMX - if (NR_PIXOPS_MMX && a != 0) { - unsigned char c[4]; - c[0] = NR_PREMUL_111 (r, a); - c[1] = NR_PREMUL_111 (g, a); - c[2] = NR_PREMUL_111 (b, a); - c[3] = a; - /* WARNING: MMX composer REQUIRES w > 0 and h > 0 */ - nr_mmx_R8G8B8A8_P_R8G8B8A8_P_A8_RGBAP (px, w, h, rs, spx, srs, c); - return; - } -#endif - - if (a == 0) { - /* Transparent FG, NOP */ - } else if (a == 255) { - /* Simple */ - for (y = h; y > 0; y--) { - unsigned char *d, *s; - d = (unsigned char *) px; - s = (unsigned char *) spx; - for (x = w; x > 0; x--) { - if (s[0] == 0) { - /* Transparent FG, NOP */ - } else { - /* Full composition */ - unsigned int invca = 255-s[0]; // By swapping the arguments GCC can better optimize these calls - d[0] = NR_COMPOSENPP_1111(d[0], invca, r); - d[1] = NR_COMPOSENPP_1111(d[1], invca, g); - d[2] = NR_COMPOSENPP_1111(d[2], invca, b); - d[3] = NR_COMPOSEA_111(s[0], d[3]); - } - d += 4; - s += 1; - } - px += rs; - spx += srs; - } - } else { - for (y = h; y > 0; y--) { - unsigned char *d, *s; - d = (unsigned char *) px; - s = (unsigned char *) spx; - for (x = w; x > 0; x--) { - unsigned int ca; - ca = NR_PREMUL_112 (s[0], a); - if (ca == 0) { - /* Transparent FG, NOP */ - } else { - /* Full composition */ - unsigned int invca = 255*255-ca; // By swapping the arguments GCC can better optimize these calls - d[0] = NR_COMPOSENPP_1211(d[0], invca, r); - d[1] = NR_COMPOSENPP_1211(d[1], invca, g); - d[2] = NR_COMPOSENPP_1211(d[2], invca, b); - d[3] = NR_COMPOSEA_211(ca, d[3]); - } - d += 4; - s += 1; - } - px += rs; - spx += srs; - } - } -} - -/* RGB */ - -void -nr_R8G8B8_R8G8B8_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - -#ifdef WITH_MMX - if (NR_PIXOPS_MMX && alpha != 0) { - /* WARNING: MMX composer REQUIRES w > 0 and h > 0 */ - nr_mmx_R8G8B8_R8G8B8_R8G8B8A8_P (px, w, h, rs, spx, srs, alpha); - return; - } -#endif - - if (alpha == 0) { - /* NOP */ - } else if (alpha == 255) { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - // dc' = (1 - alpha*sa) * dc + alpha*sc = (1 - sa) * dc + sc - if (s[3] == 0) { - /* NOP */ - } else if (s[3] == 255) { - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - } else { - d[0] = NR_COMPOSEP11_1111(s[0], s[3], d[0]); - d[1] = NR_COMPOSEP11_1111(s[1], s[3], d[1]); - d[2] = NR_COMPOSEP11_1111(s[2], s[3], d[2]); - } - d += 3; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - // dc' = (1 - alpha*sa) * dc + alpha*sc - if (a == 0) { - /* NOP */ - } else { - d[0] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[0], alpha), a, d[0]); - d[1] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[1], alpha), a, d[1]); - d[2] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[2], alpha), a, d[2]); - } - /* a == 255 is impossible, because alpha < 255 */ - d += 3; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -void -nr_R8G8B8_R8G8B8_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha) -{ - unsigned int r, c; - - if (alpha == 0) { - /* NOP */ - } else if (alpha == 255) { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - // dc' = (1 - alpha*sa) * dc + alpha*sa*sc = (1 - sa) * dc + sa*sc - if (s[3] == 0) { - /* NOP */ - } else if (s[3] == 255) { - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - } else { - d[0] = NR_COMPOSEN11_1111(s[0], s[3], d[0]); - d[1] = NR_COMPOSEN11_1111(s[1], s[3], d[1]); - d[2] = NR_COMPOSEN11_1111(s[2], s[3], d[2]); - } - d += 3; - s += 4; - } - px += rs; - spx += srs; - } - } else { - for (r = h; r > 0; r--) { - unsigned char *d = px; - const unsigned char *s = spx; - for (c = w; c > 0; c--) { - unsigned int a; - a = NR_PREMUL_112(s[3], alpha); - // dc' = (1 - alpha*sa) * dc + alpha*sa*sc - if (a == 0) { - /* NOP */ - } else { - d[0] = NR_COMPOSEN11_1211(s[0], a, d[0]); - d[1] = NR_COMPOSEN11_1211(s[1], a, d[1]); - d[2] = NR_COMPOSEN11_1211(s[2], a, d[2]); - } - /* a == 255 is impossible, because alpha < 255 */ - d += 3; - s += 4; - } - px += rs; - spx += srs; - } - } -} - -void -nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int x, y; - - for (y = h; y > 0; y--) { - unsigned char* d = px; - const unsigned char* s = spx; - const unsigned char* m = mpx; - for (x = w; x > 0; x--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - /* NOP */ - } else if (a == 255*255) { - memcpy(d, s, 3); - } else { - // dc' = (1 - m*sa) * dc + m*sc - d[0] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[0], m[0]), a, d[0]); - d[1] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[1], m[0]), a, d[1]); - d[2] = NR_COMPOSEP11_2211(NR_PREMUL_112(s[2], m[0]), a, d[2]); - } - d += 3; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - -void -nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs) -{ - unsigned int x, y; - - for (y = h; y > 0; y--) { - unsigned char* d = px; - const unsigned char* s = spx; - const unsigned char* m = mpx; - for (x = w; x > 0; x--) { - unsigned int a; - a = NR_PREMUL_112(s[3], m[0]); - if (a == 0) { - /* NOP */ - } else if (a == 255*255) { - memcpy(d, s, 3); - } else { - // dc' = (1 - m*sa) * dc + m*sa*sc - d[0] = NR_COMPOSEN11_1211(s[0], a, d[0]); - d[1] = NR_COMPOSEN11_1211(s[1], a, d[1]); - d[2] = NR_COMPOSEN11_1211(s[2], a, d[2]); - } - d += 3; - s += 4; - m += 1; - } - px += rs; - spx += srs; - mpx += mrs; - } -} - - diff --git a/src/libnr/nr-compose.h b/src/libnr/nr-compose.h deleted file mode 100644 index 4cecfac60..000000000 --- a/src/libnr/nr-compose.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __NR_COMPOSE_H__ -#define __NR_COMPOSE_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -/* FINAL DST SRC */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); - -/* FINAL DST SRC MASK */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int srs, - const unsigned char *mpx, int mrs); - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8 (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8 (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8 (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8 (unsigned char *p, int w, int h, int rs, - const unsigned char *s, int srs, - const unsigned char *m, int mrs); - -/* FINAL DST MASK COLOR */ - -void nr_R8G8B8A8_N_EMPTY_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); -void nr_R8G8B8A8_P_EMPTY_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); - -void nr_R8G8B8_R8G8B8_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); -void nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); -void nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32 (unsigned char *px, int w, int h, int rs, const unsigned char *mpx, int mrs, unsigned long rgba); - -/* RGB */ - -void nr_R8G8B8_R8G8B8_R8G8B8A8_P (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8_R8G8B8_R8G8B8A8_N (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, unsigned int alpha); -void nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs); -void nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8 (unsigned char *px, int w, int h, int rs, const unsigned char *spx, int srs, const unsigned char *mpx, int mrs); - -#endif diff --git a/src/libnr/testnr.cpp b/src/libnr/testnr.cpp deleted file mode 100644 index 12dce4c52..000000000 --- a/src/libnr/testnr.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#define __TESTNR_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#if defined (_WIN32) || defined (__WIN32__) -# include <windows.h> -#include <glib.h> -#endif - - -#include "nr-blit.h" - -static double -get_time (void) -{ - GTimeVal tv; - g_get_current_time (&tv); - return tv.tv_sec + 1e-6 * tv.tv_usec; -} - -static unsigned int -rand_byte (void) -{ - return (int) (256.0 * rand () / (RAND_MAX + 1.0)); -} - -int -main (int argc, const char **argv) -{ - double start, end; - NRPixBlock d, m[16]; - int count, i; - - srand (time (NULL)); - - printf ("Initializing buffers\n"); - - /* Destination */ - nr_pixblock_setup_fast (&d, NR_PIXBLOCK_MODE_R8G8B8A8P, 0, 0, 64, 64, 1); - d.empty = 0; - - /* Masks */ - for (i = 0; i < 16; i++) { - int r, b, c; - nr_pixblock_setup_fast (&m[i], NR_PIXBLOCK_MODE_A8, 0, 0, 64, 64, 0); - for (r = 0; r < 64; r++) { - unsigned int q; - unsigned char *p; - p = NR_PIXBLOCK_PX (&m[i]) + r * m[i].rs; - for (b = 0; b < 8; b++) { - q = rand_byte (); - if (q < 120) { - for (c = 0; c < 8; c++) *p++ = 0; - } else if (q < 240) { - for (c = 0; c < 8; c++) *p++ = 255; - } else { - for (c = 0; c < 8; c++) *p++ = rand_byte (); - } - } - } - m[i].empty = 0; - } - - printf ("Random transparency\n"); - count = 0; - start = end = get_time (); - while ((end - start) < 5.0) { - unsigned char r, g, b, a; - r = rand_byte (); - g = rand_byte (); - b = rand_byte (); - a = rand_byte (); - - for (i = 0; i < 16; i++) { - nr_blit_pixblock_mask_rgba32 (&d, &m[i], (a << 24) | (g << 16) | (b << 8) | a); - count += 1; - } - end = get_time (); - } - printf ("Did %d [64x64] random buffers in %f sec\n", count, end - start); // localizing ok - printf ("%f buffers per second\n", count / (end - start)); // localizing ok - printf ("%f pixels per second\n", count * (64 * 64) / (end - start)); // localizing ok - - return 0; -} |
