- revert horizontal/vertical, was too confusing, it acts now like any application (ie. gimp/ps) instead of talking about h/v axis - optimize both - add simple examplemaster
parent
c9972ade56
commit
41d830e0c1
|
@ -3,10 +3,19 @@ include_directories (BEFORE ${GD_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}")
|
|||
|
||||
|
||||
SET(TESTS_FILES
|
||||
tgaread
|
||||
tiffread
|
||||
resize
|
||||
copyrotated
|
||||
ellipseaa
|
||||
ellipse
|
||||
arc
|
||||
ellipsearc
|
||||
flip
|
||||
crop
|
||||
nnquant
|
||||
gif
|
||||
ellfullaa
|
||||
tgaread
|
||||
nnquant
|
||||
gif
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/* $Id$ */
|
||||
#include "gd.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
gdImagePtr loadImage(const char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
gdImagePtr im;
|
||||
|
||||
fp = fopen(name, "rb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Can't open jpeg file\n");
|
||||
gdImageDestroy(im);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
im = gdImageCreateFromJpeg(fp);
|
||||
fclose(fp);
|
||||
return im;
|
||||
}
|
||||
|
||||
int savePngImage(gdImagePtr im, const char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
fp = fopen(name, "wb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Can't save png image fromtiff.png\n");
|
||||
return 0;
|
||||
}
|
||||
gdImagePng(im, fp);
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **arg)
|
||||
{
|
||||
gdImagePtr im;
|
||||
int returncode = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: flip [filename.png]\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
im = loadImage(arg[1]);
|
||||
if (!im) goto error;
|
||||
gdImageFlipHorizontal(im);
|
||||
if (!savePngImage(im, "flip_horizontal.png")) {
|
||||
goto error;
|
||||
}
|
||||
gdImageDestroy(im);
|
||||
|
||||
im = loadImage(arg[1]);
|
||||
if (!im) goto error;
|
||||
gdImageFlipVertical(im);
|
||||
if (!savePngImage(im, "flip_vertical.png")) {
|
||||
goto error;
|
||||
}
|
||||
gdImageDestroy(im);
|
||||
|
||||
im = loadImage(arg[1]);
|
||||
if (!im) goto error;
|
||||
gdImageFlipBoth(im);
|
||||
if (!savePngImage(im, "flip_both.png")) {
|
||||
goto error;
|
||||
}
|
||||
gdImageDestroy(im);
|
||||
|
||||
goto done;
|
||||
|
||||
error:
|
||||
returncode = 1;
|
||||
|
||||
done:
|
||||
return returncode;
|
||||
}
|
|
@ -104,9 +104,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx)
|
|||
if (tga->flipv && tga->fliph) {
|
||||
gdImageFlipBoth(image);
|
||||
} else if (tga->flipv) {
|
||||
gdImageFlipHorizontal(image);
|
||||
} else if (tga->fliph) {
|
||||
gdImageFlipVertical(image);
|
||||
} else if (tga->fliph) {
|
||||
gdImageFlipHorizontal(image);
|
||||
}
|
||||
|
||||
free_tga(tga);
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#include "gd.h"
|
||||
|
||||
BGD_DECLARE(void)
|
||||
gdImageFlipHorizontal(gdImagePtr im)
|
||||
BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im)
|
||||
{
|
||||
register int x, y;
|
||||
|
||||
|
||||
if (im->trueColor) {
|
||||
int p;
|
||||
for (y = 0; y < im->sy / 2; y++) {
|
||||
int *row_dst = im->tpixels[y];
|
||||
int *row_src = im->tpixels[im->sy - 1 - y];
|
||||
for (x = 0; x < im->sx; x++) {
|
||||
p = im->tpixels[y][x];
|
||||
im->tpixels[y][x] = im->tpixels[im->sy - 1 - y][x];
|
||||
im->tpixels[im->sy - 1 - y][x] = p;
|
||||
register int p;
|
||||
p = row_dst[x];
|
||||
row_dst[x] = im->tpixels[im->sy - 1 - y][x];
|
||||
row_src[x] = p;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -24,44 +24,50 @@ gdImageFlipHorizontal(gdImagePtr im)
|
|||
im->tpixels[im->sy - 1 - y][x] = p;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BGD_DECLARE(void)
|
||||
gdImageFlipVertical(gdImagePtr im)
|
||||
BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im)
|
||||
{
|
||||
|
||||
int x, y;
|
||||
|
||||
if (im->trueColor) {
|
||||
int p;
|
||||
int *px1, *px2, tmp;
|
||||
|
||||
for (y = 0; y < im->sy; y++) {
|
||||
for (x = 0; x < im->sx / 2; x++) {
|
||||
p = im->tpixels[y][x];
|
||||
im->tpixels[y][x] = im->tpixels[y][im->sx - 1 - x];
|
||||
im->tpixels[y][im->sx - 1 - x] = p;
|
||||
px1 = im->tpixels[y];
|
||||
px2 = im->tpixels[y] + im->sx - 1;
|
||||
for (x = 0; x < (im->sx >> 1); x++) {
|
||||
tmp = *px1;
|
||||
*px1 = *px2;
|
||||
*px2 = tmp;
|
||||
px1++;
|
||||
px2--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsigned char p;
|
||||
unsigned char *px1, *px2, tmp;
|
||||
|
||||
for (y = 0; y < im->sy; y++) {
|
||||
for (x = 0; x < im->sx / 2; x++) {
|
||||
p = im->pixels[y][x];
|
||||
im->pixels[y][x] = im->pixels[y][im->sx - 1 - x];
|
||||
im->pixels[y][im->sx - 1 - x] = p;
|
||||
px1 = im->pixels[y];
|
||||
px2 = im->pixels[y] + im->sx - 1;
|
||||
for (x = 0; x < (im->sx >> 1); x++) {
|
||||
tmp = *px1;
|
||||
*px1 = *px2;
|
||||
*px2 = tmp;
|
||||
px1++;
|
||||
px2--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BGD_DECLARE(void)
|
||||
gdImageFlipBoth(gdImagePtr im)
|
||||
BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im)
|
||||
{
|
||||
gdImageFlipVertical(im);
|
||||
gdImageFlipHorizontal(im);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue