 Timestamp:
 Feb 21, 2009, 3:26:24 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpipi/trunk/pipi/resize.c
r3342 r3398 25 25 #include "pipi_internals.h" 26 26 27 /* FIXME: the algorithm does not handle alpha components properly. Resulting 28 * alpha should be the mean alpha value of the neightbouring pixels, but 29 * the colour components should be weighted with the alpha value. */ 27 30 pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h) 28 31 { … … 42 45 dw = dst>w; dh = dst>h; 43 46 44 aline = malloc( 3* dw * sizeof(float));45 line = malloc( 3* dw * sizeof(float));47 aline = malloc(4 * dw * sizeof(float)); 48 line = malloc(4 * dw * sizeof(float)); 46 49 47 memset(line, 0, 3* dw * sizeof(float));50 memset(line, 0, 4 * dw * sizeof(float)); 48 51 remy = 0; 49 52 … … 52 55 int toty = 0, ny; 53 56 54 memset(aline, 0, 3* dw * sizeof(float));57 memset(aline, 0, 4 * dw * sizeof(float)); 55 58 56 59 while(toty < sh) … … 58 61 if(remy == 0) 59 62 { 60 float r = 0, g = 0, b = 0 ;63 float r = 0, g = 0, b = 0, a = 0; 61 64 int remx = 0; 62 65 63 66 for(x = 0, x0 = 0; x < dw; x++) 64 67 { 65 float ar = 0, ag = 0, ab = 0 ;68 float ar = 0, ag = 0, ab = 0, aa = 0; 66 69 int totx = 0, nx; 67 70 … … 73 76 g = srcdata[(y0 * sw + x0) * 4 + 1]; 74 77 b = srcdata[(y0 * sw + x0) * 4 + 2]; 78 a = srcdata[(y0 * sw + x0) * 4 + 3]; 75 79 x0++; 76 80 remx = dw; … … 78 82 79 83 nx = (totx + remx <= sw) ? remx : sw  totx; 80 ar += nx * r; ag += nx * g; ab += nx * b; 84 ar += nx * r; ag += nx * g; ab += nx * b; aa += nx * a; 81 85 totx += nx; 82 86 remx = nx; 83 87 } 84 88 85 line[3 * x] = ar; 86 line[3 * x + 1] = ag; 87 line[3 * x + 2] = ab; 89 line[4 * x] = ar; 90 line[4 * x + 1] = ag; 91 line[4 * x + 2] = ab; 92 line[4 * x + 3] = aa; 88 93 } 89 94 … … 95 100 for(x = 0; x < dw; x++) 96 101 { 97 aline[3 * x] += ny * line[3 * x]; 98 aline[3 * x + 1] += ny * line[3 * x + 1]; 99 aline[3 * x + 2] += ny * line[3 * x + 2]; 102 aline[4 * x] += ny * line[4 * x]; 103 aline[4 * x + 1] += ny * line[4 * x + 1]; 104 aline[4 * x + 2] += ny * line[4 * x + 2]; 105 aline[4 * x + 3] += ny * line[4 * x + 3]; 100 106 } 101 107 toty += ny; … … 105 111 for(x = 0; x < dw; x++) 106 112 { 107 dstdata[(y * dw + x) * 4] = aline[3 * x] / (sw * sh); 108 dstdata[(y * dw + x) * 4 + 1] = aline[3 * x + 1] / (sw * sh); 109 dstdata[(y * dw + x) * 4 + 2] = aline[3 * x + 2] / (sw * sh); 113 dstdata[(y * dw + x) * 4] = aline[4 * x] / (sw * sh); 114 dstdata[(y * dw + x) * 4 + 1] = aline[4 * x + 1] / (sw * sh); 115 dstdata[(y * dw + x) * 4 + 2] = aline[4 * x + 2] / (sw * sh); 116 dstdata[(y * dw + x) * 4 + 3] = aline[4 * x + 3] / (sw * sh); 110 117 } 111 118 }
Note: See TracChangeset
for help on using the changeset viewer.