瀏覽代碼

* Starting image resizing. X-wise resize works so far.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2244 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 年之前
父節點
當前提交
84cc96a98e
共有 4 個文件被更改,包括 80 次插入0 次删除
  1. +13
    -0
      genethumb/genethumb.c
  2. +1
    -0
      pipi/Makefile.am
  3. +2
    -0
      pipi/pipi.h
  4. +64
    -0
      pipi/resize.c

+ 13
- 0
genethumb/genethumb.c 查看文件

@@ -1,5 +1,18 @@
#include "config.h"
#include "common.h"

#include <pipi.h>

int main(void)
{
pipi_image_t *i, *j;

i = pipi_load("irc.png");
j = pipi_resize(i, 100, 200);
pipi_save(j, "irc.bmp");
pipi_free(i);
pipi_free(j);

return 0;
}


+ 1
- 0
pipi/Makefile.am 查看文件

@@ -17,6 +17,7 @@ libpipi_la_SOURCES = \
pipi_internals.h \
io.c \
pixels.c \
resize.c \
$(NULL)
libpipi_la_CFLAGS = $(CFLAGS_EXTRA)
libpipi_la_LDFLAGS = $(LDFLAGS_EXTRA) \


+ 2
- 0
pipi/pipi.h 查看文件

@@ -37,6 +37,8 @@ extern int pipi_getpixel(pipi_image_t const *img,
int x, int y, int *r, int *g, int *b);
extern int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b);

extern pipi_image_t *pipi_resize(pipi_image_t const *, int, int);

#ifdef __cplusplus
}
#endif


+ 64
- 0
pipi/resize.c 查看文件

@@ -0,0 +1,64 @@
/*
* libpipi Proper image processing implementation library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* 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.
*/

/*
* resize.c: image resizing functions
*/

#include "config.h"
#include "common.h"

#include "pipi_internals.h"
#include "pipi.h"

pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
{
pipi_image_t *dst;
int x, y, x0, y0;
dst = pipi_new(w, h);

int sw = src->width;
int dw = dst->width;

for(y = 0, y0 = 0; y < dst->height; y++)
{
for(x = 0, x0 = 0; x < dst->width; x++)
{
int rem = 0, tot = 0;
int ar = 0, ag = 0, ab = 0;
int r = 0, g = 0, b = 0;
int n;

while(tot < sw)
{
if(rem == 0)
{
pipi_getpixel(src, x0, y, &r, &g, &b);
x0++;
rem = dw;
}

n = (tot + rem <= sw) ? rem : sw - tot;
ar += n * r; ag += n * g; ab += n * b;
tot += n;
rem -= n;
}

pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
}
}

return dst;
}


Loading…
取消
儲存