diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-08-14 19:22:11 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2010-08-14 19:22:11 +0000 |
| commit | aa844be794b36b44b624e579db7f0945b5d3927b (patch) | |
| tree | f83306b1ac51d8089373023162945eb25951bf68 /src/libnr | |
| parent | Fix paint bucket tool (diff) | |
| download | inkscape-aa844be794b36b44b624e579db7f0945b5d3927b.tar.gz inkscape-aa844be794b36b44b624e579db7f0945b5d3927b.zip | |
Completely remove NRPixBlock
(bzr r9508.1.67)
Diffstat (limited to 'src/libnr')
| -rw-r--r-- | src/libnr/Makefile_insert | 5 | ||||
| -rw-r--r-- | src/libnr/nr-pixblock-pattern.cpp | 127 | ||||
| -rw-r--r-- | src/libnr/nr-pixblock-pattern.h | 28 | ||||
| -rw-r--r-- | src/libnr/nr-pixblock.cpp | 457 | ||||
| -rw-r--r-- | src/libnr/nr-pixblock.h | 103 | ||||
| -rw-r--r-- | src/libnr/nr-pixops.h | 148 |
6 files changed, 0 insertions, 868 deletions
diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index 2da8e36fb..1027e0600 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -10,11 +10,6 @@ ink_common_sources += \ libnr/nr-macros.h \ libnr/nr-object.cpp \ libnr/nr-object.h \ - libnr/nr-pixblock-pattern.cpp \ - libnr/nr-pixblock-pattern.h \ - libnr/nr-pixblock.cpp \ - libnr/nr-pixblock.h \ - libnr/nr-pixops.h \ libnr/nr-point-fns.cpp \ libnr/nr-point-fns.h \ libnr/nr-point-l.h \ diff --git a/src/libnr/nr-pixblock-pattern.cpp b/src/libnr/nr-pixblock-pattern.cpp deleted file mode 100644 index aa3246297..000000000 --- a/src/libnr/nr-pixblock-pattern.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#define __NR_PIXBLOCK_PATTERN_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - - -#include <glib/gmem.h> -#include "nr-pixops.h" -#include "nr-pixblock-pattern.h" - -#define NR_NOISE_SIZE 1024 - -void -nr_pixblock_render_gray_noise (NRPixBlock *pb, NRPixBlock *mask) -{ - static unsigned char *noise = NULL; - static unsigned int seed = 0; - unsigned int v; - NRRectL clip; - int x, y, bpp; - - if (mask) { - if (mask->empty) return; - nr_rect_l_intersect (&clip, &pb->area, &mask->area); - if (nr_rect_l_test_empty(clip)) return; - } else { - clip = pb->area; - } - - if (!noise) { - int i; - noise = g_new (unsigned char, NR_NOISE_SIZE); - for (i = 0; i < NR_NOISE_SIZE; i++) noise[i] = (rand () / (RAND_MAX >> 8)) & 0xff; - } - - bpp = NR_PIXBLOCK_BPP (pb); - - v = (rand () / (RAND_MAX >> 8)) & 0xff; - - if (mask) { - for (y = clip.y0; y < clip.y1; y++) { - unsigned char *d, *m; - d = NR_PIXBLOCK_PX (pb) + (y - pb->area.y0) * pb->rs + (clip.x0 - pb->area.x0) * bpp; - m = NR_PIXBLOCK_PX (mask) + (y - mask->area.y0) * pb->rs + (clip.x0 - mask->area.x0); - for (x = clip.x0; x < clip.x1; x++) { - v = v ^ noise[seed]; - switch (pb->mode) { - case NR_PIXBLOCK_MODE_A8: - d[0] = NR_COMPOSEA_111(m[0], d[0]); - break; - case NR_PIXBLOCK_MODE_R8G8B8: - d[0] = NR_COMPOSEN11_1111 (v, m[0], d[0]); - d[1] = NR_COMPOSEN11_1111 (v, m[0], d[1]); - d[2] = NR_COMPOSEN11_1111 (v, m[0], d[2]); - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - if (m[0] != 0) { - unsigned int ca; - ca = NR_COMPOSEA_112(m[0], d[3]); - d[0] = NR_COMPOSENNN_111121 (v, m[0], d[0], d[3], ca); - d[1] = NR_COMPOSENNN_111121 (v, m[0], d[1], d[3], ca); - d[2] = NR_COMPOSENNN_111121 (v, m[0], d[2], d[3], ca); - d[3] = NR_NORMALIZE_21(ca); - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8P: - d[0] = NR_COMPOSENPP_1111 (v, m[0], d[0]); - d[1] = NR_COMPOSENPP_1111 (v, m[0], d[1]); - d[2] = NR_COMPOSENPP_1111 (v, m[0], d[2]); - d[3] = NR_COMPOSEA_111(d[3], m[0]); - break; - default: - break; - } - d += bpp; - m += 1; - if (++seed >= NR_NOISE_SIZE) { - int i; - i = (rand () / (RAND_MAX / NR_NOISE_SIZE)) % NR_NOISE_SIZE; - noise[i] ^= v; - seed = i % (NR_NOISE_SIZE >> 2); - } - } - } - } else { - for (y = clip.y0; y < clip.y1; y++) { - unsigned char *d; - d = NR_PIXBLOCK_PX (pb) + (y - pb->area.y0) * pb->rs + (clip.x0 - pb->area.x0) * bpp; - for (x = clip.x0; x < clip.x1; x++) { - v = v ^ noise[seed]; - switch (pb->mode) { - case NR_PIXBLOCK_MODE_A8: - d[0] = 255; - break; - case NR_PIXBLOCK_MODE_R8G8B8: - d[0] = v; - d[1] = v; - d[2] = v; - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - case NR_PIXBLOCK_MODE_R8G8B8A8P: - d[0] = v; - d[1] = v; - d[2] = v; - d[3] = 255; - default: - break; - } - d += bpp; - if (++seed >= NR_NOISE_SIZE) { - int i; - i = (rand () / (RAND_MAX / NR_NOISE_SIZE)) % NR_NOISE_SIZE; - noise[i] ^= v; - seed = i % (NR_NOISE_SIZE >> 2); - } - } - } - } - - pb->empty = 0; -} diff --git a/src/libnr/nr-pixblock-pattern.h b/src/libnr/nr-pixblock-pattern.h deleted file mode 100644 index 463a24379..000000000 --- a/src/libnr/nr-pixblock-pattern.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __NR_PIXBLOCK_PATTERN_H__ -#define __NR_PIXBLOCK_PATTERN_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <libnr/nr-pixblock.h> - -void nr_pixblock_render_gray_noise (NRPixBlock *pb, NRPixBlock *mask); - -#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-pixblock.cpp b/src/libnr/nr-pixblock.cpp deleted file mode 100644 index 6b2b12b7b..000000000 --- a/src/libnr/nr-pixblock.cpp +++ /dev/null @@ -1,457 +0,0 @@ -#define __NR_PIXBLOCK_C__ - -/** \file - * \brief Allocation/Setup of NRPixBlock objects. Pixel store functions. - * - * Authors: - * (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com> - * 2008, Jasper van de Gronde <th.v.d.gonde@hccnet.nl> - * - * This code is in the Public Domain - */ - -#include <cstring> -#include <string> -#include <string.h> -#include <glib/gmem.h> -#include "nr-pixblock.h" - -/// Size of buffer that needs no allocation (default 4). -#define NR_TINY_MAX sizeof (unsigned char *) - -/** - * Pixbuf initialisation using homegrown memory handling ("pixelstore"). - * - * Pixbuf sizes are differentiated into tiny, <4K, <16K, <64K, and more, - * with each type having its own method of memory handling. After allocating - * memory, the buffer is cleared if the clear flag is set. Intended to - * reduce memory fragmentation. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - */ -void -nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - int w, h, bpp; - size_t size; - - w = x1 - x0; - h = y1 - y0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - size = bpp * w * h; - - if (size <= NR_TINY_MAX) { - pb->size = NR_PIXBLOCK_SIZE_TINY; - if (clear) memset (pb->data.p, 0x0, size); - } else if (size <= 4096) { - pb->size = NR_PIXBLOCK_SIZE_4K; - pb->data.px = nr_pixelstore_4K_new (clear, 0x0); - } else if (size <= 16384) { - pb->size = NR_PIXBLOCK_SIZE_16K; - pb->data.px = nr_pixelstore_16K_new (clear, 0x0); - } else if (size <= 65536) { - pb->size = NR_PIXBLOCK_SIZE_64K; - pb->data.px = nr_pixelstore_64K_new (clear, 0x0); - } else if (size <= 262144) { - pb->size = NR_PIXBLOCK_SIZE_256K; - pb->data.px = nr_pixelstore_256K_new (clear, 0x0); - } else if (size <= 1048576) { - pb->size = NR_PIXBLOCK_SIZE_1M; - pb->data.px = nr_pixelstore_1M_new (clear, 0x0); - } else { - pb->size = NR_PIXBLOCK_SIZE_BIG; - pb->data.px = NULL; - if (size > 100000000) { // Don't even try to allocate more than 100Mb (5000x5000 RGBA - // pixels). It'll just bog the system down even if successful. FIXME: - // Can anyone suggest something better than the magic number? - g_warning ("%lu bytes requested for pixel buffer, I won't try to allocate that.", (long unsigned) size); - return; - } - pb->data.px = g_try_new (unsigned char, size); - if (pb->data.px == NULL) { // memory allocation failed - g_warning ("Could not allocate %lu bytes for pixel buffer!", (long unsigned) size); - return; - } - if (clear) memset (pb->data.px, 0x0, size); - } - - pb->mode = mode; - pb->empty = 1; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->rs = bpp * w; -} - -/** - * Pixbuf initialisation using g_new. - * - * After allocating memory, the buffer is cleared if the clear flag is set. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - FIXME: currently unused except for nr_pixblock_new and pattern tiles, replace with _fast and delete? - */ -void -nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - int w, h, bpp; - size_t size; - - w = x1 - x0; - h = y1 - y0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - size = bpp * w * h; - - if (size <= NR_TINY_MAX) { - pb->size = NR_PIXBLOCK_SIZE_TINY; - if (clear) memset (pb->data.p, 0x0, size); - } else { - pb->size = NR_PIXBLOCK_SIZE_BIG; - pb->data.px = g_new (unsigned char, size); - if (clear) memset (pb->data.px, 0x0, size); - } - - pb->mode = mode; - pb->empty = 1; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->rs = bpp * w; -} - -/** - * Pixbuf initialisation with preset values. - * - * After copying all parameters into the NRPixBlock struct, the pixel buffer is cleared if the clear flag is set. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - */ -void -nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear) -{ - int w, bpp; - - w = x1 - x0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - pb->size = NR_PIXBLOCK_SIZE_STATIC; - pb->mode = mode; - pb->empty = empty; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->data.px = px; - pb->rs = rs; - - g_assert (pb->data.px != NULL); - if (clear) { - if (rs == bpp * w) { - /// \todo How do you recognise if - /// px was an uncleared tiny buffer? - if (pb->data.px) - memset (pb->data.px, 0x0, bpp * (y1 - y0) * w); - } else { - int y; - for (y = y0; y < y1; y++) { - memset (pb->data.px + (y - y0) * rs, 0x0, bpp * w); - } - } - } -} - -/** - * Frees memory taken by pixel data in NRPixBlock. - * \param pb Pointer to pixblock. - * \pre pb and pb->data.px point to valid addresses. - * - * According to pb->size, one of the functions for freeing the pixelstore - * is called. May be called regardless of how pixbuf was set up. - */ -void -nr_pixblock_release (NRPixBlock *pb) -{ - switch (pb->size) { - case NR_PIXBLOCK_SIZE_TINY: - break; - case NR_PIXBLOCK_SIZE_4K: - nr_pixelstore_4K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_16K: - nr_pixelstore_16K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_64K: - nr_pixelstore_64K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_256K: - nr_pixelstore_256K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_1M: - nr_pixelstore_1M_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_BIG: - g_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_STATIC: - break; - default: - break; - } -} - -/** - * Allocates NRPixBlock and sets it up. - * - * \return Pointer to fresh pixblock. - * Calls g_new() and nr_pixblock_setup(). -FIXME: currently unused, delete? JG: Should be used more often! (To simplify memory management.) - */ -NRPixBlock * -nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - NRPixBlock *pb; - - pb = g_new (NRPixBlock, 1); - if (!pb) return 0; - - nr_pixblock_setup (pb, mode, x0, y0, x1, y1, clear); - if (pb->size!=NR_PIXBLOCK_SIZE_TINY && !pb->data.px) { - g_free(pb); - return 0; - } - - return pb; -} - -/** - * Allocates NRPixBlock and sets it up. - * - * \return Pointer to fresh pixblock. - * Calls g_new() and nr_pixblock_setup(). - */ -NRPixBlock * -nr_pixblock_new_fast (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - NRPixBlock *pb; - - pb = g_new (NRPixBlock, 1); - if (!pb) return 0; - - nr_pixblock_setup_fast (pb, mode, x0, y0, x1, y1, clear); - if (pb->size!=NR_PIXBLOCK_SIZE_TINY && !pb->data.px) { - g_free(pb); - return 0; - } - - return pb; -} - -/** - * Frees all memory taken by pixblock. - * - * \return NULL - */ -NRPixBlock * -nr_pixblock_free (NRPixBlock *pb) -{ - nr_pixblock_release (pb); - - g_free (pb); - - return NULL; -} - -/* PixelStore operations */ - -#define NR_4K_BLOCK 32 -static unsigned char **nr_4K_px = NULL; -static unsigned int nr_4K_len = 0; -static unsigned int nr_4K_size = 0; - -unsigned char * -nr_pixelstore_4K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_4K_len != 0) { - nr_4K_len -= 1; - px = nr_4K_px[nr_4K_len]; - } else { - px = g_new (unsigned char, 4096); - } - - if (clear) memset (px, val, 4096); - - return px; -} - -void -nr_pixelstore_4K_free (unsigned char *px) -{ - if (nr_4K_len == nr_4K_size) { - nr_4K_size += NR_4K_BLOCK; - nr_4K_px = g_renew (unsigned char *, nr_4K_px, nr_4K_size); - } - - nr_4K_px[nr_4K_len] = px; - nr_4K_len += 1; -} - -#define NR_16K_BLOCK 32 -static unsigned char **nr_16K_px = NULL; -static unsigned int nr_16K_len = 0; -static unsigned int nr_16K_size = 0; - -unsigned char * -nr_pixelstore_16K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_16K_len != 0) { - nr_16K_len -= 1; - px = nr_16K_px[nr_16K_len]; - } else { - px = g_new (unsigned char, 16384); - } - - if (clear) memset (px, val, 16384); - - return px; -} - -void -nr_pixelstore_16K_free (unsigned char *px) -{ - if (nr_16K_len == nr_16K_size) { - nr_16K_size += NR_16K_BLOCK; - nr_16K_px = g_renew (unsigned char *, nr_16K_px, nr_16K_size); - } - - nr_16K_px[nr_16K_len] = px; - nr_16K_len += 1; -} - -#define NR_64K_BLOCK 32 -static unsigned char **nr_64K_px = NULL; -static unsigned int nr_64K_len = 0; -static unsigned int nr_64K_size = 0; - -unsigned char * -nr_pixelstore_64K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_64K_len != 0) { - nr_64K_len -= 1; - px = nr_64K_px[nr_64K_len]; - } else { - px = g_new (unsigned char, 65536); - } - - if (clear) memset (px, val, 65536); - - return px; -} - -void -nr_pixelstore_64K_free (unsigned char *px) -{ - if (nr_64K_len == nr_64K_size) { - nr_64K_size += NR_64K_BLOCK; - nr_64K_px = g_renew (unsigned char *, nr_64K_px, nr_64K_size); - } - - nr_64K_px[nr_64K_len] = px; - nr_64K_len += 1; -} - -#define NR_256K_BLOCK 32 -#define NR_256K 262144 -static unsigned char **nr_256K_px = NULL; -static unsigned int nr_256K_len = 0; -static unsigned int nr_256K_size = 0; - -unsigned char * -nr_pixelstore_256K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_256K_len != 0) { - nr_256K_len -= 1; - px = nr_256K_px[nr_256K_len]; - } else { - px = g_new (unsigned char, NR_256K); - } - - if (clear) memset (px, val, NR_256K); - - return px; -} - -void -nr_pixelstore_256K_free (unsigned char *px) -{ - if (nr_256K_len == nr_256K_size) { - nr_256K_size += NR_256K_BLOCK; - nr_256K_px = g_renew (unsigned char *, nr_256K_px, nr_256K_size); - } - - nr_256K_px[nr_256K_len] = px; - nr_256K_len += 1; -} - -#define NR_1M_BLOCK 32 -#define NR_1M 1048576 -static unsigned char **nr_1M_px = NULL; -static unsigned int nr_1M_len = 0; -static unsigned int nr_1M_size = 0; - -unsigned char * -nr_pixelstore_1M_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_1M_len != 0) { - nr_1M_len -= 1; - px = nr_1M_px[nr_1M_len]; - } else { - px = g_new (unsigned char, NR_1M); - } - - if (clear) memset (px, val, NR_1M); - - return px; -} - -void -nr_pixelstore_1M_free (unsigned char *px) -{ - if (nr_1M_len == nr_1M_size) { - nr_1M_size += NR_1M_BLOCK; - nr_1M_px = g_renew (unsigned char *, nr_1M_px, nr_1M_size); - } - - nr_1M_px[nr_1M_len] = px; - nr_1M_len += 1; -} - -/* - 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-pixblock.h b/src/libnr/nr-pixblock.h deleted file mode 100644 index cedc2ad3d..000000000 --- a/src/libnr/nr-pixblock.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __NR_PIXBLOCK_H__ -#define __NR_PIXBLOCK_H__ - -/** \file - * \brief Pixel block structure. Used for low-level rendering. - * - * Authors: - * (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com> - * (C) 2005 Ralf Stephan <ralf@ark.in-berlin.de> (some cleanup) - * - * This code is in the Public Domain. - */ - -#include <libnr/nr-rect-l.h> -#include <libnr/nr-forward.h> - -/// Size indicator. Hardcoded to max. 3 bits. -typedef enum { - NR_PIXBLOCK_SIZE_TINY, ///< Fits in (unsigned char *) - NR_PIXBLOCK_SIZE_4K, ///< Pixelstore - NR_PIXBLOCK_SIZE_16K, ///< Pixelstore - NR_PIXBLOCK_SIZE_64K, ///< Pixelstore - NR_PIXBLOCK_SIZE_256K, ///< Pixelstore - NR_PIXBLOCK_SIZE_1M, ///< Pixelstore - NR_PIXBLOCK_SIZE_BIG, ///< Normally allocated - NR_PIXBLOCK_SIZE_STATIC ///< Externally managed -} NR_PIXBLOCK_SIZE; - -/// Mode indicator. Hardcoded to max. 2 bits. -typedef enum { - NR_PIXBLOCK_MODE_A8, ///< Grayscale - NR_PIXBLOCK_MODE_R8G8B8, ///< 8 bit RGB - NR_PIXBLOCK_MODE_R8G8B8A8N, ///< Normal 8 bit RGBA - NR_PIXBLOCK_MODE_R8G8B8A8P ///< Premultiplied 8 bit RGBA -} NR_PIXBLOCK_MODE; - -/// The pixel block struct. -struct NRPixBlock { - NR_PIXBLOCK_SIZE size : 3; ///< Size indicator - NR_PIXBLOCK_MODE mode : 2; ///< Mode indicator - bool empty : 1; ///< Empty flag - unsigned int rs; ///< Size of line in bytes - NRRectL area; - NRRectL visible_area; - union { - unsigned char *px; ///< Pointer to buffer - unsigned char p[sizeof (unsigned char *)]; ///< Tiny buffer - } data; -}; - -/// Returns number of bytes per pixel (1, 3, or 4). -inline int -NR_PIXBLOCK_BPP (NRPixBlock *pb) -{ - return ((pb->mode == NR_PIXBLOCK_MODE_A8) ? 1 : - (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4); -} - -/// Returns pointer to pixel data. -inline unsigned char* -NR_PIXBLOCK_PX (NRPixBlock *pb) -{ - return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? - pb->data.p : pb->data.px); -} -inline unsigned char const* -NR_PIXBLOCK_PX (NRPixBlock const *pb) -{ - return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? - pb->data.p : pb->data.px); -} - -void nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -void nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -void nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear); -void nr_pixblock_release (NRPixBlock *pb); - -NRPixBlock *nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -NRPixBlock *nr_pixblock_new_fast (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -NRPixBlock *nr_pixblock_free (NRPixBlock *pb); - -unsigned char *nr_pixelstore_4K_new (bool clear, unsigned char val); -void nr_pixelstore_4K_free (unsigned char *px); -unsigned char *nr_pixelstore_16K_new (bool clear, unsigned char val); -void nr_pixelstore_16K_free (unsigned char *px); -unsigned char *nr_pixelstore_64K_new (bool clear, unsigned char val); -void nr_pixelstore_64K_free (unsigned char *px); -unsigned char *nr_pixelstore_256K_new (bool clear, unsigned char val); -void nr_pixelstore_256K_free (unsigned char *px); -unsigned char *nr_pixelstore_1M_new (bool clear, unsigned char val); -void nr_pixelstore_1M_free (unsigned char *px); - -#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-pixops.h b/src/libnr/nr-pixops.h deleted file mode 100644 index 7eafd1a9d..000000000 --- a/src/libnr/nr-pixops.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef __NR_PIXOPS_H__ -#define __NR_PIXOPS_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * bulia byak <buliabyak@users.sf.net> - * - * This code is in public domain - */ - -#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) - -// FAST_DIVIDE assumes that 0<=num<=256*denom -// (this covers the case that num=255*denom+denom/2, which is used by DIV_ROUND) -template<unsigned int divisor> static inline unsigned int FAST_DIVIDE(unsigned int v) { return v/divisor; } -template<> inline unsigned int FAST_DIVIDE<255>(unsigned int v) { return ((v+1)*0x101) >> 16; } -template<> inline unsigned int FAST_DIVIDE<255*255>(unsigned int v) { v=(v+1)<<1; v=v+(v>>7)+((v*0x3)>>16)+(v>>22); return (v>>16)>>1; } -// FAST_DIV_ROUND assumes that 0<=num<=255*denom (DIV_ROUND should work upto num=2^32-1-(denom/2), -// but FAST_DIVIDE_BY_255 already fails at num=65790=258*255, which is not too far above 255.5*255) -template<unsigned int divisor> static inline unsigned int FAST_DIV_ROUND(unsigned int v) { return FAST_DIVIDE<divisor>(v+(divisor)/2); } -static inline unsigned int DIV_ROUND(unsigned int v, unsigned int divisor) { return (v+divisor/2)/divisor; } - -#define INK_COMPOSE(f,a,b) ( ( ((guchar) (b)) * ((guchar) (0xff - (a))) + ((guchar) (((b) ^ ~(f)) + (b)/4 - ((b)>127? 63 : 0))) * ((guchar) (a)) ) >>8) - -// Naming: OPb_i+o -// OP = operation, for example: NORMALIZE, COMPOSEA, COMPOSENNN, PREMUL, etc. -// i+o = range of input/output as powers of 2^8-1 -// for example, 213 means 0<=a<=255^2, 0<=b<=255, 0<=output<=255^3 - -// Normalize -static inline unsigned int NR_NORMALIZE_11(unsigned int v) { return v; } -static inline unsigned int NR_NORMALIZE_21(unsigned int v) { return FAST_DIV_ROUND<255>(v); } -static inline unsigned int NR_NORMALIZE_31(unsigned int v) { return FAST_DIV_ROUND<255*255>(v); } -static inline unsigned int NR_NORMALIZE_41(unsigned int v) { return FAST_DIV_ROUND<255*255*255>(v); } - -// Compose alpha channel using (1 - (1-a)*(1-b)) -// Note that these can also be rewritten to NR_COMPOSENPP(255, a, b), slightly slower, but could help if someone -// decides to use SSE or something similar (for allowing the four components to be treated the same way). -static inline unsigned int NR_COMPOSEA_213(unsigned int a, unsigned int b) { return 255*255*255 - (255*255-a)*(255-b); } -static inline unsigned int NR_COMPOSEA_112(unsigned int a, unsigned int b) { return 255*255 - (255-a)*(255-b); } -static inline unsigned int NR_COMPOSEA_211(unsigned int a, unsigned int b) { return NR_NORMALIZE_31(NR_COMPOSEA_213(a, b)); } -static inline unsigned int NR_COMPOSEA_111(unsigned int a, unsigned int b) { return NR_NORMALIZE_21(NR_COMPOSEA_112(a, b)); } - -// Operation: (1 - fa) * bc * ba + fa * fc -static inline unsigned int NR_COMPOSENNP_12114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255 * fa * fc; } -static inline unsigned int NR_COMPOSENNP_11113(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255 - fa) * ba * bc + 255 * fa * fc; } -static inline unsigned int NR_COMPOSENNP_11111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_31(NR_COMPOSENNP_11113(fc, fa, bc, ba)); } - -// Operation: (1 - fa) * bc * ba + fc -static inline unsigned int NR_COMPOSEPNP_32114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255 * fc; } -static inline unsigned int NR_COMPOSEPNP_22114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255*255 * fc; } -static inline unsigned int NR_COMPOSEPNP_11113(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255 - fa) * ba * bc + 255*255 * fc; } -static inline unsigned int NR_COMPOSEPNP_22111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_41(NR_COMPOSEPNP_22114(fc, fa, bc, ba)); } -static inline unsigned int NR_COMPOSEPNP_11111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_31(NR_COMPOSEPNP_11113(fc, fa, bc, ba)); } - -// Operation: ((1 - fa) * bc * ba + fa * fc)/a -// Reuses non-normalized versions of NR_COMPOSENNP -static inline unsigned int NR_COMPOSENNN_121131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSENNP_12114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSENNN_111121(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSENNP_11113(fc, fa, bc, ba), a); } - -// Operation: ((1 - fa) * bc * ba + fc)/a -// Reuses non-normalized versions of NR_COMPOSEPNP -static inline unsigned int NR_COMPOSEPNN_321131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_32114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSEPNN_221131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_22114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSEPNN_111121(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_11113(fc, fa, bc, ba), a); } - -// Operation: (1 - fa) * bc + fa * fc -// (1-fa)*bc+fa*fc = bc-fa*bc+fa*fc = bc+fa*(fc-bc) -// For some reason it's faster to leave the initial 255*bc term in the non-normalized version instead of factoring it out... -static inline unsigned int NR_COMPOSENPP_1213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*bc + fa*(fc-bc); } -static inline unsigned int NR_COMPOSENPP_1123(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*bc + fa*(255*fc-bc); } -static inline unsigned int NR_COMPOSENPP_1112(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*bc + fa*(fc-bc); } -static inline unsigned int NR_COMPOSENPP_1211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSENPP_1213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSENPP_1121(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSENPP_1123(fc, fa, bc)); } -static inline unsigned int NR_COMPOSENPP_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSENPP_1112(fc, fa, bc)); } - -// Operation: (1 - fa) * bc + fc -// (1-fa)*bc+fc = bc-fa*bc+fc = (bc+fc)-fa*bc -// This rewritten form results in faster code (found out through testing) -static inline unsigned int NR_COMPOSEPPP_2224(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*(bc+fc) - fa*bc; } // Note that this can temporarily overflow (but it probably doesn't cause problems) - // NR_COMPOSEPPP_2224 assumes that fa and fc have a common component (fa=a*x and fc=c*x), because then the maximum value is: - // (255*255-255*x)*255*255 + 255*x*255*255 = 255*255*( (255*255-255*x) + 255*x ) = 255*255*255*( (255-x)+x ) = 255*255*255*255 -static inline unsigned int NR_COMPOSEPPP_3213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*bc + fc - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_2213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*(255*bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_1213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*(bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_1112(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*(bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_2221(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_41(NR_COMPOSEPPP_2224(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_3211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSEPPP_3213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_2211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSEPPP_2213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_1211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSEPPP_1213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSEPPP_1112(fc, fa, bc)); } - -#define NR_COMPOSEN11_1211 NR_COMPOSENPP_1211 -#define NR_COMPOSEN11_1111 NR_COMPOSENPP_1111 -//inline unsigned int NR_COMPOSEN11_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21((255 - fa) * bc + fa * fc ); } - -#define NR_COMPOSEP11_2211 NR_COMPOSEPPP_2211 -#define NR_COMPOSEP11_1211 NR_COMPOSEPPP_1211 -#define NR_COMPOSEP11_1111 NR_COMPOSEPPP_1111 -//inline unsigned int NR_COMPOSEP11_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21((255 - fa) * bc + fc * 255); } - -// Premultiply using c*a -static inline unsigned int NR_PREMUL_134(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_224(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_123(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_112(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_314(unsigned int c, unsigned int a) { return NR_PREMUL_134(c, a); } -static inline unsigned int NR_PREMUL_213(unsigned int c, unsigned int a) { return NR_PREMUL_123(c, a); } -static inline unsigned int NR_PREMUL_131(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_134(c, a)); } -static inline unsigned int NR_PREMUL_221(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_224(c, a)); } -static inline unsigned int NR_PREMUL_121(unsigned int c, unsigned int a) { return NR_NORMALIZE_31(NR_PREMUL_123(c, a)); } -static inline unsigned int NR_PREMUL_111(unsigned int c, unsigned int a) { return NR_NORMALIZE_21(NR_PREMUL_112(c, a)); } -static inline unsigned int NR_PREMUL_311(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_314(c, a)); } -static inline unsigned int NR_PREMUL_211(unsigned int c, unsigned int a) { return NR_NORMALIZE_31(NR_PREMUL_213(c, a)); } - -// Demultiply using c/a -static inline unsigned int NR_DEMUL_131(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_231(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_121(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_331(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_221(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_111(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_431(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_321(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_211(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_421(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * a); } -static inline unsigned int NR_DEMUL_311(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * a); } -static inline unsigned int NR_DEMUL_411(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * 255 * a); } - - -#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 : |
