#!/usr/bin/perl -w
my
%imagetype2layertype
= (
RGB, RGB_IMAGE,
GRAY, GRAY_IMAGE,
INDEXED, INDEXED_IMAGE,
);
podregister {
$drawable
->is_layer or
die
"this plug-in only works for layers"
;
$image
->undo_group_start;
$drawable
->mask_bounds or
$image
->selection_all;
my
(
$x1
,
$y1
,
$x2
,
$y2
)=(
$drawable
->mask_bounds)[1..4];
my
(
$w
,
$h
)=(
$x2
-
$x1
,
$y2
-
$y1
);
my
$sel
=
$image
->selection_save;
$image
->select_rectangle(CHANNEL_OP_REPLACE,
$x1
,
$y1
,
$w
,
$h
);
$drawable
->edit_copy;
$image
->select_item(CHANNEL_OP_REPLACE,
$sel
);
$sel
->remove_channel;
my
$copy
= new Gimp::Image(
$w
,
$h
,
$image
->base_type);
$copy
->undo_disable;
my
$draw
= new Gimp::Layer(
$copy
,
$w
,
$h
,
$imagetype2layertype
{
$image
->base_type},
"temporary layer"
, 100, LAYER_MODE_NORMAL_LEGACY
);
$copy
->insert_layer (
$draw
, 0, 1);
$draw
->edit_paste(0)->anchor;
$copy
->convert_indexed (
$dither_type
, CONVERT_PALETTE_GENERATE,
$colours
, 1, 1,
""
);
$draw
->edit_copy;
$drawable
->edit_paste(1)->anchor;
$copy
->
delete
;
$image
->undo_group_end;
();
};
exit
main;