Directory full of pixel data scaling code that will eventually migrate

2000-01-05  Owen Taylor  <otaylor@redhat.com>

	* gdk-pixbuf/pixops/: Directory full of pixel data scaling
	code that will eventually migrate into libart.

	* configure.in acconfig.h: Add checks for MMX compiler support

	* gdk-pixbuf/gdk-pixbuf.h gdk-pixbuf/gdk-pixbuf-scale.c:
	Nice wrapper routines for the code in pixops that operate
	on pixbufs instead of raw data.

	* gdk-pixbuf/testpixbuf-scale: Test program for scaling
	routines.
This commit is contained in:
Owen Taylor 2000-01-05 21:33:58 +00:00 committed by Owen Taylor
parent 2bb20aee8b
commit 33e963e7af
16 changed files with 2940 additions and 1 deletions

163
demos/testpixbuf-scale.c Normal file
View File

@ -0,0 +1,163 @@
#include <gtk/gtk.h>
#include "gdk-pixbuf.h"
#include <stdio.h>
ArtFilterLevel filter_level = ART_FILTER_BILINEAR;
int overall_alpha = 255;
GdkPixbuf *pixbuf;
GtkWidget *darea;
void
set_filter_level (GtkWidget *widget, gpointer data)
{
filter_level = GPOINTER_TO_UINT (data);
gtk_widget_queue_draw (darea);
}
void
overall_changed_cb (GtkAdjustment *adjustment, gpointer data)
{
if (adjustment->value != overall_alpha)
{
overall_alpha = adjustment->value;
gtk_widget_queue_draw (darea);
}
}
gboolean
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GdkPixbuf *dest;
dest = gdk_pixbuf_new (ART_PIX_RGB, FALSE, 8, event->area.width, event->area.height);
if (pixbuf->art_pixbuf->has_alpha || overall_alpha != 255)
gdk_pixbuf_composite_color (pixbuf, dest,
0, 0, event->area.width, event->area.height,
-event->area.x, -event->area.y,
(double) widget->allocation.width / pixbuf->art_pixbuf->width,
(double) widget->allocation.height / pixbuf->art_pixbuf->height,
filter_level, overall_alpha,
event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
else
gdk_pixbuf_scale (pixbuf, dest,
0, 0, event->area.width, event->area.height,
-event->area.x, -event->area.y,
(double) widget->allocation.width / pixbuf->art_pixbuf->width,
(double) widget->allocation.height / pixbuf->art_pixbuf->height,
filter_level);
gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
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;
}
int
main(int argc, char **argv)
{
GtkWidget *window, *vbox;
GtkWidget *menuitem, *optionmenu, *menu;
GtkWidget *alignment;
GtkWidget *hbox, *label, *hscale;
GtkAdjustment *adjustment;
GtkRequisition scratch_requisition;
gtk_init (&argc, &argv);
gdk_rgb_init ();
if (argc != 2) {
fprintf (stderr, "Usage: testpixbuf-scale FILE\n");
exit (1);
}
pixbuf = gdk_pixbuf_new_from_file (argv[1]);
if (!pixbuf) {
fprintf (stderr, "Cannot load %s\n", argv[1]);
exit(1);
}
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
menu = gtk_menu_new ();
menuitem = gtk_menu_item_new_with_label ("NEAREST");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_filter_level),
GUINT_TO_POINTER (ART_FILTER_NEAREST));
gtk_widget_show (menuitem);
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("BILINEAR");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_filter_level),
GUINT_TO_POINTER (ART_FILTER_BILINEAR));
gtk_widget_show (menuitem);
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("TILES");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_filter_level),
GUINT_TO_POINTER (ART_FILTER_TILES));
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("HYPER");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_filter_level),
GUINT_TO_POINTER (ART_FILTER_HYPER));
gtk_container_add (GTK_CONTAINER (menu), menuitem);
optionmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 1);
alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new ("Overall Alpha:");
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (overall_alpha, 0, 255, 1, 10, 0));
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (overall_changed_cb), NULL);
hscale = gtk_hscale_new (adjustment);
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_box_pack_start (GTK_BOX (hbox), hscale, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (alignment), optionmenu);
gtk_widget_show_all (vbox);
/* Compute the size without the drawing area, so we know how big to make the default size */
gtk_widget_size_request (vbox, &scratch_requisition);
darea = gtk_drawing_area_new ();
gtk_box_pack_start (GTK_BOX (vbox), darea, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (darea), "expose_event",
GTK_SIGNAL_FUNC (expose_cb), NULL);
gtk_window_set_default_size (GTK_WINDOW (window),
pixbuf->art_pixbuf->width,
scratch_requisition.height + pixbuf->art_pixbuf->height);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}

