Linux GTK 缩放 (Scaling) — 缩放pixbuf和缩放并合并pixbuf

来源:互联网 发布:批量下载歌词软件 编辑:程序博客网 时间:2024/04/28 13:43

Linux GTK 缩放 (Scaling) — 缩放pixbuf和缩放并合并pixbuf

http://gtk-doc-cn.googlecode.com/svn/docs/gdk-pixbuf/gdk-pixbuf-%E7%BC%A9%E6%94%BE-%28Scaling%29.html

缩放 (Scaling)

缩放 (Scaling) — 缩放pixbuf和缩放并合并pixbuf。

 

Synopsis

#include <gdk-pixbuf/gdk-pixbuf.h>enum                GdkInterpType;GdkPixbuf *         gdk_pixbuf_scale_simple             (const GdkPixbuf *src,                                                         int dest_width,                                                         int dest_height,                                                         GdkInterpType interp_type);void                gdk_pixbuf_scale                    (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type);GdkPixbuf *         gdk_pixbuf_composite_color_simple   (const GdkPixbuf *src,                                                         int dest_width,                                                         int dest_height,                                                         GdkInterpType interp_type,                                                         int overall_alpha,                                                         int check_size,                                                         guint32 color1,                                                         guint32 color2);void                gdk_pixbuf_composite                (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type,                                                         int overall_alpha);void                gdk_pixbuf_composite_color          (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type,                                                         int overall_alpha,                                                         int check_x,                                                         int check_y,                                                         int check_size,                                                         guint32 color1,                                                         guint32 color2);enum                GdkPixbufRotation;GdkPixbuf *         gdk_pixbuf_rotate_simple            (const GdkPixbuf *src,                                                         GdkPixbufRotation angle);GdkPixbuf *         gdk_pixbuf_flip                     (const GdkPixbuf *src,                                                         gboolean horizontal);

Description

&gdk-pixbuf; 包含一些缩放pixbuf的函数,这些函数可以用来缩放pixbuf并与已有的图像合并,还可以缩放pixbuf并与实体颜色(solid color)或颜色棋盘(checkerboard)。与颜色棋盘(checkerboard)合并是图像查看和编辑软件显示带alpha通道的图像的常用方法。

因为完全特性(full-featured)函数(gdk_pixbuf_scale(),gdk_pixbuf_composite(), and gdk_pixbuf_composite_color())使用起来非常复杂而且有很多参数,所以提供了两个简单便捷的函数,gdk_pixbuf_scale_simple()gdk_pixbuf_composite_color_simple(),这两个函数按给定的大小创建一个新的pixbuf并将缩放原始图像来适应它,然后返回这个新的pixbuf。

Scaling and compositing functions take advantage of MMX hardwareacceleration on systems where MMX is supported. If gdk-pixbuf is builtwith the Sun mediaLib library, these functions are instead acceleratedusing mediaLib, which provides hardware acceleration on Intel, AMD,and Sparc chipsets. If desired, mediaLib support can be turned off bysetting the GDK_DISABLE_MEDIALIB environment variable.

下面的例子演示了通过将源图像(已经缩放到适合构件的尺寸)的一个适当的区域渲染到构件的窗体上来处理一个expose事件。这个源图像与一个棋盘(checkerboard)合成,如果源图像有alpha通道那么这个棋盘将提供一个alpha通道的视觉表现。如果源图像没有alpha通道,调用gdk_pixbuf_composite_color() 和 调用 gdk_pixbuf_scale() 的效果是完全一样的。

Example 2. 处理一个expose事件。

gbooleanexpose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data){  GdkPixbuf *dest;  dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);  gdk_pixbuf_composite_color (pixbuf, dest,                              0, 0, event->area.width, event->area.height,                              -event->area.x, -event->area.y,                              (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),                              (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),                              GDK_INTERP_BILINEAR, 255,                              event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);  gdk_draw_pixbuf (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], dest,                   0, 0, event->area.x, event->area.y,                   event->area.width, event->area.height,                   GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);    gdk_pixbuf_unref (dest);    return TRUE;}


Details

enum GdkInterpType

typedef enum {GDK_INTERP_NEAREST,GDK_INTERP_TILES,GDK_INTERP_BILINEAR,GDK_INTERP_HYPER} GdkInterpType;

This enumeration describes the different interpolation modes that can be used with the scaling functions.GDK_INTERP_NEAREST is the fastest scaling method, but has horrible quality when scaling down.GDK_INTERP_BILINEAR is the best choice if you aren't sure what to choose, it has a good speed/quality balance.

Note

Cubic filtering is missing from the list; hyperbolicinterpolation is just as fast and results in higher quality.

