Ignore:
Timestamp:
Oct 16, 2010, 11:52:38 PM (9 years ago)
Author:
Sam Hocevar
Message:

Move resize.c to an algorithm-specific file so that we can implement
other resizing methods.

Location:
libpipi/trunk/pipi/resample
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/resample/bresenham.c

    • Property svn:keywords set to Id
    r4081 r4690  
    11/*
    22 *  libpipi       Pathetic image processing interface library
    3  *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2004-2009 Sam Hocevar <sam@hocevar.net>
    44 *                All Rights Reserved
    55 *
     
    1414
    1515/*
    16  * resize.c: image resizing functions
     16 * bresenham.c: Bresenham image resizing functions
    1717 */
    1818
     
    2424#include "pipi.h"
    2525#include "pipi_internals.h"
     26
     27/* This is Bresenham resizing. I rediscovered it independently but it was
     28 * actually first described in 1995 by Tim Kientzle in "Scaling Bitmaps
     29 * with Bresenham". */
    2630
    2731/* FIXME: the algorithm does not handle alpha components properly. Resulting
     
    124128}
    125129
    126 pipi_image_t *pipi_crop(pipi_image_t *src, int w, int h, int dx, int dy)
    127 {
    128     float *srcdata, *dstdata;
    129     pipi_image_t *dst;
    130     pipi_pixels_t *srcp, *dstp;
    131     int y, off, len;
    132 
    133     srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32);
    134     srcdata = (float *)srcp->pixels;
    135 
    136     dst = pipi_new(w, h);
    137     dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
    138     dstdata = (float *)dstp->pixels;
    139 
    140     off = dx;
    141     len = w;
    142 
    143     if(dx < 0)
    144     {
    145         len += dx;
    146         dx = 0;
    147     }
    148 
    149     if(dx + len > srcp->w)
    150         len = srcp->w - dx;
    151 
    152     if(len > 0)
    153     {
    154         for(y = 0; y < h; y++)
    155         {
    156             if(y + dy < 0 || y + dy >= srcp->h)
    157                 continue;
    158 
    159             memcpy(dstdata + y * w * 4,
    160                    srcdata + ((y + dy) * srcp->w + dx) * 4,
    161                    len * 4 * sizeof(float));
    162         }
    163     }
    164 
    165     return dst;
    166 }
    167 
Note: See TracChangeset for help on using the changeset viewer.