View File

@ -7,4 +7,5 @@ Makefile
*.lo
testpixbuf
testpixbuf-drawable
testpixbuf-scale
testanimation

View File

@ -1,3 +1,17 @@
2000-01-05 Owen Taylor <otaylor@redhat.com>
* gdk-pixbuf/pixops/: Directory full of pixel data scaling
code that will eventually migrate into libart.
* configure.in acconfig.h: Add checks for MMX compiler support
* gdk-pixbuf/gdk-pixbuf.h gdk-pixbuf/gdk-pixbuf-scale.c:
Nice wrapper routines for the code in pixops that operate
on pixbufs instead of raw data.
* gdk-pixbuf/testpixbuf-scale: Test program for scaling
routines.
2000-01-05 Jonathan Blandford <jrb@redhat.com>
* doc/tmpl/animation.sgml: Documentation changes.

View File

@ -1,3 +1,5 @@
SUBDIRS = pixops
lib_LTLIBRARIES = \
libgdk_pixbuf.la
@ -38,7 +40,7 @@ libexec_LTLIBRARIES = \
$(PNM_LIB) \
$(BMP_LIB)
noinst_PROGRAMS = testpixbuf testpixbuf-drawable testanimation
noinst_PROGRAMS = testpixbuf testpixbuf-drawable testanimation testpixbuf-scale
DEPS = libgdk_pixbuf.la
INCLUDES = -I$(top_srcdir) -I$(top_builddir) \
@ -52,10 +54,12 @@ LDADDS = libgdk_pixbuf.la $(LIBART_LIBS) $(GLIB_LIBS) $(GTK_LIBS)
if INSIDE_GNOME_LIBS
testpixbuf_LDADD = $(LDADDS) $(LIBART_LIBS) -lgmodule
testpixbuf_drawable_LDADD = $(LDADDS)
testpixbuf_scale_LDADD = $(LDADDS)
testanimation_LDADD = $(LDADDS) $(LIBART_LIBS) -lgmodule
else
testpixbuf_LDADD = $(LDADDS) $(LIBART_LIBS) $(GNOME_LIBS) -lgmodule
testpixbuf_drawable_LDADD = $(LDADDS) $(GNOME_LIBS)
testpixbuf_scale_LDADD = $(LDADDS) $(GNOME_LIBS)
testanimation_LDADD = $(LDADDS) $(LIBART_LIBS) $(GNOME_LIBS) -lgmodule
endif
@ -83,6 +87,7 @@ libgdk_pixbuf_la_SOURCES = \
gdk-pixbuf-io.c \
gdk-pixbuf-loader.c \
gdk-pixbuf-render.c \
gdk-pixbuf-scale.c \
gdk-pixbuf-util.c \
$(CANVAS_SOURCEFILES)
@ -93,6 +98,8 @@ EXTRA_GNOME_LIBS = $(GNOME_LIBS)
endif
libgdk_pixbuf_la_LDFLAGS = -version-info 1:0:0 $(EXTRA_GNOME_LIBS)
libgdk_pixbuf_la_LIBADD = pixops/libpixops.la
libgdk_pixbufinclude_HEADERS = \
gdk-pixbuf.h \

View File

@ -0,0 +1,214 @@
#include "gdk-pixbuf.h"
#include "pixops/pixops.h"
#include "math.h"
/**
* gdk_pixbuf_scale:
* @src: a #GdkPixbuf
* @dest: the #GdkPixbuf into which to render the results
* @dest_x:
* @dest_y:
* @dest_width:
* @dest_height:
* @offset_x: the offset in the X direction (currently rounded to an integer)
* @offset_y: the offset in the Y direction (currently rounded to an integer)
* @scale_x: the scale factor in the X direction
* @scale_y: the scale factor in the Y direction
* @filter_level: the filter quality for the transformation.
*
* Transforms the image by source image by scaling by @scale_x and @scale_y then
* translating by @offset_x and @offset_y, then renders the rectangle
* (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
* destination drawable replacing the previous contents.
**/
void
gdk_pixbuf_scale (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,
ArtFilterLevel filter_level)
{
offset_x = floor(offset_x + 0.5);
offset_y = floor(offset_y + 0.5);
pixops_scale (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
-offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
scale_x, scale_y, filter_level);
}
/**
* gdk_pixbuf_composite:
* @src: a #GdkPixbuf
* @dest: the #GdkPixbuf into which to render the results
* @dest_x:
* @dest_y:
* @dest_width:
* @dest_height:
* @offset_x: the offset in the X direction (currently rounded to an integer)
* @offset_y: the offset in the Y direction (currently rounded to an integer)
* @scale_x: the scale factor in the X direction
* @scale_y: the scale factor in the Y direction
* @filter_level: the filter quality for the transformation.
* @overall_alpha: overall alpha for source image (0..255)
*
* Transforms the image by source image by scaling by @scale_x and @scale_y then
* translating by @offset_x and @offset_y, then composites the rectangle
* (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
* destination drawable.
**/
void
gdk_pixbuf_composite (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,
ArtFilterLevel filter_level,
int overall_alpha)
{
offset_x = floor(offset_x + 0.5);
offset_y = floor(offset_y + 0.5);
pixops_composite (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
-offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
scale_x, scale_y, filter_level, overall_alpha);
}
/**
* gdk_pixbuf_composite_color:
* @src: a #GdkPixbuf
* @dest: the #GdkPixbuf into which to render the results
* @dest_x:
* @dest_y:
* @dest_width:
* @dest_height:
* @offset_x: the offset in the X direction (currently rounded to an integer)
* @offset_y: the offset in the Y direction (currently rounded to an integer)
* @scale_x: the scale factor in the X direction
* @scale_y: the scale factor in the Y direction
* @filter_level: the filter quality for the transformation.
* @overall_alpha: overall alpha for source image (0..255)
* @check_x: the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y)
* @check_y: the Y offset for the checkboard
* @check_size: the size of checks in the checkboard (must be a power of two)
* @color1: the color of check at upper left
* @color2: the color of the other check
*
* Transforms the image by source image by scaling by @scale_x and @scale_y then
* translating by @offset_x and @offset_y, then composites the rectangle
* (@dest,@dest_y,@dest_width,@dest_height) of the resulting image with
* a checkboard of the colors @color1 and @color2 and renders it onto the
* destination drawable.
**/
void
gdk_pixbuf_composite_color (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,
ArtFilterLevel filter_level,
int overall_alpha,
int check_x,
int check_y,
int check_size,
art_u32 color1,
art_u32 color2)
{
offset_x = floor(offset_x + 0.5);
offset_y = floor(offset_y + 0.5);
pixops_composite_color (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
-offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
scale_x, scale_y, filter_level, overall_alpha, check_x, check_y, check_size, color1, color2);
}
/**
* gdk_pixbuf_scale_simple:
* @src: a #GdkPixbuf
* @dest_width: the width of destination image
* @dest_height: the height of destination image
* @filter_level: the filter quality for the transformation.
*
* Scale the #GdkPixbuf @src to @dest_width x @dest_height and render the result into
* a new #GdkPixbuf.
*
* Return value: the new #GdkPixbuf
**/
GdkPixbuf *
gdk_pixbuf_scale_simple (GdkPixbuf *src,
int dest_width,
int dest_height,
ArtFilterLevel filter_level)
{
GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);
gdk_pixbuf_scale (src, dest, 0, 0, dest_width, dest_height, 0, 0,
(double)dest_width / src->art_pixbuf->width,
(double)dest_height / src->art_pixbuf->height,
filter_level);
return dest;
}
/**
* gdk_pixbuf_composite_color_simple:
* @src: a #GdkPixbuf
* @dest_width: the width of destination image
* @dest_height: the height of destination image
* @filter_level: the filter quality for the transformation.
* @overall_alpha: overall alpha for source image (0..255)
* @check_size: the size of checks in the checkboard (must be a power of two)
* @color1: the color of check at upper left
* @color2: the color of the other check
*
* Scale the #GdkPixbuf @src to @dest_width x @dest_height composite the result with
* a checkboard of colors @color1 and @color2 and render the result into
* a new #GdkPixbuf.
*
* Return value: the new #GdkPixbuf
**/
GdkPixbuf *
gdk_pixbuf_composite_color_simple (GdkPixbuf *src,
int dest_width,
int dest_height,
ArtFilterLevel filter_level,
int overall_alpha,
int check_size,
art_u32 color1,
art_u32 color2)
{
GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);
gdk_pixbuf_composite_color (src, dest, 0, 0, dest_width, dest_height, 0, 0,
(double)dest_width / src->art_pixbuf->width,
(double)dest_height / src->art_pixbuf->height,
filter_level, overall_alpha, 0, 0, check_size, color1, color2);
return dest;
}

