GdkPixbuf API proposial
- From: Oleg Klimov <quif land ru>
- To: gtk-devel-list gnome org
- Subject: GdkPixbuf API proposial
- Date: Fri, 21 Feb 2003 14:40:03 +0300
Hello List,
I spent yesterday trying to write new GdkPixbuf API, using Owen's ideas
and thoughts of other people on the list. Now I have a set of .h files
that I like, but some new ideas arised. I'd like to hear opinions from
Owen, Bill and others.
The main idea: add some useful features, no bloating, make gdk-pixbuf
extensible.
Actualy, it is now extensible, by using
gdk_pixbuf_get_*
gdk_pixbuf_new_from_data
It is IMO the same as making struct GdkPixbuf public.
We need to propose a good way of doing extensions, so here is abstract
GdkPixbufTransform object. It contains one virtual method of rendering
rectangle, and some options (filter, edge_mode, overall_alpha,
bg_color for now).
We want each new Transform to be simple to write/maintain. That means
small, clear code. Is it hard to implement good transformation with
several interpolation modes, 3 edge modes, overall_alpha, bg_color and
two 4 src/dest format variants (RGB->RGB, RGB->RGBA, RGBA->RGB,
RGBA->RGBA) ? Answer is: hard.
If we want inner loop of Affine transformation contain no 'if's (fast),
we need large marco that gets expanded 3*3*2*2*4 = 144 times. 6 pages
of macro calls. Lots of code. (well, not exactly like this, but you've
got the point)
We've got to ged rid of this complexity. What if each transformation is
required to handle only RGBA->RGBA, no bg_color, no overall_alpha.
Interpolations (speed/quality tradeoff) and edge_mode still required.
Other variants through temprorary buffer in wrap funciton (internal).
Comments?
Anyway, here is
New features:
- GdkPixbufTransform object
- GdkPixbufAffine object, derives from GdkPixbufTransform
- GdkPixbufClippingRegion object (2 structs, 13 function calls)
- now possible to draw lines, polygons etc
- (not yet here) GdkPixbufColorAdjust, derived from GdkPixbufTransform
(brightness/contrast/saturate)
Current set of .h files attached.
(everything binary compatible with current API, something like
gdk_pixbuf_saturate_and_pixelate likely should be marked deprecated)
/* GdkPixbuf library - clipping region object
*
* Copyright (C) 1999 The Free Software Foundation
*
* Authors: Oleg Klimov <quif land ru>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GDK_PIXBUF_CLIP_H
#define GDK_PIXBUF_CLIP_H
#include "gdk-pixbuf/gdk-pixbuf.h"
G_BEGIN_DECLS
#define GDK_TYPE_PIXBUF_CLIPPING_REGION (gdk_pixbuf_clipping_region_get_type())
#define GDK_PIXBUF_CLIPPING_REGION(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GDK_TYPE_PIXBUF_CLIPPING_REGION, GdkPixbufClippingRegion))
#define GDK_IS_PIXBUF_CLIPPING_REGION(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GDK_TYPE_PIXBUF))
typedef struct _GdkPixbufClippingRegion GdkPixbufClippingRegion;
typedef struct _GdkPixbufClippingRegionClass GdkPixbufClippingRegionClass;
struct _GdkPixbufClippingRegionLine {
gint y;
gint x1;
guchar alpha1;
gint x2;
guchar alpha2;
};
struct _GdkPixbufClippingRegion {
GObject parent;
gboolean use_alpha;
gint valid_rect_x;
gint valid_rect_y;
gint valid_rect_width;
gint valid_rect_height;
GList* lines; /* y-sorted list of GdkPixbufClippingRegionLine */
};
struct _GdkPixbufClippingRegion {
GObjectClass parent_class;
};
GType gdk_pixbuf_clipping_region_get_type ();
GdkPixbufClippingRegion*
gdk_pixbuf_clipping_region_new (GdkPixbuf* src,
gint valid_rect_x,
gint valid_rect_y,
gint valid_rect_width,
gint valid_rect_height);
GdkPixbufClippingRegion*
gdk_pixbuf_clipping_region_copy (GdkPixbufClippingRegion* region);
void gdk_pixbuf_clipping_region_set_use_alpha (GdkPixbufClippingRegion* region,
gboolean use_alpha);
void gdk_pixbuf_clipping_region_all (GdkPixbufClippingRegion* region);
void gdk_pixbuf_clipping_region_nothing (GdkPixbufClippingRegion* region);
void gdk_pixbuf_clipping_region_invert (GdkPixbufClippingRegion* region);
void gdk_pixbuf_clipping_region_rect (GdkPixbufClippingRegion* region,
gdouble rect_x,
gdouble rect_y,
gdouble rect_width,
gdouble rect_height);
void gdk_pixbuf_clipping_region_line (GdkPixbufClippingRegion* region,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gdouble thickness);
void gdk_pixbuf_clipping_region_circle (GdkPixbufClippingRegion* region,
gdouble center_x,
gdouble center_y,
gdouble rad_x,
gdouble rad_y);
void gdk_pixbuf_clipping_region_poly (GdkPixbufClippingRegion* region,
gdouble* coord,
gint coord_len);
void gdk_pixbuf_clipping_region_join (GdkPixbufClippingRegion* region,
GdkPixbufClippingRegion* to_join);
void gdk_pixbuf_clipping_region_subtract (GdkPixbufClippingRegion* region,
GdkPixbufClippingRegion* to_subtract);
void gdk_pixbuf_clipping_region_intersect (GdkPixbufClippingRegion* region,
GdkPixbufClippingRegion* to_intersect);
void gdk_pixbuf_clipping_region_get_bounds (GdkPixbufClippingRegion* region,
gdouble* bound_rect_x,
gdouble* bound_rect_y,
gdouble* bound_rect_width,
gdouble* bound_rect_height);
G_END_DECLS
#endif /* GDK_PIXBUF_CLIP_H */
/* GdkPixbuf library - image transformation object
*
* Copyright (C) 1999 The Free Software Foundation
*
* Authors: Oleg Klimov <quif land ru>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GDK_PIXBUF_TRANSFORM_H
#define GDK_PIXBUF_TRANSFORM_H
#include "gdk-pixbuf/gdk-pixbuf.h"
#include "gdk-pixbuf/gdk-pixbuf-clip.h"
G_BEGIN_DECLS
typedef enum {
GDK_PIXBUF_EDGE_TRANSPARENT, /* do nothing (default) */
GDK_PIXBUF_EDGE_NEAREST, /* edges stratching mode (useful when scaling) */
GDK_PIXBUF_EDGE_TILE, /* clone src pixbuf */
} GdkPixbufEdgeMode;
#define GDK_TYPE_PIXBUF_TRANSFORM (gdk_pixbuf_transform_get_type())
#define GDK_PIXBUF_TRANSFORM(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GDK_TYPE_PIXBUF_TRANSFORM, GdkPixbufTransform))
#define GDK_IS_PIXBUF_TRANSFORM(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GDK_TYPE_PIXBUF))
typedef struct _GdkPixbufTransform GdkPixbufTransform;
typedef struct _GdkPixbufTransformClass GdkPixbufTransformClass;
struct _GdkPixbufTransform {
GObject parent;
GdkPixbufEdgeMode edge_mode;
GdkInterpType interp_type;
gint overall_alpha;
guint32 bg_color;
}
struct _GdkPixbufTransformClass {
GObjectClass parent_class;
void (*render_rect) (GdkPixbufTransform* trans,
GdkPixbuf* dst_pixbuf,
GdkPixbuf* src_pixbuf;
gint rect_x,
gint rect_y,
gint rect_width,
gint rect_height);
};
GType gdk_pixbuf_transform_get_type ();
void gdk_pixbuf_transform_set_edge_mode (GdkPixbufTransform* trans,
GdkPixbufEdgeMode mode);
void gdk_pixbuf_transform_set_interp_type (GdkPixbufTransform* trans,
GdkInterpType interp_type);
void gdk_pixbuf_transform_set_overall_alpha (GdkPixbufTransform* trans,
gint overall_alpha);
void gdk_pixbuf_transform_set_background_color (GdkPixbufTransform* trans,
guint32 color);
void gdk_pixbuf_transform_get_bounds (GdkPixbufTransform* trans,
gint* bound_rect_x,
gint* bound_rect_y,
gint* bound_rect_width,
gint* bound_rect_height,
GdkPixbuf* dest); /* dest==NULL useful */
void gdk_pixbuf_transform_render (GdkPixbufTransform* trans,
GdkPixbuf* dest_pixbuf,
GdkPixbuf* src_pixbuf);
void gdk_pixbuf_transform_render_rect (GdkPixbufTransform* trans,
GdkPixbuf* dest_pixbuf,
GdkPixbuf* src_pixbuf,
gint rect_x,
gint rect_y,
gint rect_width,
gint rect_height);
G_END_DECLS
#endif /* GDK_PIXBUF_TRANSFORM_H */
/* GdkPixbuf library - affine transformation of image
*
* Copyright (C) 1999 The Free Software Foundation
*
* Authors: Oleg Klimov <quif land ru>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GDK_PIXBUF_AFFINE_H
#define GDK_PIXBUF_AFFINE_H
#include "gdk-pixbuf/gdk-pixbuf.h"
#include "gdk-pixbuf/gdk-pixbuf-transform.h"
G_BEGIN_DECLS
#define GDK_TYPE_PIXBUF_AFFINE (gdk_pixbuf_transform_get_type())
#define GDK_PIXBUF_AFFINE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GDK_TYPE_PIXBUF_AFFINE, GdkPixbufAffine))
#define GDK_IS_PIXBUF_AFFINE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GDK_TYPE_PIXBUF))
typedef struct _GdkPixbufAffine GdkPixbufAffine;
typedef struct _GdkPixbufAffineClass GdkPixbufAffineClass;
struct _GdkPixbufAffine {
GdkPixbufTransform parent;
gdouble offset_x;
gdouble offset_y;
gdouble m00, m01;
gdouble m10, m11;
};
struct _GdkPixbufAffineClass {
GdkPixbufTransformClass parent_class;
};
GType gdk_pixbuf_affine_get_type();
GdkPixbufTransform* gdk_pixbuf_affine_new (GdkPixbuf* src);
void gdk_pixbuf_affine_reset (GdkPixbufTransform* trans);
void gdk_pixbuf_affine_set (GdkPixbufTransform* trans,
gdouble offset_x,
gdouble offset_y,
gdouble m00,
gdouble m01,
gdouble m10,
gdouble m11);
void gdk_pixbuf_affine_rotate (GdkPixbufTransform* trans,
gdouble angle);
void gdk_pixbuf_affine_scale (GdkPixbufTransform* trans,
gdouble scale_x,
gdouble scale_y);
void gdk_pixbuf_affine_offset (GdkPixbufTransform* trans,
gdouble move_x,
gdouble move_y);
/* convinience functions */
void gdk_pixbuf_affine_setup_rotate (GdkPixbufTransform* trans,
gdouble dst_x,
gdouble dst_y,
gdouble angle,
gdouble src_center_x,
gdouble src_center_y);
void gdk_pixbuf_affine_transform_vector (GdkPixbufTransform* trans,
gdouble* dst_vector_x,
gdouble* dst_vector_y,
gdouble src_vector_x,
gdouble src_vector_y);
GdkPixbuf* gdk_pixbuf_affine_rotate_simple (GdkPixbuf* src,
gdouble angle);
G_END_DECLS
#endif /* GDK_PIXBUF_AFFINE_H */
void gdk_pixbuf_copy_rect (GdkPixbuf* dest_pixbuf,
gint render_x,
gint render_y,
gint render_width,
gint render_height,
GdkPixbuf* src_pixbuf,
gint src_offset_x,
gint src_offset_y);
void gdk_pixbuf_copy_region (GdkPixbuf* dest_pixbuf,
GdkPixbufClippingRegion* render_region,
GdkPixbuf* src_pixbuf,
gint src_offset_x,
gint src_offset_y);
void gdk_pixbuf_fill_rect (GdkPixbuf* dest_pixbuf,
gint render_x,
gint render_y,
gint render_width,
gint render_height,
guint32 color);
void gdk_pixbuf_fill_region (GdkPixbuf* dest_pixbuf,
GdkPixbufClippingRegion* render_region,
guint32 color);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]