| 1 |
/* Exercise all scaling with all interpolation modes and ensure that |
| 2 |
* at least, something comes back. */ |
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#include "gd.h" |
| 7 |
|
| 8 |
#define X 100 |
| 9 |
#define Y 100 |
| 10 |
|
| 11 |
#define NX 100 |
| 12 |
#define NY 100 |
| 13 |
|
| 14 |
gdImagePtr loadImage(const char *name) |
| 15 |
{ |
| 16 |
FILE *fp; |
| 17 |
gdImagePtr im; |
| 18 |
|
| 19 |
fp = fopen(name, "rb"); |
| 20 |
if (!fp) { |
| 21 |
fprintf(stderr, "Can't open jpeg file\n"); |
| 22 |
return NULL; |
| 23 |
} |
| 24 |
|
| 25 |
im = gdImageCreateFromPng(fp); |
| 26 |
fclose(fp); |
| 27 |
return im; |
| 28 |
} |
| 29 |
|
| 30 |
int savePngImage(gdImagePtr im, const char *name) |
| 31 |
{ |
| 32 |
FILE *fp; |
| 33 |
fp = fopen(name, "wb"); |
| 34 |
if (!fp) { |
| 35 |
fprintf(stderr, "Can't save png image fromtiff.png\n"); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
gdImagePng(im, fp); |
| 39 |
fclose(fp); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
|
| 43 |
int main() { |
| 44 |
unsigned int method; |
| 45 |
gdImagePtr src; |
| 46 |
src = loadImage("fillandstroke.png"); |
| 47 |
if (!src) { |
| 48 |
printf("cannot open src image"); |
| 49 |
exit(1); |
| 50 |
} |
| 51 |
int new_width = gdImageSX(src) *3; |
| 52 |
int new_height = gdImageSY(src) *3; |
| 53 |
for(method = GD_DEFAULT; method < GD_METHOD_COUNT; method++) { /* GD_WEIGHTED4 is unsupported. */ |
| 54 |
gdImagePtr result; |
| 55 |
if (method == GD_WEIGHTED4) { |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
gdImageSetInterpolationMethod(src, method); |
| 60 |
printf("arg %i set: %i get %i\n", method, src->interpolation_id, gdImageGetInterpolationMethod(src)); |
| 61 |
|
| 62 |
result = gdImageScale(src, new_width, new_height); |
| 63 |
if (result == NULL) { |
| 64 |
printf("gdImageScale failed (method: %i).\n", method); |
| 65 |
break; |
| 66 |
} |
| 67 |
if (result->sx != new_width || result->sy != new_height) { |
| 68 |
printf("missmatch width or height\n"); |
| 69 |
gdImageDestroy(result); |
| 70 |
gdImageDestroy(src); |
| 71 |
exit(1); |
| 72 |
} |
| 73 |
|
| 74 |
char filename[255]; |
| 75 |
sprintf(filename, "scale_%i.png", method); |
| 76 |
savePngImage(result, filename); |
| 77 |
gdImageDestroy(result); |
| 78 |
}/* for*/ |
| 79 |
gdImageDestroy(src); |
| 80 |
|
| 81 |
return 0; |
| 82 |
} |