Commit c92bedb4 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added new function gimp_viewable_get_dummy_preview() which currently

2004-02-10  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpviewable.[ch]: added new function
	gimp_viewable_get_dummy_preview() which currently returns a
	completely white and opaque TempBuf of the requested size.  Added
	this useless function because this is the place where to implement
	a nicer preview if someone volunteers.

	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/image.pdb: use the new function if
	gimp->config->layer_previews is FALSE instead of returning no
	preview at all. Fixes bug #112012.

	Cleaned up the preview functions a bit and raised
	the limit for drawable previews from 128x128 to 256x256.

	* app/pdb/drawable_cmds.c
	* app/pdb/image_cmds.c
	* libgimp/gimpdrawable_pdb.c: regenerated.
parent d46dca66
2004-02-10 Michael Natterer <mitch@gimp.org>
* app/core/gimpviewable.[ch]: added new function
gimp_viewable_get_dummy_preview() which currently returns a
completely white and opaque TempBuf of the requested size. Added
this useless function because this is the place where to implement
a nicer preview if someone volunteers.
* tools/pdbgen/pdb/drawable.pdb
* tools/pdbgen/pdb/image.pdb: use the new function if
gimp->config->layer_previews is FALSE instead of returning no
preview at all. Fixes bug #112012.
Cleaned up the preview functions a bit and raised
the limit for drawable previews from 128x128 to 256x256.
* app/pdb/drawable_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpdrawable_pdb.c: regenerated.
2004-02-10 Sven Neumann <sven@gimp.org>
 
* configure.in: warn when gimpprint is older than version 4.2.6.
......@@ -555,6 +555,22 @@ gimp_viewable_get_new_preview (GimpViewable *viewable,
return NULL;
}
TempBuf *
gimp_viewable_get_dummy_preview (GimpViewable *viewable,
gint width,
gint height,
gint bpp)
{
guchar col[MAX_CHANNELS] = { 255, 255, 255, 255 };
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (bpp > 0, NULL);
return temp_buf_new (width, height, bpp, 0, 0, col);
}
GdkPixbuf *
gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
gint width,
......
......@@ -123,6 +123,11 @@ TempBuf * gimp_viewable_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
TempBuf * gimp_viewable_get_dummy_preview (GimpViewable *vieable,
gint width,
gint height,
gint bpp);
GdkPixbuf * gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height);
......
......@@ -31,6 +31,7 @@
#include "base/temp-buf.h"
#include "base/tile-manager.h"
#include "base/tile.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpdrawable-offset.h"
......@@ -1657,7 +1658,7 @@ drawable_get_pixel_invoker (Gimp *gimp,
{
if (x < gimp_item_width (GIMP_ITEM (drawable)) &&
y < gimp_item_height (GIMP_ITEM (drawable)))
{
{
num_channels = gimp_drawable_bytes (drawable);
pixel = g_new (guint8, num_channels);
......@@ -1987,40 +1988,50 @@ drawable_thumbnail_invoker (Gimp *gimp,
success = FALSE;
req_width = args[1].value.pdb_int;
if (req_width <= 0)
if (req_width <= 0 || req_width > 256)
success = FALSE;
req_height = args[2].value.pdb_int;
if (req_height <= 0)
if (req_height <= 0 || req_height > 256)
success = FALSE;
if (success)
{
TempBuf *buf;
gint dwidth, dheight;
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
TempBuf *buf;
gint dwidth, dheight;
/* Adjust the width/height ratio */
dwidth = gimp_item_width (GIMP_ITEM (drawable));
dheight = gimp_item_height (GIMP_ITEM (drawable));
if (req_width <= 128 && req_height <= 128)
{
/* Adjust the width/height ratio */
dwidth = gimp_item_width (GIMP_ITEM (drawable));
dheight = gimp_item_height (GIMP_ITEM (drawable));
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
if (gimage->gimp->config->layer_previews)
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (drawable),
req_width, req_height);
else
buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (drawable),
req_width, req_height,
gimp_drawable_has_alpha (drawable) ?
4 : 3);
buf = gimp_viewable_get_preview (GIMP_VIEWABLE (drawable),
req_width, req_height);
if (buf)
{
num_bytes = buf->height * buf->width * buf->bytes;
thumbnail_data = g_memdup (temp_buf_data (buf), num_bytes);
width = buf->width;
height = buf->height;
bpp = buf->bytes;
if (buf)
{
num_bytes = buf->height * buf->width * buf->bytes;
thumbnail_data = g_memdup (temp_buf_data (buf), num_bytes);
width = buf->width;
height = buf->height;
bpp = buf->bytes;
}
temp_buf_free (buf);
}
else
{
success = FALSE;
}
}
......@@ -2090,7 +2101,7 @@ static ProcRecord drawable_thumbnail_proc =
{
"gimp_drawable_thumbnail",
"Get a thumbnail of a drawable.",
"This function gets data from which a thumbnail of a drawable preview can be created. Maximum x or y dimension is 128 pixels. The pixels are returned in the RGB[A] format. The bpp return value gives the number of bytes in the image. The alpha channel is also returned if the drawable has one.",
"This function gets data from which a thumbnail of a drawable preview can be created. Maximum x or y dimension is 256 pixels. The pixels are returned in the RGB[A] format. The bpp return value gives the number of bytes in the image. The alpha channel is also returned if the drawable has one.",
"Andy Thomas",
"Andy Thomas",
"1999",
......
......@@ -2717,16 +2717,22 @@ image_thumbnail_invoker (Gimp *gimp,
g_assert (GIMP_VIEWABLE_MAX_PREVIEW_SIZE >= 1024);
/* Adjust the width/height ratio */
dwidth = gimage->width;
dheight = gimage->height;
dwidth = gimp_image_get_width (gimage);
dheight = gimp_image_get_height (gimage);
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (gimage),
req_width, req_height);
if (gimage->gimp->config->layer_previews)
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (gimage),
req_width, req_height);
else
buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (gimage),
req_width, req_height,
gimp_image_has_alpha (gimage) ?
4 : 3);
if (buf)
{
......@@ -2738,6 +2744,10 @@ image_thumbnail_invoker (Gimp *gimp,
temp_buf_free (buf);
}
else
{
success = FALSE;
}
}
return_args = procedural_db_return_args (&image_thumbnail_proc, success);
......
......@@ -1117,7 +1117,7 @@ gimp_drawable_offset (gint32 drawable_ID,
* Get a thumbnail of a drawable.
*
* This function gets data from which a thumbnail of a drawable preview
* can be created. Maximum x or y dimension is 128 pixels. The pixels
* can be created. Maximum x or y dimension is 256 pixels. The pixels
* are returned in the RGB[A] format. The bpp return value gives the
* number of bytes in the image. The alpha channel is also returned if
* the drawable has one.
......
......@@ -54,7 +54,7 @@ sub drawable_prop_proc {
@inargs = ( &drawable_arg );
@outargs = (
{ name => $name, type => $type, desc => $desc,
{ name => $name, type => $type, desc => $desc,
alias => "gimp_${core_type}_$func (${core_var})", no_declare => 1 }
);
}
......@@ -467,7 +467,7 @@ HELP
{
if (x < gimp_item_width (GIMP_ITEM (drawable)) &&
y < gimp_item_height (GIMP_ITEM (drawable)))
{
{
num_channels = gimp_drawable_bytes (drawable);
pixel = g_new (guint8, num_channels);
......@@ -564,9 +564,9 @@ sub drawable_thumbnail {
$blurb = 'Get a thumbnail of a drawable.';
$help = <<'HELP';
This function gets data from which a thumbnail of a drawable preview can be
created. Maximum x or y dimension is 128 pixels. The pixels are returned
in the RGB[A] format. The bpp return value gives the number of bytes in
This function gets data from which a thumbnail of a drawable preview can be
created. Maximum x or y dimension is 256 pixels. The pixels are returned
in the RGB[A] format. The bpp return value gives the number of bytes in
the image. The alpha channel is also returned if the drawable has one.
HELP
......@@ -575,12 +575,10 @@ HELP
@inargs = (
&drawable_arg,
{ name => 'width', type => '0 < int32',
desc => 'The thumbnail width',
alias => 'req_width' },
{ name => 'height', type => '0 < int32',
desc => 'The thumbnail height',
alias => 'req_height' }
{ name => 'width', type => '0 < int32 <= 256',
desc => 'The thumbnail width', alias => 'req_width' },
{ name => 'height', type => '0 < int32 <= 256',
desc => 'The thumbnail height', alias => 'req_height' }
);
@outargs = (
......@@ -596,31 +594,41 @@ HELP
%invoke = (
code => <<'CODE'
{
TempBuf *buf;
gint dwidth, dheight;
if (req_width <= 128 && req_height <= 128)
{
/* Adjust the width/height ratio */
dwidth = gimp_item_width (GIMP_ITEM (drawable));
dheight = gimp_item_height (GIMP_ITEM (drawable));
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
buf = gimp_viewable_get_preview (GIMP_VIEWABLE (drawable),
req_width, req_height);
if (buf)
{
num_bytes = buf->height * buf->width * buf->bytes;
thumbnail_data = g_memdup (temp_buf_data (buf), num_bytes);
width = buf->width;
height = buf->height;
bpp = buf->bytes;
}
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
TempBuf *buf;
gint dwidth, dheight;
/* Adjust the width/height ratio */
dwidth = gimp_item_width (GIMP_ITEM (drawable));
dheight = gimp_item_height (GIMP_ITEM (drawable));
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
if (gimage->gimp->config->layer_previews)
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (drawable),
req_width, req_height);
else
buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (drawable),
req_width, req_height,
gimp_drawable_has_alpha (drawable) ?
4 : 3);
if (buf)
{
num_bytes = buf->height * buf->width * buf->bytes;
thumbnail_data = g_memdup (temp_buf_data (buf), num_bytes);
width = buf->width;
height = buf->height;
bpp = buf->bytes;
temp_buf_free (buf);
}
else
{
success = FALSE;
}
}
CODE
......@@ -670,8 +678,8 @@ sub drawable_delete {
$blurb = 'Delete a drawable.';
$help = <<'HELP';
This procedure deletes the specified drawable. This must not be done if the
gimage containing this drawable was already deleted or if the drawable was
This procedure deletes the specified drawable. This must not be done if the
gimage containing this drawable was already deleted or if the drawable was
already removed from the image. The only case in which this procedure is
useful is if you want to get rid of a drawable which has not yet been
added to an image.
......@@ -692,10 +700,11 @@ HELP
CODE
}
@headers = qw("core/gimp.h" "core/gimplayer.h" "core/gimplayermask.h"
@headers = qw("base/tile.h" "base/tile-manager.h" "base/temp-buf.h"
"config/gimpcoreconfig.h"
"core/gimp.h" "core/gimplayer.h" "core/gimplayermask.h"
"core/gimpchannel.h" "core/gimpdrawable.h"
"core/gimpdrawable-offset.h" "base/tile.h" "base/tile-manager.h"
"base/temp-buf.h" "gimp-intl.h");
"core/gimpdrawable-offset.h" "gimp-intl.h");
@procs = qw(drawable_delete
drawable_is_layer drawable_is_layer_mask drawable_is_channel
......
......@@ -1451,16 +1451,22 @@ HELP
g_assert (GIMP_VIEWABLE_MAX_PREVIEW_SIZE >= 1024);
/* Adjust the width/height ratio */
dwidth = gimage->width;
dheight = gimage->height;
dwidth = gimp_image_get_width (gimage);
dheight = gimp_image_get_height (gimage);
if (dwidth > dheight)
req_height = MAX (1, (req_width * dheight) / dwidth);
else
req_width = MAX (1, (req_height * dwidth) / dheight);
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (gimage),
req_width, req_height);
if (gimage->gimp->config->layer_previews)
buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (gimage),
req_width, req_height);
else
buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (gimage),
req_width, req_height,
gimp_image_has_alpha (gimage) ?
4 : 3);
if (buf)
{
......@@ -1472,6 +1478,10 @@ HELP
temp_buf_free (buf);
}
else
{
success = FALSE;
}
}
CODE
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment