Re: [gtk-list] Re: Displaying JPEGs



 > From gtk-list-request@redhat.com Tue Feb 16 12:37:52 1999
 > Subject: [gtk-list] Re: Displaying JPEGs
 >
 > Woah, that is *slow*. What speed do you get if you run testrgb? I have over 
 > 7 m pixels/sec for this sort of operation.

I'm using a Pentium 133, 64MB
RedHat 5.2, glib-1.1.15, gtk+-1.1.15

16-[lclee@whim]$ ./testrgb
Visual 0x20, type = true color, depth = 16, f800:7e0:1f (system); score=8111
Chose visual 0x20, image bpp=16, lsb first
Color test time elapsed: 1.23s, 81.4 fps, 5.21 megapixels/s
Color test (dithered) time elapsed: 2.51s, 39.8 fps, 2.55 megapixels/s
Grayscale test time elapsed: 1.02s, 98.0 fps, 6.27 megapixels/s
Grayscale test (dithered) time elapsed: 3.38s, 29.6 fps, 1.89 megapixels/s

So it appear that my hardware is giving me 5.21 m pixels/s,
slower, but not outrageously so.

 > I use the following call sequence:
 >
 > in main():
 > 	gtk_init( &argc, &argv );
 > 	gdk_rgb_init();
 > 	gtk_widget_set_default_colormap( gdk_rgb_get_cmap() );
 > 	gtk_widget_set_default_visual( gdk_rgb_get_visual() );
 >
 > in expose():
 > 	gdk_draw_rgb_image( widget->window,
 >                 widget->style->white_gc,
 >                 left, top, width, height
 >                 buffer, line_skip );
 >
 > And I get fast repaints.

That's good news I think, because that probably means I'm doing something
wrong. So, if I could impose just a little more.

I stripped all the application code out of the program and it
just paints a green screen (dark to light).  It prints out
elapsed time on the xterm window. 

My times are
end display map 0.983s
end display map 114.287s
end display map 0.942s

I tend not to believe the first number because it include setup time,
This shows a ratio of 120:1 between the two methods. That's a big ratio.

IS THIS REASONABLE, OR HAVE I DONE SOMETHING SILLY?

If you are NOT running a hicolor or true color display (5:6:5) your results
may not look the same as mine. I don't think this would affect the
test timing as long as you are not in an indexed color mode, but the line to
change is in drawmap1()   pixel = ((x*64/VMX) & 0x3f) << 5;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtkbox.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkbutton.h>


#define VMX     800
#define VMY     600

void drawmap1 (GtkWidget *drawing_area);
void drawmap2 (GtkWidget *drawing_area);
gdouble get_time (void);
static void quit_func (GtkWidget *widget, gpointer dummy);

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *drawing_area;
    GtkWidget *button;
    gdouble     time0, time1;

    gtk_init (&argc, &argv);
    gdk_rgb_init ();

    gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
    gtk_widget_set_default_visual (gdk_rgb_get_visual ());

    window = gtk_widget_new (gtk_window_get_type (),
        "GtkObject::user_data", NULL,
        "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
        "GtkWindow::title", "Map",
        "GtkWindow::allow_shrink", FALSE,
        NULL);

    gtk_signal_connect (GTK_OBJECT (window), "destroy",
        (GtkSignalFunc) quit_func, NULL);

    /* get a box to put things in */
    vbox = gtk_vbox_new (FALSE, 0);

    /* get a drawing area, size it, add it to the box, display it */
    drawing_area = gtk_drawing_area_new ();
    gtk_widget_set_usize (drawing_area, VMX, VMY);
    gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
    gtk_widget_show (drawing_area);

    /* get a quit button, add it to the box, display it, connect signal */
    button = gtk_button_new_with_label ("Quit");
    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
    gtk_widget_show (button);
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
        (GtkSignalFunc) gtk_widget_destroy,
        GTK_OBJECT (window));

    /* add the box to the main windows and show it */
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);
    gtk_widget_show (window);

    gdk_image_init ();      /* ??? this has to be after gtk_widget_show */

time0=get_time ();
    drawmap1(drawing_area);
time1=get_time ();
fprintf (stderr, "end display map %.3fs\n", time1-time0);

time0=get_time ();
    drawmap2(drawing_area);
time1=get_time ();
fprintf (stderr, "end display map %.3fs\n", time1-time0);

time0=get_time ();
    drawmap1(drawing_area);
time1=get_time ();
fprintf (stderr, "end display map %.3fs\n", time1-time0);

    gtk_main ();
    return 0;
}

gdouble
get_time (void)
{
    struct timeval tv;
    struct timezone tz;

    gettimeofday (&tv, &tz);

    return tv.tv_sec + 1e-6 * tv.tv_usec;
}

static void
quit_func (GtkWidget *widget, gpointer dummy)
{
    gtk_main_quit ();
}

void
drawmap2 (GtkWidget *drawing_area)
{
    int     x,y;
    char    buf[3*VMX];

    for (y=0; y<VMY; y++) {
        char *bp = buf;
        for (x=0; x<VMX; x++) {
            *bp++ = 0;
            *bp++ = (VMX-x)*256/VMX;
            *bp++ = 0;

            gdk_draw_rgb_image (drawing_area->window,
                drawing_area->style->white_gc,
                0, y, VMX, 1, GDK_RGB_DITHER_NONE,
                buf, VMX);
        }
    }
}

void
drawmap1 (GtkWidget *drawing_area)
{
    int     x,y;
    GdkImage *image;
    guint32 pixel=0;

    image = gdk_image_get(drawing_area->window, 0,0,VMX,VMY);

    for (y=0; y<VMY; y++) {
        for (x=0; x<VMX; x++) {
            pixel = ((x*64/VMX) & 0x3f) << 5;

            gdk_image_put_pixel (image, x,y,pixel);
        }
    }

    gdk_draw_image (drawing_area->window, drawing_area->style->white_gc,
        image,
        0, 0, 0, 0, VMX, VMY);
}



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