View File

@ -27,6 +27,7 @@
#include <libart_lgpl/art_misc.h>
#include <libart_lgpl/art_pixbuf.h>
#include <libart_lgpl/art_filterlevel.h>
#include <gdk/gdk.h>
#ifdef __cplusplus
@ -162,6 +163,62 @@ GdkPixbuf *gdk_pixbuf_get_from_drawable (GdkPixbuf *dest,
int dest_x, int dest_y,
int width, int height);
/* Scaling */
void gdk_pixbuf_scale (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,
ArtFilterLevel filter_level);
void gdk_pixbuf_composite (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,
ArtFilterLevel filter_level,
int overall_alpha);
void gdk_pixbuf_composite_color (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,
ArtFilterLevel filter_level,
int overall_alpha,
int check_x,
int check_y,
int check_size,
art_u32 color1,
art_u32 color2);
GdkPixbuf *gdk_pixbuf_scale_simple (GdkPixbuf *src,
int dest_width,
int dest_height,
ArtFilterLevel filter_level);
GdkPixbuf *gdk_pixbuf_composite_color_simple (GdkPixbuf *src,
int dest_width,
int dest_height,
ArtFilterLevel filter_level,
int overall_alpha,
int check_size,
art_u32 color1,
art_u32 color2);
/* Animation support */
GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file (const char *filename);

View File

@ -0,0 +1,7 @@
Makefile
Makefile.in
.libs
.deps
*.lo
*.la
timescale

View File

@ -0,0 +1,22 @@
noinst_LTLIBRARIES = libpixops.la
INCLUDES = $(GLIB_CFLAGS)
bin_PROGRAMS = timescale
timescale_SOURCES = timescale.c
timescale_LDADD = libpixops.la $(GLIB_LIBS)
if USE_MMX
mmx_sources = \
have_mmx.S \
scale_line_22_33_mmx.S \
composite_line_22_4a4_mmx.S \
composite_line_color_22_4a4_mmx.S
endif
libpixops_la_SOURCES = \
pixops.c \
pixops.h \
pixops-internal.h \
$(mmx_sources)

View File

