plug-ins: hot's dest_buffer can have another format than src_buffer

(cherry picked from commit 32a229b049)
This commit is contained in:
Michael Natterer
2019-07-11 16:17:35 +02:00
parent f837e3c458
commit a24f75f4bd

View File

@ -309,13 +309,15 @@ pluginCore (piArgs *argp)
{ {
GeglBuffer *src_buffer; GeglBuffer *src_buffer;
GeglBuffer *dest_buffer; GeglBuffer *dest_buffer;
const Babl *format; const Babl *src_format;
const Babl *dest_format;
gint src_bpp;
gint dest_bpp;
gboolean success = TRUE; gboolean success = TRUE;
gint nl = 0; gint nl = 0;
gint y, i; gint y, i;
gint Y, I, Q; gint Y, I, Q;
gint width, height; gint width, height;
gint bpp;
gint sel_x1, sel_x2, sel_y1, sel_y2; gint sel_x1, sel_x2, sel_y1, sel_y2;
gint prog_interval; gint prog_interval;
guchar *src, *s, *dst, *d; guchar *src, *s, *dst, *d;
@ -330,11 +332,11 @@ pluginCore (piArgs *argp)
height = gimp_drawable_height (argp->drawable); height = gimp_drawable_height (argp->drawable);
if (gimp_drawable_has_alpha (argp->drawable)) if (gimp_drawable_has_alpha (argp->drawable))
format = babl_format ("R'G'B'A u8"); src_format = babl_format ("R'G'B'A u8");
else else
format = babl_format ("R'G'B' u8"); src_format = babl_format ("R'G'B' u8");
bpp = babl_format_get_bytes_per_pixel (format); dest_format = src_format;
if (argp->new_layerp) if (argp->new_layerp)
{ {
@ -362,17 +364,22 @@ pluginCore (piArgs *argp)
gimp_drawable_fill (nl, GIMP_FILL_TRANSPARENT); gimp_drawable_fill (nl, GIMP_FILL_TRANSPARENT);
gimp_image_insert_layer (argp->image, nl, -1, 0); gimp_image_insert_layer (argp->image, nl, -1, 0);
dest_format = babl_format ("R'G'B'A u8");
} }
if (! gimp_drawable_mask_intersect (argp->drawable, if (! gimp_drawable_mask_intersect (argp->drawable,
&sel_x1, &sel_y1, &width, &height)) &sel_x1, &sel_y1, &width, &height))
return success; return success;
src_bpp = babl_format_get_bytes_per_pixel (src_format);
dest_bpp = babl_format_get_bytes_per_pixel (dest_format);
sel_x2 = sel_x1 + width; sel_x2 = sel_x1 + width;
sel_y2 = sel_y1 + height; sel_y2 = sel_y1 + height;
src = g_new (guchar, width * height * bpp); src = g_new (guchar, width * height * src_bpp);
dst = g_new (guchar, width * height * 4); dst = g_new (guchar, width * height * dest_bpp);
src_buffer = gimp_drawable_get_buffer (argp->drawable); src_buffer = gimp_drawable_get_buffer (argp->drawable);
@ -387,7 +394,7 @@ pluginCore (piArgs *argp)
gegl_buffer_get (src_buffer, gegl_buffer_get (src_buffer,
GEGL_RECTANGLE (sel_x1, sel_y1, width, height), 1.0, GEGL_RECTANGLE (sel_x1, sel_y1, width, height), 1.0,
format, src, src_format, src,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
s = src; s = src;
@ -414,7 +421,7 @@ pluginCore (piArgs *argp)
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
*d++ = 0; *d++ = 0;
s += 3; s += 3;
if (bpp == 4) if (src_bpp == 4)
*d++ = *s++; *d++ = *s++;
else if (argp->new_layerp) else if (argp->new_layerp)
*d++ = 255; *d++ = 255;
@ -430,7 +437,7 @@ pluginCore (piArgs *argp)
*d++ = new_g; *d++ = new_g;
*d++ = new_b; *d++ = new_b;
s += 3; s += 3;
if (bpp == 4) if (src_bpp == 4)
*d++ = *s++; *d++ = *s++;
else if (argp->new_layerp) else if (argp->new_layerp)
*d++ = 255; *d++ = 255;
@ -537,7 +544,7 @@ pluginCore (piArgs *argp)
s += 3; s += 3;
if (bpp == 4) if (src_bpp == 4)
*d++ = *s++; *d++ = *s++;
else if (argp->new_layerp) else if (argp->new_layerp)
*d++ = 255; *d++ = 255;
@ -548,13 +555,13 @@ pluginCore (piArgs *argp)
{ {
if (! argp->new_layerp) if (! argp->new_layerp)
{ {
for (i = 0; i < bpp; i++) for (i = 0; i < src_bpp; i++)
*d++ = *s++; *d++ = *s++;
} }
else else
{ {
s += bpp; s += src_bpp;
d += 4; d += dest_bpp;
} }
} }
} }
@ -562,7 +569,7 @@ pluginCore (piArgs *argp)
gegl_buffer_set (dest_buffer, gegl_buffer_set (dest_buffer,
GEGL_RECTANGLE (sel_x1, sel_y1, width, height), 0, GEGL_RECTANGLE (sel_x1, sel_y1, width, height), 0,
format, dst, dest_format, dst,
GEGL_AUTO_ROWSTRIDE); GEGL_AUTO_ROWSTRIDE);
gimp_progress_update (1.0); gimp_progress_update (1.0);