1
0
mirror of https://frontier.innolan.net/github/AmigaExamples.git synced 2026-01-11 23:37:03 +00:00

First pass at resize utility

This commit is contained in:
alpine9000
2016-03-12 10:51:08 +11:00
parent 49c4785873
commit a601a38f83
3 changed files with 147 additions and 0 deletions

View File

@ -101,3 +101,13 @@ Notes:
# cp *.h /usr/local/include/pngquant/
# cp *.a /usr/local/lib
```
9. GraphicsMagick
```
# wget http://78.108.103.11/MIRROR/ftp/GraphicsMagick/1.3/GraphicsMagick-1.3.23.tar.gz
# tar zxfv GraphicsMagick-1.3.23.tar.gz
# cd GraphicsMagick-1.3.23
# ./configure --prefix=/usr/local
# make
# make install
```

27
tools/resize/Makefile Normal file
View File

@ -0,0 +1,27 @@
PROGRAM=./out/resize
OBJS=out/resize.o
WARN_ERROR=-Werror
HOST_WARNINGS=$(WARN_ERROR) -pedantic-errors -Wfatal-errors -Wall -Wextra -Wno-unused-parameter -Wshadow -limagequant
HOST_CFLAGS=$(HOST_WARNINGS) -O3 `GraphicsMagick-config --cppflags`
LIBS=`GraphicsMagick-config --ldflags --libs`
$(PROGRAM): out bin $(OBJS)
gcc $(OBJS) -o $(PROGRAM) $(LIBS)
-include $(OBJS:.o=.d)
out/%.o: %.c
gcc -c $(HOST_CFLAGS) $< -o $@
@gcc -MM $(HOST_CFLAGS) $*.c > out/$*.d
@mv -f out/$*.d out/$*.d.tmp
@sed 's/^.*\:/out\/&/' < out/$*.d.tmp > out/$*.d
@rm -f out/$*.d.tmp
out:
mkdir out
bin:
mkdir bin
clean:
rm -rf out bin *~

110
tools/resize/resize.c Normal file
View File

@ -0,0 +1,110 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <magick/api.h>
int
main(int argc, char **argv)
{
Image *image = 0, *resizeImage = 0, *croppedImage = 0;
char infile[MaxTextExtent];
char outfile[MaxTextExtent];
int arg = 1, exit_status = 0;
ImageInfo *imageInfo;
ExceptionInfo exception;
InitializeMagick(NULL);
imageInfo=CloneImageInfo(0);
GetExceptionInfo(&exception);
#if 0
const int targetWidth = 320;
const int targetHeight = 256;
const int interlaced = 0;
const float blur = 0.75;
#else
const int targetWidth = 320;
const int targetHeight = 512;
const int interlaced = 1;
const float blur = 0.75;
#endif
if (argc != 3) {
(void) fprintf ( stderr, "Usage: %s infile outfile\n", argv[0] );
(void) fflush(stderr);
exit_status = 1;
goto program_exit;
}
(void) strncpy(infile, argv[arg], MaxTextExtent-1 );
arg++;
(void) strncpy(outfile, argv[arg], MaxTextExtent-1 );
(void) strcpy(imageInfo->filename, infile);
image = ReadImage(imageInfo, &exception);
if (image == (Image *) NULL) {
CatchException(&exception);
exit_status = 1;
goto program_exit;
}
int width = image->columns;
int height = image->rows;
float scale = (float)height/(float)targetHeight;
int newWidth = width/scale;
resizeImage=ResizeImage(image, newWidth/(interlaced?2:1), targetHeight,
//GaussianFilter,
//BoxFilter,
//TriangleFilter,
//HermiteFilter,
//HanningFilter,
//HammingFilter,
//BlackmanFilter,
//GaussianFilter,
//QuadraticFilter,
//CubicFilter,
//CatromFilter,
//MitchellFilter,
//LanczosFilter,
BesselFilter,
//SincFilter,
blur, &exception);
RectangleInfo rect = {
.x = ((newWidth/(interlaced?2:1))-targetWidth)/2,
.y = 0,
.width = targetWidth,
.height = targetHeight
};
croppedImage = CropImage(resizeImage, &rect, &exception);
(void) strcpy(croppedImage->filename, outfile);
if (!WriteImage (imageInfo, croppedImage))
{
CatchException(&croppedImage->exception);
exit_status = 1;
goto program_exit;
}
program_exit:
if (image != (Image *) NULL)
DestroyImage(image);
if (resizeImage != (Image *)NULL)
DestroyImage(resizeImage);
if (croppedImage != (Image *)NULL)
DestroyImage(croppedImage);
if (imageInfo != (ImageInfo *) NULL)
DestroyImageInfo(imageInfo);
DestroyMagick();
return exit_status;
}