Re: A request for future gdk_scale_pixbuf...



Hi,

Have a look at the implementation of scale_simple:

GdkPixbuf *
gdk_pixbuf_scale_simple (const GdkPixbuf *src,
                         int              dest_width,
                         int              dest_height,
                         GdkInterpType    interp_type)
{
  GdkPixbuf *dest;

  g_return_val_if_fail (src != NULL, NULL);
  g_return_val_if_fail (dest_width > 0, NULL);
  g_return_val_if_fail (dest_height > 0, NULL);

  dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height);
  if (!dest)
    return NULL;

  gdk_pixbuf_scale (src, dest,  0, 0, dest_width, dest_height, 0, 0,
                    (double) dest_width / src->width,
                    (double) dest_height / src->height,
                    interp_type);

  return dest;
}

This is the function people would normally actually choose to use. The
others are sort of an exercise in overgenericity, though they may be
useful from time to time.
 
b) the API documentation, as written, implies that the function
actually reallocates the source pixbuf and changes the pixels inside
it. I am guessing that it really just reads the source pixbuf line by
line and performs an implicit transformation before blitting the
result to the destination pixbuf, but that's not what the
documentation says :)

I can see how the docs are confusing, I'll clarify them.
 
I was hoping that it worked like the drawing code in (say) OS/2, where
you specify a source rect within the source bitmap and a destination
rect within the destination bitmap. That way, everything is always an
integer.

scale_simple() only shows you integers. (It uses floats internally,
but if things ever come out wrong just file a bug report and we'll fix
it - they shouldn't come out wrong.)

In GTK 2 you can create a "subpixbuf" of the source image, in order to
scale only a subregion of it. gdk-pixbuf 0.x standalone lib doesn't
have this though, so you have to use the full gdk_pixbuf_scale() to
scale only a subregion.

I guess it's possible to wrap the function to get the behavior I
desire, but I'm still working with trying to understand how it works :/

scale_simple() source code should make it fairly clear how to do the
simple thing, I hope.

Havoc



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]