@ -0,0 +1,208 @@
.file "composite_line_22_4a4_mmx.S"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl pixops_composite_line_22_4a4_mmx
.type pixops_composite_line_22_4a4_mmx,@function
/*
* Arguments
*
* weights: 8(%ebp)
* p: 12(%ebp) %esi
* q1: 16(%ebp)
* q2: 20(%ebp)
* xstep: 24(%ebp)
* p_end: 28(%ebp)
* xinit: 32(%ebp)
*
*/
pixops_composite_line_22_4a4_mmx:
/*
* Function call entry
*/
pushl %ebp
movl %esp,%ebp
subl $28,%esp
pushl %edi
pushl %esi
pushl %ebx
/* Locals:
* int x %ebx
* int x_scaled -24(%ebp)
*/
/*
* Setup
*/
/* Initialize variables */
movl 32(%ebp),%ebx
movl 32(%ebp),%edx
sarl $16,%edx
movl 12(%ebp),%esi
movl %edx,-24(%ebp)
cmpl %esi,28(%ebp)
je .out
/* Load initial values into %mm1, %mm3 */
shll $2, %edx
pxor %mm4, %mm4
movl 16(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm1
punpcklbw %mm4, %mm1
pmullw %mm5,%mm1
movl -24(%ebp),%edx
shll $2, %edx
movl 20(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm3
punpcklbw %mm4, %mm3
pmullw %mm5,%mm3
psrlw $8,%mm1
psrlw $8,%mm3
addl $65536,%ebx
movl %ebx,%edx
sarl $16,%edx
jmp .newx
.p2align 4,,7
.loop:
/* int x_index = (x & 0xf000) >> 12 */
movl %ebx,%eax
andl $0xf000,%eax
shrl $7,%eax
movq (%edi,%eax),%mm4
pmullw %mm0,%mm4
movq 8(%edi,%eax),%mm5
pmullw %mm1,%mm5
movq 16(%edi,%eax),%mm6
movq 24(%edi,%eax),%mm7
pmullw %mm2,%mm6
pmullw %mm3,%mm7
paddw %mm4, %mm5
paddw %mm6, %mm7
paddw %mm5, %mm7
movl $0xffff,%ecx
movd %ecx,%mm4
psllq $48,%mm4
movq %mm4,%mm6
psubw %mm7,%mm4
pand %mm6,%mm4
movq %mm4,%mm5
psrlq $16,%mm4
por %mm4,%mm5
psrlq $32,%mm5
por %mm4,%mm5
psrlw $8,%mm5
movd (%esi),%mm7
pxor %mm4,%mm4
punpcklbw %mm4, %mm7
pmullw %mm7,%mm5
/* x += x_step; */
addl 24(%ebp),%ebx
/* x_scale = x >> 16; */
movl %ebx,%edx
sarl $16,%edx
paddw %mm5,%mm6
psrlw $8,%mm6
packuswb %mm6, %mm6
movd %mm6,(%esi)
addl $4, %esi
cmpl %esi,28(%ebp)
je .out
cmpl %edx,-24(%ebp)
je .loop
.newx:
movl %edx,-24(%ebp)
/*
* Load the two new values into %mm1, %mm3, move old values into %mm0, %mm2
*/
movq %mm1, %mm0
movq %mm3, %mm2
shll $2, %edx
# %mm4 will always be already clear here
# pxor %mm4, %mm4
movl 16(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
/*
* mull destroyed %edx, need to reconstitute
*/
movl -24(%ebp),%edx
shll $2, %edx
orl $0xff000000, %eax
movd %eax, %mm1
punpcklbw %mm4, %mm1
pmullw %mm5,%mm1
movl 20(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm3
punpcklbw %mm4, %mm3
pmullw %mm5,%mm3
psrlw $8,%mm1
psrlw $8,%mm3
movl 8(%ebp),%edi
jmp .loop
.out:
movl %esi,%eax
emms
leal -40(%ebp),%esp
popl %ebx
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret

View File

@ -0,0 +1,219 @@
.file "composite_line_color_22_4a4_mmx.S"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl pixops_composite_line_color_22_4a4_mmx
.type pixops_composite_line_color_22_4a4_mmx,@function
/*
* Arguments
*
* weights: 8(%ebp)
* p: 12(%ebp) %esi
* q1: 16(%ebp)
* q2: 20(%ebp)
* xstep: 24(%ebp)
* p_end: 28(%ebp)
* xinit: 32(%ebp)
* dest_x: 36(%ebp)
* check_shift: 40(%ebp)
* colors: 44(%ebp)
*
*/
pixops_composite_line_color_22_4a4_mmx:
/*
* Function call entry
*/
pushl %ebp
movl %esp,%ebp
subl $28,%esp
pushl %edi
pushl %esi
pushl %ebx
/* Locals:
* int x %ebx
* int x_scaled -24(%ebp)
*/
/*
* Setup
*/
/* Initialize variables */
movl 32(%ebp),%ebx
movl 32(%ebp),%edx
sarl $16,%edx
movl 12(%ebp),%esi
movl %edx,-24(%ebp)
cmpl %esi,28(%ebp)
je .out
/* Load initial values into %mm1, %mm3 */
shll $2, %edx
pxor %mm4, %mm4
movl 16(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm1
punpcklbw %mm4, %mm1
pmullw %mm5,%mm1
/*
* mull destroyed %edx, need to reconstitute
*/
movl -24(%ebp),%edx
shll $2, %edx
movl 20(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm3
punpcklbw %mm4, %mm3
pmullw %mm5,%mm3
psrlw $8,%mm1
psrlw $8,%mm3
addl $65536,%ebx
movl %ebx,%edx
sarl $16,%edx
jmp .newx
.p2align 4,,7
.loop:
/* int x_index = (x & 0xf000) >> 12 */
movl %ebx,%eax
andl $0xf000,%eax
shrl $7,%eax
movq (%edi,%eax),%mm4
pmullw %mm0,%mm4
movq 8(%edi,%eax),%mm5
pmullw %mm1,%mm5
movq 16(%edi,%eax),%mm6
movq 24(%edi,%eax),%mm7
pmullw %mm2,%mm6
pmullw %mm3,%mm7
paddw %mm4, %mm5
paddw %mm6, %mm7
paddw %mm5, %mm7
movl $0xffff,%ecx
movd %ecx,%mm4
psllq $48,%mm4
movq %mm4,%mm6
psubw %mm7,%mm4
pand %mm6,%mm4
movq %mm4,%mm5
psrlq $16,%mm4
por %mm4,%mm5
psrlq $32,%mm5
por %mm4,%mm5
psrlw $8,%mm5
movl 36(%ebp),%eax
incl 36(%ebp)
movl 40(%ebp),%ecx
shrl %cl,%eax
andl $1,%eax
movl 44(%ebp),%ecx
movq (%ecx,%eax,8),%mm6
pmullw %mm6,%mm5
/* x += x_step; */
addl 24(%ebp),%ebx
/* x_scale = x >> 16; */
movl %ebx,%edx
sarl $16,%edx
paddw %mm5,%mm7
psrlw $8,%mm7
packuswb %mm7, %mm7
movd %mm7,(%esi)
addl $4, %esi
cmpl %esi,28(%ebp)
je .out
cmpl %edx,-24(%ebp)
je .loop
.newx:
movl %edx,-24(%ebp)
/*
* Load the two new values into %mm1, %mm3, move old values into %mm0, %mm2
*/
movq %mm1, %mm0
movq %mm3, %mm2
shll $2, %edx
pxor %mm4, %mm4
movl 16(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
/*
* mull destroyed %edx, need to reconstitute
*/
movl -24(%ebp),%edx
shll $2, %edx
orl $0xff000000, %eax
movd %eax, %mm1
punpcklbw %mm4, %mm1
pmullw %mm5,%mm1
movl 20(%ebp),%edi
movl (%edi, %edx), %eax
movd (%edi, %edx), %mm5
punpcklbw %mm4, %mm5
shrl $24, %eax
movl $0x010101, %ecx
mull %ecx
orl $0xff000000, %eax
movd %eax, %mm3
punpcklbw %mm4, %mm3
pmullw %mm5,%mm3
psrlw $8,%mm1
psrlw $8,%mm3
movl 8(%ebp),%edi
jmp .loop
.out:
movl %esi,%eax
emms
leal -40(%ebp),%esp
popl %ebx
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret

View File

@ -0,0 +1,42 @@
.file "have_mmx.S"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl pixops_have_mmx
.type pixops_have_mmx,@function
pixops_have_mmx:
push %ebx
# Check if bit 21 in flags word is writeable
pushfl
popl %eax
movl %eax,%ebx
xorl $0x00200000, %eax
pushl %eax
popfl
pushfl
popl %eax
cmpl %eax, %ebx
je .notfound
# OK, we have CPUID
movl $1, %eax
cpuid
test $0x00800000, %edx
jz .notfound
movl $1, %eax
jmp .out
.notfound:
movl $0, %eax
.out:
popl %ebx
ret

View File

@ -0,0 +1,7 @@
#ifdef USE_MMX
art_u8 *pixops_scale_line_22_33_mmx (art_u32 weights[16][8], art_u8 *p, art_u8 *q1, art_u8 *q2, int x_step, art_u8 *p_stop, int x_init);
art_u8 *pixops_composite_line_22_4a4_mmx (art_u32 weights[16][8], art_u8 *p, art_u8 *q1, art_u8 *q2, int x_step, art_u8 *p_stop, int x_init);
art_u8 *pixops_composite_line_color_22_4a4_mmx (art_u32 weights[16][8], art_u8 *p, art_u8 *q1, art_u8 *q2, int x_step, art_u8 *p_stop, int x_init, int dest_x, int check_shift, int *colors);
int pixops_have_mmx (void);
#endif

1519
gdk-pixbuf/pixops/pixops.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
#include <libart_lgpl/art_misc.h>
#include <libart_lgpl/art_filterlevel.h>
/* Scale src_buf from src_width / src_height by factors scale_x, scale_y
* and composite the portion corresponding to
* render_x, render_y, render_width, render_height in the new
* coordinate system into dest_buf starting at 0, 0
*/
void pixops_composite (art_u8 *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
art_u8 *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
ArtFilterLevel filter_level,
int overall_alpha);
/* Scale src_buf from src_width / src_height by factors scale_x, scale_y
* and composite the portion corresponding to
* render_x, render_y, render_width, render_height in the new
* coordinate system against a checkboard with checks of size check_size
* of the colors color1 and color2 into dest_buf starting at 0, 0
*/
void pixops_composite_color (art_u8 *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
art_u8 *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
ArtFilterLevel filter_level,
int overall_alpha,
int check_x,
int check_y,
int check_size,
art_u32 color1,
art_u32 color2);
/* Scale src_buf from src_width / src_height by factors scale_x, scale_y
* and composite the portion corresponding to
* render_x, render_y, render_width, render_height in the new
* coordinate system into dest_buf starting at 0, 0
*/
void pixops_scale (art_u8 *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
art_u8 *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
ArtFilterLevel filter_level);

View File

@ -0,0 +1,152 @@
.file "scale_line_22_33_mmx.S"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl pixops_scale_line_22_33_mmx
.type pixops_scale_line_22_33_mmx,@function
/*
* Arguments
*
* weights: 8(%ebp)
* p: 12(%ebp) %esi
* q1: 16(%ebp)
* q2: 20(%ebp)
* xstep: 24(%ebp)
* p_end: 28(%ebp)
* xinit: 32(%ebp)
*
*/
pixops_scale_line_22_33_mmx:
/*
* Function call entry
*/
pushl %ebp
movl %esp,%ebp
subl $28,%esp
pushl %edi
pushl %esi
pushl %ebx
/* Locals:
* int x %ebx
* int x_scaled -24(%ebp)
*/
/*
* Setup
*/
/* Initialize variables */
movl 32(%ebp),%ebx
movl 32(%ebp),%edx
sarl $16,%edx
movl 12(%ebp),%esi
cmpl %esi,28(%ebp)
je .out
/* Load initial values into %mm1, %mm3 */
leal (%edx,%edx,2),%edx # Multiply by 3
movl 16(%ebp),%edi
pxor %mm4, %mm4
movzbl 2(%edi,%edx),%ecx
shll $16,%ecx
movzwl (%edi,%edx),%eax
orl %eax,%ecx
movd %ecx, %mm1
punpcklbw %mm4, %mm1
movl 20(%ebp),%edi
movzbl 2(%edi,%edx),%ecx
shll $16,%ecx
movzwl (%edi,%edx),%eax
orl %eax,%ecx
movd %ecx, %mm3
punpcklbw %mm4, %mm3
addl $65536,%ebx
movl %ebx,%edx
sarl $16,%edx
jmp .newx
.p2align 4,,7
.loop:
/* int x_index = (x & 0xf000) >> 12 */
movl %ebx,%eax
andl $0xf000,%eax
shrl $7,%eax
movq (%edi,%eax),%mm4
pmullw %mm0,%mm4
movq 8(%edi,%eax),%mm5
pmullw %mm1,%mm5
movq 16(%edi,%eax),%mm6
movq 24(%edi,%eax),%mm7
pmullw %mm2,%mm6
pmullw %mm3,%mm7
paddw %mm4, %mm5
paddw %mm6, %mm7
paddw %mm5, %mm7
psrlw $8, %mm7
packuswb %mm7, %mm7
movd %mm7, %eax
movb %al, (%esi)
shrl $8, %eax
movw %ax, 1(%esi)
addl $3, %esi
cmpl %esi,28(%ebp)
je .out
/* x += x_step; */
addl 24(%ebp),%ebx
/* x_scale = x >> 16; */
movl %ebx,%edx
sarl $16,%edx
cmpl %edx,-24(%ebp)
je .loop
.newx:
movl %edx,-24(%ebp)
/*
* Load the two new values into %mm1, %mm3, move old values into %mm0, %mm2
*/
movq %mm1, %mm0
movq %mm3, %mm2
leal (%edx,%edx,2),%edx # Multiply by 3
movl 16(%ebp),%edi
pxor %mm4, %mm4
movzbl 2(%edi,%edx),%ecx
shll $16,%ecx
movzwl (%edi,%edx),%eax
orl %eax,%ecx
movd %ecx, %mm1
punpcklbw %mm4, %mm1
movl 20(%ebp),%edi
movzbl 2(%edi,%edx),%ecx
shll $16,%ecx
movzwl (%edi,%edx),%eax
orl %eax,%ecx
movd %ecx, %mm3
punpcklbw %mm4, %mm3
movl 8(%ebp),%edi
jmp .loop
.out:
movl %esi,%eax
emms
leal -40(%ebp),%esp
popl %ebx
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret

View File

@ -0,0 +1,227 @@
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include "pixops.h"
struct timeval start_time;
void start_timing (void)
{
gettimeofday (&start_time, NULL);
}
double
stop_timing (const char *test, int iterations, int bytes)
{
struct timeval stop_time;
double msecs;
gettimeofday (&stop_time, NULL);
if (stop_time.tv_usec < start_time.tv_usec)
{
stop_time.tv_usec += 1000000;
stop_time.tv_sec -= 1;
}
msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
(stop_time.tv_usec - start_time.tv_usec) / 1000.;
printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));
return ((double)bytes * iterations) / (1000*msecs);
}
void
init_array (double times[3][3][4])
{
int i, j, k;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
for (k=0; j<4; k++)
times[i][j][k] = -1;
}
void
dump_array (double times[3][3][4])
{
int i, j, k;
printf(" 3\t4\t4a\n");
for (i=0; i<3; i++)
{
for (j=0; j<4; j++)
{
if (j == 0)
switch (i)
{
case 0:
printf("3 ");
break;
case 1:
printf("4 ");
break;
case 2:
printf("4a ");
break;
}
else
printf(" ");
printf("%6.2f %6.2f %6.2f",
times[i][0][j], times[i][1][j], times[i][2][j]);
switch (j)
{
case ART_FILTER_NEAREST:
printf (" NEAREST\n");
break;
case ART_FILTER_TILES:
printf (" TILES\n");
break;
case ART_FILTER_BILINEAR:
printf (" BILINEAR\n");
break;
case ART_FILTER_HYPER:
printf (" HYPER\n");
break;
}
}
}
printf("\n");
}
#define ITERS 10
int main (int argc, char **argv)
{
int src_width, src_height, dest_width, dest_height;
char *src_buf, *dest_buf;
int src_index, dest_index;
int i;
double scale_times[3][3][4];
double composite_times[3][3][4];
double composite_color_times[3][3][4];
if (argc == 5)
{
src_width = atoi(argv[1]);
src_height = atoi(argv[2]);
dest_width = atoi(argv[3]);
dest_height = atoi(argv[4]);
}
else if (argc == 1)
{
src_width = 343;
src_height = 343;
dest_width = 711;
dest_height = 711;
}
else
{
fprintf (stderr, "Usage: scale [src_width src_height dest_width dest_height]\n");
exit(1);
}
printf ("Scaling from (%d, %d) to (%d, %d)\n\n", src_width, src_height, dest_width, dest_height);
for (src_index = 0; src_index < 3; src_index++)
for (dest_index = 0; dest_index < 3; dest_index++)
{
int src_channels = (src_index == 0) ? 3 : 4;
int src_has_alpha = (src_index == 2);
int dest_channels = (dest_index == 0) ? 3 : 4;
int dest_has_alpha = (dest_index == 2);
int src_rowstride = (src_channels*src_width + 3) & ~3;
int dest_rowstride = (dest_channels *dest_width + 3) & ~3;
int filter_level;
src_buf = malloc(src_rowstride * src_height);
memset (src_buf, 0x80, src_rowstride * src_height);
dest_buf = malloc(dest_rowstride * dest_height);
memset (dest_buf, 0x80, dest_rowstride * dest_height);
for (filter_level = ART_FILTER_NEAREST ; filter_level <= ART_FILTER_HYPER; filter_level++)
{
printf ("src_channels = %d (%s); dest_channels = %d (%s); filter_level=",
src_channels, src_has_alpha ? "alpha" : "no alpha",
dest_channels, dest_has_alpha ? "alpha" : "no alpha");
switch (filter_level)
{
case ART_FILTER_NEAREST:
printf ("ART_FILTER_NEAREST\n");
break;
case ART_FILTER_TILES:
printf ("ART_FILTER_TILES\n");
break;
case ART_FILTER_BILINEAR:
printf ("ART_FILTER_BILINEAR\n");
break;
case ART_FILTER_HYPER:
printf ("ART_FILTER_HYPER\n");
break;
}
printf("\t\t\titers\ttotal\t\tmsecs/iter\tMpixels/sec\t\n");
if (!(src_has_alpha && !dest_has_alpha))
{
start_timing ();
for (i = 0; i < ITERS; i++)
{
pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
filter_level);
}
scale_times[src_index][dest_index][filter_level] =
stop_timing (" scale\t\t", ITERS, dest_height * dest_width);
}
start_timing ();
for (i = 0; i < ITERS; i++)
{
pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
filter_level, 255);
}
composite_times[src_index][dest_index][filter_level] =
stop_timing (" composite\t\t", ITERS, dest_height * dest_width);
start_timing ();
for (i = 0; i < ITERS; i++)
{
pixops_composite_color (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
filter_level, 255, 0, 0, 16, 0xaaaaaa, 0x555555);
}
composite_color_times[src_index][dest_index][filter_level] =
stop_timing (" composite color\t", ITERS, dest_height * dest_width);
printf ("\n");
}
printf ("\n");
free (src_buf);
free (dest_buf);
}
printf ("SCALE\n=====\n\n");
dump_array (scale_times);
printf ("COMPOSITE\n=========\n\n");
dump_array (composite_times);
printf ("COMPOSITE_COLOR\n===============\n\n");
dump_array (composite_color_times);
}