Просмотр исходного кода

* Fixed a bug in the naive resizing code.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2246 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 17 лет назад
Родитель
Сommit
bf052a018a
2 измененных файлов: 12 добавлений и 12 удалений
  1. +1
    -1
      genethumb/genethumb.c
  2. +11
    -11
      pipi/resize.c

+ 1
- 1
genethumb/genethumb.c Просмотреть файл

@@ -8,7 +8,7 @@ int main(void)
pipi_image_t *i, *j;

i = pipi_load("irc.png");
j = pipi_resize(i, 1000, 114);
j = pipi_resize(i, 240, 240);
pipi_save(j, "irc.bmp");
pipi_free(i);
pipi_free(j);


+ 11
- 11
pipi/resize.c Просмотреть файл

@@ -19,6 +19,9 @@
#include "config.h"
#include "common.h"

#include <stdlib.h>
#include <string.h>

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

@@ -26,7 +29,7 @@ pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
{
int *aline, *line;
pipi_image_t *dst;
int x, y, x0, y0, sw, dw, sh, dh, remy = 0;
int x, y, x0, y0, sw, dw, sh, dh, remy;

dst = pipi_new(w, h);

@@ -36,22 +39,26 @@ pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
aline = malloc(3 * dw * sizeof(int));
line = malloc(3 * dw * sizeof(int));

memset(line, 0, 3 * dw * sizeof(int));
remy = 0;

for(y = 0, y0 = 0; y < dst->height; y++)
{
int toty = 0, ny;

memset(aline, 0, 3 * dw * sizeof(int));
memset(line, 0, 3 * dw * sizeof(int));

while(toty < sh)
{
if(remy == 0)
{
int r = 0, g = 0, b = 0;
int remx = 0;

for(x = 0, x0 = 0; x < dst->width; x++)
{
int remx = 0, totx = 0, nx;
int ar = 0, ag = 0, ab = 0;
int r = 0, g = 0, b = 0;
int totx = 0, nx;

while(totx < sw)
{
@@ -71,13 +78,10 @@ pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
line[3 * x] = ar;
line[3 * x + 1] = ag;
line[3 * x + 2] = ab;
/* HACK */
pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
}

y0++;
remy = dh;
//printf(" remy is now %i\n", remy);
}

ny = (toty + remy <= sh) ? remy : sh - toty;
@@ -89,17 +93,13 @@ pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
}
toty += ny;
remy -= ny;
//printf(" remy-- %i\n", remy);
}
//printf("pasting line %i (src line now %i)\n", y, y0);

#if 0
for(x = 0; x < dst->width; x++)
pipi_setpixel(dst, x, y,
aline[3 * x] / (sw * sh),
aline[3 * x + 1] / (sw * sh),
aline[3 * x + 2] / (sw * sh));
#endif
}

free(aline);


Загрузка…
Отмена
Сохранить