summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2010-08-05 04:01:01 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2010-08-05 04:01:01 +0000
commit13e643c744ca21ea6f5a50d404bec8aac886a808 (patch)
tree94f0ad849ad7f2ad60fb442848a46f31a89fe1a0 /src
parentFix mask rendering to use luminance-to-alpha (diff)
downloadinkscape-13e643c744ca21ea6f5a50d404bec8aac886a808.tar.gz
inkscape-13e643c744ca21ea6f5a50d404bec8aac886a808.zip
Wholesale cruft removal part 5; completely remove RasterFont
(bzr r9508.1.50)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/dialogs/text-edit.cpp74
-rw-r--r--src/display/Makefile_insert1
-rw-r--r--src/display/nr-filter-pixops.h152
-rw-r--r--src/libnr/Makefile_insert19
-rw-r--r--src/libnr/nr-blit.cpp300
-rw-r--r--src/libnr/nr-blit.h32
-rw-r--r--src/libnr/nr-compose-reference.cpp266
-rw-r--r--src/libnr/nr-compose-reference.h69
-rw-r--r--src/libnr/nr-compose-test.h457
-rw-r--r--src/libnr/nr-compose.cpp1197
-rw-r--r--src/libnr/nr-compose.h69
-rw-r--r--src/libnr/testnr.cpp92
-rw-r--r--src/libnrtype/FontInstance.cpp76
-rw-r--r--src/libnrtype/Makefile_insert4
-rw-r--r--src/libnrtype/RasterFont.cpp435
-rw-r--r--src/libnrtype/RasterFont.h66
-rw-r--r--src/libnrtype/font-instance.h12
-rw-r--r--src/libnrtype/font-lister.cpp3
-rw-r--r--src/libnrtype/nrtype-forward.h3
-rw-r--r--src/libnrtype/raster-glyph.h49
-rw-r--r--src/libnrtype/raster-position.h46
-rw-r--r--src/widgets/font-selector.cpp326
-rw-r--r--src/widgets/font-selector.h15
24 files changed, 61 insertions, 3704 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 03b58c610..3845823f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -259,7 +259,7 @@ TESTS = $(check_PROGRAMS) ../share/extensions/test/run-all-extension-tests
XFAIL_TESTS = $(check_PROGRAMS) ../share/extensions/test/run-all-extension-tests
# including the the testsuites here ensures that they get distributed
-cxxtests_SOURCES = cxxtests.cpp libnr/nr-compose-reference.cpp $(CXXTEST_TESTSUITES)
+cxxtests_SOURCES = cxxtests.cpp $(CXXTEST_TESTSUITES)
cxxtests_LDADD = $(all_libs)
cxxtests.cpp: $(CXXTEST_TESTSUITES) $(CXXTEST_TEMPLATE)
diff --git a/src/dialogs/text-edit.cpp b/src/dialogs/text-edit.cpp
index dc71de7c3..957a3c63c 100644
--- a/src/dialogs/text-edit.cpp
+++ b/src/dialogs/text-edit.cpp
@@ -364,8 +364,11 @@ sp_text_edit_dialog (void)
}
/* Font preview */
- GtkWidget *preview = sp_font_preview_new ();
- gtk_box_pack_start (GTK_BOX (vb), preview, TRUE, TRUE, 4);
+ GtkLabel *preview = (GtkLabel*) gtk_label_new(NULL);
+ gtk_label_set_ellipsize(preview, PANGO_ELLIPSIZE_END);
+ gtk_label_set_justify(preview, GTK_JUSTIFY_CENTER);
+ gtk_label_set_line_wrap(preview, FALSE);
+ gtk_box_pack_start (GTK_BOX (vb), (GtkWidget*) preview, TRUE, TRUE, 4);
g_object_set_data (G_OBJECT (dlg), "preview", preview);
}
@@ -684,7 +687,7 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (TRUE));
- GtkWidget *notebook = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "notebook");
+ //GtkWidget *notebook = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "notebook");
GtkWidget *textw = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "textw");
GtkWidget *fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel");
GtkWidget *preview = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "preview");
@@ -695,6 +698,12 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
SPItem *text = sp_ted_get_selected_text_item ();
+ /* TRANSLATORS: Test string used in text and font dialog (when no
+ * text has been entered) to get a preview of the font. Choose
+ * some representative characters that users of your locale will be
+ * interested in. */
+ gchar *phrase = g_strdup(_("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"));
+
Inkscape::XML::Node *repr;
if (text)
{
@@ -719,12 +728,10 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
gtk_text_buffer_set_text (tb, str, strlen (str));
gtk_text_buffer_set_modified (tb, FALSE);
}
- sp_font_preview_set_phrase (SP_FONT_PREVIEW (preview), str);
- g_free (str);
+ phrase = str;
} else {
gtk_text_buffer_set_text (tb, "", 0);
- sp_font_preview_set_phrase (SP_FONT_PREVIEW (preview), NULL);
}
} // end of if (docontent)
repr = SP_OBJECT_REPR (text);
@@ -761,7 +768,13 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
if (font) {
// the font is oversized, so we need to pass the true size separately
sp_font_selector_set_font (SP_FONT_SELECTOR (fontsel), font, query->font_size.computed);
- sp_font_preview_set_font (SP_FONT_PREVIEW (preview), font, SP_FONT_SELECTOR(fontsel));
+ char *desc = pango_font_description_to_string(font->descr);
+ double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel));
+ gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>",
+ desc, (int) size * PANGO_SCALE, phrase);
+ gtk_label_set_markup(GTK_LABEL(preview), markup);
+ g_free(desc);
+ g_free(markup);
font->Unref();
font=NULL;
}
@@ -799,7 +812,7 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
sp_style_unref(query);
}
-
+ g_free(phrase);
g_object_set_data (G_OBJECT (dlg), "blocked", NULL);
}
@@ -807,7 +820,7 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
static void
sp_text_edit_dialog_text_changed (GtkTextBuffer *tb, GtkWidget *dlg)
{
- GtkWidget *textw, *preview, *apply, *def;
+ GtkWidget *textw, *preview, *apply, *def, *fontsel;
GtkTextIter start, end;
gchar *str;
@@ -820,14 +833,23 @@ sp_text_edit_dialog_text_changed (GtkTextBuffer *tb, GtkWidget *dlg)
preview = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "preview");
apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply");
def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default");
+ fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel");
gtk_text_buffer_get_bounds (tb, &start, &end);
str = gtk_text_buffer_get_text (tb, &start, &end, TRUE);
-
- if (str && *str) {
- sp_font_preview_set_phrase (SP_FONT_PREVIEW (preview), str);
+ font_instance *font = sp_font_selector_get_font(SP_FONT_SELECTOR(fontsel));
+
+ if (font) {
+ gchar *phrase = str && *str ? str : _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()");
+ char *desc = pango_font_description_to_string(font->descr);
+ double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel));
+ gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>",
+ desc, (int) size * PANGO_SCALE, phrase);
+ gtk_label_set_markup(GTK_LABEL(preview), markup);
+ g_free(desc);
+ g_free(markup);
} else {
- sp_font_preview_set_phrase (SP_FONT_PREVIEW (preview), NULL);
+ gtk_label_set_markup(GTK_LABEL(preview), NULL);
}
g_free (str);
@@ -852,7 +874,9 @@ sp_text_edit_dialog_font_changed ( SPFontSelector *fsel,
font_instance *font,
GtkWidget *dlg )
{
- GtkWidget *preview, *apply, *def;
+ GtkWidget *preview, *apply, *def, *fontsel;
+ GtkTextIter start, end;
+ gchar *str;
if (g_object_get_data (G_OBJECT (dlg), "blocked"))
return;
@@ -862,11 +886,27 @@ sp_text_edit_dialog_font_changed ( SPFontSelector *fsel,
preview = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "preview");
apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply");
def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default");
+ fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel");
+
+ GtkTextBuffer *tb = (GtkTextBuffer*)g_object_get_data (G_OBJECT (dlg), "text");
+ gtk_text_buffer_get_bounds (tb, &start, &end);
+ str = gtk_text_buffer_get_text (tb, &start, &end, TRUE);
- sp_font_preview_set_font (SP_FONT_PREVIEW (preview), font, SP_FONT_SELECTOR(fsel));
+ if (font) {
+ gchar *phrase = str && *str ? str : _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()");
+ char *desc = pango_font_description_to_string(font->descr);
+ double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel));
+ gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>",
+ desc, (int) size * PANGO_SCALE, phrase);
+ gtk_label_set_markup(GTK_LABEL(preview), markup);
+ g_free(desc);
+ g_free(markup);
+ } else {
+ gtk_label_set_markup(GTK_LABEL(preview), NULL);
+ }
+ g_free(str);
- if (text)
- {
+ if (text) {
gtk_widget_set_sensitive (apply, TRUE);
}
gtk_widget_set_sensitive (def, TRUE);
diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert
index 843f5aa8f..a860c6a44 100644
--- a/src/display/Makefile_insert
+++ b/src/display/Makefile_insert
@@ -71,7 +71,6 @@ ink_common_sources += \
display/nr-filter-morphology.h \
display/nr-filter-offset.cpp \
display/nr-filter-offset.h \
- display/nr-filter-pixops.h \
display/nr-filter-primitive.cpp \
display/nr-filter-primitive.h \
display/nr-filter-slot.cpp \
diff --git a/src/display/nr-filter-pixops.h b/src/display/nr-filter-pixops.h
deleted file mode 100644
index b2db7067a..000000000
--- a/src/display/nr-filter-pixops.h
+++ /dev/null
@@ -1,152 +0,0 @@
-#ifndef __NR_FILTER_PIXOPS_H__
-#define __NR_FILTER_PIXOPS_H__
-
-#include "libnr/nr-pixblock.h"
-
-/*
- * Per-pixel image manipulation functions.
- * These can be used by all filter primitives, which combine two images on
- * per-pixel basis. These are at least feBlend, feComposite and feMerge.
- *
- * Authors:
- * Niko Kiirala <niko@kiirala.com>
- *
- * Copyright (C) 2007 authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-namespace Inkscape {
-namespace Filters {
-
-/**
- * Mixes the two input images using the function given as template.
- * The result is placed in out.
- * The mixing function should have the following type:
- * void mix(unsigned char *result, unsigned char const *in1,
- * unsigned char const *in2);
- * Each of the parameters for mix-function is a pointer to four bytes of data,
- * giving the RGBA values for that pixel. The mix function must only access
- * the four bytes beginning at a pointer given as parameter.
- */
-/*
- * The implementation is in a header file because of the template. It has to
- * be in the same compilation unit as the code using it. Otherwise, linking
- * the program will not succeed.
- */
-template <void(*blend)(unsigned char *cr, unsigned char const *ca, unsigned char const *cb)>
-void pixops_mix(NRPixBlock &out, NRPixBlock &in1, NRPixBlock &in2) {
- unsigned char *in1_data = NR_PIXBLOCK_PX(&in1);
- unsigned char *in2_data = NR_PIXBLOCK_PX(&in2);
- unsigned char *out_data = NR_PIXBLOCK_PX(&out);
- unsigned char zero_rgba[4] = {0, 0, 0, 0};
-
- if (in1.area.y0 < in2.area.y0) {
- // in1 begins before in2 on y-axis
- for (int y = in1.area.y0 ; y < in2.area.y0 ; y++) {
- int out_line = (y - out.area.y0) * out.rs;
- int in_line = (y - in1.area.y0) * in1.rs;
- for (int x = in1.area.x0 ; x < in1.area.x1 ; x++) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- in1_data + in_line + 4 * (x - in1.area.x0),
- zero_rgba);
- }
- }
- } else if (in1.area.y0 > in2.area.y0) {
- // in2 begins before in1 on y-axis
- for (int y = in2.area.y0 ; y < in1.area.y0 ; y++) {
- int out_line = (y - out.area.y0) * out.rs;
- int in_line = (y - in2.area.y0) * in2.rs;
- for (int x = in2.area.x0 ; x < in2.area.x1 ; x++) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- zero_rgba,
- in2_data + in_line + 4 * (x - in2.area.x0));
- }
- }
- }
-
- for (int y = std::max(in1.area.y0, in2.area.y0) ;
- y < std::min(in1.area.y1, in2.area.y1) ; ++y) {
- int out_line = (y - out.area.y0) * out.rs;
- int in1_line = (y - in1.area.y0) * in1.rs;
- int in2_line = (y - in2.area.y0) * in2.rs;
-
- if (in1.area.x0 < in2.area.x0) {
- // in1 begins before in2 on x-axis
- for (int x = in1.area.x0 ; x < in2.area.x0 ; ++x) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- in1_data + in1_line + 4 * (x - in1.area.x0),
- zero_rgba);
- }
- } else if (in1.area.x0 > in2.area.x0) {
- // in2 begins before in1 on x-axis
- for (int x = in2.area.x0 ; x < in1.area.x0 ; ++x) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- zero_rgba,
- in2_data + in2_line + 4 * (x - in2.area.x0));
- }
- }
-
- for (int x = std::max(in1.area.x0, in2.area.x0) ;
- x < std::min(in1.area.x1, in2.area.x1) ; ++x) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- in1_data + in1_line + 4 * (x - in1.area.x0),
- in2_data + in2_line + 4 * (x - in2.area.x0));
- }
-
- if (in1.area.x1 > in2.area.x1) {
- // in1 ends after in2 on x-axis
- for (int x = in2.area.x1 ; x < in1.area.x1 ; ++x) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- in1_data + in1_line + 4 * (x - in1.area.x0),
- zero_rgba);
- }
- } else if (in1.area.x1 < in2.area.x1) {
- // in2 ends after in1 on x-axis
- for (int x = in1.area.x1 ; x < in2.area.x1 ; ++x) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- zero_rgba,
- in2_data + in2_line + 4 * (x - in2.area.x0));
- }
- }
- }
-
- if (in1.area.y1 > in2.area.y1) {
- // in1 ends after in2 on y-axis
- for (int y = in2.area.y1 ; y < in1.area.y1 ; y++) {
- int out_line = (y - out.area.y0) * out.rs;
- int in_line = (y - in1.area.y0) * in1.rs;
- for (int x = in1.area.x0 ; x < in1.area.x1 ; x++) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- in1_data + in_line + 4 * (x - in1.area.x0),
- zero_rgba);
- }
- }
- } else if (in1.area.y1 < in2.area.y1) {
- // in2 ends after in1 on y-axis
- for (int y = in1.area.y1 ; y < in2.area.y1 ; y++) {
- int out_line = (y - out.area.y0) * out.rs;
- int in_line = (y - in2.area.y0) * in2.rs;
- for (int x = in2.area.x0 ; x < in2.area.x1 ; x++) {
- blend(out_data + out_line + 4 * (x - out.area.x0),
- zero_rgba,
- in2_data + in_line + 4 * (x - in2.area.x0));
- }
- }
- }
-}
-
-} /* namespace Filters */
-} /* namespace Inkscape */
-
-#endif // __NR_FILTER_PIXOPS_H_
-/*
- 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/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;
-}
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index bdf700346..a41f7d370 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -24,7 +24,6 @@
#include "libnr/nr-rect.h"
#include "libnrtype/font-glyph.h"
#include "libnrtype/font-instance.h"
-#include "libnrtype/RasterFont.h"
#include "livarot/Path.h"
#include "util/unordered-containers.h"
@@ -44,8 +43,6 @@ struct font_style_equal : public std::binary_function<font_style, font_style, bo
bool operator()(font_style const &a, font_style const &b) const;
};
-typedef INK_UNORDERED_MAP<font_style, raster_font*, font_style_hash, font_style_equal> StyleMap;
-
static const double STROKE_WIDTH_THREASHOLD = 0.01;
@@ -182,7 +179,6 @@ font_instance::font_instance(void) :
nbGlyph(0),
maxGlyph(0),
glyphs(0),
- loadedPtr(new StyleMap()),
theFace(0)
{
//printf("font instance born\n");
@@ -190,12 +186,6 @@ font_instance::font_instance(void) :
font_instance::~font_instance(void)
{
- if ( loadedPtr ) {
- StyleMap* tmp = static_cast<StyleMap*>(loadedPtr);
- delete tmp;
- loadedPtr = 0;
- }
-
if ( daddy ) {
daddy->UnrefFace(this);
daddy = 0;
@@ -793,72 +783,6 @@ double font_instance::Advance(int glyph_id,bool vertical)
return 0;
}
-
-raster_font* font_instance::RasterFont(const Geom::Matrix &trs, double stroke_width, bool vertical, JoinType stroke_join, ButtType stroke_cap, float /*miter_limit*/)
-{
- font_style nStyle;
- nStyle.transform=trs;
- nStyle.vertical=vertical;
- nStyle.stroke_width=stroke_width;
- nStyle.stroke_cap=stroke_cap;
- nStyle.stroke_join=stroke_join;
- nStyle.nbDash=0;
- nStyle.dash_offset=0;
- nStyle.dashes=NULL;
- return RasterFont(nStyle);
-}
-
-raster_font* font_instance::RasterFont(const font_style &inStyle)
-{
- raster_font *res=NULL;
- double *savDashes=NULL;
- font_style nStyle=inStyle;
- // for some evil reason font_style doesn't have a copy ctor, so the
- // stuff that should be done there is done here instead (because the
- // raster_font ctor copies nStyle).
- if ( (nStyle.stroke_width > 0) && (nStyle.nbDash > 0) && nStyle.dashes ) {
- savDashes=nStyle.dashes;
- nStyle.dashes=(double*)malloc(nStyle.nbDash*sizeof(double));
- memcpy(nStyle.dashes,savDashes,nStyle.nbDash*sizeof(double));
- }
- StyleMap& loadedStyles = *static_cast<StyleMap*>(loadedPtr);
- if ( loadedStyles.find(nStyle) == loadedStyles.end() ) {
- raster_font *nR = new raster_font(nStyle);
- nR->Ref();
- nR->daddy=this;
- loadedStyles[nStyle]=nR;
- res=nR;
- if ( res ) {
- Ref();
- }
- } else {
- res=loadedStyles[nStyle];
- res->Ref();
- if ( nStyle.dashes ) {
- free(nStyle.dashes); // since they're not taken by a new rasterfont
- }
- }
- nStyle.dashes=savDashes;
- return res;
-}
-
-void font_instance::RemoveRasterFont(raster_font* who)
-{
- if ( who ) {
- StyleMap& loadedStyles = *static_cast<StyleMap*>(loadedPtr);
- if ( loadedStyles.find(who->style) == loadedStyles.end() ) {
- //g_print("RemoveRasterFont failed \n");
- // not found
- } else {
- loadedStyles.erase(loadedStyles.find(who->style));
- //g_print("RemoveRasterFont\n");
- Unref();
- }
- }
-}
-
-
-
/*
Local Variables:
mode:c++
diff --git a/src/libnrtype/Makefile_insert b/src/libnrtype/Makefile_insert
index 8f45dc94d..7cd99e1a8 100644
--- a/src/libnrtype/Makefile_insert
+++ b/src/libnrtype/Makefile_insert
@@ -20,10 +20,6 @@ ink_common_sources += \
libnrtype/one-box.h \
libnrtype/one-glyph.h \
libnrtype/one-para.h \
- libnrtype/RasterFont.cpp \
- libnrtype/RasterFont.h \
- libnrtype/raster-glyph.h \
- libnrtype/raster-position.h \
libnrtype/text-boundary.h \
libnrtype/TextWrapper.cpp \
libnrtype/TextWrapper.h \
diff --git a/src/libnrtype/RasterFont.cpp b/src/libnrtype/RasterFont.cpp
deleted file mode 100644
index 14f6c7afa..000000000
--- a/src/libnrtype/RasterFont.cpp
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * RasterFont.cpp
- * testICU
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "RasterFont.h"
-
-#include <livarot/float-line.h>
-#include <livarot/int-line.h>
-#include <livarot/Path.h>
-#include <livarot/Shape.h>
-#include <libnr/nr-pixblock.h>
-#include <libnrtype/font-instance.h>
-#include <libnrtype/raster-glyph.h>
-#include <libnrtype/raster-position.h>
-
-
-static void glyph_run_A8_OR (raster_info &dest,void */*data*/,int st,float vst,int en,float ven);
-
-void font_style::Apply(Path* src,Shape* dest) {
- src->Convert(1);
- if ( stroke_width > 0 ) {
- if ( nbDash > 0 ) {
- double dlen = 0.0;
- const float scale = 1/*Geom::expansion(transform)*/;
- for (int i = 0; i < nbDash; i++) dlen += dashes[i] * scale;
- if (dlen >= 0.01) {
- float sc_offset = dash_offset * scale;
- float *tdashs=(float*)malloc((nbDash+1)*sizeof(float));
- while ( sc_offset >= dlen ) sc_offset-=dlen;
- tdashs[0]=dashes[0] * scale;
- for (int i=1;i<nbDash;i++) tdashs[i] = tdashs[i - 1] + dashes[i] * scale;
- src->DashPolyline(0.0,0.0,dlen,nbDash,tdashs,true,sc_offset);
- free(tdashs);
- }
- }
- src->Stroke(dest, false, 0.5*stroke_width, stroke_join, stroke_cap, 0.5*stroke_width*stroke_miter_limit);
- } else {
- src->Fill(dest,0);
- }
-}
-
-raster_font::raster_font(font_style const &fstyle) :
- daddy(NULL),
- refCount(0),
- style(fstyle),
- glyph_id_to_raster_glyph_no(),
- nbBase(0),
- maxBase(0),
- bases(NULL)
-{
- // printf("raster font born\n");
-}
-
-raster_font::~raster_font(void)
-{
-// printf("raster font death\n");
- if ( daddy ) daddy->RemoveRasterFont(this);
- daddy=NULL;
- if ( style.dashes ) free(style.dashes);
- style.dashes=NULL;
- for (int i=0;i<nbBase;i++) delete bases[i];
- if ( bases ) free(bases);
-}
-
-void raster_font::Unref(void)
-{
- refCount--;
-// printf("raster %x unref'd %i\n",this,refCount);
- if ( refCount <= 0 ) {
- if ( daddy ) daddy->RemoveRasterFont(this);
- daddy=NULL;
- delete this;
- }
-}
-void raster_font::Ref(void)
-{
- refCount++;
-// printf("raster %x ref'd %i\n",this,refCount);
-}
-raster_glyph* raster_font::GetGlyph(int glyph_id)
-{
- raster_glyph *res=NULL;
- if ( glyph_id_to_raster_glyph_no.find(glyph_id) == glyph_id_to_raster_glyph_no.end() ) {
- LoadRasterGlyph(glyph_id);
- if ( glyph_id_to_raster_glyph_no.find(glyph_id) == glyph_id_to_raster_glyph_no.end() ) { // recheck
- } else {
- res=bases[glyph_id_to_raster_glyph_no[glyph_id]];
- }
- } else {
- res=bases[glyph_id_to_raster_glyph_no[glyph_id]];
- }
- return res;
-}
-Geom::Point raster_font::Advance(int glyph_id)
-{
- if ( daddy == NULL ) return Geom::Point(0,0);
- double a=daddy->Advance(glyph_id,style.vertical);
- Geom::Point f_a=(style.vertical)?Geom::Point(0,a):Geom::Point(a,0);
- return f_a*style.transform;
-}
-void raster_font::BBox(int glyph_id,NRRect *area)
-{
- area->x0=area->y0=area->x1=area->y1=0;
- if ( daddy == NULL ) return;
- Geom::OptRect res=daddy->BBox(glyph_id);
- if (res) {
- Geom::Point bmi=res->min(),bma=res->max();
- Geom::Point tlp(bmi[0],bmi[1]),trp(bma[0],bmi[1]),blp(bmi[0],bma[1]),brp(bma[0],bma[1]);
- tlp=tlp*style.transform;
- trp=trp*style.transform;
- blp=blp*style.transform;
- brp=brp*style.transform;
- *res=Geom::Rect(tlp,trp);
- res->expandTo(blp);
- res->expandTo(brp);
- area->x0=(res->min())[0];
- area->y0=(res->min())[1];
- area->x1=(res->max())[0];
- area->y1=(res->max())[1];
- } else {
- nr_rect_d_set_empty(area);
- }
-}
-
-void raster_font::LoadRasterGlyph(int glyph_id)
-{
- raster_glyph *res=NULL;
- if ( glyph_id_to_raster_glyph_no.find(glyph_id) == glyph_id_to_raster_glyph_no.end() ) {
- res=new raster_glyph();
- res->daddy=this;
- res->glyph_id=glyph_id;
- if ( nbBase >= maxBase ) {
- maxBase=2*nbBase+1;
- bases=(raster_glyph**)realloc(bases,maxBase*sizeof(raster_glyph*));
- }
- bases[nbBase]=res;
- glyph_id_to_raster_glyph_no[glyph_id]=nbBase;
- nbBase++;
- } else {
- res=bases[glyph_id_to_raster_glyph_no[glyph_id]];
- }
- if ( res == NULL ) return;
- if ( res->polygon ) return;
- if ( res->outline == NULL ) {
- if ( daddy == NULL ) return;
- Path* outline=daddy->Outline(glyph_id,NULL);
- res->outline=new Path;
- if ( outline ) {
- res->outline->Copy(outline);
- }
- res->outline->Transform(style.transform);
- }
- Shape* temp=new Shape;
- res->polygon=new Shape;
- style.Apply(res->outline,temp);
- if ( style.stroke_width > 0 ) {
- res->polygon->ConvertToShape(temp,fill_nonZero);
- } else {
- res->polygon->ConvertToShape(temp,fill_oddEven);
- }
- delete temp;
-
- res->SetSubPixelPositionning(4);
-}
-void raster_font::RemoveRasterGlyph(raster_glyph* who)
-{
- if ( who == NULL ) return;
- int glyph_id=who->glyph_id;
- if ( glyph_id_to_raster_glyph_no.find(glyph_id) == glyph_id_to_raster_glyph_no.end() ) {
- int no=glyph_id_to_raster_glyph_no[glyph_id];
- if ( no >= nbBase-1 ) {
- } else {
- bases[no]=bases[--nbBase];
- glyph_id_to_raster_glyph_no[bases[no]->glyph_id]=no;
- }
- glyph_id_to_raster_glyph_no.erase(glyph_id_to_raster_glyph_no.find(glyph_id));
- } else {
- // not here
- }
-}
-
-/*int top,bottom; // baseline is y=0
- int* run_on_line; // array of size (bottom-top+1): run_on_line[i] gives the number of runs on line top+i
- int nbRun;
- float_ligne_run* runs;*/
-
-raster_position::raster_position(void)
-{
- top=0;
- bottom=-1;
- run_on_line=NULL;
- nbRun=0;
- runs=NULL;
-}
-raster_position::~raster_position(void)
-{
- if ( run_on_line ) free(run_on_line);
- if ( runs ) free(runs);
-}
-
-void raster_position::AppendRuns(std::vector<float_ligne_run> const &r,int y)
-{
- if ( top > bottom ) {
- top=bottom=y;
- if ( run_on_line ) free(run_on_line);
- run_on_line=(int*)malloc(sizeof(int));
- run_on_line[0]=0;
- } else {
- if ( y < top ) {
- // printf("wtf?\n");
- return;
- } else if ( y > bottom ) {
- int ob=bottom;
- bottom=y;
- run_on_line=(int*)realloc(run_on_line,(bottom-top+1)*sizeof(int));
- for (int i=ob+1;i<=bottom;i++) run_on_line[i-top]=0;
- }
- }
-
- if ( r.empty() == false) {
- run_on_line[y - top] = r.size();
- runs = (float_ligne_run *) realloc(runs, (nbRun + r.size()) * sizeof(float_ligne_run));
-
- for (int i = 0; i < int(r.size()); i++) {
- runs[nbRun + i] = r[i];
- }
-
- nbRun += r.size();
- }
-}
-void raster_position::Blit(float ph,int pv,NRPixBlock &over)
-{
- int base_y=top+pv;
- int first_y=top+pv,last_y=bottom+pv;
- if ( first_y < over.area.y0 ) first_y=over.area.y0;
- if ( last_y >= over.area.y1 ) last_y=over.area.y1-1;
- if ( first_y > last_y ) return;
- IntLigne *theIL=new IntLigne();
- FloatLigne *theI=new FloatLigne();
-
- char* mdata=(char*)over.data.px;
- if ( over.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)over.data.p;
-
- for (int y=first_y;y<=last_y;y++) {
- int first_r=0,last_r=0;
- for (int i=base_y;i<y;i++) first_r+=run_on_line[i-base_y];
- last_r=first_r+run_on_line[y-base_y]-1;
- if ( first_r <= last_r ) {
- theI->Reset();
- for (int i=first_r;i<=last_r;i++) theI->AddRun(runs[i].st+ph,runs[i].en+ph,runs[i].vst,runs[i].ven,runs[i].pente);
-// for (int i=first_r;i<=last_r;i++) {runs[i].st+=ph;runs[i].en+=ph;}
-// theI->nbRun=theI->maxRun=last_r-first_r+1;
-// theI->runs=runs+first_r;
-
- theIL->Copy(theI);
- raster_info dest;
- dest.startPix=over.area.x0;
- dest.endPix=over.area.x1;
- dest.sth=over.area.x0;
- dest.stv=y;
- dest.buffer=((uint32_t*)(mdata+(over.rs*(y-over.area.y0))));
- theIL->Raster(dest,NULL,glyph_run_A8_OR);
-
-// theI->nbRun=theI->maxRun=0;
-// theI->runs=NULL;
-// for (int i=first_r;i<=last_r;i++) {runs[i].st-=ph;runs[i].en-=ph;}
- }
- }
- delete theIL;
- delete theI;
-}
-
-
-/* raster_font* daddy;
- int glyph_id;
-
- Path* outline;
- Shape* polygon;
-
- int nb_sub_pixel;
- raster_position* sub_pixel;*/
-
-raster_glyph::raster_glyph(void)
-{
- daddy=NULL;
- glyph_id=0;
- outline=NULL;
- polygon=NULL;
- nb_sub_pixel=0;
- sub_pixel=NULL;
-}
-raster_glyph::~raster_glyph(void)
-{
- if ( outline ) delete outline;
- if ( polygon ) delete polygon;
- if ( sub_pixel ) delete [] sub_pixel;
-}
-
-
-void raster_glyph::SetSubPixelPositionning(int nb_pos)
-{
- nb_sub_pixel=nb_pos;
- if ( nb_sub_pixel <= 0 ) nb_sub_pixel=0;
- if ( sub_pixel ) delete [] sub_pixel;
- sub_pixel=NULL;
- if ( nb_sub_pixel > 0 ) {
- sub_pixel=new raster_position[nb_pos];
- if ( polygon ) {
- for (int i=0;i<nb_sub_pixel;i++) LoadSubPixelPosition(i);
- }
- }
-}
-void raster_glyph::LoadSubPixelPosition(int no)
-{
- if ( no < 0 || no >= nb_sub_pixel ) return;
- if ( sub_pixel[no].top <= sub_pixel[no].bottom ) return;
- if ( polygon == NULL ) {
- if ( daddy == NULL ) return;
- daddy->LoadRasterGlyph(glyph_id);
- if ( polygon == NULL ) return;
- }
-
- float sub_delta=((float)no)/((float)nb_sub_pixel);
-
- polygon->CalcBBox();
-
- float l=polygon->leftX,r=polygon->rightX,t=polygon->topY,b=polygon->bottomY;
- int il,ir,it,ib;
- il=(int)floor(l);
- ir=(int)ceil(r);
- it=(int)floor(t);
- ib=(int)ceil(b);
-
- // version par FloatLigne
- int curPt;
- float curY;
- polygon->BeginQuickRaster(curY, curPt);
-
- FloatLigne* theI=new FloatLigne();
-
- polygon->DirectQuickScan(curY,curPt,(float)(it-1)+sub_delta,true,1.0);
-
- for (int y=it-1;y<ib;y++) {
- theI->Reset();
- polygon->QuickScan(curY,curPt,((float)(y+1))+sub_delta,theI,1.0);
- theI->Flatten();
-
- sub_pixel[no].AppendRuns(theI->runs, y);
- }
- polygon->EndQuickRaster();
- delete theI;
-}
-
-void raster_glyph::Blit(const Geom::Point &at,NRPixBlock &over)
-{
- if ( nb_sub_pixel <= 0 ) return;
- int pv=(int)ceil(at[1]);
- double dec=4*(ceil(at[1])-at[1]);
- int no=(int)floor(dec);
- sub_pixel[no].Blit(at[0],pv,over);
-}
-
-
-
-static void
-glyph_run_A8_OR (raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
-{
- if ( st >= en ) return;
- if ( vst < 0 ) vst=0;
- if ( vst > 1 ) vst=1;
- if ( ven < 0 ) ven=0;
- if ( ven > 1 ) ven=1;
- float sv=vst;
- float dv=ven-vst;
- int len=en-st;
- unsigned char* d=(unsigned char*)dest.buffer;
- d+=(st-dest.startPix);
- if ( fabs(dv) < 0.001 ) {
- if ( vst > 0.999 ) {
- /* Simple copy */
- while (len > 0) {
- d[0] = 255;
- d += 1;
- len -= 1;
- }
- } else {
- sv*=256;
- unsigned int c0_24=(int)sv;
- c0_24&=0xFF;
- while (len > 0) {
- unsigned int da;
- /* Draw */
- da = 65025 - (255 - c0_24) * (255 - d[0]);
- d[0] = (da + 127) / 255;
- d += 1;
- len -= 1;
- }
- }
- } else {
- if ( en <= st+1 ) {
- sv=0.5*(vst+ven);
- sv*=256;
- unsigned int c0_24=(int)sv;
- c0_24&=0xFF;
- unsigned int da;
- /* Draw */
- da = 65025 - (255 - c0_24) * (255 - d[0]);
- d[0] = (da + 127) / 255;
- } else {
- dv/=len;
- sv+=0.5*dv; // correction trapezoidale
- sv*=16777216;
- dv*=16777216;
- int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
- int s0_24 = static_cast<int>(dv);
- while (len > 0) {
- unsigned int ca, da;
- /* Draw */
- ca = c0_24 >> 16;
- if ( ca > 255 ) ca=255;
- da = 65025 - (255 - ca) * (255 - d[0]);
- d[0] = (da + 127) / 255;
- d += 1;
- c0_24 += s0_24;
- c0_24 = CLAMP (c0_24, 0, 16777216);
- len -= 1;
- }
- }
- }
-}
diff --git a/src/libnrtype/RasterFont.h b/src/libnrtype/RasterFont.h
deleted file mode 100644
index 015121b42..000000000
--- a/src/libnrtype/RasterFont.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * RasterFont.h
- * testICU
- *
- */
-
-#ifndef my_raster_font
-#define my_raster_font
-
-#include <map>
-
-#include <libnr/nr-forward.h>
-#include <libnrtype/nrtype-forward.h>
-#include <libnrtype/font-style.h>
-
-// one rasterfont is one way to draw a font on the screen
-// the way it's drawn is stored in style
-class raster_font {
-public:
- font_instance* daddy;
- int refCount;
-
- font_style style;
-
- std::map<int,int> glyph_id_to_raster_glyph_no;
- // an array of glyphs in this rasterfont.
- // it's a bit redundant with the one in the daddy font_instance, but these glyphs
- // contains the real rasterization data
- int nbBase,maxBase;
- raster_glyph** bases;
-
- explicit raster_font(font_style const &fstyle);
- virtual ~raster_font(void);
-
- void Unref(void);
- void Ref(void);
-
- // utility functions
- Geom::Point Advance(int glyph_id);
- void BBox(int glyph_id,NRRect *area);
-
- // attempts to load a glyph and return a raster_glyph on which you can call Blit
- raster_glyph* GetGlyph(int glyph_id);
- // utility
- void LoadRasterGlyph(int glyph_id); // refreshes outline/polygon if needed
- void RemoveRasterGlyph(raster_glyph* who);
-
-private:
- /* Disable the default copy constructor and operator=: they do the wrong thing for refCount. */
- raster_font(raster_font const &);
- raster_font &operator=(raster_font const &);
-};
-
-#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 :
diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h
index d52bd723f..e9bd291d2 100644
--- a/src/libnrtype/font-instance.h
+++ b/src/libnrtype/font-instance.h
@@ -67,15 +67,6 @@ public:
// for generating slanted cursors for oblique fonts
Geom::OptRect BBox(int glyph_id);
- // creates a rasterfont for the given style
- raster_font* RasterFont(Geom::Matrix const &trs, double stroke_width,
- bool vertical = false, JoinType stroke_join = join_straight,
- ButtType stroke_cap = butt_straight, float miter_limit = 4.0);
- // the dashes array in iStyle is copied
- raster_font* RasterFont(font_style const &iStyle);
- // private use: tells the font_instance that the raster_font 'who' has died
- void RemoveRasterFont(raster_font *who);
-
// attribute queries
unsigned Name(gchar *str, unsigned size);
unsigned PSName(gchar *str, unsigned size);
@@ -85,9 +76,6 @@ public:
private:
void FreeTheFace();
- // hashmap to get the raster_font for a given style
- void* loadedPtr;
-
#ifdef USE_PANGO_WIN32
HFONT theFace;
#else
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp
index a7160f5f0..bbed89b55 100644
--- a/src/libnrtype/font-lister.cpp
+++ b/src/libnrtype/font-lister.cpp
@@ -2,10 +2,7 @@
# include <config.h>
#endif
-#include <libnr/nr-blit.h>
#include <libnrtype/font-instance.h>
-#include <libnrtype/raster-glyph.h>
-#include <libnrtype/RasterFont.h>
#include <libnrtype/TextWrapper.h>
#include <libnrtype/one-glyph.h>
diff --git a/src/libnrtype/nrtype-forward.h b/src/libnrtype/nrtype-forward.h
index f3344f2fd..6050ffa6b 100644
--- a/src/libnrtype/nrtype-forward.h
+++ b/src/libnrtype/nrtype-forward.h
@@ -5,9 +5,6 @@ class font_factory;
struct font_glyph;
class font_instance;
struct font_style;
-class raster_font;
-class raster_glyph;
-class raster_position;
#endif /* !SEEN_LIBNRTYPE_NRTYPE_FORWARD_H */
diff --git a/src/libnrtype/raster-glyph.h b/src/libnrtype/raster-glyph.h
deleted file mode 100644
index 82a0b3f8e..000000000
--- a/src/libnrtype/raster-glyph.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef SEEN_LIBNRTYPE_RASTER_GLYPH_H
-#define SEEN_LIBNRTYPE_RASTER_GLYPH_H
-
-#include <libnr/nr-forward.h>
-#include <libnrtype/nrtype-forward.h>
-#include <livarot/livarot-forward.h>
-
-// a little utility class that holds data to render a styled glyph
-// ie. it's like a polygon. its function is to wrap the subpixel positionning
-class raster_glyph {
-public:
- // raster_font that created me
- raster_font* daddy;
- // the glyph i am (the style is in daddy)
- int glyph_id;
- // internal structure: the styled path, and the associated uncrossed polygon
- // they could be removed after the raster_position have been computed
- Path* outline; // transformed by the matrix in style (may be factorized, but is small)
- Shape* polygon;
- // subpixel positions
- // nb_sub_pixel is set to 4 when the glyph is created (it's hardcoded)
- int nb_sub_pixel;
- raster_position* sub_pixel;
-
- raster_glyph(void);
- virtual ~raster_glyph(void);
-
- // utility
- void SetSubPixelPositionning(int nb_pos);
- void LoadSubPixelPosition(int no);
-
- // the interesting function: blits the glyph onto over
- // over should be a mask, ie a NRPixBlock with one 8bit plane
- void Blit(Geom::Point const &at, NRPixBlock &over); // alpha only
-};
-
-
-#endif /* !SEEN_LIBNRTYPE_RASTER_GLYPH_H */
-
-/*
- 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 :
diff --git a/src/libnrtype/raster-position.h b/src/libnrtype/raster-position.h
deleted file mode 100644
index 744b6dddd..000000000
--- a/src/libnrtype/raster-position.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef SEEN_LIBNRTYPE_RASTER_POSITION_H
-#define SEEN_LIBNRTYPE_RASTER_POSITION_H
-
-#include <vector>
-
-#include <libnr/nr-forward.h>
-#include <libnrtype/nrtype-forward.h>
-#include <livarot/livarot-forward.h>
-
-// one subpixel position
-// it's basically a set of trapezoids (=float_ligne_run) representing the black areas of the glyph
-// all trapezoids are in the same array, hence the run_on_line array to give the number of
-// trapezoids on each line
-// trapezoids store the x-positions as float, and are shifted to the x blit position
-// so it's "exact" in the x direction and subpixel in the y direction
-class raster_position {
-public:
- int top, bottom; // baseline is y=0
- // top is the first pixel, bottom is the last
- int* run_on_line; // array of size (bottom-top+1): run_on_line[i] gives the number of runs on line top+i
- int nbRun;
- float_ligne_run* runs;
-
-public:
- raster_position();
- virtual ~raster_position();
-
- // stuff runs into the structure
- void AppendRuns(std::vector<float_ligne_run> const &r, int y);
- // blits the trapezoids.
- void Blit(float ph, int pv, NRPixBlock &over);
-};
-
-
-#endif /* !SEEN_LIBNRTYPE_RASTER_POSITION_H */
-
-/*
- 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 :
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp
index ce0893430..cac4caee0 100644
--- a/src/widgets/font-selector.cpp
+++ b/src/widgets/font-selector.cpp
@@ -20,13 +20,7 @@
# include "config.h"
#endif
-#include <libnr/nr-blit.h>
-#include <libnr/nr-convert2geom.h>
#include <libnrtype/font-instance.h>
-#include <libnrtype/raster-glyph.h>
-#include <libnrtype/RasterFont.h>
-#include <libnrtype/TextWrapper.h>
-#include <libnrtype/one-glyph.h>
#include <libnrtype/font-lister.h>
#include <2geom/transforms.h>
@@ -40,11 +34,10 @@
#include <gtk/gtkentry.h>
#include <gtk/gtkdrawingarea.h>
-#include "../display/nr-plain-stuff-gdk.h"
#include <glibmm/i18n.h>
-#include "../desktop.h"
-#include "font-selector.h"
+#include "desktop.h"
+#include "widgets/font-selector.h"
/* SPFontSelector */
@@ -521,321 +514,6 @@ double sp_font_selector_get_size(SPFontSelector *fsel)
return fsel->fontsize;
}
-/* SPFontPreview */
-
-struct SPFontPreview
-{
- GtkDrawingArea darea;
-
- font_instance *font;
- raster_font *rfont;
- gchar *phrase;
- unsigned long rgba;
-};
-
-struct SPFontPreviewClass
-{
- GtkDrawingAreaClass parent_class;
-};
-
-static void sp_font_preview_class_init(SPFontPreviewClass *c);
-static void sp_font_preview_init(SPFontPreview *fsel);
-static void sp_font_preview_destroy(GtkObject *object);
-
-void sp_font_preview_size_request(GtkWidget *widget, GtkRequisition *req);
-static gint sp_font_preview_expose(GtkWidget *widget, GdkEventExpose *event);
-
-static GtkDrawingAreaClass *fp_parent_class = NULL;
-
-GType sp_font_preview_get_type()
-{
- static GType type = 0;
- if (!type) {
- GTypeInfo info = {
- sizeof(SPFontPreviewClass),
- 0, // base_init
- 0, // base_finalize
- (GClassInitFunc)sp_font_preview_class_init,
- 0, // class_finalize
- 0, // class_data
- sizeof(SPFontPreview),
- 0, // n_preallocs
- (GInstanceInitFunc)sp_font_preview_init,
- 0 // value_table
- };
- type = g_type_register_static(GTK_TYPE_DRAWING_AREA, "SPFontPreview", &info, static_cast<GTypeFlags>(0));
- }
- return type;
-}
-
-static void sp_font_preview_class_init (SPFontPreviewClass *c)
-{
- GtkObjectClass *object_class = (GtkObjectClass *) c;
- GtkWidgetClass *widget_class = (GtkWidgetClass *) c;
-
- fp_parent_class = (GtkDrawingAreaClass*) gtk_type_class(GTK_TYPE_DRAWING_AREA);
-
- object_class->destroy = sp_font_preview_destroy;
-
- widget_class->size_request = sp_font_preview_size_request;
- widget_class->expose_event = sp_font_preview_expose;
-}
-
-static void sp_font_preview_init(SPFontPreview *fprev)
-{
- fprev->rgba = 0x000000ff;
-}
-
-static void sp_font_preview_destroy(GtkObject *object)
-{
- SPFontPreview *fprev = SP_FONT_PREVIEW (object);
-
- if (fprev->rfont) {
- fprev->rfont->Unref();
- fprev->rfont = NULL;
- }
-
- if (fprev->font) {
- fprev->font->Unref();
- fprev->font = NULL;
- }
-
- g_free(fprev->phrase);
- fprev->phrase = NULL;
-
- if (GTK_OBJECT_CLASS (fp_parent_class)->destroy) {
- GTK_OBJECT_CLASS (fp_parent_class)->destroy(object);
- }
-}
-
-void sp_font_preview_size_request(GtkWidget */*widget*/, GtkRequisition *req)
-{
- req->width = 256;
- req->height = 32;
-}
-
-#define SPFP_MAX_LEN 64
-
-static gint sp_font_preview_expose(GtkWidget *widget, GdkEventExpose *event)
-{
- SPFontPreview *fprev = SP_FONT_PREVIEW(widget);
-
- if (GTK_WIDGET_DRAWABLE (widget)) {
- if (fprev->rfont) {
-
- int glyphs[SPFP_MAX_LEN];
- double hpos[SPFP_MAX_LEN];
-
- font_instance *tface = fprev->rfont->daddy;
-
- double theSize = fprev->rfont->style.transform.descrim();
-
- gchar const *p;
- if (fprev->phrase) {
- p = fprev->phrase;
- } else {
- /* TRANSLATORS: Test string used in text and font dialog (when no
- * text has been entered) to get a preview of the font. Choose
- * some representative characters that users of your locale will be
- * interested in. */
- p = _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()");
- }
- int len = 0;
-
- NRRect bbox;
- bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
-
- text_wrapper* str_text=new text_wrapper;
- str_text->SetDefaultFont(tface);
- str_text->AppendUTF8(p,-1);
- if ( str_text->uni32_length > 0 ) {
- str_text->DoLayout();
- if ( str_text->glyph_length > 0 ) {
- PangoFont *curPF = NULL;
- font_instance *curF = NULL;
- for (int i = 0; i < str_text->glyph_length && i < SPFP_MAX_LEN; i++) {
- if ( str_text->glyph_text[i].font != curPF ) {
- curPF = str_text->glyph_text[i].font;
- if (curF) {
- curF->Unref();
- }
- curF = NULL;
- if ( curPF ) {
- PangoFontDescription* pfd = pango_font_describe(curPF);
- curF = (font_factory::Default())->Face(pfd);
- pango_font_description_free(pfd);
- }
- }
- Geom::Point base_pt(str_text->glyph_text[i].x, str_text->glyph_text[i].y);
- base_pt *= theSize;
-
- glyphs[len] = str_text->glyph_text[i].gl;
- hpos[len] = base_pt[0];
- len++;
- if ( curF ) {
- Geom::OptRect nbbox = curF->BBox(str_text->glyph_text[i].gl);
- if (nbbox) {
- bbox.x0 = MIN(bbox.x0, base_pt[Geom::X] + theSize * (nbbox->min())[0]);
- bbox.y0 = MIN(bbox.y0, base_pt[Geom::Y] - theSize * (nbbox->max())[1]);
- bbox.x1 = MAX(bbox.x1, base_pt[Geom::X] + theSize * (nbbox->max())[0]);
- bbox.y1 = MAX(bbox.y1, base_pt[Geom::Y] - theSize * (nbbox->min())[1]);
- }
- }
- }
- if ( curF ) {
- curF->Unref();
- }
- }
- }
-
- // XXX: FIXME: why does this code ignore adv.y
- /* while (p && *p && (len < SPFP_MAX_LEN)) {
- unsigned int unival;
- NRRect gbox;
- unival = g_utf8_get_char (p);
- glyphs[len] = tface->MapUnicodeChar( unival);
- hpos[len] = (int)px;
- Geom::Point adv = fprev->rfont->Advance(glyphs[len]);
- fprev->rfont->BBox( glyphs[len], &gbox);
- bbox.x0 = MIN (px + gbox.x0, bbox.x0);
- bbox.y0 = MIN (py + gbox.y0, bbox.y0);
- bbox.x1 = MAX (px + gbox.x1, bbox.x1);
- bbox.y1 = MAX (py + gbox.y1, bbox.y1);
- px += adv[Geom::X];
- len += 1;
- p = g_utf8_next_char (p);
- }*/
-
- float startx = (widget->allocation.width - (bbox.x1 - bbox.x0)) / 2;
- float starty = widget->allocation.height - (widget->allocation.height - (bbox.y1 - bbox.y0)) / 2 - bbox.y1;
-
- for (int y = event->area.y; y < event->area.y + event->area.height; y += 64) {
- for (int x = event->area.x; x < event->area.x + event->area.width; x += 64) {
- NRPixBlock pb, m;
- int x0 = x;
- int y0 = y;
- int x1 = MIN(x0 + 64, event->area.x + event->area.width);
- int y1 = MIN(y0 + 64, event->area.y + event->area.height);
- guchar *ps = nr_pixelstore_16K_new (TRUE, 0xff);
- nr_pixblock_setup_extern(&pb, NR_PIXBLOCK_MODE_R8G8B8, x0, y0, x1, y1, ps, 3 * (x1 - x0), FALSE, FALSE);
- nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, x0, y0, x1, y1, TRUE);
- pb.empty = FALSE;
-
- PangoFont *curPF = NULL;
- font_instance *curF = NULL;
- raster_font *curRF = NULL;
- for (int i=0; i < len; i++) {
- if ( str_text->glyph_text[i].font != curPF ) {
- curPF=str_text->glyph_text[i].font;
- if ( curF ) {
- curF->Unref();
- }
- curF = NULL;
- if ( curPF ) {
- PangoFontDescription* pfd = pango_font_describe(curPF);
- curF=(font_factory::Default())->Face(pfd);
- pango_font_description_free(pfd);
- }
- if ( curF ) {
- if ( curRF ) {
- curRF->Unref();
- }
- curRF = NULL;
- curRF = curF->RasterFont(fprev->rfont->style);
- }
- }
- raster_glyph *g = (curRF) ? curRF->GetGlyph(glyphs[i]) : NULL;
- if ( g ) {
- g->Blit(Geom::Point(hpos[i] + startx, starty), m);
- }
- }
- if (curRF) {
- curRF->Unref();
- }
- if (curF) {
- curF->Unref();
- }
-
- nr_blit_pixblock_mask_rgba32(&pb, &m, fprev->rgba);
- gdk_draw_rgb_image(widget->window, widget->style->black_gc,
- x0, y0, x1 - x0, y1 - y0,
- GDK_RGB_DITHER_NONE, NR_PIXBLOCK_PX (&pb), pb.rs);
- nr_pixblock_release(&m);
- nr_pixblock_release(&pb);
- nr_pixelstore_16K_free(ps);
- }
- }
-
- delete str_text;
-
- } else {
- nr_gdk_draw_gray_garbage(widget->window, widget->style->black_gc,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
- }
- }
-
- return TRUE;
-}
-
-GtkWidget * sp_font_preview_new()
-{
- GtkWidget *w = (GtkWidget*) gtk_type_new(SP_TYPE_FONT_PREVIEW);
-
- return w;
-}
-
-void sp_font_preview_set_font(SPFontPreview *fprev, font_instance *font, SPFontSelector *fsel)
-{
- if (font)
- {
- font->Ref();
- }
-
- if (fprev->font)
- {
- fprev->font->Unref();
- }
-
- fprev->font = font;
-
- if (fprev->rfont)
- {
- fprev->rfont->Unref();
- fprev->rfont=NULL;
- }
-
- if (fprev->font)
- {
- Geom::Matrix flip(Geom::Scale(fsel->fontsize, -fsel->fontsize));
- fprev->rfont = fprev->font->RasterFont(flip, 0);
- }
-
- if (GTK_WIDGET_DRAWABLE (fprev)) gtk_widget_queue_draw (GTK_WIDGET (fprev));
-}
-
-void sp_font_preview_set_rgba32(SPFontPreview *fprev, guint32 rgba)
-{
- fprev->rgba = rgba;
- if (GTK_WIDGET_DRAWABLE (fprev)) {
- gtk_widget_queue_draw (GTK_WIDGET (fprev));
- }
-}
-
-void sp_font_preview_set_phrase(SPFontPreview *fprev, const gchar *phrase)
-{
- g_free (fprev->phrase);
- if (phrase) {
- fprev->phrase = g_strdup (phrase);
- } else {
- fprev->phrase = NULL;
- }
- if (GTK_WIDGET_DRAWABLE(fprev)) {
- gtk_widget_queue_draw (GTK_WIDGET (fprev));
- }
-}
-
-
/*
Local Variables:
mode:c++
diff --git a/src/widgets/font-selector.h b/src/widgets/font-selector.h
index 094db0343..2c4e26610 100644
--- a/src/widgets/font-selector.h
+++ b/src/widgets/font-selector.h
@@ -17,16 +17,11 @@
#include <glib.h>
struct SPFontSelector;
-struct SPFontPreview;
#define SP_TYPE_FONT_SELECTOR (sp_font_selector_get_type ())
#define SP_FONT_SELECTOR(o) (GTK_CHECK_CAST ((o), SP_TYPE_FONT_SELECTOR, SPFontSelector))
#define SP_IS_FONT_SELECTOR(o) (GTK_CHECK_TYPE ((o), SP_TYPE_FONT_SELECTOR))
-#define SP_TYPE_FONT_PREVIEW (sp_font_preview_get_type ())
-#define SP_FONT_PREVIEW(o) (GTK_CHECK_CAST ((o), SP_TYPE_FONT_PREVIEW, SPFontPreview))
-#define SP_IS_FONT_PREVIEW(o) (GTK_CHECK_TYPE ((o), SP_TYPE_FONT_PREVIEW))
-
#include <libnrtype/nrtype-forward.h>
#include <gtk/gtkwidget.h>
@@ -41,16 +36,6 @@ void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, doubl
font_instance *sp_font_selector_get_font (SPFontSelector *fsel);
double sp_font_selector_get_size (SPFontSelector *fsel);
-/* SPFontPreview */
-
-GtkType sp_font_preview_get_type (void);
-
-GtkWidget *sp_font_preview_new (void);
-
-void sp_font_preview_set_font (SPFontPreview *fprev, font_instance *font, SPFontSelector *fsel);
-void sp_font_preview_set_rgba32 (SPFontPreview *fprev, guint32 rgba);
-void sp_font_preview_set_phrase (SPFontPreview *fprev, const gchar *phrase);
-
#endif