Ver código fonte

* 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 anos atrás
pai
commit
bf052a018a
2 arquivos alterados com 12 adições e 12 exclusões
  1. +1
    -1
      genethumb/genethumb.c
  2. +11
    -11
      pipi/resize.c

+ 1
- 1
genethumb/genethumb.c Ver arquivo

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


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


+ 11
- 11
pipi/resize.c Ver arquivo

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


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

#include "pipi_internals.h" #include "pipi_internals.h"
#include "pipi.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; int *aline, *line;
pipi_image_t *dst; 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); 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)); aline = malloc(3 * dw * sizeof(int));
line = 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++) for(y = 0, y0 = 0; y < dst->height; y++)
{ {
int toty = 0, ny; int toty = 0, ny;


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


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

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


while(totx < sw) 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] = ar;
line[3 * x + 1] = ag; line[3 * x + 1] = ag;
line[3 * x + 2] = ab; line[3 * x + 2] = ab;
/* HACK */
pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
} }


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


ny = (toty + remy <= sh) ? remy : sh - toty; ny = (toty + remy <= sh) ? remy : sh - toty;
@@ -89,17 +93,13 @@ pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
} }
toty += ny; toty += ny;
remy -= 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++) for(x = 0; x < dst->width; x++)
pipi_setpixel(dst, x, y, pipi_setpixel(dst, x, y,
aline[3 * x] / (sw * sh), aline[3 * x] / (sw * sh),
aline[3 * x + 1] / (sw * sh), aline[3 * x + 1] / (sw * sh),
aline[3 * x + 2] / (sw * sh)); aline[3 * x + 2] / (sw * sh));
#endif
} }


free(aline); free(aline);


Carregando…
Cancelar
Salvar