From: kiirala Date: Tue, 12 Jun 2007 19:04:36 +0000 (+0000) Subject: Filter effects: support for SourceAlpha and BackgroundAlpha X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8c8bc76acb37f197eddfd29d36865c15461e4fbb;p=inkscape.git Filter effects: support for SourceAlpha and BackgroundAlpha --- diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index a4d747001..462da04c5 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -75,6 +75,8 @@ display_libspdisplay_a_SOURCES = \ display/nr-filter-offset.h \ display/nr-filter-slot.cpp \ display/nr-filter-slot.h \ + display/nr-filter-getalpha.cpp \ + display/nr-filter-getalpha.h \ display/nr-filter-types.h \ display/pixblock-scaler.cpp \ display/pixblock-scaler.h \ diff --git a/src/display/nr-filter-getalpha.cpp b/src/display/nr-filter-getalpha.cpp new file mode 100644 index 000000000..1aba770a3 --- /dev/null +++ b/src/display/nr-filter-getalpha.cpp @@ -0,0 +1,49 @@ +/* + * Functions for extracting alpha channel from NRPixBlocks. + * + * Author: + * Niko Kiirala + * + * Copyright (C) 2007 Niko Kiirala + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/nr-filter-getalpha.h" +#include "libnr/nr-blit.h" +#include "libnr/nr-pixblock.h" + +namespace NR { + +NRPixBlock *filter_get_alpha(NRPixBlock *src) +{ + NRPixBlock *dst = new NRPixBlock; + nr_pixblock_setup_fast(dst, NR_PIXBLOCK_MODE_R8G8B8A8P, + src->area.x0, src->area.y0, + src->area.x1, src->area.y1, false); + nr_blit_pixblock_pixblock(dst, src); + + unsigned char *data = NR_PIXBLOCK_PX(dst); + int end = dst->rs * (dst->area.y1 - dst->area.y0); + for (int i = 0 ; i < end ; i += 4) { + data[i + 0] = 0; + data[i + 1] = 0; + data[i + 2] = 0; + } + dst->empty = false; + + return dst; +} + +} // namespace NR + +/* + 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/display/nr-filter-getalpha.h b/src/display/nr-filter-getalpha.h new file mode 100644 index 000000000..cfbca0bc1 --- /dev/null +++ b/src/display/nr-filter-getalpha.h @@ -0,0 +1,33 @@ +#ifndef __NR_FILTER_GETALPHA_H__ +#define __NR_FILTER_GETALPHA_H__ + +/* + * Functions for extracting alpha channel from NRPixBlocks. + * + * Author: + * Niko Kiirala + * + * Copyright (C) 2007 Niko Kiirala + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "libnr/nr-pixblock.h" + +namespace NR { + +NRPixBlock *filter_get_alpha(NRPixBlock *src); + +} + +#endif /* __NR_FILTER_GETALPHA_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/display/nr-filter-slot.cpp b/src/display/nr-filter-slot.cpp index 32fc00f99..3cdc20ede 100644 --- a/src/display/nr-filter-slot.cpp +++ b/src/display/nr-filter-slot.cpp @@ -18,6 +18,7 @@ #include "display/nr-arena-item.h" #include "display/nr-filter-types.h" #include "display/nr-filter-slot.h" +#include "display/nr-filter-getalpha.h" #include "libnr/nr-pixblock.h" #include "libnr/nr-blit.h" @@ -66,22 +67,12 @@ NRPixBlock *FilterSlot::get(int slot_nr) || slot_nr == NR_FILTER_STROKEPAINT)) { /* If needed, fetch background */ - if (slot_nr == NR_FILTER_BACKGROUNDIMAGE - || slot_nr == NR_FILTER_BACKGROUNDALPHA) - { + if (slot_nr == NR_FILTER_BACKGROUNDIMAGE) { NRPixBlock *pb; pb = nr_arena_item_get_background(_arena_item); if (pb) { - NRPixBlock *bg = new NRPixBlock; - nr_pixblock_setup_fast(bg, pb->mode, - pb->area.x0, pb->area.y0, - pb->area.x1, pb->area.y1, true); - bool empty = pb->empty; pb->empty = false; - nr_blit_pixblock_pixblock(bg, pb); - pb->empty = empty; - bg->empty = false; - this->set(NR_FILTER_BACKGROUNDIMAGE, bg); + this->set(NR_FILTER_BACKGROUNDIMAGE, pb); } else { NRPixBlock *source = this->get(NR_FILTER_SOURCEGRAPHIC); pb = new NRPixBlock(); @@ -97,19 +88,19 @@ NRPixBlock *FilterSlot::get(int slot_nr) pb->empty = FALSE; this->set(NR_FILTER_BACKGROUNDIMAGE, pb); } - } - /* If only a alpha channel is needed, strip it from full image */ - if (slot_nr == NR_FILTER_SOURCEALPHA) { - // TODO - } - if (slot_nr == NR_FILTER_BACKGROUNDALPHA) { + } else if (slot_nr == NR_FILTER_SOURCEALPHA) { + /* If only a alpha channel is needed, strip it from full image */ + NRPixBlock *src = get(NR_FILTER_SOURCEGRAPHIC); + NRPixBlock *sa = filter_get_alpha(src); + set(NR_FILTER_SOURCEALPHA, sa); + } else if (slot_nr == NR_FILTER_BACKGROUNDALPHA) { + NRPixBlock *src = get(NR_FILTER_BACKGROUNDIMAGE); + NRPixBlock *ba = filter_get_alpha(src); + set(NR_FILTER_BACKGROUNDALPHA, ba); + } else if (slot_nr == NR_FILTER_FILLPAINT) { + /* When a paint is needed, fetch it from arena item */ // TODO - } - /* When a paint is needed, fetch it from arena item */ - if (slot_nr == NR_FILTER_FILLPAINT) { - // TODO - } - if (slot_nr == NR_FILTER_STROKEPAINT) { + } else if (slot_nr == NR_FILTER_STROKEPAINT) { // TODO } } @@ -137,8 +128,8 @@ int FilterSlot::get_slot_count() int seek = _slot_count; do { seek--; - } while (_slot[seek] == NULL); - + } while (!_slot[seek] && _slot_number[seek] == NR_FILTER_SLOT_NOT_SET); + return seek + 1; } @@ -170,7 +161,7 @@ int FilterSlot::_get_index(int slot_nr) int seek = _slot_count; do { seek--; - } while (_slot[seek] == NULL && seek > 0); + } while (_slot_number[seek] == NR_FILTER_SLOT_NOT_SET && seek >= 0); /* If there is no space for more slots, create more space */ if (seek == _slot_count - 1) { NRPixBlock **new_slot = new NRPixBlock*[_slot_count * 2];