Blame gdk-pixbuf/pixops/pixops.c

Packit a4058c
/*
Packit a4058c
 * Copyright (C) 2000 Red Hat, Inc
Packit a4058c
 * mediaLib integration Copyright (c) 2001-2007 Sun Microsystems, Inc.
Packit a4058c
 * All rights reserved.  (Brian Cameron, Dmitriy Demin, James Cheng,
Packit a4058c
 * Padraig O'Briain)
Packit a4058c
 *
Packit a4058c
 * This library is free software; you can redistribute it and/or
Packit a4058c
 * modify it under the terms of the GNU Lesser General Public
Packit a4058c
 * License as published by the Free Software Foundation; either
Packit a4058c
 * version 2 of the License, or (at your option) any later version.
Packit a4058c
 *
Packit a4058c
 * This library is distributed in the hope that it will be useful,
Packit a4058c
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4058c
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4058c
 * Lesser General Public License for more details.
Packit a4058c
 *
Packit a4058c
 * You should have received a copy of the GNU Lesser General Public
Packit a4058c
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit a4058c
 */
Packit a4058c
#include "config.h"
Packit a4058c
#include <math.h>
Packit a4058c
#include <glib.h>
Packit a4058c
Packit a4058c
#include "../fallback-c89.c"
Packit a4058c
#include "pixops.h"
Packit a4058c
#include "pixops-internal.h"
Packit a4058c
Packit a4058c
#define SUBSAMPLE_BITS 4
Packit a4058c
#define SUBSAMPLE (1 << SUBSAMPLE_BITS)
Packit a4058c
#define SUBSAMPLE_MASK ((1 << SUBSAMPLE_BITS)-1)
Packit a4058c
#define SCALE_SHIFT 16
Packit a4058c
Packit a4058c
static void
Packit a4058c
_pixops_scale_real (guchar        *dest_buf,
Packit a4058c
                    int            render_x0,
Packit a4058c
                    int            render_y0,
Packit a4058c
                    int            render_x1,
Packit a4058c
                    int            render_y1,
Packit a4058c
                    int            dest_rowstride,
Packit a4058c
                    int            dest_channels,
Packit a4058c
                    gboolean       dest_has_alpha,
Packit a4058c
                    const guchar  *src_buf,
Packit a4058c
                    int            src_width,
Packit a4058c
                    int            src_height,
Packit a4058c
                    int            src_rowstride,
Packit a4058c
                    int            src_channels,
Packit a4058c
                    gboolean       src_has_alpha,
Packit a4058c
                    double         scale_x,
Packit a4058c
                    double         scale_y,
Packit a4058c
                    PixopsInterpType  interp_type);
Packit a4058c
Packit a4058c
typedef struct _PixopsFilter PixopsFilter;
Packit a4058c
typedef struct _PixopsFilterDimension PixopsFilterDimension;
Packit a4058c
Packit a4058c
struct _PixopsFilterDimension
Packit a4058c
{
Packit a4058c
  int n;
Packit a4058c
  double offset;
Packit a4058c
  double *weights;
Packit a4058c
};
Packit a4058c
Packit a4058c
struct _PixopsFilter
Packit a4058c
{
Packit a4058c
  PixopsFilterDimension x;
Packit a4058c
  PixopsFilterDimension y;
Packit a4058c
  double overall_alpha;
Packit a4058c
}; 
Packit a4058c
Packit a4058c
typedef guchar *(*PixopsLineFunc) (int *weights, int n_x, int n_y,
Packit a4058c
				   guchar *dest, int dest_x, guchar *dest_end,
Packit a4058c
				   int dest_channels, int dest_has_alpha,
Packit a4058c
				   guchar **src, int src_channels,
Packit a4058c
				   gboolean src_has_alpha, int x_init,
Packit a4058c
				   int x_step, int src_width, int check_size,
Packit a4058c
				   guint32 color1, guint32 color2);
Packit a4058c
typedef void (*PixopsPixelFunc)   (guchar *dest, int dest_x, int dest_channels,
Packit a4058c
				   int dest_has_alpha, int src_has_alpha,
Packit a4058c
				   int check_size, guint32 color1,
Packit a4058c
				   guint32 color2,
Packit a4058c
				   guint r, guint g, guint b, guint a);
Packit a4058c
Packit a4058c
#ifdef USE_MEDIALIB
Packit a4058c
#include <stdlib.h>
Packit a4058c
#include <dlfcn.h>
Packit a4058c
#include <mlib_image.h>
Packit a4058c
Packit a4058c
#ifdef HAVE_STRINGS_H
Packit a4058c
#include <strings.h>
Packit a4058c
#endif
Packit a4058c
Packit a4058c
#ifdef HAVE_STRING_H
Packit a4058c
#include <string.h>
Packit a4058c
#endif
Packit a4058c
Packit a4058c
#if defined(HAVE_SYS_SYSTEMINFO_H)
Packit a4058c
#include <sys/systeminfo.h>
Packit a4058c
#elif defined(HAVE_SYS_SYSINFO_H)
Packit a4058c
#include <sys/sysinfo.h>
Packit a4058c
#endif
Packit a4058c
Packit a4058c
static void pixops_medialib_composite    (guchar          *dest_buf,
Packit a4058c
                                          int              dest_width,
Packit a4058c
                                          int              dest_height,
Packit a4058c
                                          int              dest_rowstride,
Packit a4058c
                                          int              dest_channels,
Packit a4058c
                                          int              dest_has_alpha,
Packit a4058c
                                          const guchar    *src_buf,
Packit a4058c
                                          int              src_width,
Packit a4058c
                                          int              src_height,
Packit a4058c
                                          int              src_rowstride,
Packit a4058c
                                          int              src_channels,
Packit a4058c
                                          int              src_has_alpha,
Packit a4058c
                                          int              dest_x,
Packit a4058c
                                          int              dest_y,
Packit a4058c
                                          int              dest_region_width,
Packit a4058c
                                          int              dest_region_height,
Packit a4058c
                                          double           offset_x,
Packit a4058c
                                          double           offset_y,
Packit a4058c
                                          double           scale_x,
Packit a4058c
                                          double           scale_y,
Packit a4058c
                                          PixopsInterpType interp_type,
Packit a4058c
                                          int              overall_alpha);
Packit a4058c
Packit a4058c
static void pixops_medialib_scale        (guchar          *dest_buf,
Packit a4058c
                                          int              dest_width,
Packit a4058c
                                          int              dest_height,
Packit a4058c
                                          int              dest_rowstride,
Packit a4058c
                                          int              dest_channels,
Packit a4058c
                                          int              dest_has_alpha,
Packit a4058c
                                          const guchar    *src_buf,
Packit a4058c
                                          int              src_width,
Packit a4058c
                                          int              src_height,
Packit a4058c
                                          int              src_rowstride,
Packit a4058c
                                          int              src_channels,
Packit a4058c
                                          int              src_has_alpha,
Packit a4058c
                                          int              dest_x,
Packit a4058c
                                          int              dest_y,
Packit a4058c
                                          int              dest_region_width,
Packit a4058c
                                          int              dest_region_height,
Packit a4058c
                                          double           offset_x,
Packit a4058c
                                          double           offset_y,
Packit a4058c
                                          double           scale_x,
Packit a4058c
                                          double           scale_y,
Packit a4058c
                                          PixopsInterpType interp_type);
Packit a4058c
Packit a4058c
typedef struct _mlInterp mlInterp;
Packit a4058c
Packit a4058c
struct _mlInterp
Packit a4058c
{
Packit a4058c
  double       tx;
Packit a4058c
  double       ty;
Packit a4058c
  PixopsFilter po_filter;
Packit a4058c
  void         *interp_table;
Packit a4058c
};
Packit a4058c
Packit a4058c
static gboolean medialib_initialized = FALSE;
Packit a4058c
static gboolean use_medialib         = TRUE;
Packit a4058c
Packit a4058c
/*
Packit a4058c
 * Sun mediaLib(tm) support.
Packit a4058c
 *
Packit a4058c
 *   http://www.sun.com/processors/vis/mlib.html
Packit a4058c
 *
Packit a4058c
 */
Packit a4058c
static void
Packit a4058c
_pixops_use_medialib ()
Packit a4058c
{
Packit a4058c
  char *mlib_version_string;
Packit a4058c
  char  sys_info[257];
Packit a4058c
  long  count;
Packit a4058c
Packit a4058c
  medialib_initialized = TRUE; 
Packit a4058c
Packit a4058c
  if (getenv ("GDK_DISABLE_MEDIALIB"))
Packit a4058c
    {
Packit a4058c
      use_medialib = FALSE;
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  /*
Packit a4058c
   * The imaging functions we want to use were added in mediaLib version 2.
Packit a4058c
   * So turn off mediaLib support if the user has an older version.
Packit a4058c
   * mlib_version returns a string in this format:
Packit a4058c
   *
Packit a4058c
   * mediaLib:0210:20011101:v8plusa
Packit a4058c
   * ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
Packit a4058c
   * libname  vers  build   ISALIST identifier
Packit a4058c
   *                date    (in this case sparcv8plus+vis)
Packit a4058c
   * 
Packit a4058c
   * The first 2 digits of the version are the major version.  The 3rd digit
Packit a4058c
   * is the minor version, and the 4th digit is the micro version.  So the
Packit a4058c
   * above string corresponds to version 2.1.0.  In the following test we only
Packit a4058c
   * care about the major version.
Packit a4058c
   */
Packit a4058c
  mlib_version_string = mlib_version ();
Packit a4058c
Packit a4058c
  count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
Packit a4058c
Packit a4058c
  if (count != -1)
Packit a4058c
    {
Packit a4058c
      if (strcmp (sys_info, "i386") == 0)
Packit a4058c
        {
Packit a4058c
          char *mlib_target_isa = &mlib_version_string[23];
Packit a4058c
Packit a4058c
          /*
Packit a4058c
           * For x86 processors mediaLib generic C implementation
Packit a4058c
           * does not give any performance advantage so disable it
Packit a4058c
           */
Packit a4058c
          if (strncmp (mlib_target_isa, "sse", 3) != 0)
Packit a4058c
            {
Packit a4058c
              use_medialib = FALSE;
Packit a4058c
              return;
Packit a4058c
            }
Packit a4058c
Packit a4058c
          /*
Packit a4058c
           * For x86 processors use of libumem conflicts with
Packit a4058c
           * mediaLib, so avoid using it.
Packit a4058c
           */
Packit a4058c
          if (dlsym (RTLD_PROBE,   "umem_alloc") != NULL)
Packit a4058c
            {
Packit a4058c
              use_medialib = FALSE;
Packit a4058c
              return;
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      /* Failed to get system architecture, disable mediaLib anyway */
Packit a4058c
      use_medialib = FALSE;
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
#endif
Packit a4058c
Packit a4058c
static int
Packit a4058c
get_check_shift (int check_size)
Packit a4058c
{
Packit a4058c
  int check_shift = 0;
Packit a4058c
  g_return_val_if_fail (check_size >= 0, 4);
Packit a4058c
Packit a4058c
  while (!(check_size & 1))
Packit a4058c
    {
Packit a4058c
      check_shift++;
Packit a4058c
      check_size >>= 1;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return check_shift;
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_scale_nearest (guchar        *dest_buf,
Packit a4058c
		      int            render_x0,
Packit a4058c
		      int            render_y0,
Packit a4058c
		      int            render_x1,
Packit a4058c
		      int            render_y1,
Packit a4058c
		      int            dest_rowstride,
Packit a4058c
		      int            dest_channels,
Packit a4058c
		      gboolean       dest_has_alpha,
Packit a4058c
		      const guchar  *src_buf,
Packit a4058c
		      int            src_width,
Packit a4058c
		      int            src_height,
Packit a4058c
		      int            src_rowstride,
Packit a4058c
		      int            src_channels,
Packit a4058c
		      gboolean       src_has_alpha,
Packit a4058c
		      double         scale_x,
Packit a4058c
		      double         scale_y)
Packit a4058c
{
Packit a4058c
  gint64 i;
Packit a4058c
  gint64 x;
Packit a4058c
  gint64 x_step = (1 << SCALE_SHIFT) / scale_x;
Packit a4058c
  gint64 y_step = (1 << SCALE_SHIFT) / scale_y;
Packit a4058c
  gint64 xmax, xstart, xstop, x_pos, y_pos;
Packit a4058c
  const guchar *p;
Packit a4058c
Packit a4058c
#define INNER_LOOP(SRC_CHANNELS,DEST_CHANNELS,ASSIGN_PIXEL)     \
Packit a4058c
      xmax = x + (render_x1 - render_x0) * x_step;              \
Packit a4058c
      xstart = MIN (0, xmax);                                   \
Packit a4058c
      xstop = MIN (src_width << SCALE_SHIFT, xmax);             \
Packit a4058c
      p = src + (CLAMP (x, xstart, xstop) >> SCALE_SHIFT) * SRC_CHANNELS; \
Packit a4058c
      while (x < xstart)                                        \
Packit a4058c
        {                                                       \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x += x_step;                                          \
Packit a4058c
        }                                                       \
Packit a4058c
      while (x < xstop)                                         \
Packit a4058c
        {                                                       \
Packit a4058c
          p = src + (x >> SCALE_SHIFT) * SRC_CHANNELS;          \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x += x_step;                                          \
Packit a4058c
        }                                                       \
Packit a4058c
      x_pos = x >> SCALE_SHIFT;                                 \
Packit a4058c
      p = src + CLAMP (x_pos, 0, src_width - 1) * SRC_CHANNELS; \
Packit a4058c
      while (x < xmax)                                          \
Packit a4058c
        {                                                       \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x += x_step;                                          \
Packit a4058c
        }
Packit a4058c
Packit a4058c
  for (i = 0; i < (render_y1 - render_y0); i++)
Packit a4058c
    {
Packit a4058c
      const guchar *src;
Packit a4058c
      guchar       *dest;
Packit a4058c
      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
Packit a4058c
      y_pos = CLAMP (y_pos, 0, src_height - 1);
Packit a4058c
      src  = src_buf + (gsize)y_pos * src_rowstride;
Packit a4058c
      dest = dest_buf + (gsize)i * dest_rowstride;
Packit a4058c
Packit a4058c
      x = render_x0 * x_step + x_step / 2;
Packit a4058c
Packit a4058c
      if (src_channels == 3)
Packit a4058c
	{
Packit a4058c
	  if (dest_channels == 3)
Packit a4058c
	    {
Packit a4058c
	      INNER_LOOP (3, 3, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2]);
Packit a4058c
	    }
Packit a4058c
	  else
Packit a4058c
	    {
Packit a4058c
	      INNER_LOOP (3, 4, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2];dest[3]=0xff);
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
      else if (src_channels == 4)
Packit a4058c
	{
Packit a4058c
	  if (dest_channels == 3)
Packit a4058c
	    {
Packit a4058c
	      INNER_LOOP (4, 3, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2]);
Packit a4058c
	    }
Packit a4058c
	  else
Packit a4058c
	    {
Packit a4058c
	      guint32 *p32;
Packit a4058c
	      INNER_LOOP(4, 4, p32=(guint32*)dest;*p32=*((guint32*)p));
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_composite_nearest (guchar        *dest_buf,
Packit a4058c
			  int            render_x0,
Packit a4058c
			  int            render_y0,
Packit a4058c
			  int            render_x1,
Packit a4058c
			  int            render_y1,
Packit a4058c
			  int            dest_rowstride,
Packit a4058c
			  int            dest_channels,
Packit a4058c
			  gboolean       dest_has_alpha,
Packit a4058c
			  const guchar  *src_buf,
Packit a4058c
			  int            src_width,
Packit a4058c
			  int            src_height,
Packit a4058c
			  int            src_rowstride,
Packit a4058c
			  int            src_channels,
Packit a4058c
			  gboolean       src_has_alpha,
Packit a4058c
			  double         scale_x,
Packit a4058c
			  double         scale_y,
Packit a4058c
			  int            overall_alpha)
Packit a4058c
{
Packit a4058c
  gint64 i;
Packit a4058c
  gint64 x;
Packit a4058c
  gint64 x_step = (1 << SCALE_SHIFT) / scale_x;
Packit a4058c
  gint64 y_step = (1 << SCALE_SHIFT) / scale_y;
Packit a4058c
  gint64 xmax, xstart, xstop, x_pos, y_pos;
Packit a4058c
  const guchar *p;
Packit a4058c
  unsigned int  a0;
Packit a4058c
Packit a4058c
  for (i = 0; i < (render_y1 - render_y0); i++)
Packit a4058c
    {
Packit a4058c
      const guchar *src;
Packit a4058c
      guchar       *dest;
Packit a4058c
      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
Packit a4058c
      y_pos = CLAMP (y_pos, 0, src_height - 1);
Packit a4058c
      src  = src_buf + (gsize)y_pos * src_rowstride;
Packit a4058c
      dest = dest_buf + (gsize)i * dest_rowstride;
Packit a4058c
Packit a4058c
      x = render_x0 * x_step + x_step / 2;
Packit a4058c
      
Packit a4058c
      INNER_LOOP(src_channels, dest_channels,
Packit a4058c
	  if (src_has_alpha)
Packit a4058c
	    a0 = (p[3] * overall_alpha) / 0xff;
Packit a4058c
	  else
Packit a4058c
	    a0 = overall_alpha;
Packit a4058c
Packit a4058c
          switch (a0)
Packit a4058c
            {
Packit a4058c
            case 0:
Packit a4058c
              break;
Packit a4058c
            case 255:
Packit a4058c
              dest[0] = p[0];
Packit a4058c
              dest[1] = p[1];
Packit a4058c
              dest[2] = p[2];
Packit a4058c
              if (dest_has_alpha)
Packit a4058c
                dest[3] = 0xff;
Packit a4058c
              break;
Packit a4058c
            default:
Packit a4058c
              if (dest_has_alpha)
Packit a4058c
                {
Packit a4058c
                  unsigned int w0 = 0xff * a0;
Packit a4058c
                  unsigned int w1 = (0xff - a0) * dest[3];
Packit a4058c
                  unsigned int w = w0 + w1;
Packit a4058c
Packit a4058c
		  dest[0] = (w0 * p[0] + w1 * dest[0]) / w;
Packit a4058c
		  dest[1] = (w0 * p[1] + w1 * dest[1]) / w;
Packit a4058c
		  dest[2] = (w0 * p[2] + w1 * dest[2]) / w;
Packit a4058c
		  dest[3] = w / 0xff;
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  unsigned int a1 = 0xff - a0;
Packit a4058c
		  unsigned int tmp;
Packit a4058c
Packit a4058c
		  tmp = a0 * p[0] + a1 * dest[0] + 0x80;
Packit a4058c
                  dest[0] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
		  tmp = a0 * p[1] + a1 * dest[1] + 0x80;
Packit a4058c
                  dest[1] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
		  tmp = a0 * p[2] + a1 * dest[2] + 0x80;
Packit a4058c
                  dest[2] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
                }
Packit a4058c
              break;
Packit a4058c
            }
Packit a4058c
	);
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_composite_nearest_noscale (guchar        *dest_buf,
Packit a4058c
				  int            render_x0,
Packit a4058c
				  int            render_y0,
Packit a4058c
				  int            render_x1,
Packit a4058c
				  int            render_y1,
Packit a4058c
				  int            dest_rowstride,
Packit a4058c
				  int            dest_channels,
Packit a4058c
				  gboolean       dest_has_alpha,
Packit a4058c
				  const guchar  *src_buf,
Packit a4058c
				  int            src_width,
Packit a4058c
				  int            src_height,
Packit a4058c
				  int            src_rowstride,
Packit a4058c
				  int            src_channels,
Packit a4058c
				  gboolean       src_has_alpha,
Packit a4058c
				  int            overall_alpha)
Packit a4058c
{
Packit a4058c
  gint64 i;
Packit a4058c
  gint64 x;
Packit a4058c
  gint64 xmax, xstart, xstop, y_pos;
Packit a4058c
  const guchar *p;
Packit a4058c
  unsigned int  a0;
Packit a4058c
Packit a4058c
#define INNER_LOOP_NOSCALE(SRC_CHANNELS,DEST_CHANNELS,ASSIGN_PIXEL) \
Packit a4058c
      xmax = x + (render_x1 - render_x0);                       \
Packit a4058c
      xstart = MIN (0, xmax);                                   \
Packit a4058c
      xstop = MIN (src_width, xmax);                            \
Packit a4058c
      p = src + CLAMP (x, xstart, xstop) * SRC_CHANNELS;        \
Packit a4058c
      while (x < xstart)                                        \
Packit a4058c
        {                                                       \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x++;                                                  \
Packit a4058c
        }                                                       \
Packit a4058c
      p = src + x * SRC_CHANNELS;                               \
Packit a4058c
      while (x < xstop)                                         \
Packit a4058c
        {                                                       \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x++;                                                  \
Packit a4058c
          p += SRC_CHANNELS;                                    \
Packit a4058c
        }                                                       \
Packit a4058c
      p = src + CLAMP (x, 0, src_width - 1) * SRC_CHANNELS;     \
Packit a4058c
      while (x < xmax)                                          \
Packit a4058c
        {                                                       \
Packit a4058c
          ASSIGN_PIXEL;                                         \
Packit a4058c
          dest += DEST_CHANNELS;                                \
Packit a4058c
          x++;                                                  \
Packit a4058c
        }
Packit a4058c
Packit a4058c
  for (i = 0; i < (render_y1 - render_y0); i++)
Packit a4058c
    {
Packit a4058c
      const guchar *src;
Packit a4058c
      guchar       *dest;
Packit a4058c
      y_pos = i + render_y0;
Packit a4058c
      y_pos = CLAMP (y_pos, 0, src_height - 1);
Packit a4058c
      src  = src_buf + (gsize)y_pos * src_rowstride;
Packit a4058c
      dest = dest_buf + (gsize)i * dest_rowstride;
Packit a4058c
Packit a4058c
      x = render_x0;
Packit a4058c
Packit a4058c
      INNER_LOOP_NOSCALE(src_channels, dest_channels,
Packit a4058c
	  if (src_has_alpha)
Packit a4058c
	    a0 = (p[3] * overall_alpha) / 0xff;
Packit a4058c
	  else
Packit a4058c
	    a0 = overall_alpha;
Packit a4058c
Packit a4058c
	  switch (a0)
Packit a4058c
	    {
Packit a4058c
	    case 0:
Packit a4058c
	      break;
Packit a4058c
	    case 255:
Packit a4058c
	      dest[0] = p[0];
Packit a4058c
	      dest[1] = p[1];
Packit a4058c
	      dest[2] = p[2];
Packit a4058c
	      if (dest_has_alpha)
Packit a4058c
		dest[3] = 0xff;
Packit a4058c
	      break;
Packit a4058c
	    default:
Packit a4058c
	      if (dest_has_alpha)
Packit a4058c
	        {
Packit a4058c
		  unsigned int w0 = 0xff * a0;
Packit a4058c
		  unsigned int w1 = (0xff - a0) * dest[3];
Packit a4058c
		  unsigned int w = w0 + w1;
Packit a4058c
Packit a4058c
		  dest[0] = (w0 * p[0] + w1 * dest[0]) / w;
Packit a4058c
		  dest[1] = (w0 * p[1] + w1 * dest[1]) / w;
Packit a4058c
		  dest[2] = (w0 * p[2] + w1 * dest[2]) / w;
Packit a4058c
		  dest[3] = w / 0xff;
Packit a4058c
	        }
Packit a4058c
	      else
Packit a4058c
	        {
Packit a4058c
		  unsigned int a1 = 0xff - a0;
Packit a4058c
		  unsigned int tmp;
Packit a4058c
Packit a4058c
		  tmp = a0 * p[0] + a1 * dest[0] + 0x80;
Packit a4058c
		  dest[0] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
		  tmp = a0 * p[1] + a1 * dest[1] + 0x80;
Packit a4058c
		  dest[1] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
		  tmp = a0 * p[2] + a1 * dest[2] + 0x80;
Packit a4058c
		  dest[2] = (tmp + (tmp >> 8)) >> 8;
Packit a4058c
	        }
Packit a4058c
	      break;
Packit a4058c
	    }
Packit a4058c
	);
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
#undef INNER_LOOP_NOSCALE
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_composite_color_nearest (guchar        *dest_buf,
Packit a4058c
				int            render_x0,
Packit a4058c
				int            render_y0,
Packit a4058c
				int            render_x1,
Packit a4058c
				int            render_y1,
Packit a4058c
				int            dest_rowstride,
Packit a4058c
				int            dest_channels,
Packit a4058c
				gboolean       dest_has_alpha,
Packit a4058c
				const guchar  *src_buf,
Packit a4058c
				int            src_width,
Packit a4058c
				int            src_height,
Packit a4058c
				int            src_rowstride,
Packit a4058c
				int            src_channels,
Packit a4058c
				gboolean       src_has_alpha,
Packit a4058c
				double         scale_x,
Packit a4058c
				double         scale_y,
Packit a4058c
				int            overall_alpha,
Packit a4058c
				int            check_x,
Packit a4058c
				int            check_y,
Packit a4058c
				int            check_size,
Packit a4058c
				guint32        color1,
Packit a4058c
				guint32        color2)
Packit a4058c
{
Packit a4058c
  gint64 i, j;
Packit a4058c
  gint64 x;
Packit a4058c
  gint64 x_step = (1 << SCALE_SHIFT) / scale_x;
Packit a4058c
  gint64 y_step = (1 << SCALE_SHIFT) / scale_y;
Packit a4058c
  int r1, g1, b1, r2, g2, b2;
Packit a4058c
  int check_shift = get_check_shift (check_size);
Packit a4058c
  gint64 xmax, xstart, xstop, x_pos, y_pos;
Packit a4058c
  const guchar *p;
Packit a4058c
  unsigned int  a0;
Packit a4058c
Packit a4058c
  for (i = 0; i < (render_y1 - render_y0); i++)
Packit a4058c
    {
Packit a4058c
      const guchar *src;
Packit a4058c
      guchar       *dest;
Packit a4058c
      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
Packit a4058c
      y_pos = CLAMP (y_pos, 0, src_height - 1);
Packit a4058c
      src  = src_buf + (gsize)y_pos * src_rowstride;
Packit a4058c
      dest = dest_buf + (gsize)i * dest_rowstride;
Packit a4058c
Packit a4058c
      x = render_x0 * x_step + x_step / 2;
Packit a4058c
      
Packit a4058c
      
Packit a4058c
      if (((i + check_y) >> check_shift) & 1)
Packit a4058c
	{
Packit a4058c
	  r1 = (color2 & 0xff0000) >> 16;
Packit a4058c
	  g1 = (color2 & 0xff00) >> 8;
Packit a4058c
	  b1 = color2 & 0xff;
Packit a4058c
Packit a4058c
	  r2 = (color1 & 0xff0000) >> 16;
Packit a4058c
	  g2 = (color1 & 0xff00) >> 8;
Packit a4058c
	  b2 = color1 & 0xff;
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  r1 = (color1 & 0xff0000) >> 16;
Packit a4058c
	  g1 = (color1 & 0xff00) >> 8;
Packit a4058c
	  b1 = color1 & 0xff;
Packit a4058c
Packit a4058c
	  r2 = (color2 & 0xff0000) >> 16;
Packit a4058c
	  g2 = (color2 & 0xff00) >> 8;
Packit a4058c
	  b2 = color2 & 0xff;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      j = 0;
Packit a4058c
      INNER_LOOP(src_channels, dest_channels,
Packit a4058c
	  if (src_has_alpha)
Packit a4058c
	    a0 = (p[3] * overall_alpha + 0xff) >> 8;
Packit a4058c
	  else
Packit a4058c
	    a0 = overall_alpha;
Packit a4058c
Packit a4058c
          switch (a0)
Packit a4058c
            {
Packit a4058c
            case 0:
Packit a4058c
              if (((j + check_x) >> check_shift) & 1)
Packit a4058c
                {
Packit a4058c
                  dest[0] = r2; 
Packit a4058c
                  dest[1] = g2; 
Packit a4058c
                  dest[2] = b2;
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  dest[0] = r1; 
Packit a4058c
                  dest[1] = g1; 
Packit a4058c
                  dest[2] = b1;
Packit a4058c
                }
Packit a4058c
            break;
Packit a4058c
            case 255:
Packit a4058c
	      dest[0] = p[0];
Packit a4058c
	      dest[1] = p[1];
Packit a4058c
	      dest[2] = p[2];
Packit a4058c
              break;
Packit a4058c
            default:
Packit a4058c
		     {
Packit a4058c
		       unsigned int tmp;
Packit a4058c
              if (((j + check_x) >> check_shift) & 1)
Packit a4058c
                {
Packit a4058c
                  tmp = ((int) p[0] - r2) * a0;
Packit a4058c
                  dest[0] = r2 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                  tmp = ((int) p[1] - g2) * a0;
Packit a4058c
                  dest[1] = g2 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                  tmp = ((int) p[2] - b2) * a0;
Packit a4058c
                  dest[2] = b2 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  tmp = ((int) p[0] - r1) * a0;
Packit a4058c
                  dest[0] = r1 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                  tmp = ((int) p[1] - g1) * a0;
Packit a4058c
                  dest[1] = g1 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                  tmp = ((int) p[2] - b1) * a0;
Packit a4058c
                  dest[2] = b1 + ((tmp + (tmp >> 8) + 0x80) >> 8);
Packit a4058c
                }
Packit a4058c
		     }
Packit a4058c
              break;
Packit a4058c
            }
Packit a4058c
	  
Packit a4058c
	  if (dest_channels == 4)
Packit a4058c
	    dest[3] = 0xff;
Packit a4058c
Packit a4058c
		 j++;
Packit a4058c
	);
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
#undef INNER_LOOP
Packit a4058c
Packit a4058c
static void
Packit a4058c
composite_pixel (guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,
Packit a4058c
		 int src_has_alpha, int check_size, guint32 color1, guint32 color2,
Packit a4058c
		 guint r, guint g, guint b, guint a)
Packit a4058c
{
Packit a4058c
  if (dest_has_alpha)
Packit a4058c
    {
Packit a4058c
      unsigned int w0 = a - (a >> 8);
Packit a4058c
      unsigned int w1 = ((0xff0000 - a) >> 8) * dest[3];
Packit a4058c
      unsigned int w = w0 + w1;
Packit a4058c
      
Packit a4058c
      if (w != 0)
Packit a4058c
	{
Packit a4058c
	  dest[0] = (r - (r >> 8) + w1 * dest[0]) / w;
Packit a4058c
	  dest[1] = (g - (g >> 8) + w1 * dest[1]) / w;
Packit a4058c
	  dest[2] = (b - (b >> 8) + w1 * dest[2]) / w;
Packit a4058c
	  dest[3] = w / 0xff00;
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  dest[0] = 0;
Packit a4058c
	  dest[1] = 0;
Packit a4058c
	  dest[2] = 0;
Packit a4058c
	  dest[3] = 0;
Packit a4058c
	}
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      dest[0] = (r + (0xff0000 - a) * dest[0]) / 0xff0000;
Packit a4058c
      dest[1] = (g + (0xff0000 - a) * dest[1]) / 0xff0000;
Packit a4058c
      dest[2] = (b + (0xff0000 - a) * dest[2]) / 0xff0000;
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
static guchar *
Packit a4058c
composite_line (int *weights, int n_x, int n_y,
Packit a4058c
		guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
Packit a4058c
		guchar **src, int src_channels, gboolean src_has_alpha,
Packit a4058c
		int x_init, int x_step, int src_width,
Packit a4058c
		int check_size, guint32 color1, guint32 color2)
Packit a4058c
{
Packit a4058c
  int x = x_init;
Packit a4058c
  int i, j;
Packit a4058c
Packit a4058c
  while (dest < dest_end)
Packit a4058c
    {
Packit a4058c
      int x_scaled = x >> SCALE_SHIFT;
Packit a4058c
      unsigned int r = 0, g = 0, b = 0, a = 0;
Packit a4058c
      int *pixel_weights;
Packit a4058c
      
Packit a4058c
      pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y;
Packit a4058c
      
Packit a4058c
      for (i=0; i
Packit a4058c
	{
Packit a4058c
	  guchar *q = src[i] + x_scaled * src_channels;
Packit a4058c
	  int *line_weights = pixel_weights + n_x * i;
Packit a4058c
	  
Packit a4058c
	  for (j=0; j
Packit a4058c
	    {
Packit a4058c
	      unsigned int ta;
Packit a4058c
Packit a4058c
	      if (src_has_alpha)
Packit a4058c
		ta = q[3] * line_weights[j];
Packit a4058c
	      else
Packit a4058c
		ta = 0xff * line_weights[j];
Packit a4058c
	      
Packit a4058c
	      r += ta * q[0];
Packit a4058c
	      g += ta * q[1];
Packit a4058c
	      b += ta * q[2];
Packit a4058c
	      a += ta;
Packit a4058c
Packit a4058c
	      q += src_channels;
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
Packit a4058c
      if (dest_has_alpha)
Packit a4058c
	{
Packit a4058c
	  unsigned int w0 = a - (a >> 8);
Packit a4058c
	  unsigned int w1 = ((0xff0000 - a) >> 8) * dest[3];
Packit a4058c
	  unsigned int w = w0 + w1;
Packit a4058c
Packit a4058c
	  if (w != 0)
Packit a4058c
	    {
Packit a4058c
	      dest[0] = (r - (r >> 8) + w1 * dest[0]) / w;
Packit a4058c
	      dest[1] = (g - (g >> 8) + w1 * dest[1]) / w;
Packit a4058c
	      dest[2] = (b - (b >> 8) + w1 * dest[2]) / w;
Packit a4058c
	      dest[3] = w / 0xff00;
Packit a4058c
	    }
Packit a4058c
	  else
Packit a4058c
	    {
Packit a4058c
	      dest[0] = 0;
Packit a4058c
	      dest[1] = 0;
Packit a4058c
	      dest[2] = 0;
Packit a4058c
	      dest[3] = 0;
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  dest[0] = (r + (0xff0000 - a) * dest[0]) / 0xff0000;
Packit a4058c
	  dest[1] = (g + (0xff0000 - a) * dest[1]) / 0xff0000;
Packit a4058c
	  dest[2] = (b + (0xff0000 - a) * dest[2]) / 0xff0000;
Packit a4058c
	}
Packit a4058c
      
Packit a4058c
      dest += dest_channels;
Packit a4058c
      x += x_step;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return dest;
Packit a4058c
}
Packit a4058c
Packit a4058c
static guchar *
Packit a4058c
composite_line_22_4a4 (int *weights, int n_x, int n_y,
Packit a4058c
		       guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
Packit a4058c
		       guchar **src, int src_channels, gboolean src_has_alpha,
Packit a4058c
		       int x_init, int x_step, int src_width,
Packit a4058c
		       int check_size, guint32 color1, guint32 color2)
Packit a4058c
{
Packit a4058c
  int x = x_init;
Packit a4058c
  guchar *src0 = src[0];
Packit a4058c
  guchar *src1 = src[1];
Packit a4058c
Packit a4058c
  g_return_val_if_fail (src_channels != 3, dest);
Packit a4058c
  g_return_val_if_fail (src_has_alpha, dest);
Packit a4058c
  
Packit a4058c
  while (dest < dest_end)
Packit a4058c
    {
Packit a4058c
      int x_scaled = x >> SCALE_SHIFT;
Packit a4058c
      unsigned int r, g, b, a, ta;
Packit a4058c
      int *pixel_weights;
Packit a4058c
      guchar *q0, *q1;
Packit a4058c
      int w1, w2, w3, w4;
Packit a4058c
      
Packit a4058c
      q0 = src0 + x_scaled * 4;
Packit a4058c
      q1 = src1 + x_scaled * 4;
Packit a4058c
      
Packit a4058c
      pixel_weights = (int *)((char *)weights +
Packit a4058c
	((x >> (SCALE_SHIFT - SUBSAMPLE_BITS - 4)) & (SUBSAMPLE_MASK << 4)));
Packit a4058c
      
Packit a4058c
      w1 = pixel_weights[0];
Packit a4058c
      w2 = pixel_weights[1];
Packit a4058c
      w3 = pixel_weights[2];
Packit a4058c
      w4 = pixel_weights[3];
Packit a4058c
Packit a4058c
      a = w1 * q0[3];
Packit a4058c
      r = a * q0[0];
Packit a4058c
      g = a * q0[1];
Packit a4058c
      b = a * q0[2];
Packit a4058c
Packit a4058c
      ta = w2 * q0[7];
Packit a4058c
      r += ta * q0[4];
Packit a4058c
      g += ta * q0[5];
Packit a4058c
      b += ta * q0[6];
Packit a4058c
      a += ta;
Packit a4058c
Packit a4058c
      ta = w3 * q1[3];
Packit a4058c
      r += ta * q1[0];
Packit a4058c
      g += ta * q1[1];
Packit a4058c
      b += ta * q1[2];
Packit a4058c
      a += ta;
Packit a4058c
Packit a4058c
      ta = w4 * q1[7];
Packit a4058c
      r += ta * q1[4];
Packit a4058c
      g += ta * q1[5];
Packit a4058c
      b += ta * q1[6];
Packit a4058c
      a += ta;
Packit a4058c
Packit a4058c
      dest[0] = ((0xff0000 - a) * dest[0] + r) >> 24;
Packit a4058c
      dest[1] = ((0xff0000 - a) * dest[1] + g) >> 24;
Packit a4058c
      dest[2] = ((0xff0000 - a) * dest[2] + b) >> 24;
Packit a4058c
      dest[3] = a >> 16;
Packit a4058c
      
Packit a4058c
      dest += 4;
Packit a4058c
      x += x_step;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return dest;
Packit a4058c
}
Packit a4058c
Packit a4058c
#ifdef USE_MMX
Packit a4058c
static guchar *
Packit a4058c
composite_line_22_4a4_mmx_stub (int *weights, int n_x, int n_y, guchar *dest,
Packit a4058c
				int dest_x, guchar *dest_end,
Packit a4058c
				int dest_channels, int dest_has_alpha,
Packit a4058c
				guchar **src, int src_channels,
Packit a4058c
				gboolean src_has_alpha, int x_init,
Packit a4058c
				int x_step, int src_width, int check_size,
Packit a4058c
				guint32 color1, guint32 color2)
Packit a4058c
{
Packit a4058c
  guint32 mmx_weights[16][8];
Packit a4058c
  int j;
Packit a4058c
Packit a4058c
  for (j=0; j<16; j++)
Packit a4058c
    {
Packit a4058c
      mmx_weights[j][0] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][1] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][2] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][3] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][4] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][5] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][6] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
      mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return _pixops_composite_line_22_4a4_mmx (mmx_weights, dest, src[0], src[1],
Packit a4058c
					    x_step, dest_end, x_init);
Packit a4058c
}
Packit a4058c
#endif /* USE_MMX */
Packit a4058c
Packit a4058c
static void
Packit a4058c
composite_pixel_color (guchar *dest, int dest_x, int dest_channels,
Packit a4058c
		       int dest_has_alpha, int src_has_alpha, int check_size,
Packit a4058c
		       guint32 color1, guint32 color2, guint r, guint g,
Packit a4058c
		       guint b, guint a)
Packit a4058c
{
Packit a4058c
  int dest_r, dest_g, dest_b;
Packit a4058c
  int check_shift = get_check_shift (check_size);
Packit a4058c
Packit a4058c
  if ((dest_x >> check_shift) & 1)
Packit a4058c
    {
Packit a4058c
      dest_r = (color2 & 0xff0000) >> 16;
Packit a4058c
      dest_g = (color2 & 0xff00) >> 8;
Packit a4058c
      dest_b = color2 & 0xff;
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      dest_r = (color1 & 0xff0000) >> 16;
Packit a4058c
      dest_g = (color1 & 0xff00) >> 8;
Packit a4058c
      dest_b = color1 & 0xff;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  dest[0] = ((0xff0000 - a) * dest_r + r) >> 24;
Packit a4058c
  dest[1] = ((0xff0000 - a) * dest_g + g) >> 24;
Packit a4058c
  dest[2] = ((0xff0000 - a) * dest_b + b) >> 24;
Packit a4058c
Packit a4058c
  if (dest_has_alpha)
Packit a4058c
    dest[3] = 0xff;
Packit a4058c
  else if (dest_channels == 4)
Packit a4058c
    dest[3] = a >> 16;
Packit a4058c
}
Packit a4058c
Packit a4058c
static guchar *
Packit a4058c
composite_line_color (int *weights, int n_x, int n_y, guchar *dest,
Packit a4058c
		      int dest_x, guchar *dest_end, int dest_channels,
Packit a4058c
		      int dest_has_alpha, guchar **src, int src_channels,
Packit a4058c
		      gboolean src_has_alpha, int x_init, int x_step,
Packit a4058c
		      int src_width, int check_size, guint32 color1,
Packit a4058c
		      guint32 color2)
Packit a4058c
{
Packit a4058c
  int x = x_init;
Packit a4058c
  int i, j;
Packit a4058c
  int check_shift = get_check_shift (check_size);
Packit a4058c
  int dest_r1, dest_g1, dest_b1;
Packit a4058c
  int dest_r2, dest_g2, dest_b2;
Packit a4058c
Packit a4058c
  g_return_val_if_fail (check_size != 0, dest);
Packit a4058c
Packit a4058c
  dest_r1 = (color1 & 0xff0000) >> 16;
Packit a4058c
  dest_g1 = (color1 & 0xff00) >> 8;
Packit a4058c
  dest_b1 = color1 & 0xff;
Packit a4058c
Packit a4058c
  dest_r2 = (color2 & 0xff0000) >> 16;
Packit a4058c
  dest_g2 = (color2 & 0xff00) >> 8;
Packit a4058c
  dest_b2 = color2 & 0xff;
Packit a4058c
Packit a4058c
  while (dest < dest_end)
Packit a4058c
    {
Packit a4058c
      int x_scaled = x >> SCALE_SHIFT;
Packit a4058c
      unsigned int r = 0, g = 0, b = 0, a = 0;
Packit a4058c
      int *pixel_weights;
Packit a4058c
      
Packit a4058c
      pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y;
Packit a4058c
Packit a4058c
      for (i=0; i
Packit a4058c
	{
Packit a4058c
	  guchar *q = src[i] + x_scaled * src_channels;
Packit a4058c
	  int *line_weights = pixel_weights + n_x * i;
Packit a4058c
	  
Packit a4058c
	  for (j=0; j
Packit a4058c
	    {
Packit a4058c
	      unsigned int ta;
Packit a4058c
	      
Packit a4058c
	      if (src_has_alpha)
Packit a4058c
		ta = q[3] * line_weights[j];
Packit a4058c
	      else
Packit a4058c
		ta = 0xff * line_weights[j];
Packit a4058c
		  
Packit a4058c
	      r += ta * q[0];
Packit a4058c
	      g += ta * q[1];
Packit a4058c
	      b += ta * q[2];
Packit a4058c
	      a += ta;
Packit a4058c
Packit a4058c
	      q += src_channels;
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
Packit a4058c
      if ((dest_x >> check_shift) & 1)
Packit a4058c
	{
Packit a4058c
	  dest[0] = ((0xff0000 - a) * dest_r2 + r) >> 24;
Packit a4058c
	  dest[1] = ((0xff0000 - a) * dest_g2 + g) >> 24;
Packit a4058c
	  dest[2] = ((0xff0000 - a) * dest_b2 + b) >> 24;
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  dest[0] = ((0xff0000 - a) * dest_r1 + r) >> 24;
Packit a4058c
	  dest[1] = ((0xff0000 - a) * dest_g1 + g) >> 24;
Packit a4058c
	  dest[2] = ((0xff0000 - a) * dest_b1 + b) >> 24;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      if (dest_has_alpha)
Packit a4058c
	dest[3] = 0xff;
Packit a4058c
      else if (dest_channels == 4)
Packit a4058c
	dest[3] = a >> 16;
Packit a4058c
	
Packit a4058c
      dest += dest_channels;
Packit a4058c
      x += x_step;
Packit a4058c
      dest_x++;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return dest;
Packit a4058c
}
Packit a4058c
Packit a4058c
#ifdef USE_MMX
Packit a4058c
static guchar *
Packit a4058c
composite_line_color_22_4a4_mmx_stub (int *weights, int n_x, int n_y,
Packit a4058c
				      guchar *dest, int dest_x,
Packit a4058c
				      guchar *dest_end, int dest_channels,
Packit a4058c
				      int dest_has_alpha, guchar **src,
Packit a4058c
				      int src_channels, gboolean src_has_alpha,
Packit a4058c
				      int x_init, int x_step, int src_width,
Packit a4058c
				      int check_size, guint32 color1,
Packit a4058c
				      guint32 color2)
Packit a4058c
{
Packit a4058c
  guint32 mmx_weights[16][8];
Packit a4058c
  int check_shift = get_check_shift (check_size);
Packit a4058c
  int colors[4];
Packit a4058c
  int j;
Packit a4058c
Packit a4058c
  for (j=0; j<16; j++)
Packit a4058c
    {
Packit a4058c
      mmx_weights[j][0] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][1] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][2] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][3] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][4] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][5] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][6] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
      mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
    }
Packit a4058c
Packit a4058c
  colors[0] = (color1 & 0xff00) << 8 | (color1 & 0xff);
Packit a4058c
  colors[1] = (color1 & 0xff0000) >> 16;
Packit a4058c
  colors[2] = (color2 & 0xff00) << 8 | (color2 & 0xff);
Packit a4058c
  colors[3] = (color2 & 0xff0000) >> 16;
Packit a4058c
Packit a4058c
  return _pixops_composite_line_color_22_4a4_mmx (mmx_weights, dest, src[0],
Packit a4058c
    src[1], x_step, dest_end, x_init, dest_x, check_shift, colors);
Packit a4058c
}
Packit a4058c
#endif /* USE_MMX */
Packit a4058c
Packit a4058c
static void
Packit a4058c
scale_pixel (guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,
Packit a4058c
	     int src_has_alpha, int check_size, guint32 color1, guint32 color2,
Packit a4058c
	     guint r, guint g, guint b, guint a)
Packit a4058c
{
Packit a4058c
  if (src_has_alpha)
Packit a4058c
    {
Packit a4058c
      if (a)
Packit a4058c
	{
Packit a4058c
	  dest[0] = r / a;
Packit a4058c
	  dest[1] = g / a;
Packit a4058c
	  dest[2] = b / a;
Packit a4058c
	  dest[3] = a >> 16;
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  dest[0] = 0;
Packit a4058c
	  dest[1] = 0;
Packit a4058c
	  dest[2] = 0;
Packit a4058c
	  dest[3] = 0;
Packit a4058c
	}
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      dest[0] = (r + 0xffffff) >> 24;
Packit a4058c
      dest[1] = (g + 0xffffff) >> 24;
Packit a4058c
      dest[2] = (b + 0xffffff) >> 24;
Packit a4058c
      
Packit a4058c
      if (dest_has_alpha)
Packit a4058c
	dest[3] = 0xff;
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
static guchar *
Packit a4058c
scale_line (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
Packit a4058c
	    guchar *dest_end, int dest_channels, int dest_has_alpha,
Packit a4058c
	    guchar **src, int src_channels, gboolean src_has_alpha, int x_init,
Packit a4058c
	    int x_step, int src_width, int check_size, guint32 color1,
Packit a4058c
	    guint32 color2)
Packit a4058c
{
Packit a4058c
  int x = x_init;
Packit a4058c
  int i, j;
Packit a4058c
Packit a4058c
  while (dest < dest_end)
Packit a4058c
    {
Packit a4058c
      int x_scaled = x >> SCALE_SHIFT;
Packit a4058c
      int *pixel_weights;
Packit a4058c
Packit a4058c
      pixel_weights = weights +
Packit a4058c
        ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y;
Packit a4058c
Packit a4058c
      if (src_has_alpha)
Packit a4058c
	{
Packit a4058c
	  unsigned int r = 0, g = 0, b = 0, a = 0;
Packit a4058c
	  for (i=0; i
Packit a4058c
	    {
Packit a4058c
	      guchar *q = src[i] + x_scaled * src_channels;
Packit a4058c
	      int *line_weights  = pixel_weights + n_x * i;
Packit a4058c
	      
Packit a4058c
	      for (j=0; j
Packit a4058c
		{
Packit a4058c
		  unsigned int ta;
Packit a4058c
		  
Packit a4058c
		  ta = q[3] * line_weights[j];
Packit a4058c
		  r += ta * q[0];
Packit a4058c
		  g += ta * q[1];
Packit a4058c
		  b += ta * q[2];
Packit a4058c
		  a += ta;
Packit a4058c
		  
Packit a4058c
		  q += src_channels;
Packit a4058c
		}
Packit a4058c
	    }
Packit a4058c
Packit a4058c
	  if (a)
Packit a4058c
	    {
Packit a4058c
	      dest[0] = r / a;
Packit a4058c
	      dest[1] = g / a;
Packit a4058c
	      dest[2] = b / a;
Packit a4058c
	      dest[3] = a >> 16;
Packit a4058c
	    }
Packit a4058c
	  else
Packit a4058c
	    {
Packit a4058c
	      dest[0] = 0;
Packit a4058c
	      dest[1] = 0;
Packit a4058c
	      dest[2] = 0;
Packit a4058c
	      dest[3] = 0;
Packit a4058c
	    }
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  unsigned int r = 0, g = 0, b = 0;
Packit a4058c
	  for (i=0; i
Packit a4058c
	    {
Packit a4058c
	      guchar *q = src[i] + x_scaled * src_channels;
Packit a4058c
	      int *line_weights  = pixel_weights + n_x * i;
Packit a4058c
	      
Packit a4058c
	      for (j=0; j
Packit a4058c
		{
Packit a4058c
		  unsigned int ta = line_weights[j];
Packit a4058c
		  
Packit a4058c
		  r += ta * q[0];
Packit a4058c
		  g += ta * q[1];
Packit a4058c
		  b += ta * q[2];
Packit a4058c
Packit a4058c
		  q += src_channels;
Packit a4058c
		}
Packit a4058c
	    }
Packit a4058c
Packit a4058c
	  dest[0] = (r + 0xffff) >> 16;
Packit a4058c
	  dest[1] = (g + 0xffff) >> 16;
Packit a4058c
	  dest[2] = (b + 0xffff) >> 16;
Packit a4058c
	  
Packit a4058c
	  if (dest_has_alpha)
Packit a4058c
	    dest[3] = 0xff;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      dest += dest_channels;
Packit a4058c
      
Packit a4058c
      x += x_step;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return dest;
Packit a4058c
}
Packit a4058c
Packit a4058c
#ifdef USE_MMX 
Packit a4058c
static guchar *
Packit a4058c
scale_line_22_33_mmx_stub (int *weights, int n_x, int n_y, guchar *dest,
Packit a4058c
			   int dest_x, guchar *dest_end, int dest_channels,
Packit a4058c
			   int dest_has_alpha, guchar **src, int src_channels,
Packit a4058c
			   gboolean src_has_alpha, int x_init, int x_step,
Packit a4058c
			   int src_width, int check_size, guint32 color1,
Packit a4058c
			   guint32 color2)
Packit a4058c
{
Packit a4058c
  guint32 mmx_weights[16][8];
Packit a4058c
  int j;
Packit a4058c
Packit a4058c
  for (j=0; j<16; j++)
Packit a4058c
    {
Packit a4058c
      mmx_weights[j][0] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][1] = 0x00010001 * (weights[4*j] >> 8);
Packit a4058c
      mmx_weights[j][2] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][3] = 0x00010001 * (weights[4*j + 1] >> 8);
Packit a4058c
      mmx_weights[j][4] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][5] = 0x00010001 * (weights[4*j + 2] >> 8);
Packit a4058c
      mmx_weights[j][6] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
      mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8);
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return _pixops_scale_line_22_33_mmx (mmx_weights, dest, src[0], src[1],
Packit a4058c
				       x_step, dest_end, x_init);
Packit a4058c
}
Packit a4058c
#endif /* USE_MMX */
Packit a4058c
Packit a4058c
static guchar *
Packit a4058c
scale_line_22_33 (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
Packit a4058c
		  guchar *dest_end, int dest_channels, int dest_has_alpha,
Packit a4058c
		  guchar **src, int src_channels, gboolean src_has_alpha,
Packit a4058c
		  int x_init, int x_step, int src_width,
Packit a4058c
		  int check_size, guint32 color1, guint32 color2)
Packit a4058c
{
Packit a4058c
  int x = x_init;
Packit a4058c
  guchar *src0 = src[0];
Packit a4058c
  guchar *src1 = src[1];
Packit a4058c
  
Packit a4058c
  while (dest < dest_end)
Packit a4058c
    {
Packit a4058c
      unsigned int r, g, b;
Packit a4058c
      int x_scaled = x >> SCALE_SHIFT;
Packit a4058c
      int *pixel_weights;
Packit a4058c
      guchar *q0, *q1;
Packit a4058c
      int w1, w2, w3, w4;
Packit a4058c
Packit a4058c
      q0 = src0 + x_scaled * 3;
Packit a4058c
      q1 = src1 + x_scaled * 3;
Packit a4058c
      
Packit a4058c
      pixel_weights = weights +
Packit a4058c
        ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * 4;
Packit a4058c
Packit a4058c
      w1 = pixel_weights[0];
Packit a4058c
      w2 = pixel_weights[1];
Packit a4058c
      w3 = pixel_weights[2];
Packit a4058c
      w4 = pixel_weights[3];
Packit a4058c
Packit a4058c
      r = w1 * q0[0];
Packit a4058c
      g = w1 * q0[1];
Packit a4058c
      b = w1 * q0[2];
Packit a4058c
Packit a4058c
      r += w2 * q0[3];
Packit a4058c
      g += w2 * q0[4];
Packit a4058c
      b += w2 * q0[5];
Packit a4058c
Packit a4058c
      r += w3 * q1[0];
Packit a4058c
      g += w3 * q1[1];
Packit a4058c
      b += w3 * q1[2];
Packit a4058c
Packit a4058c
      r += w4 * q1[3];
Packit a4058c
      g += w4 * q1[4];
Packit a4058c
      b += w4 * q1[5];
Packit a4058c
Packit a4058c
      dest[0] = (r + 0x8000) >> 16;
Packit a4058c
      dest[1] = (g + 0x8000) >> 16;
Packit a4058c
      dest[2] = (b + 0x8000) >> 16;
Packit a4058c
      
Packit a4058c
      dest += 3;
Packit a4058c
      x += x_step;
Packit a4058c
    }
Packit a4058c
  
Packit a4058c
  return dest;
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
process_pixel (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
Packit a4058c
	       int dest_channels, int dest_has_alpha, guchar **src,
Packit a4058c
	       int src_channels, gboolean src_has_alpha, int x_start,
Packit a4058c
	       int src_width, int check_size, guint32 color1, guint32 color2,
Packit a4058c
	       PixopsPixelFunc pixel_func)
Packit a4058c
{
Packit a4058c
  unsigned int r = 0, g = 0, b = 0, a = 0;
Packit a4058c
  int i, j;
Packit a4058c
  
Packit a4058c
  for (i=0; i
Packit a4058c
    {
Packit a4058c
      int *line_weights  = weights + n_x * i;
Packit a4058c
Packit a4058c
      for (j=0; j
Packit a4058c
	{
Packit a4058c
	  unsigned int ta;
Packit a4058c
	  guchar *q;
Packit a4058c
Packit a4058c
	  if (x_start + j < 0)
Packit a4058c
	    q = src[i];
Packit a4058c
	  else if (x_start + j < src_width)
Packit a4058c
	    q = src[i] + (x_start + j) * src_channels;
Packit a4058c
	  else
Packit a4058c
	    q = src[i] + (src_width - 1) * src_channels;
Packit a4058c
Packit a4058c
	  if (src_has_alpha)
Packit a4058c
	    ta = q[3] * line_weights[j];
Packit a4058c
	  else
Packit a4058c
	    ta = 0xff * line_weights[j];
Packit a4058c
Packit a4058c
	  r += ta * q[0];
Packit a4058c
	  g += ta * q[1];
Packit a4058c
	  b += ta * q[2];
Packit a4058c
	  a += ta;
Packit a4058c
	}
Packit a4058c
    }
Packit a4058c
Packit a4058c
  (*pixel_func) (dest, dest_x, dest_channels, dest_has_alpha, src_has_alpha,
Packit a4058c
    check_size, color1, color2, r, g, b, a);
Packit a4058c
}
Packit a4058c
Packit a4058c
static void 
Packit a4058c
correct_total (int    *weights, 
Packit a4058c
               int    n_x, 
Packit a4058c
               int    n_y,
Packit a4058c
               int    total, 
Packit a4058c
               double overall_alpha)
Packit a4058c
{
Packit a4058c
  int correction = (int)(0.5 + 65536 * overall_alpha) - total;
Packit a4058c
  int remaining, c, d, i;
Packit a4058c
  
Packit a4058c
  if (correction != 0)
Packit a4058c
    {
Packit a4058c
      remaining = correction;
Packit a4058c
      for (d = 1, c = correction; c != 0 && remaining != 0; d++, c = correction / d) 
Packit a4058c
	for (i = n_x * n_y - 1; i >= 0 && c != 0 && remaining != 0; i--) 
Packit a4058c
	  if (*(weights + i) + c >= 0) 
Packit a4058c
	    {
Packit a4058c
	      *(weights + i) += c;
Packit a4058c
	      remaining -= c;
Packit a4058c
	      if ((0 < remaining && remaining < c) ||
Packit a4058c
		  (0 > remaining && remaining > c))
Packit a4058c
		c = remaining;
Packit a4058c
	    }
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
static int *
Packit a4058c
make_filter_table (PixopsFilter *filter)
Packit a4058c
{
Packit a4058c
  int i_offset, j_offset;
Packit a4058c
  int n_x = filter->x.n;
Packit a4058c
  int n_y = filter->y.n;
Packit a4058c
  int *weights;
Packit a4058c
Packit a4058c
  /* check n_x doesn't overflow */
Packit a4058c
  if (G_MAXINT / (SUBSAMPLE * SUBSAMPLE) < n_x)
Packit a4058c
    return NULL;
Packit a4058c
Packit a4058c
  /* check n_y doesn't overflow */
Packit a4058c
  if (G_MAXINT / (SUBSAMPLE * SUBSAMPLE * n_x) < n_y)
Packit a4058c
    return NULL;
Packit a4058c
Packit a4058c
  weights = g_try_new (int, SUBSAMPLE * SUBSAMPLE * n_x * n_y);
Packit a4058c
  if (!weights)
Packit a4058c
    return NULL; /* overflow, bail */
Packit a4058c
Packit a4058c
  for (i_offset=0; i_offset < SUBSAMPLE; i_offset++)
Packit a4058c
    for (j_offset=0; j_offset < SUBSAMPLE; j_offset++)
Packit a4058c
      {
Packit a4058c
        double weight;
Packit a4058c
        int *pixel_weights = weights + ((i_offset*SUBSAMPLE) + j_offset) * n_x * n_y;
Packit a4058c
        int total = 0;
Packit a4058c
        int i, j;
Packit a4058c
Packit a4058c
        for (i=0; i < n_y; i++)
Packit a4058c
          for (j=0; j < n_x; j++)
Packit a4058c
            {
Packit a4058c
              weight = filter->x.weights[(j_offset * n_x) + j] *
Packit a4058c
                       filter->y.weights[(i_offset * n_y) + i] *
Packit a4058c
                       filter->overall_alpha * 65536 + 0.5;
Packit a4058c
Packit a4058c
              total += (int)weight;
Packit a4058c
Packit a4058c
              *(pixel_weights + n_x * i + j) = weight;
Packit a4058c
            }
Packit a4058c
Packit a4058c
        correct_total (pixel_weights, n_x, n_y, total, filter->overall_alpha);
Packit a4058c
      }
Packit a4058c
Packit a4058c
  return weights;
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_process (guchar         *dest_buf,
Packit a4058c
		int             render_x0,
Packit a4058c
		int             render_y0,
Packit a4058c
		int             render_x1,
Packit a4058c
		int             render_y1,
Packit a4058c
		int             dest_rowstride,
Packit a4058c
		int             dest_channels,
Packit a4058c
		gboolean        dest_has_alpha,
Packit a4058c
		const guchar   *src_buf,
Packit a4058c
		int             src_width,
Packit a4058c
		int             src_height,
Packit a4058c
		int             src_rowstride,
Packit a4058c
		int             src_channels,
Packit a4058c
		gboolean        src_has_alpha,
Packit a4058c
		double          scale_x,
Packit a4058c
		double          scale_y,
Packit a4058c
		int             check_x,
Packit a4058c
		int             check_y,
Packit a4058c
		int             check_size,
Packit a4058c
		guint32         color1,
Packit a4058c
		guint32         color2,
Packit a4058c
		PixopsFilter   *filter,
Packit a4058c
		PixopsLineFunc  line_func,
Packit a4058c
		PixopsPixelFunc pixel_func)
Packit a4058c
{
Packit a4058c
  gint64 i, j;
Packit a4058c
  gint64 x, y;			/* X and Y position in source (fixed_point) */
Packit a4058c
Packit a4058c
  guchar **line_bufs;
Packit a4058c
  int *filter_weights;
Packit a4058c
Packit a4058c
  gint64 x_step;
Packit a4058c
  gint64 y_step;
Packit a4058c
Packit a4058c
  int check_shift;
Packit a4058c
  gint64 scaled_x_offset;
Packit a4058c
Packit a4058c
  gint64 run_end_x;
Packit a4058c
  gint64 run_end_index;
Packit a4058c
Packit a4058c
  x_step = (1 << SCALE_SHIFT) / scale_x; /* X step in source (fixed point) */
Packit a4058c
  y_step = (1 << SCALE_SHIFT) / scale_y; /* Y step in source (fixed point) */
Packit a4058c
Packit a4058c
  if (x_step == 0 || y_step == 0)
Packit a4058c
    return; /* overflow, bail out */
Packit a4058c
Packit a4058c
  filter_weights = make_filter_table (filter);
Packit a4058c
  if (!filter_weights)
Packit a4058c
    return; /* overflow, bail out */
Packit a4058c
Packit a4058c
  line_bufs = g_new (guchar *, filter->y.n);
Packit a4058c
Packit a4058c
  check_shift = check_size ? get_check_shift (check_size) : 0;
Packit a4058c
Packit a4058c
  scaled_x_offset = floor (filter->x.offset * (1 << SCALE_SHIFT));
Packit a4058c
Packit a4058c
  /* Compute the index where we run off the end of the source buffer. The
Packit a4058c
   * furthest source pixel we access at index i is:
Packit a4058c
   *
Packit a4058c
   *  ((render_x0 + i) * x_step + scaled_x_offset) >> SCALE_SHIFT + filter->x.n - 1
Packit a4058c
   *
Packit a4058c
   * So, run_end_index is the smallest i for which this pixel is src_width,
Packit a4058c
   * i.e, for which:
Packit a4058c
   *
Packit a4058c
   *  (i + render_x0) * x_step >= ((src_width - filter->x.n + 1) << SCALE_SHIFT) - scaled_x_offset
Packit a4058c
   *
Packit a4058c
   */
Packit a4058c
#define MYDIV(a,b) ((a) > 0 ? (a) / (b) : ((a) - (b) + 1) / (b))    /* Division so that -1/5 = -1 */
Packit a4058c
Packit a4058c
  run_end_x = (((src_width - filter->x.n + 1) << SCALE_SHIFT) - scaled_x_offset);
Packit a4058c
  run_end_index = MYDIV (run_end_x + x_step - 1, x_step) - render_x0;
Packit a4058c
  run_end_index = MIN (run_end_index, render_x1 - render_x0);
Packit a4058c
Packit a4058c
  y = render_y0 * y_step + floor (filter->y.offset * (1 << SCALE_SHIFT));
Packit a4058c
  for (i = 0; i < (render_y1 - render_y0); i++)
Packit a4058c
    {
Packit a4058c
      int dest_x;
Packit a4058c
      int y_start = y >> SCALE_SHIFT;
Packit a4058c
      int x_start;
Packit a4058c
      int *run_weights = filter_weights +
Packit a4058c
                         ((y >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) *
Packit a4058c
                         filter->x.n * filter->y.n * SUBSAMPLE;
Packit a4058c
      guchar *new_outbuf;
Packit a4058c
      guint32 tcolor1, tcolor2;
Packit a4058c
Packit a4058c
      guchar *outbuf = dest_buf + (gsize)dest_rowstride * i;
Packit a4058c
      guchar *outbuf_end = outbuf + dest_channels * (render_x1 - render_x0);
Packit a4058c
Packit a4058c
      if (((i + check_y) >> check_shift) & 1)
Packit a4058c
	{
Packit a4058c
	  tcolor1 = color2;
Packit a4058c
	  tcolor2 = color1;
Packit a4058c
	}
Packit a4058c
      else
Packit a4058c
	{
Packit a4058c
	  tcolor1 = color1;
Packit a4058c
	  tcolor2 = color2;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      for (j=0; j<filter->y.n; j++)
Packit a4058c
	{
Packit a4058c
	  if (y_start <  0)
Packit a4058c
	    line_bufs[j] = (guchar *)src_buf;
Packit a4058c
	  else if (y_start < src_height)
Packit a4058c
	    line_bufs[j] = (guchar *)src_buf + (gsize)src_rowstride * y_start;
Packit a4058c
	  else
Packit a4058c
	    line_bufs[j] = (guchar *)src_buf + (gsize)src_rowstride * (src_height - 1);
Packit a4058c
Packit a4058c
	  y_start++;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      dest_x = check_x;
Packit a4058c
      x = render_x0 * x_step + scaled_x_offset;
Packit a4058c
      x_start = x >> SCALE_SHIFT;
Packit a4058c
Packit a4058c
      while (x_start < 0 && outbuf < outbuf_end)
Packit a4058c
	{
Packit a4058c
	  process_pixel (run_weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * (filter->x.n * filter->y.n), filter->x.n, filter->y.n,
Packit a4058c
			 outbuf, dest_x, dest_channels, dest_has_alpha,
Packit a4058c
			 line_bufs, src_channels, src_has_alpha,
Packit a4058c
			 x >> SCALE_SHIFT, src_width,
Packit a4058c
			 check_size, tcolor1, tcolor2, pixel_func);
Packit a4058c
Packit a4058c
	  x += x_step;
Packit a4058c
	  x_start = x >> SCALE_SHIFT;
Packit a4058c
	  dest_x++;
Packit a4058c
	  outbuf += dest_channels;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      new_outbuf = (*line_func) (run_weights, filter->x.n, filter->y.n,
Packit a4058c
				 outbuf, dest_x, dest_buf + (gsize)dest_rowstride *
Packit a4058c
				 i + run_end_index * dest_channels,
Packit a4058c
				 dest_channels, dest_has_alpha,
Packit a4058c
				 line_bufs, src_channels, src_has_alpha,
Packit a4058c
				 x, x_step, src_width, check_size, tcolor1,
Packit a4058c
				 tcolor2);
Packit a4058c
Packit a4058c
      dest_x += (new_outbuf - outbuf) / dest_channels;
Packit a4058c
Packit a4058c
      x = (dest_x - check_x + render_x0) * x_step + scaled_x_offset;
Packit a4058c
      outbuf = new_outbuf;
Packit a4058c
Packit a4058c
      while (outbuf < outbuf_end)
Packit a4058c
	{
Packit a4058c
	  process_pixel (run_weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * (filter->x.n * filter->y.n), filter->x.n, filter->y.n,
Packit a4058c
			 outbuf, dest_x, dest_channels, dest_has_alpha,
Packit a4058c
			 line_bufs, src_channels, src_has_alpha,
Packit a4058c
			 x >> SCALE_SHIFT, src_width,
Packit a4058c
			 check_size, tcolor1, tcolor2, pixel_func);
Packit a4058c
Packit a4058c
	  x += x_step;
Packit a4058c
	  dest_x++;
Packit a4058c
	  outbuf += dest_channels;
Packit a4058c
	}
Packit a4058c
Packit a4058c
      y += y_step;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  g_free (line_bufs);
Packit a4058c
  g_free (filter_weights);
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Compute weights for reconstruction by replication followed by
Packit a4058c
 * sampling with a box filter
Packit a4058c
 */
Packit a4058c
static gboolean
Packit a4058c
tile_make_weights (PixopsFilterDimension *dim,
Packit a4058c
		   double                 scale)
Packit a4058c
{
Packit a4058c
  int n = ceil (1 / scale + 1);
Packit a4058c
  double *pixel_weights;
Packit a4058c
  int offset;
Packit a4058c
  int i;
Packit a4058c
Packit a4058c
  pixel_weights = g_try_malloc_n (sizeof (double) * SUBSAMPLE, n);
Packit a4058c
  if (pixel_weights == NULL)
Packit a4058c
    return FALSE;
Packit a4058c
Packit a4058c
  dim->n = n;
Packit a4058c
  dim->offset = 0;
Packit a4058c
  dim->weights = pixel_weights;
Packit a4058c
Packit a4058c
  for (offset = 0; offset < SUBSAMPLE; offset++)
Packit a4058c
    {
Packit a4058c
      double x = (double)offset / SUBSAMPLE;
Packit a4058c
      double a = x + 1 / scale;
Packit a4058c
Packit a4058c
      for (i = 0; i < n; i++)
Packit a4058c
        {
Packit a4058c
          if (i < x)
Packit a4058c
            {
Packit a4058c
              if (i + 1 > x)
Packit a4058c
                *(pixel_weights++)  = (MIN (i + 1, a) - x) * scale;
Packit a4058c
              else
Packit a4058c
                *(pixel_weights++) = 0;
Packit a4058c
            }
Packit a4058c
          else
Packit a4058c
            {
Packit a4058c
              if (a > i)
Packit a4058c
                *(pixel_weights++)  = (MIN (i + 1, a) - i) * scale;
Packit a4058c
              else
Packit a4058c
                *(pixel_weights++) = 0;
Packit a4058c
            }
Packit a4058c
       }
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return TRUE;
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Compute weights for a filter that, for minification
Packit a4058c
 * is the same as 'tiles', and for magnification, is bilinear
Packit a4058c
 * reconstruction followed by a sampling with a delta function.
Packit a4058c
 */
Packit a4058c
static gboolean
Packit a4058c
bilinear_magnify_make_weights (PixopsFilterDimension *dim,
Packit a4058c
			       double                 scale)
Packit a4058c
{
Packit a4058c
  double *pixel_weights;
Packit a4058c
  int n;
Packit a4058c
  int offset;
Packit a4058c
  int i;
Packit a4058c
Packit a4058c
  if (scale > 1.0)            /* Linear */
Packit a4058c
    {
Packit a4058c
      n = 2;
Packit a4058c
      dim->offset = 0.5 * (1 / scale - 1);
Packit a4058c
    }
Packit a4058c
  else                          /* Tile */
Packit a4058c
    {
Packit a4058c
      n = ceil (1.0 + 1.0 / scale);
Packit a4058c
      dim->offset = 0.0;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  dim->n = n;
Packit a4058c
  dim->weights = g_try_malloc_n (sizeof (double) * SUBSAMPLE, n);
Packit a4058c
  if (dim->weights == NULL)
Packit a4058c
    return FALSE;
Packit a4058c
Packit a4058c
  pixel_weights = dim->weights;
Packit a4058c
Packit a4058c
  for (offset=0; offset < SUBSAMPLE; offset++)
Packit a4058c
    {
Packit a4058c
      double x = (double)offset / SUBSAMPLE;
Packit a4058c
Packit a4058c
      if (scale > 1.0)      /* Linear */
Packit a4058c
        {
Packit a4058c
          for (i = 0; i < n; i++)
Packit a4058c
            *(pixel_weights++) = (((i == 0) ? (1 - x) : x) / scale) * scale;
Packit a4058c
        }
Packit a4058c
      else                  /* Tile */
Packit a4058c
        {
Packit a4058c
          double a = x + 1 / scale;
Packit a4058c
Packit a4058c
          /*           x
Packit a4058c
           * ---------|--.-|----|--.-|-------  SRC
Packit a4058c
           * ------------|---------|---------  DEST
Packit a4058c
           */
Packit a4058c
          for (i = 0; i < n; i++)
Packit a4058c
            {
Packit a4058c
              if (i < x)
Packit a4058c
                {
Packit a4058c
                  if (i + 1 > x)
Packit a4058c
                    *(pixel_weights++) = (MIN (i + 1, a) - x) * scale;
Packit a4058c
                  else
Packit a4058c
                    *(pixel_weights++) = 0;
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  if (a > i)
Packit a4058c
                    *(pixel_weights++) = (MIN (i + 1, a) - i) * scale;
Packit a4058c
                  else
Packit a4058c
                    *(pixel_weights++) = 0;
Packit a4058c
                }
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return TRUE;
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Computes the integral from b0 to b1 of
Packit a4058c
 *
Packit a4058c
 * f(x) = x; 0 <= x < 1
Packit a4058c
 * f(x) = 0; otherwise
Packit a4058c
 *
Packit a4058c
 * We combine two of these to compute the convolution of
Packit a4058c
 * a box filter with a triangular spike.
Packit a4058c
 */
Packit a4058c
static double
Packit a4058c
linear_box_half (double b0, double b1)
Packit a4058c
{
Packit a4058c
  double a0, a1;
Packit a4058c
  double x0, x1;
Packit a4058c
Packit a4058c
  a0 = 0.;
Packit a4058c
  a1 = 1.;
Packit a4058c
Packit a4058c
  if (a0 < b0)
Packit a4058c
    {
Packit a4058c
      if (a1 > b0)
Packit a4058c
        {
Packit a4058c
          x0 = b0;
Packit a4058c
          x1 = MIN (a1, b1);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        return 0;
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      if (b1 > a0)
Packit a4058c
        {
Packit a4058c
          x0 = a0;
Packit a4058c
          x1 = MIN (a1, b1);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        return 0;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return 0.5 * (x1*x1 - x0*x0);
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Compute weights for reconstructing with bilinear
Packit a4058c
 * interpolation, then sampling with a box filter
Packit a4058c
 */
Packit a4058c
static gboolean
Packit a4058c
bilinear_box_make_weights (PixopsFilterDimension *dim,
Packit a4058c
			   double                 scale)
Packit a4058c
{
Packit a4058c
  int n = ceil (1/scale + 3.0);
Packit a4058c
  double *pixel_weights;
Packit a4058c
  double w;
Packit a4058c
  int offset, i;
Packit a4058c
Packit a4058c
  pixel_weights = g_malloc_n (sizeof (double) * SUBSAMPLE, n);
Packit a4058c
  if (pixel_weights == NULL)
Packit a4058c
    return FALSE;
Packit a4058c
Packit a4058c
  dim->offset = -1.0;
Packit a4058c
  dim->n = n;
Packit a4058c
  dim->weights = pixel_weights;
Packit a4058c
Packit a4058c
  for (offset = 0; offset < SUBSAMPLE; offset++)
Packit a4058c
    {
Packit a4058c
      double x = (double)offset / SUBSAMPLE;
Packit a4058c
      double a = x + 1 / scale;
Packit a4058c
Packit a4058c
      for (i = 0; i < n; i++)
Packit a4058c
        {
Packit a4058c
          w  = linear_box_half (0.5 + i - a, 0.5 + i - x);
Packit a4058c
          w += linear_box_half (1.5 + x - i, 1.5 + a - i);
Packit a4058c
      
Packit a4058c
          *(pixel_weights++) = w * scale;
Packit a4058c
        }
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return TRUE;
Packit a4058c
}
Packit a4058c
Packit a4058c
static gboolean
Packit a4058c
make_weights (PixopsFilter     *filter,
Packit a4058c
	      PixopsInterpType  interp_type,	      
Packit a4058c
	      double            scale_x,
Packit a4058c
	      double            scale_y)
Packit a4058c
{
Packit a4058c
  switch (interp_type)
Packit a4058c
    {
Packit a4058c
    case PIXOPS_INTERP_NEAREST:
Packit a4058c
    default:
Packit a4058c
      g_assert_not_reached ();
Packit a4058c
      return FALSE;
Packit a4058c
Packit a4058c
    case PIXOPS_INTERP_TILES:
Packit a4058c
      if (!tile_make_weights (&filter->x, scale_x))
Packit a4058c
        return FALSE;
Packit a4058c
      if (!tile_make_weights (&filter->y, scale_y))
Packit a4058c
        {
Packit a4058c
          g_free (filter->x.weights);
Packit a4058c
          return FALSE;
Packit a4058c
        }
Packit a4058c
      return TRUE;
Packit a4058c
      
Packit a4058c
    case PIXOPS_INTERP_BILINEAR:
Packit a4058c
      if (!bilinear_magnify_make_weights (&filter->x, scale_x))
Packit a4058c
        return FALSE;
Packit a4058c
      if (!bilinear_magnify_make_weights (&filter->y, scale_y))
Packit a4058c
        {
Packit a4058c
          g_free (filter->x.weights);
Packit a4058c
          return FALSE;
Packit a4058c
        }
Packit a4058c
      return TRUE;
Packit a4058c
      
Packit a4058c
    case PIXOPS_INTERP_HYPER:
Packit a4058c
      if (!bilinear_box_make_weights (&filter->x, scale_x))
Packit a4058c
        return FALSE;
Packit a4058c
      if (!bilinear_box_make_weights (&filter->y, scale_y))
Packit a4058c
        {
Packit a4058c
          g_free (filter->x.weights);
Packit a4058c
          return FALSE;
Packit a4058c
        }
Packit a4058c
      return TRUE;
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Two-step scaler begins */
Packit a4058c
Packit a4058c
/* make_filter_table() bloats out in VM usage and consumes 100% CPU for
Packit a4058c
 * tens of seconds when downscaling by a large factor.
Packit a4058c
 * https://bugzilla.gnome.org/show_bug.cgi?id=80925
Packit a4058c
 * We work round this by doing extreme reductions in two steps.
Packit a4058c
 *
Packit a4058c
 * The excessive CPU usage is accompanied by an excessive RAM usage because
Packit a4058c
 * make_weights() allocates two arrays of weights proportional in size to
Packit a4058c
 * n_x = (1 / scale_x + 3) and n_y = (1 / scale_y + 3),  then make_filter_table()
Packit a4058c
 * allocates and fills an array of SUBSAMPLE * SUBSAMPLE * n_x * n_y doubles.
Packit a4058c
 * Empirically, on machines with plenty of RAM, the execution time slopes upward
Packit a4058c
 * when n_filters > 1000.
Packit a4058c
 * SUBSAMPLE is 16 so each filter takes 16 x 16 doubles (8 bytes) = 2kb RAM.
Packit a4058c
 * Limiting it to 1000 filters limits the scaler's RAM consumption to about 2MB
Packit a4058c
 * which should be OK on machines with relatively little memory.
Packit a4058c
 *
Packit a4058c
 * GDK_INTER_BILINEAR, GDK_INTERP_TILES and GDK_INTER_HYPER all have
Packit a4058c
 * similar symptoms; only GDK_INTERP_NEAREST does not need this trick.
Packit a4058c
 **/
Packit a4058c
#define MAX_FILTERS 1000
Packit a4058c
Packit a4058c
/* Check whether prescaling is necessary to avoid the bug */
Packit a4058c
static gboolean
Packit a4058c
need_to_prescale (double           scale_x,
Packit a4058c
		  double           scale_y,
Packit a4058c
		  PixopsInterpType interp_type)
Packit a4058c
{
Packit a4058c
  int n_x, n_y; /* See make_weights() */
Packit a4058c
Packit a4058c
  /* The testsuite sets this to compare the results with and without it. */
Packit a4058c
  if (g_getenv ("GDK_PIXBUF_DISABLE_TWO_STEP_SCALER"))
Packit a4058c
    return FALSE;
Packit a4058c
Packit a4058c
  /* Calculate the number of weights created in make_weights() */
Packit a4058c
  switch (interp_type) {
Packit a4058c
  case PIXOPS_INTERP_HYPER:
Packit a4058c
    n_x = ceil (1 / scale_x + 3);
Packit a4058c
    n_y = ceil (1 / scale_y + 3);
Packit a4058c
    break;
Packit a4058c
  case PIXOPS_INTERP_TILES:
Packit a4058c
  case PIXOPS_INTERP_BILINEAR:
Packit a4058c
    n_x = ceil (1 / scale_x + 1);
Packit a4058c
    n_y = ceil (1 / scale_y + 1);
Packit a4058c
    break;
Packit a4058c
  case PIXOPS_INTERP_NEAREST:
Packit a4058c
    /* Doesn't need the optimization */
Packit a4058c
    return FALSE;
Packit a4058c
  default:
Packit a4058c
    g_assert_not_reached ();
Packit a4058c
  }
Packit a4058c
Packit a4058c
  /* Limit the number of filters created by make_filter_table(). */
Packit a4058c
  return (n_x * n_y > MAX_FILTERS);
Packit a4058c
}
Packit a4058c
Packit a4058c
/* Prescale the source image.
Packit a4058c
 * If successful, it changes the source buffer's parameters to reflect the
Packit a4058c
 * half-scaled image and the scaling factors to reflect the scaling left to do.
Packit a4058c
 * It returns a pointer to the new image data or NULL, so that the caller knows
Packit a4058c
 * whether they have to free the temporary buffer or not.
Packit a4058c
 */
Packit a4058c
static guchar *
Packit a4058c
prescale (const guchar     **src_bufp,
Packit a4058c
	  int               *src_widthp,
Packit a4058c
	  int               *src_heightp,
Packit a4058c
	  int               *src_rowstridep,
Packit a4058c
	  int                src_channels,
Packit a4058c
	  gboolean           src_has_alpha,
Packit a4058c
	  double            *scale_xp,
Packit a4058c
	  double            *scale_yp,
Packit a4058c
	  PixopsInterpType   interp_type)
Packit a4058c
{
Packit a4058c
  /* Give local names to parameters that may be modified */
Packit a4058c
  const guchar *src_buf = *src_bufp;
Packit a4058c
  int           src_width = *src_widthp;
Packit a4058c
  int           src_height = *src_heightp;
Packit a4058c
  int           src_rowstride = *src_rowstridep;
Packit a4058c
  double        scale_x = *scale_xp;
Packit a4058c
  double        scale_y = *scale_yp;
Packit a4058c
Packit a4058c
  /* How much we prescale each axis by */
Packit a4058c
  double prescale_x, prescale_y;
Packit a4058c
Packit a4058c
  /* The prescaled image */
Packit a4058c
  int tmp_width, tmp_height;
Packit a4058c
  int tmp_rowstride;
Packit a4058c
  int tmp_channels;
Packit a4058c
  gboolean tmp_has_alpha;
Packit a4058c
  guchar *tmp_buf;
Packit a4058c
Packit a4058c
  /* The time taken by make_filter_table() is roughly proportional to
Packit a4058c
   * 1/scale_x * 1/scale_y, i.e. to the area reduction factor, so we
Packit a4058c
   * reduce the image in two steps, each of which reduces the total area
Packit a4058c
   * by the same factor. */
Packit a4058c
  prescale_x = sqrt (scale_x);
Packit a4058c
  prescale_y = sqrt (scale_y);
Packit a4058c
Packit a4058c
  /* Scale the whole source image into a top-left-aligned temporary pixbuf.
Packit a4058c
   * render_[xy][01] are done in the final scaling, not here, as they are
Packit a4058c
   * measured in the coordinate system of the scaled image. */
Packit a4058c
  tmp_width = lrint (src_width * prescale_x);
Packit a4058c
  tmp_height = lrint (src_height * prescale_y);
Packit a4058c
Packit a4058c
  /* We are below the gdk_ interface, so create the temp image manually.
Packit a4058c
   * Code copied from gdk_pixbuf_new() */
Packit a4058c
  tmp_channels = src_channels;
Packit a4058c
  tmp_has_alpha = src_has_alpha;
Packit a4058c
  tmp_rowstride = ((tmp_width * tmp_channels) + 3) & ~3;
Packit a4058c
  tmp_buf = g_try_malloc_n (tmp_height, tmp_rowstride);
Packit a4058c
  if (!tmp_buf)
Packit a4058c
    return NULL; /* Skip the prescaling */
Packit a4058c
Packit a4058c
  /* Prescale to an intermediate size */
Packit a4058c
  _pixops_scale (tmp_buf, tmp_width, tmp_height, tmp_rowstride,
Packit a4058c
		 tmp_channels, tmp_has_alpha, src_buf, src_width,
Packit a4058c
		 src_height, src_rowstride, src_channels, src_has_alpha,
Packit a4058c
		 0, 0, tmp_width, tmp_height, 0.0, 0.0,
Packit a4058c
		 prescale_x, prescale_y,
Packit a4058c
		 interp_type);
Packit a4058c
Packit a4058c
  /* The second call to the scaler reads from the prescaled image */
Packit a4058c
  *src_bufp = tmp_buf;
Packit a4058c
  *src_widthp = tmp_width;
Packit a4058c
  *src_heightp = tmp_height;
Packit a4058c
  *src_rowstridep = tmp_rowstride;
Packit a4058c
Packit a4058c
  /* Calculate how much scaling is left to do */
Packit a4058c
  *scale_xp /= prescale_x;
Packit a4058c
  *scale_yp /= prescale_y;
Packit a4058c
Packit a4058c
  return tmp_buf;
Packit a4058c
}
Packit a4058c
/* End of two-step scaler */
Packit a4058c
Packit a4058c
static void
Packit a4058c
_pixops_composite_color_real (guchar          *dest_buf,
Packit a4058c
			      int              render_x0,
Packit a4058c
			      int              render_y0,
Packit a4058c
			      int              render_x1,
Packit a4058c
			      int              render_y1,
Packit a4058c
			      int              dest_rowstride,
Packit a4058c
			      int              dest_channels,
Packit a4058c
			      gboolean         dest_has_alpha,
Packit a4058c
			      const guchar    *src_buf,
Packit a4058c
			      int              src_width,
Packit a4058c
			      int              src_height,
Packit a4058c
			      int              src_rowstride,
Packit a4058c
			      int              src_channels,
Packit a4058c
			      gboolean         src_has_alpha,
Packit a4058c
			      double           scale_x,
Packit a4058c
			      double           scale_y,
Packit a4058c
			      PixopsInterpType interp_type,
Packit a4058c
			      int              overall_alpha,
Packit a4058c
			      int              check_x,
Packit a4058c
			      int              check_y,
Packit a4058c
			      int              check_size,
Packit a4058c
			      guint32          color1,
Packit a4058c
			      guint32          color2)
Packit a4058c
{
Packit a4058c
  PixopsFilter filter;
Packit a4058c
  PixopsLineFunc line_func;
Packit a4058c
  guchar *tmp_buf = NULL;
Packit a4058c
  
Packit a4058c
#ifdef USE_MMX
Packit a4058c
  gboolean found_mmx = _pixops_have_mmx ();
Packit a4058c
#endif
Packit a4058c
Packit a4058c
  g_return_if_fail (!(dest_channels == 3 && dest_has_alpha));
Packit a4058c
  g_return_if_fail (!(src_channels == 3 && src_has_alpha));
Packit a4058c
Packit a4058c
  if (scale_x == 0 || scale_y == 0)
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (interp_type == PIXOPS_INTERP_NEAREST)
Packit a4058c
    {
Packit a4058c
      pixops_composite_color_nearest (dest_buf, render_x0, render_y0,
Packit a4058c
				      render_x1, render_y1, dest_rowstride,
Packit a4058c
				      dest_channels, dest_has_alpha, src_buf,
Packit a4058c
				      src_width, src_height, src_rowstride,
Packit a4058c
				      src_channels, src_has_alpha, scale_x,
Packit a4058c
				      scale_y, overall_alpha, check_x, check_y,
Packit a4058c
				      check_size, color1, color2);
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  if (need_to_prescale (scale_x, scale_y, interp_type))
Packit a4058c
    tmp_buf = prescale (&src_buf, &src_width, &src_height, &src_rowstride,
Packit a4058c
			src_channels, src_has_alpha,
Packit a4058c
			&scale_x, &scale_y, interp_type);
Packit a4058c
  
Packit a4058c
  filter.overall_alpha = overall_alpha / 255.;
Packit a4058c
  if (!make_weights (&filter, interp_type, scale_x, scale_y))
Packit a4058c
    return;
Packit a4058c
Packit a4058c
#ifdef USE_MMX
Packit a4058c
  if (filter.x.n == 2 && filter.y.n == 2 &&
Packit a4058c
      dest_channels == 4 && src_channels == 4 &&
Packit a4058c
      src_has_alpha && !dest_has_alpha && found_mmx)
Packit a4058c
    line_func = composite_line_color_22_4a4_mmx_stub;
Packit a4058c
  else
Packit a4058c
#endif
Packit a4058c
    line_func = composite_line_color;
Packit a4058c
  
Packit a4058c
  pixops_process (dest_buf, render_x0, render_y0, render_x1, render_y1,
Packit a4058c
		  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
		  src_buf, src_width, src_height, src_rowstride, src_channels,
Packit a4058c
		  src_has_alpha, scale_x, scale_y, check_x, check_y, check_size, color1, color2,
Packit a4058c
		  &filter, line_func, composite_pixel_color);
Packit a4058c
Packit a4058c
  g_free (filter.x.weights);
Packit a4058c
  g_free (filter.y.weights);
Packit a4058c
  if (tmp_buf)
Packit a4058c
    g_free (tmp_buf);
Packit a4058c
}
Packit a4058c
Packit a4058c
void
Packit a4058c
_pixops_composite_color (guchar          *dest_buf,
Packit a4058c
			 int              dest_width,
Packit a4058c
			 int              dest_height,
Packit a4058c
			 int              dest_rowstride,
Packit a4058c
			 int              dest_channels,
Packit a4058c
			 gboolean         dest_has_alpha,
Packit a4058c
			 const guchar    *src_buf,
Packit a4058c
			 int              src_width,
Packit a4058c
			 int              src_height,
Packit a4058c
			 int              src_rowstride,
Packit a4058c
			 int              src_channels,
Packit a4058c
			 gboolean         src_has_alpha,
Packit a4058c
			 int              dest_x,
Packit a4058c
			 int              dest_y,
Packit a4058c
			 int              dest_region_width,
Packit a4058c
			 int              dest_region_height,
Packit a4058c
			 double           offset_x,
Packit a4058c
			 double           offset_y,
Packit a4058c
			 double           scale_x,
Packit a4058c
			 double           scale_y,
Packit a4058c
			 PixopsInterpType interp_type,
Packit a4058c
			 int              overall_alpha,
Packit a4058c
			 int              check_x,
Packit a4058c
			 int              check_y,
Packit a4058c
			 int              check_size,
Packit a4058c
			 guint32          color1,
Packit a4058c
			 guint32          color2)
Packit a4058c
{
Packit a4058c
  guchar *new_dest_buf;
Packit a4058c
  int render_x0;
Packit a4058c
  int render_y0;
Packit a4058c
  int render_x1;
Packit a4058c
  int render_y1;
Packit a4058c
Packit a4058c
  if (!src_has_alpha && overall_alpha == 255)
Packit a4058c
    {
Packit a4058c
      _pixops_scale (dest_buf, dest_width, dest_height, dest_rowstride,
Packit a4058c
		     dest_channels, dest_has_alpha, src_buf, src_width,
Packit a4058c
		     src_height, src_rowstride, src_channels, src_has_alpha,
Packit a4058c
		     dest_x, dest_y, dest_region_width, dest_region_height,
Packit a4058c
		     offset_x, offset_y, scale_x, scale_y, interp_type);
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x *
Packit a4058c
                 dest_channels;
Packit a4058c
  render_x0 = dest_x - offset_x;
Packit a4058c
  render_y0 = dest_y - offset_y;
Packit a4058c
  render_x1 = dest_x + dest_region_width  - offset_x;
Packit a4058c
  render_y1 = dest_y + dest_region_height - offset_y;
Packit a4058c
Packit a4058c
  _pixops_composite_color_real (new_dest_buf, render_x0, render_y0, render_x1,
Packit a4058c
				render_y1, dest_rowstride, dest_channels,
Packit a4058c
				dest_has_alpha, src_buf, src_width,
Packit a4058c
				src_height, src_rowstride, src_channels,
Packit a4058c
				src_has_alpha, scale_x, scale_y,
Packit a4058c
				(PixopsInterpType)interp_type, overall_alpha,
Packit a4058c
				check_x, check_y, check_size, color1, color2);
Packit a4058c
}
Packit a4058c
Packit a4058c
/**
Packit a4058c
 * _pixops_composite_real:
Packit a4058c
 * @dest_buf: pointer to location to store result
Packit a4058c
 * @render_x0: x0 of region of scaled source to store into @dest_buf
Packit a4058c
 * @render_y0: y0 of region of scaled source to store into @dest_buf
Packit a4058c
 * @render_x1: x1 of region of scaled source to store into @dest_buf
Packit a4058c
 * @render_y1: y1 of region of scaled source to store into @dest_buf
Packit a4058c
 * @dest_rowstride: rowstride of @dest_buf
Packit a4058c
 * @dest_channels: number of channels in @dest_buf
Packit a4058c
 * @dest_has_alpha: whether @dest_buf has alpha
Packit a4058c
 * @src_buf: pointer to source pixels
Packit a4058c
 * @src_width: width of source (used for clipping)
Packit a4058c
 * @src_height: height of source (used for clipping)
Packit a4058c
 * @src_rowstride: rowstride of source
Packit a4058c
 * @src_channels: number of channels in @src_buf
Packit a4058c
 * @src_has_alpha: whether @src_buf has alpha
Packit a4058c
 * @scale_x: amount to scale source by in X direction
Packit a4058c
 * @scale_y: amount to scale source by in Y direction
Packit a4058c
 * @interp_type: type of enumeration
Packit a4058c
 * @overall_alpha: overall alpha factor to multiply source by
Packit a4058c
 * 
Packit a4058c
 * Scale source buffer by scale_x / scale_y, then composite a given rectangle
Packit a4058c
 * of the result into the destination buffer.
Packit a4058c
 **/
Packit a4058c
static void
Packit a4058c
_pixops_composite_real (guchar          *dest_buf,
Packit a4058c
			int              render_x0,
Packit a4058c
			int              render_y0,
Packit a4058c
			int              render_x1,
Packit a4058c
			int              render_y1,
Packit a4058c
			int              dest_rowstride,
Packit a4058c
			int              dest_channels,
Packit a4058c
			gboolean         dest_has_alpha,
Packit a4058c
			const guchar    *src_buf,
Packit a4058c
			int              src_width,
Packit a4058c
			int              src_height,
Packit a4058c
			int              src_rowstride,
Packit a4058c
			int              src_channels,
Packit a4058c
			gboolean         src_has_alpha,
Packit a4058c
			double           scale_x,
Packit a4058c
			double           scale_y,
Packit a4058c
			PixopsInterpType interp_type,
Packit a4058c
			int              overall_alpha)
Packit a4058c
{
Packit a4058c
  PixopsFilter filter;
Packit a4058c
  PixopsLineFunc line_func;
Packit a4058c
  guchar *tmp_buf = NULL;
Packit a4058c
  
Packit a4058c
#ifdef USE_MMX
Packit a4058c
  gboolean found_mmx = _pixops_have_mmx ();
Packit a4058c
#endif
Packit a4058c
Packit a4058c
  g_return_if_fail (!(dest_channels == 3 && dest_has_alpha));
Packit a4058c
  g_return_if_fail (!(src_channels == 3 && src_has_alpha));
Packit a4058c
Packit a4058c
  if (scale_x == 0 || scale_y == 0)
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (interp_type == PIXOPS_INTERP_NEAREST)
Packit a4058c
    {
Packit a4058c
      if (scale_x == 1.0 && scale_y == 1.0)
Packit a4058c
	pixops_composite_nearest_noscale (dest_buf, render_x0, render_y0, render_x1, render_y1,
Packit a4058c
					  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
					  src_buf, src_width, src_height, src_rowstride, src_channels,
Packit a4058c
					  src_has_alpha, overall_alpha);
Packit a4058c
      else
Packit a4058c
	pixops_composite_nearest (dest_buf, render_x0, render_y0, render_x1, render_y1,
Packit a4058c
				  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
				  src_buf, src_width, src_height, src_rowstride, src_channels,
Packit a4058c
				  src_has_alpha, scale_x, scale_y, overall_alpha);
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  if (need_to_prescale (scale_x, scale_y, interp_type))
Packit a4058c
    tmp_buf = prescale (&src_buf, &src_width, &src_height, &src_rowstride,
Packit a4058c
			src_channels, src_has_alpha,
Packit a4058c
			&scale_x, &scale_y, interp_type);
Packit a4058c
  
Packit a4058c
  filter.overall_alpha = overall_alpha / 255.;
Packit a4058c
  if (!make_weights (&filter, interp_type, scale_x, scale_y))
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (filter.x.n == 2 && filter.y.n == 2 && dest_channels == 4 &&
Packit a4058c
      src_channels == 4 && src_has_alpha && !dest_has_alpha)
Packit a4058c
    {
Packit a4058c
#ifdef USE_MMX
Packit a4058c
      if (found_mmx)
Packit a4058c
	line_func = composite_line_22_4a4_mmx_stub;
Packit a4058c
      else
Packit a4058c
#endif	
Packit a4058c
	line_func = composite_line_22_4a4;
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    line_func = composite_line;
Packit a4058c
  
Packit a4058c
  pixops_process (dest_buf, render_x0, render_y0, render_x1, render_y1,
Packit a4058c
		  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
		  src_buf, src_width, src_height, src_rowstride, src_channels,
Packit a4058c
		  src_has_alpha, scale_x, scale_y, 0, 0, 0, 0, 0, 
Packit a4058c
		  &filter, line_func, composite_pixel);
Packit a4058c
Packit a4058c
  g_free (filter.x.weights);
Packit a4058c
  g_free (filter.y.weights);
Packit a4058c
  if (tmp_buf)
Packit a4058c
    g_free (tmp_buf);
Packit a4058c
}
Packit a4058c
Packit a4058c
void
Packit a4058c
_pixops_composite (guchar          *dest_buf,
Packit a4058c
                   int              dest_width,
Packit a4058c
                   int              dest_height,
Packit a4058c
                   int              dest_rowstride,
Packit a4058c
                   int              dest_channels,
Packit a4058c
                   int              dest_has_alpha,
Packit a4058c
                   const guchar    *src_buf,
Packit a4058c
                   int              src_width,
Packit a4058c
                   int              src_height,
Packit a4058c
                   int              src_rowstride,
Packit a4058c
                   int              src_channels,
Packit a4058c
                   int              src_has_alpha,
Packit a4058c
                   int              dest_x,
Packit a4058c
                   int              dest_y,
Packit a4058c
                   int              dest_region_width,
Packit a4058c
                   int              dest_region_height,
Packit a4058c
                   double           offset_x,
Packit a4058c
                   double           offset_y,
Packit a4058c
                   double           scale_x,
Packit a4058c
                   double           scale_y,
Packit a4058c
                   PixopsInterpType interp_type,
Packit a4058c
                   int              overall_alpha)
Packit a4058c
{
Packit a4058c
  guchar *new_dest_buf;
Packit a4058c
  int render_x0;
Packit a4058c
  int render_y0;
Packit a4058c
  int render_x1;
Packit a4058c
  int render_y1;
Packit a4058c
Packit a4058c
  if (!src_has_alpha && overall_alpha == 255)
Packit a4058c
    {
Packit a4058c
      _pixops_scale (dest_buf, dest_width, dest_height, dest_rowstride,
Packit a4058c
		     dest_channels, dest_has_alpha, src_buf, src_width,
Packit a4058c
		     src_height, src_rowstride, src_channels, src_has_alpha,
Packit a4058c
		     dest_x, dest_y, dest_region_width, dest_region_height,
Packit a4058c
		     offset_x, offset_y, scale_x, scale_y, interp_type);
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
#ifdef USE_MEDIALIB
Packit a4058c
  pixops_medialib_composite (dest_buf, dest_width, dest_height, dest_rowstride,
Packit a4058c
                             dest_channels, dest_has_alpha, src_buf,
Packit a4058c
                             src_width, src_height, src_rowstride,
Packit a4058c
                             src_channels, src_has_alpha, dest_x, dest_y,
Packit a4058c
                             dest_region_width, dest_region_height, offset_x,
Packit a4058c
			     offset_y, scale_x, scale_y,
Packit a4058c
                             (PixopsInterpType)interp_type, overall_alpha);
Packit a4058c
  return;
Packit a4058c
#endif
Packit a4058c
Packit a4058c
  new_dest_buf = dest_buf + (gsize)dest_y * dest_rowstride + (gsize)dest_x * dest_channels;
Packit a4058c
  render_x0 = dest_x - offset_x;
Packit a4058c
  render_y0 = dest_y - offset_y;
Packit a4058c
  render_x1 = dest_x + dest_region_width  - offset_x;
Packit a4058c
  render_y1 = dest_y + dest_region_height - offset_y;
Packit a4058c
Packit a4058c
  _pixops_composite_real (new_dest_buf, render_x0, render_y0, render_x1,
Packit a4058c
			  render_y1, dest_rowstride, dest_channels,
Packit a4058c
			  dest_has_alpha, src_buf, src_width, src_height,
Packit a4058c
			  src_rowstride, src_channels, src_has_alpha, scale_x,
Packit a4058c
			  scale_y, (PixopsInterpType)interp_type,
Packit a4058c
			  overall_alpha);
Packit a4058c
}
Packit a4058c
Packit a4058c
#ifdef USE_MEDIALIB
Packit a4058c
static void
Packit a4058c
medialib_get_interpolation (mlInterp * ml_interp,
Packit a4058c
                            PixopsInterpType interp_type,
Packit a4058c
                            double scale_x,
Packit a4058c
                            double scale_y,
Packit a4058c
                            double overall_alpha)
Packit a4058c
{
Packit a4058c
  mlib_s32 leftPadding, topPadding;
Packit a4058c
  ml_interp->interp_table = NULL;
Packit a4058c
Packit a4058c
 /*
Packit a4058c
  * medialib 2.1 and later supports scaling with user-defined interpolation
Packit a4058c
  * tables, so this logic is used.  
Packit a4058c
  *
Packit a4058c
  * bilinear_magnify_make_weights builds an interpolation table of size 2x2 if
Packit a4058c
  * the scale factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.  These map
Packit a4058c
  * most closely to MLIB_BILINEAR, which uses an interpolation table of size
Packit a4058c
  * 2x2.
Packit a4058c
  *
Packit a4058c
  * tile_make_weights builds an interpolation table of size 2x2 if the scale
Packit a4058c
  * factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.  These map most
Packit a4058c
  * closely to MLIB_BILINEAR, which uses an interpolation table of size 2x2.
Packit a4058c
  *
Packit a4058c
  * bilinear_box_make_weights builds an interpolation table of size 4x4 if the
Packit a4058c
  * scale factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.  These map most
Packit a4058c
  * closely to MLIB_BICUBIC, which uses an interpolation table of size 4x4.
Packit a4058c
  *
Packit a4058c
  * PIXOPS_INTERP_NEAREST calls pixops_scale_nearest which does not use an
Packit a4058c
  * interpolation table.  This maps to MLIB_NEAREST.
Packit a4058c
  */
Packit a4058c
  switch (interp_type)
Packit a4058c
    {
Packit a4058c
    case PIXOPS_INTERP_BILINEAR:
Packit a4058c
      bilinear_magnify_make_weights (&(ml_interp->po_filter.x), scale_x);
Packit a4058c
      bilinear_magnify_make_weights (&(ml_interp->po_filter.y), scale_y);
Packit a4058c
      leftPadding = 0;
Packit a4058c
      topPadding  = 0;
Packit a4058c
Packit a4058c
      if (scale_x <= 1.0)
Packit a4058c
          ml_interp->tx = 0.5 * (1 - scale_x);
Packit a4058c
      else
Packit a4058c
          ml_interp->tx = 0.0;
Packit a4058c
Packit a4058c
      if (scale_y <= 1.0)
Packit a4058c
          ml_interp->ty = 0.5 * (1 - scale_y);
Packit a4058c
      else
Packit a4058c
          ml_interp->ty = 0.0;
Packit a4058c
Packit a4058c
      break;
Packit a4058c
Packit a4058c
    case PIXOPS_INTERP_TILES:
Packit a4058c
      tile_make_weights (&(ml_interp->po_filter.x), scale_x);
Packit a4058c
      tile_make_weights (&(ml_interp->po_filter.y), scale_y);
Packit a4058c
      leftPadding   = 0;
Packit a4058c
      topPadding    = 0;
Packit a4058c
      ml_interp->tx = 0.5 * (1 - scale_x);
Packit a4058c
      ml_interp->ty = 0.5 * (1 - scale_y);
Packit a4058c
      break;
Packit a4058c
Packit a4058c
    case PIXOPS_INTERP_HYPER:
Packit a4058c
      bilinear_box_make_weights (&(ml_interp->po_filter.x), scale_x);
Packit a4058c
      bilinear_box_make_weights (&(ml_interp->po_filter.y), scale_y);
Packit a4058c
      leftPadding   = 1;
Packit a4058c
      topPadding    = 1;
Packit a4058c
      ml_interp->tx = 0.5 * (1 - scale_x);
Packit a4058c
      ml_interp->ty = 0.5 * (1 - scale_y);
Packit a4058c
      break;
Packit a4058c
Packit a4058c
    case PIXOPS_INTERP_NEAREST:
Packit a4058c
    default:
Packit a4058c
      /*
Packit a4058c
       * Note that this function should not be called in the
Packit a4058c
       * PIXOPS_INTERP_NEAREST case since it does not use an interpolation
Packit a4058c
       * table.
Packit a4058c
       */
Packit a4058c
      g_assert_not_reached ();
Packit a4058c
      break;
Packit a4058c
    }
Packit a4058c
Packit a4058c
 /* 
Packit a4058c
  * If overall_alpha is not 1.0, then multiply the vectors built by the
Packit a4058c
  * sqrt (overall_alpha).  This will cause overall_alpha to get evenly
Packit a4058c
  * blended across both axis.
Packit a4058c
  *
Packit a4058c
  * Note there is no need to multiply the vectors built by the various
Packit a4058c
  * make-weight functions by sqrt (overall_alpha) since the make-weight
Packit a4058c
  * functions are called with overall_alpha hardcoded to 1.0.
Packit a4058c
  */
Packit a4058c
  if (overall_alpha != 1.0)
Packit a4058c
    {
Packit a4058c
      double sqrt_alpha = sqrt (overall_alpha);
Packit a4058c
      int i;
Packit a4058c
Packit a4058c
      for (i=0; i < SUBSAMPLE * ml_interp->po_filter.x.n; i++)
Packit a4058c
         ml_interp->po_filter.x.weights[i] *= sqrt_alpha;
Packit a4058c
      for (i=0; i < SUBSAMPLE * ml_interp->po_filter.y.n; i++)
Packit a4058c
         ml_interp->po_filter.y.weights[i] *= sqrt_alpha;
Packit a4058c
    }
Packit a4058c
    
Packit a4058c
  ml_interp->interp_table = (void *) mlib_ImageInterpTableCreate (MLIB_DOUBLE,
Packit a4058c
    ml_interp->po_filter.x.n, ml_interp->po_filter.y.n, leftPadding,
Packit a4058c
    topPadding, SUBSAMPLE_BITS, SUBSAMPLE_BITS, 8,
Packit a4058c
    ml_interp->po_filter.x.weights, ml_interp->po_filter.y.weights);
Packit a4058c
Packit a4058c
  g_free (ml_interp->po_filter.x.weights);
Packit a4058c
  g_free (ml_interp->po_filter.y.weights);  
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
pixops_medialib_composite (guchar          *dest_buf,
Packit a4058c
                           int              dest_width,
Packit a4058c
                           int              dest_height,
Packit a4058c
                           int              dest_rowstride,
Packit a4058c
                           int              dest_channels,
Packit a4058c
                           int              dest_has_alpha,
Packit a4058c
                           const guchar    *src_buf,
Packit a4058c
                           int              src_width,
Packit a4058c
                           int              src_height,
Packit a4058c
                           int              src_rowstride,
Packit a4058c
                           int              src_channels,
Packit a4058c
                           int              src_has_alpha,
Packit a4058c
                           int              dest_x,
Packit a4058c
                           int              dest_y,
Packit a4058c
                           int              dest_region_width,
Packit a4058c
                           int              dest_region_height,
Packit a4058c
                           double           offset_x,
Packit a4058c
                           double           offset_y,
Packit a4058c
                           double           scale_x,
Packit a4058c
                           double           scale_y,
Packit a4058c
                           PixopsInterpType interp_type,
Packit a4058c
                           int              overall_alpha)
Packit a4058c
{
Packit a4058c
  mlib_blend blend;
Packit a4058c
  g_return_if_fail (!(dest_channels == 3 && dest_has_alpha));
Packit a4058c
  g_return_if_fail (!(src_channels == 3 && src_has_alpha));
Packit a4058c
Packit a4058c
  if (scale_x == 0 || scale_y == 0)
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (!medialib_initialized)
Packit a4058c
    _pixops_use_medialib ();
Packit a4058c
Packit a4058c
  if (!use_medialib)
Packit a4058c
    {
Packit a4058c
      /* Use non-mediaLib version */
Packit a4058c
      _pixops_composite_real (dest_buf + (gsize)dest_y * dest_rowstride + (gsize)dest_x *
Packit a4058c
			      dest_channels, dest_x - offset_x, dest_y -
Packit a4058c
			      offset_y, dest_x + dest_region_width - offset_x,
Packit a4058c
			      dest_y + dest_region_height - offset_y,
Packit a4058c
			      dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
			      src_buf, src_width, src_height, src_rowstride,
Packit a4058c
			      src_channels, src_has_alpha, scale_x, scale_y,
Packit a4058c
			      interp_type, overall_alpha);
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    {
Packit a4058c
      mlInterp ml_interp;
Packit a4058c
      mlib_image img_src, img_dest;
Packit a4058c
      double ml_offset_x, ml_offset_y;
Packit a4058c
Packit a4058c
      if (!src_has_alpha && overall_alpha == 255 &&
Packit a4058c
	  dest_channels <= src_channels) 
Packit a4058c
        {
Packit a4058c
          pixops_medialib_scale (dest_buf, dest_region_width,
Packit a4058c
				 dest_region_height, dest_rowstride,
Packit a4058c
				 dest_channels, dest_has_alpha, src_buf,
Packit a4058c
				 src_width, src_height, src_rowstride,
Packit a4058c
				 src_channels, src_has_alpha, dest_x, dest_y,
Packit a4058c
				 dest_region_width, dest_region_height,
Packit a4058c
				 offset_x, offset_y, scale_x, scale_y,
Packit a4058c
				 interp_type);
Packit a4058c
          return;
Packit a4058c
        }
Packit a4058c
Packit a4058c
      mlib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
Packit a4058c
			   src_width, src_height, src_rowstride, src_buf);
Packit a4058c
Packit a4058c
      if (dest_x == 0 && dest_y == 0 &&
Packit a4058c
          dest_width  == dest_region_width &&
Packit a4058c
          dest_height == dest_region_height)
Packit a4058c
        {
Packit a4058c
          mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
Packit a4058c
			       dest_width, dest_height, dest_rowstride,
Packit a4058c
			       dest_buf);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        {
Packit a4058c
	  mlib_u8 *data = dest_buf + (gsize)dest_y * dest_rowstride +
Packit a4058c
				     (gsize)dest_x * dest_channels;
Packit a4058c
Packit a4058c
          mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
Packit a4058c
			       dest_region_width, dest_region_height,
Packit a4058c
			       dest_rowstride, data);
Packit a4058c
        }
Packit a4058c
Packit a4058c
      ml_offset_x = floor (offset_x) - dest_x;
Packit a4058c
      ml_offset_y = floor (offset_y) - dest_y;
Packit a4058c
Packit a4058c
      if (interp_type == PIXOPS_INTERP_NEAREST)
Packit a4058c
        {
Packit a4058c
          blend = src_has_alpha ? MLIB_BLEND_GTK_SRC_OVER2 : MLIB_BLEND_GTK_SRC;
Packit a4058c
Packit a4058c
          mlib_ImageZoomTranslateBlend (&img_dest,
Packit a4058c
                                        &img_src,
Packit a4058c
                                        scale_x,
Packit a4058c
                                        scale_y,
Packit a4058c
                                        ml_offset_x,
Packit a4058c
                                        ml_offset_y,
Packit a4058c
                                        MLIB_NEAREST,
Packit a4058c
                                        MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                        blend,
Packit a4058c
                                        overall_alpha,
Packit a4058c
                                        1);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        {
Packit a4058c
          blend = src_has_alpha ? MLIB_BLEND_GTK_SRC_OVER : MLIB_BLEND_GTK_SRC;
Packit a4058c
Packit a4058c
          if (interp_type == PIXOPS_INTERP_BILINEAR &&
Packit a4058c
	      scale_x > 1.0 && scale_y > 1.0)
Packit a4058c
            {
Packit a4058c
              mlib_ImageZoomTranslateBlend (&img_dest,
Packit a4058c
                                            &img_src,
Packit a4058c
                                            scale_x,
Packit a4058c
                                            scale_y,
Packit a4058c
                                            ml_offset_x,
Packit a4058c
                                            ml_offset_y,
Packit a4058c
                                            MLIB_BILINEAR,
Packit a4058c
                                            MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                            blend,
Packit a4058c
                                            overall_alpha,
Packit a4058c
                                            1);
Packit a4058c
            }
Packit a4058c
          else
Packit a4058c
            {
Packit a4058c
              medialib_get_interpolation (&ml_interp, interp_type, scale_x,
Packit a4058c
					  scale_y, overall_alpha/255.0);
Packit a4058c
Packit a4058c
              if (ml_interp.interp_table != NULL)
Packit a4058c
                {
Packit a4058c
                  mlib_ImageZoomTranslateTableBlend (&img_dest,
Packit a4058c
                                                     &img_src,
Packit a4058c
                                                     scale_x,
Packit a4058c
                                                     scale_y,
Packit a4058c
                                                     ml_offset_x + ml_interp.tx,
Packit a4058c
                                                     ml_offset_y + ml_interp.ty,
Packit a4058c
                                                     ml_interp.interp_table,
Packit a4058c
                                                     MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                                     blend,
Packit a4058c
                                                     1);
Packit a4058c
                  mlib_ImageInterpTableDelete (ml_interp.interp_table);
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  /* Should not happen - Use non-mediaLib version */
Packit a4058c
                  _pixops_composite_real (dest_buf + (gsize)dest_y * dest_rowstride +
Packit a4058c
                                          (gsize)dest_x * dest_channels,
Packit a4058c
                                          dest_x - offset_x, dest_y - offset_y,
Packit a4058c
                                          dest_x + dest_region_width - offset_x,
Packit a4058c
                                          dest_y + dest_region_height - offset_y,
Packit a4058c
                                          dest_rowstride, dest_channels,
Packit a4058c
                                          dest_has_alpha, src_buf, src_width,
Packit a4058c
                                          src_height, src_rowstride,
Packit a4058c
                                          src_channels, src_has_alpha, scale_x,
Packit a4058c
                                          scale_y, interp_type, overall_alpha);
Packit a4058c
                }
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
#endif
Packit a4058c
Packit a4058c
static void
Packit a4058c
_pixops_scale_real (guchar        *dest_buf,
Packit a4058c
		    int            render_x0,
Packit a4058c
		    int            render_y0,
Packit a4058c
		    int            render_x1,
Packit a4058c
		    int            render_y1,
Packit a4058c
		    int            dest_rowstride,
Packit a4058c
		    int            dest_channels,
Packit a4058c
		    gboolean       dest_has_alpha,
Packit a4058c
		    const guchar  *src_buf,
Packit a4058c
		    int            src_width,
Packit a4058c
		    int            src_height,
Packit a4058c
		    int            src_rowstride,
Packit a4058c
		    int            src_channels,
Packit a4058c
		    gboolean       src_has_alpha,
Packit a4058c
		    double         scale_x,
Packit a4058c
		    double         scale_y,
Packit a4058c
		    PixopsInterpType  interp_type)
Packit a4058c
{
Packit a4058c
  PixopsFilter filter;
Packit a4058c
  PixopsLineFunc line_func;
Packit a4058c
  guchar *tmp_buf = NULL;	/* Temporary image for two-step scaling */
Packit a4058c
Packit a4058c
#ifdef USE_MMX
Packit a4058c
  gboolean found_mmx = _pixops_have_mmx ();
Packit a4058c
#endif
Packit a4058c
Packit a4058c
  g_return_if_fail (!(dest_channels == 3 && dest_has_alpha));
Packit a4058c
  g_return_if_fail (!(src_channels == 3 && src_has_alpha));
Packit a4058c
  g_return_if_fail (!(src_has_alpha && !dest_has_alpha));
Packit a4058c
Packit a4058c
  if (scale_x == 0 || scale_y == 0)
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (interp_type == PIXOPS_INTERP_NEAREST)
Packit a4058c
    {
Packit a4058c
      pixops_scale_nearest (dest_buf, render_x0, render_y0, render_x1,
Packit a4058c
			    render_y1, dest_rowstride, dest_channels,
Packit a4058c
			    dest_has_alpha, src_buf, src_width, src_height,
Packit a4058c
			    src_rowstride, src_channels, src_has_alpha,
Packit a4058c
			    scale_x, scale_y);
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  if (need_to_prescale (scale_x, scale_y, interp_type))
Packit a4058c
    tmp_buf = prescale (&src_buf, &src_width, &src_height, &src_rowstride,
Packit a4058c
			src_channels, src_has_alpha,
Packit a4058c
			&scale_x, &scale_y, interp_type);
Packit a4058c
  
Packit a4058c
  filter.overall_alpha = 1.0;
Packit a4058c
  if (!make_weights (&filter, interp_type, scale_x, scale_y))
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (filter.x.n == 2 && filter.y.n == 2 && dest_channels == 3 && src_channels == 3)
Packit a4058c
    {
Packit a4058c
#ifdef USE_MMX
Packit a4058c
      if (found_mmx)
Packit a4058c
	line_func = scale_line_22_33_mmx_stub;
Packit a4058c
      else
Packit a4058c
#endif
Packit a4058c
	line_func = scale_line_22_33;
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    line_func = scale_line;
Packit a4058c
  
Packit a4058c
  pixops_process (dest_buf, render_x0, render_y0, render_x1, render_y1,
Packit a4058c
		  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
		  src_buf, src_width, src_height, src_rowstride, src_channels,
Packit a4058c
		  src_has_alpha, scale_x, scale_y, 0, 0, 0, 0, 0,
Packit a4058c
		  &filter, line_func, scale_pixel);
Packit a4058c
Packit a4058c
  g_free (filter.x.weights);
Packit a4058c
  g_free (filter.y.weights);
Packit a4058c
  g_clear_pointer (&tmp_buf, g_free);
Packit a4058c
}
Packit a4058c
Packit a4058c
void
Packit a4058c
_pixops_scale (guchar          *dest_buf,
Packit a4058c
               int              dest_width,
Packit a4058c
               int              dest_height,
Packit a4058c
               int              dest_rowstride,
Packit a4058c
               int              dest_channels,
Packit a4058c
               int              dest_has_alpha,
Packit a4058c
               const guchar    *src_buf,
Packit a4058c
               int              src_width,
Packit a4058c
               int              src_height,
Packit a4058c
               int              src_rowstride,
Packit a4058c
               int              src_channels,
Packit a4058c
               int              src_has_alpha,
Packit a4058c
               int              dest_x,
Packit a4058c
               int              dest_y,
Packit a4058c
               int              dest_region_width,
Packit a4058c
               int              dest_region_height,
Packit a4058c
               double           offset_x,
Packit a4058c
               double           offset_y,
Packit a4058c
               double           scale_x,
Packit a4058c
               double           scale_y,
Packit a4058c
               PixopsInterpType interp_type)
Packit a4058c
{
Packit a4058c
  guchar *new_dest_buf;
Packit a4058c
  int render_x0;
Packit a4058c
  int render_y0;
Packit a4058c
  int render_x1;
Packit a4058c
  int render_y1;
Packit a4058c
Packit a4058c
#ifdef USE_MEDIALIB
Packit a4058c
  pixops_medialib_scale (dest_buf, dest_width, dest_height, dest_rowstride,
Packit a4058c
                         dest_channels, dest_has_alpha, src_buf, src_width,
Packit a4058c
                         src_height, src_rowstride, src_channels,
Packit a4058c
                         src_has_alpha, dest_x, dest_y, dest_region_width,
Packit a4058c
			 dest_region_height, offset_x, offset_y, scale_x,
Packit a4058c
			 scale_y, (PixopsInterpType)interp_type);
Packit a4058c
  return;
Packit a4058c
#endif
Packit a4058c
Packit a4058c
  new_dest_buf = dest_buf + (gsize)dest_y * dest_rowstride + (gsize)dest_x * dest_channels;
Packit a4058c
  render_x0    = dest_x - offset_x;
Packit a4058c
  render_y0    = dest_y - offset_y;
Packit a4058c
  render_x1    = dest_x + dest_region_width  - offset_x;
Packit a4058c
  render_y1    = dest_y + dest_region_height - offset_y;
Packit a4058c
Packit a4058c
  _pixops_scale_real (new_dest_buf, render_x0, render_y0, render_x1,
Packit a4058c
                      render_y1, dest_rowstride, dest_channels,
Packit a4058c
                      dest_has_alpha, src_buf, src_width, src_height,
Packit a4058c
                      src_rowstride, src_channels, src_has_alpha,
Packit a4058c
                      scale_x, scale_y, (PixopsInterpType)interp_type);
Packit a4058c
}
Packit a4058c
Packit a4058c
#ifdef USE_MEDIALIB
Packit a4058c
static void
Packit a4058c
pixops_medialib_scale     (guchar          *dest_buf,
Packit a4058c
                           int              dest_width,
Packit a4058c
                           int              dest_height,
Packit a4058c
                           int              dest_rowstride,
Packit a4058c
                           int              dest_channels,
Packit a4058c
                           int              dest_has_alpha,
Packit a4058c
                           const guchar    *src_buf,
Packit a4058c
                           int              src_width,
Packit a4058c
                           int              src_height,
Packit a4058c
                           int              src_rowstride,
Packit a4058c
                           int              src_channels,
Packit a4058c
                           int              src_has_alpha,
Packit a4058c
                           int              dest_x,
Packit a4058c
                           int              dest_y,
Packit a4058c
                           int              dest_region_width,
Packit a4058c
                           int              dest_region_height,
Packit a4058c
                           double           offset_x,
Packit a4058c
                           double           offset_y,
Packit a4058c
                           double           scale_x,
Packit a4058c
                           double           scale_y,
Packit a4058c
                           PixopsInterpType interp_type)
Packit a4058c
{
Packit a4058c
  if (scale_x == 0 || scale_y == 0)
Packit a4058c
    return;
Packit a4058c
Packit a4058c
  if (!medialib_initialized)
Packit a4058c
    _pixops_use_medialib ();
Packit a4058c
 
Packit a4058c
  /*
Packit a4058c
   * We no longer support mediaLib 2.1 because it has a core dumping problem
Packit a4058c
   * in the mlib_ImageZoomTranslateTable function that has been corrected in
Packit a4058c
   * 2.2.  Although the mediaLib_zoom function could be used, it does not
Packit a4058c
   * work properly if the source and destination images have different 
Packit a4058c
   * values for "has_alpha" or "num_channels".  The complicated if-logic
Packit a4058c
   * required to support both versions is not worth supporting
Packit a4058c
   * mediaLib 2.1 moving forward.
Packit a4058c
   */
Packit a4058c
  if (!use_medialib)
Packit a4058c
    {
Packit a4058c
      _pixops_scale_real (dest_buf + (gsize)dest_y * dest_rowstride + (gsize)dest_x *
Packit a4058c
			  dest_channels, dest_x - offset_x, dest_y - offset_y,
Packit a4058c
			  dest_x + dest_region_width - offset_x,
Packit a4058c
			  dest_y + dest_region_height - offset_y,
Packit a4058c
			  dest_rowstride, dest_channels, dest_has_alpha,
Packit a4058c
			  src_buf, src_width, src_height, src_rowstride,
Packit a4058c
			  src_channels, src_has_alpha, scale_x, scale_y,
Packit a4058c
			  interp_type);
Packit a4058c
    }
Packit a4058c
  else 
Packit a4058c
    {
Packit a4058c
      mlInterp ml_interp;
Packit a4058c
      mlib_image img_orig_src, img_src, img_dest;
Packit a4058c
      double ml_offset_x, ml_offset_y;
Packit a4058c
      guchar *tmp_buf = NULL;
Packit a4058c
Packit a4058c
      mlib_ImageSetStruct (&img_orig_src, MLIB_BYTE, src_channels, src_width, 
Packit a4058c
			   src_height, src_rowstride, src_buf);
Packit a4058c
Packit a4058c
      if (dest_x == 0 && dest_y == 0 &&
Packit a4058c
          dest_width == dest_region_width &&
Packit a4058c
          dest_height == dest_region_height)
Packit a4058c
        {
Packit a4058c
          mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
Packit a4058c
			       dest_width, dest_height, dest_rowstride,
Packit a4058c
			       dest_buf);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        {
Packit a4058c
	  mlib_u8 *data = dest_buf + (gsize)dest_y * dest_rowstride +
Packit a4058c
				     (gsize)dest_x * dest_channels;
Packit a4058c
Packit a4058c
          mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
Packit a4058c
			       dest_region_width, dest_region_height,
Packit a4058c
			       dest_rowstride, data);
Packit a4058c
        }
Packit a4058c
Packit a4058c
      ml_offset_x = floor (offset_x) - dest_x;
Packit a4058c
      ml_offset_y = floor (offset_y) - dest_y;
Packit a4058c
Packit a4058c
     /*
Packit a4058c
      * Note that zoomTranslate and zoomTranslateTable are faster
Packit a4058c
      * than zoomTranslateBlend and zoomTranslateTableBlend.  However
Packit a4058c
      * the faster functions only work in the following case:
Packit a4058c
      *
Packit a4058c
      *   if (src_channels == dest_channels &&
Packit a4058c
      *       (!src_alpha && interp_table != PIXOPS_INTERP_NEAREST))
Packit a4058c
      *
Packit a4058c
      * We use the faster versions if we can.
Packit a4058c
      *
Packit a4058c
      * Note when the interp_type is BILINEAR and the interpolation
Packit a4058c
      * table will be size 2x2 (when both x/y scale factors > 1.0),
Packit a4058c
      * then we do not bother building the interpolation table.   In
Packit a4058c
      * this case we can just use MLIB_BILINEAR, which is faster than
Packit a4058c
      * using a specified interpolation table.
Packit a4058c
      */
Packit a4058c
      img_src = img_orig_src;
Packit a4058c
Packit a4058c
      if (!src_has_alpha)
Packit a4058c
        {
Packit a4058c
          if (src_channels > dest_channels)
Packit a4058c
            {
Packit a4058c
              int channels  = 3;
Packit a4058c
              int rowstride = (channels * src_width + 3) & ~3;
Packit a4058c
        
Packit a4058c
              tmp_buf = g_malloc_n (src_rowstride, src_height);
Packit a4058c
Packit a4058c
              if (src_buf != NULL)
Packit a4058c
                {
Packit a4058c
                  src_channels  = channels;
Packit a4058c
                  src_rowstride = rowstride;
Packit a4058c
          
Packit a4058c
                  mlib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
Packit a4058c
				       src_width, src_height, src_rowstride,
Packit a4058c
				       tmp_buf);
Packit a4058c
                  mlib_ImageChannelExtract (&img_src, &img_orig_src, 0xE);  
Packit a4058c
                }
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
    
Packit a4058c
      if (interp_type == PIXOPS_INTERP_NEAREST)
Packit a4058c
        {
Packit a4058c
          if (src_channels == dest_channels)
Packit a4058c
            {
Packit a4058c
              mlib_ImageZoomTranslate (&img_dest,
Packit a4058c
                                       &img_src,
Packit a4058c
                                       scale_x,
Packit a4058c
                                       scale_y,
Packit a4058c
                                       ml_offset_x,
Packit a4058c
                                       ml_offset_y,
Packit a4058c
                                       MLIB_NEAREST,
Packit a4058c
                                       MLIB_EDGE_SRC_EXTEND_INDEF);
Packit a4058c
            }
Packit a4058c
          else
Packit a4058c
            {
Packit a4058c
              mlib_ImageZoomTranslateBlend (&img_dest,
Packit a4058c
                                            &img_src,
Packit a4058c
                                            scale_x,
Packit a4058c
                                            scale_y,
Packit a4058c
                                            ml_offset_x,
Packit a4058c
                                            ml_offset_y,
Packit a4058c
                                            MLIB_NEAREST,
Packit a4058c
                                            MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                            MLIB_BLEND_GTK_SRC,
Packit a4058c
                                            1.0,
Packit a4058c
                                            1);
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
      else if (src_channels == dest_channels && !src_has_alpha)
Packit a4058c
        {
Packit a4058c
          if (interp_type == PIXOPS_INTERP_BILINEAR &&
Packit a4058c
              scale_x > 1.0 && scale_y > 1.0)
Packit a4058c
            {
Packit a4058c
               mlib_ImageZoomTranslate (&img_dest,
Packit a4058c
                                        &img_src,
Packit a4058c
                                        scale_x,
Packit a4058c
                                        scale_y,
Packit a4058c
                                        ml_offset_x,
Packit a4058c
                                        ml_offset_y,
Packit a4058c
                                        MLIB_BILINEAR,
Packit a4058c
                                        MLIB_EDGE_SRC_EXTEND_INDEF);
Packit a4058c
            }
Packit a4058c
          else
Packit a4058c
            {
Packit a4058c
              medialib_get_interpolation (&ml_interp, interp_type,
Packit a4058c
                                          scale_x, scale_y, 1.0);
Packit a4058c
Packit a4058c
              if (ml_interp.interp_table != NULL)
Packit a4058c
                {
Packit a4058c
                  mlib_ImageZoomTranslateTable (&img_dest, 
Packit a4058c
                                                &img_src,
Packit a4058c
                                                scale_x,
Packit a4058c
                                                scale_y,
Packit a4058c
                                                ml_offset_x + ml_interp.tx,
Packit a4058c
                                                ml_offset_y + ml_interp.ty,
Packit a4058c
                                                ml_interp.interp_table,
Packit a4058c
                                                MLIB_EDGE_SRC_EXTEND_INDEF);
Packit a4058c
Packit a4058c
	          mlib_ImageInterpTableDelete (ml_interp.interp_table);
Packit a4058c
                }
Packit a4058c
              else
Packit a4058c
                {
Packit a4058c
                  /* Should not happen. */
Packit a4058c
                  mlib_filter  ml_filter;
Packit a4058c
Packit a4058c
                  switch (interp_type)
Packit a4058c
                    {
Packit a4058c
                    case PIXOPS_INTERP_BILINEAR:
Packit a4058c
                      ml_filter = MLIB_BILINEAR;
Packit a4058c
                      break;
Packit a4058c
Packit a4058c
                    case PIXOPS_INTERP_TILES:
Packit a4058c
                      ml_filter = MLIB_BILINEAR;
Packit a4058c
                      break;
Packit a4058c
Packit a4058c
                    case PIXOPS_INTERP_HYPER:
Packit a4058c
                      ml_filter = MLIB_BICUBIC;
Packit a4058c
                      break;
Packit a4058c
                    }
Packit a4058c
Packit a4058c
                  mlib_ImageZoomTranslate (&img_dest,
Packit a4058c
                                           &img_src,
Packit a4058c
                                           scale_x,
Packit a4058c
                                           scale_y,
Packit a4058c
                                           ml_offset_x,
Packit a4058c
                                           ml_offset_y,
Packit a4058c
                                           ml_filter,
Packit a4058c
                                           MLIB_EDGE_SRC_EXTEND_INDEF);
Packit a4058c
                }
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
Packit a4058c
      /* Deal with case where src_channels != dest_channels || src_has_alpha */
Packit a4058c
      else if (interp_type == PIXOPS_INTERP_BILINEAR &&
Packit a4058c
               scale_x > 1.0 && scale_y > 1.0)
Packit a4058c
        {
Packit a4058c
          mlib_ImageZoomTranslateBlend (&img_dest,
Packit a4058c
                                        &img_src,
Packit a4058c
                                        scale_x,
Packit a4058c
                                        scale_y,
Packit a4058c
                                        ml_offset_x,
Packit a4058c
                                        ml_offset_y,
Packit a4058c
                                        MLIB_BILINEAR,
Packit a4058c
                                        MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                        MLIB_BLEND_GTK_SRC,
Packit a4058c
                                        1.0,
Packit a4058c
                                        1);
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        {
Packit a4058c
          medialib_get_interpolation (&ml_interp, interp_type,
Packit a4058c
                                      scale_x, scale_y, 1.0);
Packit a4058c
Packit a4058c
          if (ml_interp.interp_table != NULL)
Packit a4058c
            {
Packit a4058c
              mlib_ImageZoomTranslateTableBlend (&img_dest,
Packit a4058c
                                                 &img_src,
Packit a4058c
                                                 scale_x,
Packit a4058c
                                                 scale_y,
Packit a4058c
                                                 ml_offset_x + ml_interp.tx,
Packit a4058c
                                                 ml_offset_y + ml_interp.ty,
Packit a4058c
                                                 ml_interp.interp_table,
Packit a4058c
                                                 MLIB_EDGE_SRC_EXTEND_INDEF,
Packit a4058c
                                                 MLIB_BLEND_GTK_SRC,
Packit a4058c
                                                 1);
Packit a4058c
              mlib_ImageInterpTableDelete (ml_interp.interp_table);
Packit a4058c
            }
Packit a4058c
          else
Packit a4058c
            {
Packit a4058c
              mlib_filter  ml_filter;
Packit a4058c
Packit a4058c
              switch (interp_type)
Packit a4058c
                {
Packit a4058c
                case PIXOPS_INTERP_BILINEAR:
Packit a4058c
                  ml_filter = MLIB_BILINEAR;
Packit a4058c
                  break;
Packit a4058c
            
Packit a4058c
                case PIXOPS_INTERP_TILES:
Packit a4058c
                  ml_filter = MLIB_BILINEAR;
Packit a4058c
                  break;
Packit a4058c
Packit a4058c
                case PIXOPS_INTERP_HYPER:
Packit a4058c
                  ml_filter = MLIB_BICUBIC;
Packit a4058c
                  break;
Packit a4058c
                }
Packit a4058c
Packit a4058c
              mlib_ImageZoomTranslate (&img_dest,
Packit a4058c
                                       &img_src,
Packit a4058c
                                       scale_x,
Packit a4058c
                                       scale_y,
Packit a4058c
                                       ml_offset_x,
Packit a4058c
                                       ml_offset_y,
Packit a4058c
                                       ml_filter,
Packit a4058c
                                       MLIB_EDGE_SRC_EXTEND_INDEF);
Packit a4058c
            }
Packit a4058c
        }
Packit a4058c
Packit a4058c
      if (tmp_buf != NULL)
Packit a4058c
        g_free (tmp_buf);
Packit a4058c
    }
Packit a4058c
}
Packit a4058c
#endif