Updated with upstream update
This commit is contained in:
@ -918,6 +918,98 @@ pika_gegl_index_to_mask (GeglBuffer *indexed_buffer,
|
||||
});
|
||||
}
|
||||
|
||||
gboolean
|
||||
pika_gegl_is_index_used (GeglBuffer *indexed_buffer,
|
||||
const GeglRectangle *indexed_rect,
|
||||
const Babl *indexed_format,
|
||||
gint index)
|
||||
{
|
||||
GeglBufferIterator *iter;
|
||||
gboolean found = FALSE;
|
||||
|
||||
if (! indexed_rect)
|
||||
indexed_rect = gegl_buffer_get_extent (indexed_buffer);
|
||||
|
||||
iter = gegl_buffer_iterator_new (indexed_buffer, indexed_rect, 0,
|
||||
indexed_format,
|
||||
GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1);
|
||||
|
||||
/* I initially had an implementation using gegl_parallel_distribute_area()
|
||||
* which turned out to be much slower than the simpler iteration on the whole
|
||||
* buffer at once. I think the cost of threading and using GRWLock is just far
|
||||
* too high for such very basic value check.
|
||||
* See gegl_parallel_distribute_area() implementation in commit dbaa8b6a1c.
|
||||
*/
|
||||
while (gegl_buffer_iterator_next (iter))
|
||||
{
|
||||
const guchar *indexed = (const guchar *) iter->items[0].data;
|
||||
gint count = iter->length;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
if (*indexed == index)
|
||||
{
|
||||
/*
|
||||
* Position of one item using this color index:
|
||||
gint x = iter->items[0].roi.x + (iter->length - count - 1) % iter->items[0].roi.width;
|
||||
gint y = iter->items[0].roi.y + (gint) ((iter->length - count - 1) / iter->items[0].roi.width);
|
||||
*/
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
indexed++;
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
gegl_buffer_iterator_stop (iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void
|
||||
pika_gegl_shift_index (GeglBuffer *indexed_buffer,
|
||||
const GeglRectangle *indexed_rect,
|
||||
const Babl *indexed_format,
|
||||
gint from_index,
|
||||
gint shift)
|
||||
{
|
||||
gboolean indexed_format_has_alpha;
|
||||
|
||||
if (! indexed_rect)
|
||||
indexed_rect = gegl_buffer_get_extent (indexed_buffer);
|
||||
|
||||
indexed_format_has_alpha = babl_format_has_alpha (indexed_format);
|
||||
|
||||
gegl_parallel_distribute_area (
|
||||
indexed_rect, PIXELS_PER_THREAD,
|
||||
[=] (const GeglRectangle *indexed_area)
|
||||
{
|
||||
GeglBufferIterator *iter;
|
||||
|
||||
iter = gegl_buffer_iterator_new (indexed_buffer, indexed_area, 0,
|
||||
indexed_format,
|
||||
GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE, 1);
|
||||
|
||||
while (gegl_buffer_iterator_next (iter))
|
||||
{
|
||||
guchar *indexed = (guchar *) iter->items[0].data;
|
||||
gint count = iter->length;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
if (*indexed >= from_index)
|
||||
*indexed += shift;
|
||||
|
||||
indexed += (indexed_format_has_alpha ? 2 : 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
pika_gegl_convert_color_profile_progress (PikaProgress *progress,
|
||||
gdouble value)
|
||||
|
@ -91,6 +91,15 @@ void pika_gegl_index_to_mask (GeglBuffer *indexed_buffer
|
||||
GeglBuffer *mask_buffer,
|
||||
const GeglRectangle *mask_rect,
|
||||
gint index);
|
||||
gboolean pika_gegl_is_index_used (GeglBuffer *indexed_buffer,
|
||||
const GeglRectangle *indexed_rect,
|
||||
const Babl *indexed_format,
|
||||
gint index);
|
||||
void pika_gegl_shift_index (GeglBuffer *indexed_buffer,
|
||||
const GeglRectangle *indexed_rect,
|
||||
const Babl *indexed_format,
|
||||
gint from_index,
|
||||
gint shift);
|
||||
|
||||
void pika_gegl_convert_color_profile (GeglBuffer *src_buffer,
|
||||
const GeglRectangle *src_rect,
|
||||
|
Reference in New Issue
Block a user