GDK_INTERP_NEAREST

Nearest neighbor sampling; this is the fastest and lowest quality mode. Quality is normally unacceptable when scaling down, but may be OK when scaling up.

GDK_INTERP_TILES

This is an accurate simulation of the PostScript image operator without any interpolation enabled. Each pixel is rendered as a tiny parallelogram of solid color, the edges of which are implemented with antialiasing. It resembles nearest neighbor for enlargement, and bilinear for reduction.

GDK_INTERP_BILINEAR

Best quality/speed balance; use this mode by default. Bilinear interpolation. For enlargement, it is equivalent to point-sampling the ideal bilinear-interpolated image. For reduction, it is equivalent to laying down small tiles and integrating over the coverage area.

GDK_INTERP_HYPER

This is the slowest and highest quality reconstruction function. It is derived from the hyperbolic filters in Wolberg's "Digital Image Warping", and is formally defined as the hyperbolic-filter sampling the ideal hyperbolic-filter interpolated image (the filter is designed to be idempotent for 1:1 pixel mapping).

gdk_pixbuf_scale_simple ()

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

创建一个包含 src 缩放到 dest_widthdest_height 的新的 GdkPixbuf。保持 src 不受影响。如果想速度最大化可以给interp_type 传递 GDK_INTERP_NEAREST(但当 GDK_INTERP_NEAREST 缩小时图像一般会变的相当难看)。 interp_type 默认值为 GDK_INTERP_BILINEAR,该值提供了一个合理的质量和速度。

通过创建一个指向 $src 的 sub-pixbuf 可以缩放 src 的一部分;参见gdk_pixbuf_new_subpixbuf()

更复杂的缩放/合成请参见 gdk_pixbuf_scale()gdk_pixbuf_composite()

src :

a GdkPixbuf

dest_width :

目标图像的宽度

dest_height :

目标图像的高度

interp_type :

变形时使用的插值类型。

Returns :

一个新的 GdkPixbuf,内存不足返回 NULL。. [transfer full]

gdk_pixbuf_scale ()

void                gdk_pixbuf_scale                    (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type);

通过 scale_x 和 $scale_y 指定的缩放以及 offset_xoffset_y 指定的偏移量创建一个原始图像src 的变形图像,并将其一个矩形区域(dest_x,dest_y, dest_width,dest_height)渲染到目标图像以取代先前的内容。

先尝试使用 gdk_pixbuf_scale_simple() ,如果 gdk_pixbuf_scale_simple() 不够强大时你可以退回来使用这是一个工业强度(industrial-strength)的有用工具。

如果源矩形重叠在同一个pixbuf目标矩形,在缩放渲染artifacts结果的期间它会被覆盖。

src :

a GdkPixbuf

dest :

这个 GdkPixbuf 要渲染的目标。

dest_x :

要渲染的区域的左坐标值。

dest_y :

要渲染的区域的顶坐标值。

dest_width :

要渲染的区域的宽度。

dest_height :

要渲染的区域的高度。

offset_x :

X 方向的偏移值(当前近似到整数)。

offset_x :

Y 方向的偏移值(当前近似到整数)。

scale_x :

X 坐标方向上的比例数

scale_y :

Y 坐标方向上的比例数

interp_type :

变形时使用的插值类型。

gdk_pixbuf_composite_color_simple ()

GdkPixbuf *         gdk_pixbuf_composite_color_simple   (const GdkPixbuf *src,                                                         int dest_width,                                                         int dest_height,                                                         GdkInterpType interp_type,                                                         int overall_alpha,                                                         int check_size,                                                         guint32 color1,                                                         guint32 color2);

通过缩放 srcdest_width xdest_height 并将结果与颜色为 color1color2 的棋盘合成来创建一个新的GdkPixbuf

src :

a GdkPixbuf

dest_width :

目标图像的宽度

dest_height :

目标图像的高度

interp_type :

变形时使用的插值类型。

overall_alpha :

原图像的整体 alpha 值(0..255)

check_size :

棋盘(checkboard)的格子数(必须为2次方幂) color1: 左上方的格子的颜色color2: 其他格子的颜色。

Returns :

一个新的 GdkPixbuf,内存不足返回 NULL。. [transfer full]

gdk_pixbuf_composite ()

void                gdk_pixbuf_composite                (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type,                                                         int overall_alpha);

通过 scale_x 和 $scale_y 指定的缩放以及 offset_xoffset_y 指定的偏移量创建一个原始图像src 的变形图像。这给出了一个在目标 pixbuf 坐标里的一个图像。该图像昂的一个矩形区域(dest_x,dest_y, dest_width,dest_height)会和原始目标图像的相应矩形区域合成。

