mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-23 20:30:15 +00:00
Added scaling of pixmaps. Currently doesn't work, however, since I'm
Added scaling of pixmaps. Currently doesn't work, however, since I'm guessing how art_rgb_affine really works. Mark
This commit is contained in:
parent
1922a3ed01
commit
96ba724fc5
@ -1,3 +1,4 @@
|
||||
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
@ -44,34 +45,47 @@ quit_func (GtkWidget *widget, gpointer dummy)
|
||||
|
||||
expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
|
||||
{
|
||||
GdkPixBuf *pixbuf = (GdkPixBuf *)data;
|
||||
gint x1, y1, x2, y2;
|
||||
GdkPixBuf *pixbuf;
|
||||
|
||||
if (pixbuf->art_pixbuf->has_alpha){
|
||||
gdk_draw_rgb_32_image (drawing_area->window,
|
||||
drawing_area->style->black_gc,
|
||||
event->area.x, event->area.y,
|
||||
event->area.width,
|
||||
event->area.height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
pixbuf->art_pixbuf->pixels
|
||||
+ (event->area.y * pixbuf->art_pixbuf->rowstride)
|
||||
+ (event->area.x * pixbuf->art_pixbuf->n_channels),
|
||||
pixbuf->art_pixbuf->rowstride);
|
||||
}else{
|
||||
gdk_draw_rgb_image (drawing_area->window,
|
||||
drawing_area->style->white_gc,
|
||||
event->area.x, event->area.y,
|
||||
event->area.width,
|
||||
event->area.height,
|
||||
GDK_RGB_DITHER_NORMAL,
|
||||
pixbuf->art_pixbuf->pixels
|
||||
+ (event->area.y * pixbuf->art_pixbuf->rowstride)
|
||||
+ (event->area.x * pixbuf->art_pixbuf->n_channels),
|
||||
pixbuf->art_pixbuf->rowstride);
|
||||
}
|
||||
pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
|
||||
|
||||
if (pixbuf->art_pixbuf->has_alpha){
|
||||
gdk_draw_rgb_32_image (drawing_area->window,
|
||||
drawing_area->style->black_gc,
|
||||
0, 0,
|
||||
pixbuf->art_pixbuf->width,
|
||||
pixbuf->art_pixbuf->height,
|
||||
GDK_RGB_DITHER_NORMAL,
|
||||
pixbuf->art_pixbuf->pixels,
|
||||
pixbuf->art_pixbuf->rowstride);
|
||||
} else {
|
||||
gdk_draw_rgb_image (drawing_area->window,
|
||||
drawing_area->style->white_gc,
|
||||
0, 0,
|
||||
pixbuf->art_pixbuf->width,
|
||||
pixbuf->art_pixbuf->height,
|
||||
GDK_RGB_DITHER_NORMAL,
|
||||
pixbuf->art_pixbuf->pixels,
|
||||
pixbuf->art_pixbuf->rowstride);
|
||||
}
|
||||
}
|
||||
|
||||
config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
|
||||
{
|
||||
GdkPixBuf *pixbuf, *spb;
|
||||
|
||||
pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
|
||||
|
||||
g_print("X:%d Y:%d\n", event->width, event->height);
|
||||
|
||||
if (((event->width) != (pixbuf->art_pixbuf->width)) ||
|
||||
((event->height) != (pixbuf->art_pixbuf->height))) {
|
||||
spb = gdk_pixbuf_scale(pixbuf, event->width, event->height);
|
||||
gdk_pixbuf_free (pixbuf);
|
||||
gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", spb);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
new_testrgb_window (GdkPixBuf *pixbuf)
|
||||
{
|
||||
@ -88,7 +102,7 @@ new_testrgb_window (GdkPixBuf *pixbuf)
|
||||
"GtkObject::user_data", NULL,
|
||||
"GtkWindow::type", GTK_WINDOW_TOPLEVEL,
|
||||
"GtkWindow::title", "testrgb",
|
||||
"GtkWindow::allow_shrink", FALSE,
|
||||
"GtkWindow::allow_shrink", TRUE,
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||
(GtkSignalFunc) quit_func, NULL);
|
||||
@ -97,11 +111,15 @@ new_testrgb_window (GdkPixBuf *pixbuf)
|
||||
|
||||
drawing_area = gtk_drawing_area_new ();
|
||||
|
||||
gtk_widget_set_usize (drawing_area, w, h);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
|
||||
gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
|
||||
GTK_SIGNAL_FUNC (expose_func), pixbuf);
|
||||
GTK_SIGNAL_FUNC(expose_func), NULL);
|
||||
gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
|
||||
GTK_SIGNAL_FUNC (config_func), NULL);
|
||||
|
||||
gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
|
||||
|
||||
gtk_widget_show (drawing_area);
|
||||
|
||||
@ -137,14 +155,11 @@ main (int argc, char **argv)
|
||||
gtk_widget_set_default_visual (gdk_rgb_get_visual ());
|
||||
|
||||
i = 1;
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i])
|
||||
{
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
pixbuf = gdk_pixbuf_load_image (argv[i]);
|
||||
|
||||
if (pixbuf)
|
||||
{
|
||||
if (pixbuf) {
|
||||
new_testrgb_window (pixbuf);
|
||||
found_valid = TRUE;
|
||||
}
|
||||
|
@ -1,3 +1,13 @@
|
||||
1999-07-16 Mark Crichton <crichton@gimp.org>
|
||||
|
||||
* src/testpixbuf.c (config_func): ConfigureEvent handler. This
|
||||
calls gdk_pixbuf_scale. However, something is not working.
|
||||
N.B.: current pixmap is now stored in user_data with a key of
|
||||
"pixmap"
|
||||
|
||||
* src/gdk-pixbuf.c (gdk_pixbuf_scale): Implemented scaling function.
|
||||
Something is still borked, however.
|
||||
|
||||
1999-07-15 Larry Ewing <lewing@gimp.org>
|
||||
|
||||
* src/io-jpeg.c (image_load): add raph@gimp.org's fix to the jpeg
|
||||
@ -11,11 +21,11 @@
|
||||
* src/testpixbuf.c (expose_func): added an almost proper expose
|
||||
handler for testpixbuf
|
||||
|
||||
1999-07-13 <crichton@gimp.org>
|
||||
1999-07-13 Mark Crichton <crichton@gimp.org>
|
||||
|
||||
* configure.in: Fixed GIF check. Replaced " with '
|
||||
* src/gdk-pixbuf.c: More (minor) work on gdk_pixbuf_scale
|
||||
|
||||
1999-07-13 <crichton@gimp.org>
|
||||
1999-07-13 Mark Crichton <crichton@gimp.org>
|
||||
|
||||
* configure.in: I am a bonehead. Added gif-lib check.
|
@ -6,6 +6,9 @@
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <libart_lgpl/art_misc.h>
|
||||
#include <libart_lgpl/art_rgb_affine.h>
|
||||
#include <libart_lgpl/art_alphagamma.h>
|
||||
#include "gdk-pixbuf.h"
|
||||
|
||||
|
||||
@ -19,35 +22,70 @@ gdk_pixbuf_destroy (GdkPixBuf *pixbuf)
|
||||
void
|
||||
gdk_pixbuf_ref (GdkPixBuf *pixbuf)
|
||||
{
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
|
||||
pixbuf->ref_count++;
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
|
||||
pixbuf->ref_count++;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_pixbuf_unref (GdkPixBuf *pixbuf)
|
||||
{
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
g_return_if_fail (pixbuf->ref_count == 0);
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
g_return_if_fail (pixbuf->ref_count == 0);
|
||||
|
||||
pixbuf->ref_count--;
|
||||
if (pixbuf->ref_count)
|
||||
gdk_pixbuf_destroy (pixbuf);
|
||||
}
|
||||
|
||||
pixbuf->ref_count--;
|
||||
if (pixbuf->ref_count)
|
||||
gdk_pixbuf_destroy (pixbuf);
|
||||
void
|
||||
gdk_pixbuf_free (GdkPixBuf *pixbuf)
|
||||
{
|
||||
art_free(pixbuf->art_pixbuf->pixels);
|
||||
art_pixbuf_free_shallow(pixbuf->art_pixbuf);
|
||||
g_free(pixbuf);
|
||||
}
|
||||
|
||||
GdkPixBuf *
|
||||
gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
|
||||
{
|
||||
GdkPixBuf *spb;
|
||||
art_u8 *pixels;
|
||||
double affine[6];
|
||||
ArtAlphaGamma *alphagamma;
|
||||
|
||||
alphagamma = NULL;
|
||||
|
||||
affine[0] = affine[3] = 1;
|
||||
affine[4] = affine[5] = 0;
|
||||
|
||||
affine[1] = w / (pixbuf->art_pixbuf->width);
|
||||
affine[2] = h / (pixbuf->art_pixbuf->height);
|
||||
|
||||
spb = g_new (GdkPixBuf, 1);
|
||||
|
||||
if (pixbuf->art_pixbuf->has_alpha) {
|
||||
/* Following code is WRONG....of course, the code for this
|
||||
* transform isn't in libart yet.
|
||||
*/
|
||||
#if 0
|
||||
pixels = art_alloc (h * w * 4);
|
||||
art_rgb_affine( pixels, 0, 0, w, h, (w * 4),
|
||||
pixbuf->art_pixbuf->pixels,
|
||||
pixbuf->art_pixbuf->width,
|
||||
pixbuf->art_pixbuf->height,
|
||||
pixbuf->art_pixbuf->rowstride,
|
||||
affine, ART_FILTER_NEAREST, alphagamma);
|
||||
spb->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
|
||||
#endif
|
||||
} else {
|
||||
art_alloc (h * w * 3);
|
||||
art_rgb_affine( pixels, 0, 0, w, h, (w * 3),
|
||||
pixbuf->art_pixbuf->pixels,
|
||||
pixbuf->art_pixbuf->width,
|
||||
pixbuf->art_pixbuf->height,
|
||||
pixbuf->art_pixbuf->rowstride,
|
||||
affine, ART_FILTER_NEAREST, alphagamma);
|
||||
spb->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-basic-offset: 4
|
||||
* c-file-offsets: ((substatement-open . 0))
|
||||
* End:
|
||||
*/
|
||||
|
||||
|
@ -14,6 +14,9 @@ GdkPixBuf *gdk_pixbuf_load_image (const char *file);
|
||||
void gdk_pixbuf_save_image (const char *format_id, const char *file, ...);
|
||||
void gdk_pixbuf_ref (GdkPixBuf *pixbuf);
|
||||
void gdk_pixbuf_unref (GdkPixBuf *pixbuf);
|
||||
GdkPixBuf gdk_pixbuf_duplicate (GdkPixBuf *pixbuf);
|
||||
GdkPixBuf *gdk_pixbuf_duplicate (GdkPixBuf *pixbuf);
|
||||
GdkPixBuf *gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h);
|
||||
|
||||
void gdk_pixbuf_free (GdkPixBuf *pixbuf);
|
||||
|
||||
#endif /* _GDK_PIXBUF_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user