mirror of https://github.com/GNOME/gimp.git
plug-ins: port depth-merge to GEGL, stupid 8-bit port only
This commit is contained in:
parent
d93e928703
commit
7cd78f436d
|
@ -475,6 +475,7 @@ depth_merge_LDADD = \
|
|||
$(libgimpcolor) \
|
||||
$(libgimpbase) \
|
||||
$(GTK_LIBS) \
|
||||
$(GEGL_LIBS) \
|
||||
$(RT_LIBS) \
|
||||
$(INTLLIBS) \
|
||||
$(depth_merge_RC)
|
||||
|
|
|
@ -84,11 +84,11 @@ typedef struct _DepthMerge
|
|||
DepthMergeInterface *interface;
|
||||
DepthMergeParams params;
|
||||
|
||||
GimpDrawable *resultDrawable;
|
||||
GimpDrawable *source1Drawable;
|
||||
GimpDrawable *source2Drawable;
|
||||
GimpDrawable *depthMap1Drawable;
|
||||
GimpDrawable *depthMap2Drawable;
|
||||
gint32 resultDrawable_id;
|
||||
gint32 source1Drawable_id;
|
||||
gint32 source2Drawable_id;
|
||||
gint32 depthMap1Drawable_id;
|
||||
gint32 depthMap2Drawable_id;
|
||||
gint selectionX;
|
||||
gint selectionY;
|
||||
gint selectionWidth;
|
||||
|
@ -125,22 +125,15 @@ static void dialogValueScaleUpdateCallback (GtkAdjustment *adjustment,
|
|||
gpointer data);
|
||||
|
||||
static void util_fillReducedBuffer (guchar *dest,
|
||||
const Babl *dest_format,
|
||||
gint destWidth,
|
||||
gint destHeight,
|
||||
gint destBPP,
|
||||
gboolean destHasAlpha,
|
||||
GimpDrawable *sourceDrawable,
|
||||
gint32 sourceDrawable_id,
|
||||
gint x0,
|
||||
gint y0,
|
||||
gint sourceWidth,
|
||||
gint sourceHeight);
|
||||
static void util_convertColorspace (guchar *dest,
|
||||
gint destBPP,
|
||||
gboolean destHasAlpha,
|
||||
const guchar *source,
|
||||
gint sourceBPP,
|
||||
gboolean sourceHasAlpha,
|
||||
gint length);
|
||||
|
||||
|
||||
/* ----- plug-in entry points ----- */
|
||||
|
||||
|
@ -207,13 +200,13 @@ run (const gchar *name,
|
|||
{
|
||||
static GimpParam values[1];
|
||||
GimpRunMode runMode;
|
||||
GimpPDBStatusType status;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
DepthMerge dm;
|
||||
|
||||
INIT_I18N ();
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
runMode = (GimpRunMode) param[0].data.d_int32;
|
||||
status = GIMP_PDB_SUCCESS;
|
||||
runMode = param[0].data.d_int32;
|
||||
|
||||
*numReturnVals = 1;
|
||||
*returnVals = values;
|
||||
|
@ -268,15 +261,15 @@ run (const gchar *name,
|
|||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
gimp_tile_cache_ntiles ((dm.resultDrawable->width +
|
||||
gimp_tile_width () - 1) / gimp_tile_width ());
|
||||
|
||||
if (!DepthMerge_execute (&dm))
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (runMode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
|
||||
if (runMode == GIMP_RUN_INTERACTIVE)
|
||||
gimp_set_data (PLUG_IN_PROC,
|
||||
&(dm.params), sizeof (DepthMergeParams));
|
||||
|
@ -309,34 +302,28 @@ DepthMerge_construct (DepthMerge *dm)
|
|||
{
|
||||
dm->interface = NULL;
|
||||
|
||||
dm->resultDrawable = gimp_drawable_get (dm->params.result);
|
||||
if (! gimp_drawable_mask_intersect (dm->resultDrawable->drawable_id,
|
||||
dm->resultDrawable_id = dm->params.result;
|
||||
|
||||
if (! gimp_drawable_mask_intersect (dm->resultDrawable_id,
|
||||
&(dm->selectionX), &(dm->selectionY),
|
||||
&(dm->selectionWidth),
|
||||
&(dm->selectionHeight)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
dm->resultHasAlpha = gimp_drawable_has_alpha (dm->resultDrawable->drawable_id);
|
||||
|
||||
dm->source1Drawable =
|
||||
(dm->params.source1 == -1) ? NULL : gimp_drawable_get (dm->params.source1);
|
||||
dm->resultHasAlpha = gimp_drawable_has_alpha (dm->resultDrawable_id);
|
||||
|
||||
dm->source2Drawable =
|
||||
(dm->params.source2 == -1) ? NULL : gimp_drawable_get (dm->params.source2);
|
||||
|
||||
dm->depthMap1Drawable =
|
||||
(dm->params.depthMap1 == -1) ?
|
||||
NULL : gimp_drawable_get (dm->params.depthMap1);
|
||||
|
||||
dm->depthMap2Drawable =
|
||||
(dm->params.depthMap2 == -1) ?
|
||||
NULL : gimp_drawable_get (dm->params.depthMap2);
|
||||
dm->source1Drawable_id = dm->params.source1;
|
||||
dm->source2Drawable_id = dm->params.source2;
|
||||
dm->depthMap1Drawable_id = dm->params.depthMap1;
|
||||
dm->depthMap2Drawable_id = dm->params.depthMap2;
|
||||
|
||||
dm->params.overlap = CLAMP (dm->params.overlap, 0, 2);
|
||||
dm->params.offset = CLAMP (dm->params.offset, -1, 1);
|
||||
dm->params.scale1 = CLAMP (dm->params.scale1, -1, 1);
|
||||
dm->params.scale2 = CLAMP (dm->params.scale2, -1, 1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -351,44 +338,21 @@ DepthMerge_destroy (DepthMerge *dm)
|
|||
g_free (dm->interface->previewDepthMap2);
|
||||
g_free (dm->interface);
|
||||
}
|
||||
if (dm->resultDrawable != NULL)
|
||||
gimp_drawable_detach (dm->resultDrawable);
|
||||
|
||||
if (dm->source1Drawable != NULL)
|
||||
gimp_drawable_detach (dm->source1Drawable);
|
||||
|
||||
if (dm->source2Drawable != NULL)
|
||||
gimp_drawable_detach (dm->source2Drawable);
|
||||
|
||||
if (dm->depthMap1Drawable != NULL)
|
||||
gimp_drawable_detach (dm->depthMap1Drawable);
|
||||
|
||||
if (dm->depthMap2Drawable != NULL)
|
||||
gimp_drawable_detach (dm->depthMap2Drawable);
|
||||
}
|
||||
|
||||
static gint32
|
||||
DepthMerge_execute (DepthMerge *dm)
|
||||
{
|
||||
int x, y;
|
||||
GimpPixelRgn source1Rgn, source2Rgn;
|
||||
GimpPixelRgn depthMap1Rgn, depthMap2Rgn;
|
||||
GimpPixelRgn resultRgn;
|
||||
GeglBuffer *source1_buffer = NULL;
|
||||
GeglBuffer *source2_buffer = NULL;
|
||||
GeglBuffer *depthMap1_buffer = NULL;
|
||||
GeglBuffer *depthMap2_buffer = NULL;
|
||||
GeglBuffer *result_buffer;
|
||||
guchar *source1Row, *source2Row;
|
||||
guchar *depthMap1Row, *depthMap2Row;
|
||||
guchar *resultRow;
|
||||
guchar *tempRow;
|
||||
gboolean source1HasAlpha;
|
||||
gboolean source2HasAlpha;
|
||||
gboolean depthMap1HasAlpha;
|
||||
gboolean depthMap2HasAlpha;
|
||||
|
||||
/* initialize */
|
||||
|
||||
source1HasAlpha = FALSE;
|
||||
source2HasAlpha = FALSE;
|
||||
depthMap1HasAlpha = FALSE;
|
||||
depthMap2HasAlpha = FALSE;
|
||||
|
||||
gimp_progress_init (_("Depth-merging"));
|
||||
|
||||
|
@ -399,123 +363,110 @@ DepthMerge_execute (DepthMerge *dm)
|
|||
depthMap2Row = g_new (guchar, dm->selectionWidth );
|
||||
tempRow = g_new (guchar, dm->selectionWidth * 4);
|
||||
|
||||
if (dm->source1Drawable != NULL)
|
||||
if (dm->source1Drawable_id > 0)
|
||||
{
|
||||
source1HasAlpha = gimp_drawable_has_alpha (dm->source1Drawable->drawable_id);
|
||||
gimp_pixel_rgn_init (&source1Rgn, dm->source1Drawable,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight,
|
||||
FALSE, FALSE);
|
||||
source1_buffer = gimp_drawable_get_buffer (dm->source1Drawable_id);
|
||||
}
|
||||
else
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
source1Row[4 * x ] = 0;
|
||||
source1Row[4 * x + 1] = 0;
|
||||
source1Row[4 * x + 2] = 0;
|
||||
source1Row[4 * x + 3] = 255;
|
||||
}
|
||||
if (dm->source2Drawable != NULL)
|
||||
{
|
||||
source2HasAlpha = gimp_drawable_has_alpha (dm->source2Drawable->drawable_id);
|
||||
gimp_pixel_rgn_init (&source2Rgn, dm->source2Drawable,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight,
|
||||
FALSE, FALSE);
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
source1Row[4 * x ] = 0;
|
||||
source1Row[4 * x + 1] = 0;
|
||||
source1Row[4 * x + 2] = 0;
|
||||
source1Row[4 * x + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
if (dm->source2Drawable_id > 0)
|
||||
{
|
||||
source2_buffer = gimp_drawable_get_buffer (dm->source2Drawable_id);
|
||||
}
|
||||
else
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
source2Row[4 * x ] = 0;
|
||||
source2Row[4 * x + 1] = 0;
|
||||
source2Row[4 * x + 2] = 0;
|
||||
source2Row[4 * x + 3] = 255;
|
||||
}
|
||||
if (dm->depthMap1Drawable != NULL)
|
||||
{
|
||||
depthMap1HasAlpha = gimp_drawable_has_alpha (dm->depthMap1Drawable->drawable_id);
|
||||
gimp_pixel_rgn_init (&depthMap1Rgn, dm->depthMap1Drawable,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight,
|
||||
FALSE, FALSE);
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
source2Row[4 * x ] = 0;
|
||||
source2Row[4 * x + 1] = 0;
|
||||
source2Row[4 * x + 2] = 0;
|
||||
source2Row[4 * x + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
if (dm->depthMap1Drawable_id > 0)
|
||||
{
|
||||
depthMap1_buffer = gimp_drawable_get_buffer (dm->depthMap1Drawable_id);
|
||||
}
|
||||
else
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
depthMap1Row[x] = 0;
|
||||
}
|
||||
if (dm->depthMap2Drawable != NULL)
|
||||
{
|
||||
depthMap2HasAlpha = gimp_drawable_has_alpha (dm->depthMap2Drawable->drawable_id);
|
||||
gimp_pixel_rgn_init (&depthMap2Rgn, dm->depthMap2Drawable,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight,
|
||||
FALSE, FALSE);
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
depthMap1Row[x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (dm->depthMap2Drawable_id > 0)
|
||||
{
|
||||
depthMap2_buffer = gimp_drawable_get_buffer (dm->depthMap2Drawable_id);
|
||||
}
|
||||
else
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
depthMap2Row[x] = 0;
|
||||
}
|
||||
gimp_pixel_rgn_init (&resultRgn, dm->resultDrawable,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight,
|
||||
TRUE, TRUE);
|
||||
{
|
||||
for (x = 0; x < dm->selectionWidth; x++)
|
||||
{
|
||||
depthMap2Row[x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
result_buffer = gimp_drawable_get_shadow_buffer (dm->resultDrawable_id);
|
||||
|
||||
for (y = dm->selectionY; y < (dm->selectionY + dm->selectionHeight); y++)
|
||||
{
|
||||
if (dm->source1Drawable != NULL)
|
||||
if (dm->source1Drawable_id > 0)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&source1Rgn, tempRow,
|
||||
dm->selectionX, y,
|
||||
dm->selectionWidth);
|
||||
util_convertColorspace (source1Row, 4, TRUE,
|
||||
tempRow,
|
||||
dm->source1Drawable->bpp, source1HasAlpha,
|
||||
dm->selectionWidth);
|
||||
gegl_buffer_get (source1_buffer,
|
||||
GEGL_RECTANGLE (dm->selectionX, y,
|
||||
dm->selectionWidth, 1), 1.0,
|
||||
babl_format ("R'G'B'A u8"), source1Row,
|
||||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
}
|
||||
if (dm->source2Drawable != NULL)
|
||||
|
||||
if (dm->source2Drawable_id > 0)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&source2Rgn, tempRow,
|
||||
dm->selectionX, y,
|
||||
dm->selectionWidth);
|
||||
util_convertColorspace (source2Row, 4, TRUE,
|
||||
tempRow,
|
||||
dm->source2Drawable->bpp, source2HasAlpha,
|
||||
dm->selectionWidth);
|
||||
gegl_buffer_get (source2_buffer,
|
||||
GEGL_RECTANGLE (dm->selectionX, y,
|
||||
dm->selectionWidth, 1), 1.0,
|
||||
babl_format ("R'G'B'A u8"), source2Row,
|
||||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
}
|
||||
if (dm->depthMap1Drawable != NULL)
|
||||
|
||||
if (dm->depthMap1Drawable_id > 0)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&depthMap1Rgn, tempRow,
|
||||
dm->selectionX, y,
|
||||
dm->selectionWidth);
|
||||
util_convertColorspace (depthMap1Row, 1, FALSE,
|
||||
tempRow,
|
||||
dm->depthMap1Drawable->bpp, depthMap1HasAlpha,
|
||||
dm->selectionWidth);
|
||||
gegl_buffer_get (depthMap1_buffer,
|
||||
GEGL_RECTANGLE (dm->selectionX, y,
|
||||
dm->selectionWidth, 1), 1.0,
|
||||
babl_format ("Y' u8"), depthMap1Row,
|
||||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
}
|
||||
if (dm->depthMap2Drawable != NULL)
|
||||
|
||||
if (dm->depthMap2Drawable_id > 0)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&depthMap2Rgn, tempRow,
|
||||
dm->selectionX, y,
|
||||
dm->selectionWidth);
|
||||
util_convertColorspace (depthMap2Row, 1, FALSE,
|
||||
tempRow,
|
||||
dm->depthMap2Drawable->bpp, depthMap2HasAlpha,
|
||||
dm->selectionWidth);
|
||||
gegl_buffer_get (depthMap2_buffer,
|
||||
GEGL_RECTANGLE (dm->selectionX, y,
|
||||
dm->selectionWidth, 1), 1.0,
|
||||
babl_format ("Y' u8"), depthMap2Row,
|
||||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
}
|
||||
|
||||
DepthMerge_executeRegion (dm,
|
||||
source1Row, source2Row, depthMap1Row, depthMap2Row,
|
||||
resultRow,
|
||||
dm->selectionWidth);
|
||||
util_convertColorspace (tempRow, dm->resultDrawable->bpp, dm->resultHasAlpha,
|
||||
resultRow, 4, TRUE,
|
||||
dm->selectionWidth);
|
||||
|
||||
gimp_pixel_rgn_set_row (&resultRgn, tempRow,
|
||||
dm->selectionX, y,
|
||||
dm->selectionWidth);
|
||||
gegl_buffer_set (result_buffer,
|
||||
GEGL_RECTANGLE (dm->selectionX, y,
|
||||
dm->selectionWidth, 1), 0,
|
||||
babl_format ("R'G'B'A u8"), resultRow,
|
||||
GEGL_AUTO_ROWSTRIDE);
|
||||
|
||||
gimp_progress_update ((double)(y-dm->selectionY) /
|
||||
(double)(dm->selectionHeight - 1));
|
||||
|
@ -529,11 +480,26 @@ DepthMerge_execute (DepthMerge *dm)
|
|||
g_free (tempRow);
|
||||
|
||||
gimp_progress_update (1.0);
|
||||
gimp_drawable_flush (dm->resultDrawable);
|
||||
gimp_drawable_merge_shadow (dm->resultDrawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (dm->resultDrawable->drawable_id,
|
||||
|
||||
if (source1_buffer)
|
||||
g_object_unref (source1_buffer);
|
||||
|
||||
if (source2_buffer)
|
||||
g_object_unref (source2_buffer);
|
||||
|
||||
if (depthMap1_buffer)
|
||||
g_object_unref (depthMap1_buffer);
|
||||
|
||||
if (depthMap2_buffer)
|
||||
g_object_unref (depthMap2_buffer);
|
||||
|
||||
g_object_unref (result_buffer);
|
||||
|
||||
gimp_drawable_merge_shadow (dm->resultDrawable_id, TRUE);
|
||||
gimp_drawable_update (dm->resultDrawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -815,40 +781,43 @@ DepthMerge_buildPreviewSourceImage (DepthMerge *dm)
|
|||
g_new (guchar, dm->interface->previewWidth *
|
||||
dm->interface->previewHeight * 4);
|
||||
util_fillReducedBuffer (dm->interface->previewSource1,
|
||||
babl_format ("R'G'B'A u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
4, TRUE,
|
||||
dm->source1Drawable,
|
||||
dm->source1Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
dm->interface->previewSource2 =
|
||||
g_new (guchar, dm->interface->previewWidth *
|
||||
dm->interface->previewHeight * 4);
|
||||
util_fillReducedBuffer (dm->interface->previewSource2,
|
||||
babl_format ("R'G'B'A u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
4, TRUE,
|
||||
dm->source2Drawable,
|
||||
dm->source2Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
dm->interface->previewDepthMap1 =
|
||||
g_new (guchar, dm->interface->previewWidth *
|
||||
dm->interface->previewHeight * 1);
|
||||
util_fillReducedBuffer (dm->interface->previewDepthMap1,
|
||||
babl_format ("Y' u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
1, FALSE,
|
||||
dm->depthMap1Drawable,
|
||||
dm->depthMap1Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
dm->interface->previewDepthMap2 =
|
||||
g_new (guchar, dm->interface->previewWidth *
|
||||
dm->interface->previewHeight * 1);
|
||||
util_fillReducedBuffer (dm->interface->previewDepthMap2,
|
||||
babl_format ("Y' u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
1, FALSE,
|
||||
dm->depthMap2Drawable,
|
||||
dm->depthMap2Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
}
|
||||
|
@ -917,21 +886,16 @@ static void
|
|||
dialogSource1ChangedCallback (GtkWidget *widget,
|
||||
DepthMerge *dm)
|
||||
{
|
||||
if (dm->source1Drawable)
|
||||
gimp_drawable_detach (dm->source1Drawable);
|
||||
|
||||
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
||||
&dm->params.source1);
|
||||
|
||||
dm->source1Drawable = ((dm->params.source1 == -1) ?
|
||||
NULL :
|
||||
gimp_drawable_get (dm->params.source1));
|
||||
dm->source1Drawable_id = dm->params.source1;
|
||||
|
||||
util_fillReducedBuffer (dm->interface->previewSource1,
|
||||
babl_format ("R'G'B'A u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
4, TRUE,
|
||||
dm->source1Drawable,
|
||||
dm->source1Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
|
@ -942,21 +906,16 @@ static void
|
|||
dialogSource2ChangedCallback (GtkWidget *widget,
|
||||
DepthMerge *dm)
|
||||
{
|
||||
if (dm->source2Drawable)
|
||||
gimp_drawable_detach (dm->source2Drawable);
|
||||
|
||||
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
||||
&dm->params.source2);
|
||||
|
||||
dm->source2Drawable = ((dm->params.source2 == -1) ?
|
||||
NULL :
|
||||
gimp_drawable_get (dm->params.source2));
|
||||
dm->source2Drawable_id = dm->params.source2;
|
||||
|
||||
util_fillReducedBuffer (dm->interface->previewSource2,
|
||||
babl_format ("R'G'B'A u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
4, TRUE,
|
||||
dm->source2Drawable,
|
||||
dm->source2Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
|
@ -967,21 +926,16 @@ static void
|
|||
dialogDepthMap1ChangedCallback (GtkWidget *widget,
|
||||
DepthMerge *dm)
|
||||
{
|
||||
if (dm->depthMap1Drawable)
|
||||
gimp_drawable_detach (dm->depthMap1Drawable);
|
||||
|
||||
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
||||
&dm->params.depthMap1);
|
||||
|
||||
dm->depthMap1Drawable = ((dm->params.depthMap1 == -1) ?
|
||||
NULL :
|
||||
gimp_drawable_get (dm->params.depthMap1));
|
||||
dm->depthMap1Drawable_id = dm->params.depthMap1;
|
||||
|
||||
util_fillReducedBuffer (dm->interface->previewDepthMap1,
|
||||
babl_format ("Y' u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
1, FALSE,
|
||||
dm->depthMap1Drawable,
|
||||
dm->depthMap1Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
|
@ -992,21 +946,16 @@ static void
|
|||
dialogDepthMap2ChangedCallback (GtkWidget *widget,
|
||||
DepthMerge *dm)
|
||||
{
|
||||
if (dm->depthMap2Drawable)
|
||||
gimp_drawable_detach (dm->depthMap2Drawable);
|
||||
|
||||
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
||||
&dm->params.depthMap2);
|
||||
|
||||
dm->depthMap2Drawable = ((dm->params.depthMap2 == -1) ?
|
||||
NULL :
|
||||
gimp_drawable_get (dm->params.depthMap2));
|
||||
dm->depthMap2Drawable_id = dm->params.depthMap2;;
|
||||
|
||||
util_fillReducedBuffer (dm->interface->previewDepthMap2,
|
||||
babl_format ("Y' u8"),
|
||||
dm->interface->previewWidth,
|
||||
dm->interface->previewHeight,
|
||||
1, FALSE,
|
||||
dm->depthMap2Drawable,
|
||||
dm->depthMap2Drawable_id,
|
||||
dm->selectionX, dm->selectionY,
|
||||
dm->selectionWidth, dm->selectionHeight);
|
||||
|
||||
|
@ -1027,177 +976,69 @@ dialogValueScaleUpdateCallback (GtkAdjustment *adjustment,
|
|||
/* ----- Utility routines ----- */
|
||||
|
||||
static void
|
||||
util_fillReducedBuffer (guchar *dest,
|
||||
gint destWidth,
|
||||
gint destHeight,
|
||||
gint destBPP,
|
||||
gboolean destHasAlpha,
|
||||
GimpDrawable *sourceDrawable,
|
||||
gint x0,
|
||||
gint y0,
|
||||
gint sourceWidth,
|
||||
gint sourceHeight)
|
||||
util_fillReducedBuffer (guchar *dest,
|
||||
const Babl *dest_format,
|
||||
gint destWidth,
|
||||
gint destHeight,
|
||||
gint32 sourceDrawable_id,
|
||||
gint x0,
|
||||
gint y0,
|
||||
gint sourceWidth,
|
||||
gint sourceHeight)
|
||||
{
|
||||
GimpPixelRgn rgn;
|
||||
guchar *sourceBuffer, *reducedRowBuffer;
|
||||
guchar *sourceBufferPos, *reducedRowBufferPos;
|
||||
guchar *sourceBufferRow;
|
||||
gint x, y, i, yPrime;
|
||||
gboolean sourceHasAlpha;
|
||||
gint sourceBpp;
|
||||
gint *sourceRowOffsetLookup;
|
||||
GeglBuffer *buffer;
|
||||
guchar *sourceBuffer, *reducedRowBuffer;
|
||||
guchar *sourceBufferPos, *reducedRowBufferPos;
|
||||
guchar *sourceBufferRow;
|
||||
gint x, y, i, yPrime;
|
||||
gint destBPP;
|
||||
gint *sourceRowOffsetLookup;
|
||||
|
||||
if ((sourceDrawable == NULL) || (sourceWidth == 0) || (sourceHeight == 0))
|
||||
destBPP = babl_format_get_bytes_per_pixel (dest_format);
|
||||
|
||||
if ((sourceDrawable_id < 1) || (sourceWidth == 0) || (sourceHeight == 0))
|
||||
{
|
||||
for (x = 0; x < destWidth * destHeight * destBPP; x++)
|
||||
dest[x] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sourceBpp = sourceDrawable->bpp;
|
||||
|
||||
sourceBuffer = g_new (guchar, sourceWidth * sourceHeight * sourceBpp);
|
||||
reducedRowBuffer = g_new (guchar, destWidth * sourceBpp);
|
||||
sourceBuffer = g_new (guchar, sourceWidth * sourceHeight * destBPP);
|
||||
reducedRowBuffer = g_new (guchar, destWidth * destBPP);
|
||||
sourceRowOffsetLookup = g_new (int, destWidth);
|
||||
gimp_pixel_rgn_init (&rgn, sourceDrawable,
|
||||
x0, y0, sourceWidth, sourceHeight,
|
||||
FALSE, FALSE);
|
||||
sourceHasAlpha = gimp_drawable_has_alpha (sourceDrawable->drawable_id);
|
||||
|
||||
buffer = gimp_drawable_get_buffer (sourceDrawable_id);
|
||||
|
||||
for (x = 0; x < destWidth; x++)
|
||||
sourceRowOffsetLookup[x] = (x * (sourceWidth - 1) / (destWidth - 1)) * sourceBpp;
|
||||
sourceRowOffsetLookup[x] = (x * (sourceWidth - 1) / (destWidth - 1)) * destBPP;
|
||||
|
||||
gimp_pixel_rgn_get_rect (&rgn, sourceBuffer,
|
||||
x0, y0, sourceWidth, sourceHeight);
|
||||
gegl_buffer_get (buffer,
|
||||
GEGL_RECTANGLE (x0, y0, sourceWidth, sourceHeight), 1.0,
|
||||
dest_format, sourceBuffer,
|
||||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
|
||||
for (y = 0; y < destHeight; y++)
|
||||
{
|
||||
yPrime = y * (sourceHeight - 1) / (destHeight - 1);
|
||||
sourceBufferRow = &(sourceBuffer[yPrime * sourceWidth * sourceBpp]);
|
||||
sourceBufferRow = &(sourceBuffer[yPrime * sourceWidth * destBPP]);
|
||||
reducedRowBufferPos = reducedRowBuffer;
|
||||
|
||||
for (x = 0; x < destWidth; x++)
|
||||
{
|
||||
sourceBufferPos = sourceBufferRow + sourceRowOffsetLookup[x];
|
||||
for (i = 0; i < sourceBpp; i++)
|
||||
for (i = 0; i < destBPP; i++)
|
||||
reducedRowBufferPos[i] = sourceBufferPos[i];
|
||||
reducedRowBufferPos += sourceBpp;
|
||||
reducedRowBufferPos += destBPP;
|
||||
}
|
||||
util_convertColorspace(&(dest[y * destWidth * destBPP]), destBPP, destHasAlpha,
|
||||
reducedRowBuffer, sourceDrawable->bpp, sourceHasAlpha,
|
||||
destWidth);
|
||||
|
||||
memcpy (&(dest[y * destWidth * destBPP]), reducedRowBuffer,
|
||||
destWidth * destBPP);
|
||||
}
|
||||
|
||||
g_object_unref (buffer);
|
||||
|
||||
g_free (sourceBuffer);
|
||||
g_free (reducedRowBuffer);
|
||||
g_free (sourceRowOffsetLookup);
|
||||
}
|
||||
|
||||
/* Utterly pathetic kludge to convert between color spaces;
|
||||
likes gray and rgb best, of course. Others will be creatively mutilated,
|
||||
and even rgb->gray is pretty bad */
|
||||
static void
|
||||
util_convertColorspace (guchar *dest,
|
||||
gint destBPP,
|
||||
gboolean destHasAlpha,
|
||||
const guchar *source,
|
||||
gint sourceBPP,
|
||||
gboolean sourceHasAlpha,
|
||||
gint length)
|
||||
{
|
||||
gint i, j;
|
||||
gint sourcePos, destPos;
|
||||
gint accum;
|
||||
gint sourceColorBPP = sourceHasAlpha ? (sourceBPP - 1) : sourceBPP;
|
||||
gint destColorBPP = destHasAlpha ? (destBPP - 1) : destBPP;
|
||||
|
||||
if ((sourceColorBPP == destColorBPP) &&
|
||||
(sourceBPP == destBPP ))
|
||||
{
|
||||
j = length * sourceBPP;
|
||||
for (i = 0; i < j; i++)
|
||||
dest[i] = source[i];
|
||||
return;
|
||||
}
|
||||
|
||||
if (sourceColorBPP == destColorBPP)
|
||||
{
|
||||
for (i = destPos = sourcePos = 0;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
for (j = 0; j < destColorBPP; j++)
|
||||
dest[destPos + j] = source[sourcePos + j];
|
||||
}
|
||||
}
|
||||
else if (sourceColorBPP == 1)
|
||||
{
|
||||
/* Duplicate single "gray" source byte across all dest bytes */
|
||||
for (i = destPos = sourcePos = 0;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
for (j = 0; j < destColorBPP; j++)
|
||||
dest[destPos + j] = source[sourcePos];
|
||||
}
|
||||
}
|
||||
else if (destColorBPP == 1)
|
||||
{
|
||||
/* Average all source bytes into single "gray" dest byte */
|
||||
for (i = destPos = sourcePos = 0;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
accum = 0;
|
||||
for (j = 0; j < sourceColorBPP; j++)
|
||||
accum += source[sourcePos + j];
|
||||
dest[destPos] = accum/sourceColorBPP;
|
||||
}
|
||||
}
|
||||
else if (destColorBPP < sourceColorBPP)
|
||||
{
|
||||
/* Copy as many corresponding bytes from source to dest as will fit */
|
||||
for (i = destPos = sourcePos = 0;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
for (j = 0; j < destColorBPP; j++)
|
||||
dest[destPos + j] = source[sourcePos + j];
|
||||
}
|
||||
}
|
||||
else /* destColorBPP > sourceColorBPP */
|
||||
{
|
||||
/* Fill extra dest bytes with zero */
|
||||
for (i = destPos = sourcePos = 0;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
for (j = 0; j < sourceColorBPP; j++)
|
||||
dest[destPos + j] = source[destPos + j];
|
||||
for ( ; j < destColorBPP; j++)
|
||||
dest[destPos + j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (destHasAlpha)
|
||||
{
|
||||
if (sourceHasAlpha)
|
||||
{
|
||||
for (i = 0, destPos = destColorBPP, sourcePos = sourceColorBPP;
|
||||
i < length;
|
||||
i++, destPos += destBPP, sourcePos += sourceBPP)
|
||||
{
|
||||
dest[destPos] = source[sourcePos];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0, destPos = destColorBPP;
|
||||
i < length;
|
||||
i++, destPos += destBPP)
|
||||
{
|
||||
dest[destPos] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
'crop-zealous' => { gegl => 1 },
|
||||
'curve-bend' => { ui => 1, gegl => 1 },
|
||||
'decompose' => { ui => 1, gegl => 1 },
|
||||
'depth-merge' => { ui => 1 },
|
||||
'depth-merge' => { ui => 1, gegl => 1 },
|
||||
'despeckle' => { ui => 1, gegl => 1 },
|
||||
'destripe' => { ui => 1, gegl => 1 },
|
||||
'emboss' => { ui => 1 },
|
||||
|
|
Loading…
Reference in New Issue