当目标矩形包含一个并不在源图像之内的一个区域时,则源图像的边缘将被无限大的复制。

Figure 1. pixbuf 的合成

pixbuf 的合成


src :

a GdkPixbuf

dest :

这个 GdkPixbuf 要渲染的目标。

dest_x :

要渲染的区域的左坐标值。

dest_y :

要渲染的区域的顶坐标值。

dest_width :

要渲染的区域的宽度。

dest_height :

要渲染的区域的高度。

offset_x :

X 方向的偏移值(当前近似到整数)。

offset_x :

Y 方向的偏移值(当前近似到整数)。

scale_x :

X 坐标方向上的比例数

scale_y :

Y 坐标方向上的比例数

interp_type :

变形时使用的插值类型。

overall_alpha :

原图像的整体 alpha 值(0..255)

gdk_pixbuf_composite_color ()

void                gdk_pixbuf_composite_color          (const GdkPixbuf *src,                                                         GdkPixbuf *dest,                                                         int dest_x,                                                         int dest_y,                                                         int dest_width,                                                         int dest_height,                                                         double offset_x,                                                         double offset_y,                                                         double scale_x,                                                         double scale_y,                                                         GdkInterpType interp_type,                                                         int overall_alpha,                                                         int check_x,                                                         int check_y,                                                         int check_size,                                                         guint32 color1,                                                         guint32 color2);

通过 scale_xscale_y 指定的缩放以及offset_xoffset_y 指定的偏移量创建一个原始图像src 的变形图像,然后将这个变型图像的一个矩形区域(dest_x ,dest_y,dest_width, dest_height)与color1color2 组成的棋盘(checkboard)合成,并将其渲染到目标图像。

参见 gdk_pixbuf_composite_color_simple() ,一个适用于很多任务的比该函数更少参数的函数。

src :

a GdkPixbuf

dest :

这个 GdkPixbuf 要渲染的目标。

dest_x :

要渲染的区域的左坐标值。

dest_y :

要渲染的区域的顶坐标值。

dest_width :

要渲染的区域的宽度。

dest_height :

要渲染的区域的高度。

offset_x :

X 方向的偏移值(当前近似到整数)。

offset_x :

Y 方向的偏移值(当前近似到整数)。

scale_x :

X 坐标方向上的比例数

scale_y :

Y 坐标方向上的比例数

interp_type :

变形时使用的插值类型。

overall_alpha :

原图像的整体 alpha 值(0..255)

check_x :

棋盘(checkboard)的X偏移值(棋盘的起点位置在 -check_x, -check_y)。

check_y :

棋盘(checkboard)的Y偏移值。

check_size :

棋盘(checkboard)的格子数(必须为2次方幂) color1: 左上方的格子的颜色color2: 其他格子的颜色。

enum GdkPixbufRotation

typedef enum {GDK_PIXBUF_ROTATE_NONE             =   0,GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE =  90,GDK_PIXBUF_ROTATE_UPSIDEDOWN       = 180,GDK_PIXBUF_ROTATE_CLOCKWISE        = 270} GdkPixbufRotation;

The possible rotations which can be passed to gdk_pixbuf_rotate_simple().To make them easier to use, their numerical values are the actual degrees.

GDK_PIXBUF_ROTATE_NONE

No rotation.

GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE

Rotate by 90 degrees.

GDK_PIXBUF_ROTATE_UPSIDEDOWN

Rotate by 180 degrees.

GDK_PIXBUF_ROTATE_CLOCKWISE

Rotate by 270 degrees.

gdk_pixbuf_rotate_simple ()

GdkPixbuf *         gdk_pixbuf_rotate_simple            (const GdkPixbuf *src,                                                         GdkPixbufRotation angle);

旋转一个 pixbuf 90度的倍数,以一个新的 pixbuf 返回结果。

src :

a GdkPixbuf

angle :

旋转的角度

Returns :

一个新的 GdkPixbuf,内存不足返回 NULL。. [transfer full]

Since 2.6


gdk_pixbuf_flip ()

GdkPixbuf *         gdk_pixbuf_flip                     (const GdkPixbuf *src,                                                         gboolean horizontal);

水平或竖直反转一个 pixbuf,以一个新的 pixbuf 返回结果。

src :

a GdkPixbuf

horizontal :

TRUE 为水平反转,FALSE 竖直反转。

Returns :

一个新的 GdkPixbuf,内存不足返回 NULL。. [transfer full]

Since 2.6

See Also

GdkRGB.

原创粉丝点击