other resizing methods. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@4690 92316355-f0b4-4df1-b90c-862c8a59935fmaster
| @@ -25,11 +25,12 @@ libpipi_la_SOURCES = \ | |||
| codec.c \ | |||
| stock.c \ | |||
| colorstring.c \ | |||
| resize.c \ | |||
| crop.c \ | |||
| dither.c \ | |||
| accessors.c \ | |||
| sequence.c \ | |||
| $(codec_sources) \ | |||
| $(resample_sources) \ | |||
| $(paint_sources) \ | |||
| $(render_sources) \ | |||
| $(combine_sources) \ | |||
| @@ -49,6 +50,9 @@ codec_libs = | |||
| codec_sources = \ | |||
| codec/oric.c | |||
| resample_sources = \ | |||
| resample/bresenham.c | |||
| paint_sources = \ | |||
| paint/floodfill.c \ | |||
| paint/line.c \ | |||
| @@ -0,0 +1,68 @@ | |||
| /* | |||
| * libpipi Pathetic image processing interface library | |||
| * Copyright (c) 2004-2009 Sam Hocevar <sam@hocevar.net> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id$ | |||
| * | |||
| * This library is free software. It comes without any warranty, to | |||
| * the extent permitted by applicable law. You can redistribute it | |||
| * and/or modify it under the terms of the Do What The Fuck You Want | |||
| * To Public License, Version 2, as published by Sam Hocevar. See | |||
| * http://sam.zoy.org/wtfpl/COPYING for more details. | |||
| */ | |||
| /* | |||
| * crop.c: image cropping functions | |||
| */ | |||
| #include "config.h" | |||
| #include <stdlib.h> | |||
| #include <string.h> | |||
| #include "pipi.h" | |||
| #include "pipi_internals.h" | |||
| pipi_image_t *pipi_crop(pipi_image_t *src, int w, int h, int dx, int dy) | |||
| { | |||
| float *srcdata, *dstdata; | |||
| pipi_image_t *dst; | |||
| pipi_pixels_t *srcp, *dstp; | |||
| int y, off, len; | |||
| srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32); | |||
| srcdata = (float *)srcp->pixels; | |||
| dst = pipi_new(w, h); | |||
| dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); | |||
| dstdata = (float *)dstp->pixels; | |||
| off = dx; | |||
| len = w; | |||
| if(dx < 0) | |||
| { | |||
| len += dx; | |||
| dx = 0; | |||
| } | |||
| if(dx + len > srcp->w) | |||
| len = srcp->w - dx; | |||
| if(len > 0) | |||
| { | |||
| for(y = 0; y < h; y++) | |||
| { | |||
| if(y + dy < 0 || y + dy >= srcp->h) | |||
| continue; | |||
| memcpy(dstdata + y * w * 4, | |||
| srcdata + ((y + dy) * srcp->w + dx) * 4, | |||
| len * 4 * sizeof(float)); | |||
| } | |||
| } | |||
| return dst; | |||
| } | |||
| @@ -239,7 +239,7 @@ | |||
| > | |||
| </File> | |||
| <File | |||
| RelativePath=".\resize.c" | |||
| RelativePath=".\crop.c" | |||
| > | |||
| </File> | |||
| <File | |||
| @@ -270,6 +270,14 @@ | |||
| > | |||
| </File> | |||
| </Filter> | |||
| <Filter | |||
| Name="resample" | |||
| > | |||
| <File | |||
| RelativePath=".\resample\bresenham.c" | |||
| > | |||
| </File> | |||
| </Filter> | |||
| <Filter | |||
| Name="combine" | |||
| > | |||
| @@ -1,6 +1,6 @@ | |||
| /* | |||
| * libpipi Pathetic image processing interface library | |||
| * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
| * Copyright (c) 2004-2009 Sam Hocevar <sam@hocevar.net> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id$ | |||
| @@ -13,7 +13,7 @@ | |||
| */ | |||
| /* | |||
| * resize.c: image resizing functions | |||
| * bresenham.c: Bresenham image resizing functions | |||
| */ | |||
| #include "config.h" | |||
| @@ -24,6 +24,10 @@ | |||
| #include "pipi.h" | |||
| #include "pipi_internals.h" | |||
| /* This is Bresenham resizing. I rediscovered it independently but it was | |||
| * actually first described in 1995 by Tim Kientzle in "Scaling Bitmaps | |||
| * with Bresenham". */ | |||
| /* FIXME: the algorithm does not handle alpha components properly. Resulting | |||
| * alpha should be the mean alpha value of the neightbouring pixels, but | |||
| * the colour components should be weighted with the alpha value. */ | |||
| @@ -123,45 +127,3 @@ pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h) | |||
| return dst; | |||
| } | |||
| pipi_image_t *pipi_crop(pipi_image_t *src, int w, int h, int dx, int dy) | |||
| { | |||
| float *srcdata, *dstdata; | |||
| pipi_image_t *dst; | |||
| pipi_pixels_t *srcp, *dstp; | |||
| int y, off, len; | |||
| srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32); | |||
| srcdata = (float *)srcp->pixels; | |||
| dst = pipi_new(w, h); | |||
| dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); | |||
| dstdata = (float *)dstp->pixels; | |||
| off = dx; | |||
| len = w; | |||
| if(dx < 0) | |||
| { | |||
| len += dx; | |||
| dx = 0; | |||
| } | |||
| if(dx + len > srcp->w) | |||
| len = srcp->w - dx; | |||
| if(len > 0) | |||
| { | |||
| for(y = 0; y < h; y++) | |||
| { | |||
| if(y + dy < 0 || y + dy >= srcp->h) | |||
| continue; | |||
| memcpy(dstdata + y * w * 4, | |||
| srcdata + ((y + dy) * srcp->w + dx) * 4, | |||
| len * 4 * sizeof(float)); | |||
| } | |||
| } | |||
| return dst; | |||
| } | |||