소스 검색

* Image resizing test.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2245 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 17 년 전
부모
커밋
00a1db9608
2개의 변경된 파일66개의 추가작업 그리고 20개의 파일을 삭제
  1. +1
    -1
      genethumb/genethumb.c
  2. +65
    -19
      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, 100, 200);
j = pipi_resize(i, 1000, 114);
pipi_save(j, "irc.bmp");
pipi_free(i);
pipi_free(j);


+ 65
- 19
pipi/resize.c 파일 보기

@@ -24,41 +24,87 @@

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;
int x, y, x0, y0, sw, dw, sh, dh, remy = 0;

dst = pipi_new(w, h);

int sw = src->width;
int dw = dst->width;
sw = src->width; sh = src->height;
dw = dst->width; dh = dst->height;

aline = malloc(3 * dw * sizeof(int));
line = malloc(3 * dw * sizeof(int));

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;
int toty = 0, ny;

while(tot < sw)
memset(aline, 0, 3 * dw * sizeof(int));
memset(line, 0, 3 * dw * sizeof(int));

while(toty < sh)
{
if(remy == 0)
{
if(rem == 0)
for(x = 0, x0 = 0; x < dst->width; x++)
{
pipi_getpixel(src, x0, y, &r, &g, &b);
x0++;
rem = dw;
int remx = 0, totx = 0, nx;
int ar = 0, ag = 0, ab = 0;
int r = 0, g = 0, b = 0;

while(totx < sw)
{
if(remx == 0)
{
pipi_getpixel(src, x0, y0, &r, &g, &b);
x0++;
remx = dw;
}

nx = (totx + remx <= sw) ? remx : sw - totx;
ar += nx * r; ag += nx * g; ab += nx * b;
totx += nx;
remx -= nx;
}

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);
}

n = (tot + rem <= sw) ? rem : sw - tot;
ar += n * r; ag += n * g; ab += n * b;
tot += n;
rem -= n;
y0++;
remy = dh;
//printf(" remy is now %i\n", remy);
}

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

return dst;
}


불러오는 중...
취소
저장