diff options
| author | Nakidai <nakidai@disroot.org> | 2024-09-22 16:05:27 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-09-22 16:05:27 +0300 |
| commit | 13feee2e6c44417f9f5a1a9560eccc463aaef449 (patch) | |
| tree | a4f9734635725d76b0c13f551c9bfb95dca55e64 | |
| download | cpetpet-13feee2e6c44417f9f5a1a9560eccc463aaef449.tar.gz cpetpet-13feee2e6c44417f9f5a1a9560eccc463aaef449.zip | |
Add files
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | LICENSE | 9 | ||||
| -rw-r--r-- | Makefile | 37 | ||||
| -rw-r--r-- | README | 7 | ||||
| -rwxr-xr-x | configure | 46 | ||||
| -rw-r--r-- | cpetpet.c | 74 | ||||
| -rw-r--r-- | cpetpet.h | 9 | ||||
| -rw-r--r-- | share/cpetpet/pet0.gif | bin | 0 -> 2764 bytes | |||
| -rw-r--r-- | share/cpetpet/pet1.gif | bin | 0 -> 2745 bytes | |||
| -rw-r--r-- | share/cpetpet/pet2.gif | bin | 0 -> 3042 bytes | |||
| -rw-r--r-- | share/cpetpet/pet3.gif | bin | 0 -> 3042 bytes | |||
| -rw-r--r-- | share/cpetpet/pet4.gif | bin | 0 -> 2934 bytes | |||
| -rw-r--r-- | share/cpetpet/pet5.gif | bin | 0 -> 2934 bytes | |||
| -rw-r--r-- | share/cpetpet/pet6.gif | bin | 0 -> 2936 bytes | |||
| -rw-r--r-- | share/cpetpet/pet7.gif | bin | 0 -> 2936 bytes | |||
| -rw-r--r-- | share/cpetpet/pet8.gif | bin | 0 -> 2598 bytes | |||
| -rw-r--r-- | share/cpetpet/pet9.gif | bin | 0 -> 2598 bytes |
17 files changed, 187 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2baa8e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +compile_flags.txt +config.* +*.a +*.o +*.so diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..058f14e --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright 2024 nakidai + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..099cbec --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +include config.mk + +CFLAGS += $(shell MagickWand-config --cflags) +CFLAGS += -std=c99 + +LDFLAGS += $(shell MagickWand-config --ldflags --libs) + +RM = rm -f +SRCDIR = src +OBJDIR = obj +OBJS = cpetpet.o + +all: cpetpet.a cpetpet.so + +$(OBJS): config.h cpetpet.h + +cpetpet.a cpetpet.so: $(OBJS) + +cpetpet.so: + cc -shared -o $@ ${LDFLAGS} ${LDLIBS} $^ + +cpetpet.a: + ar rcs $@ $^ + +install: all + install -d $(DESTDIR)/lib $(DESTDIR)/share/cpetpet + install -m644 cpetpet.a $(DESTDIR)/lib + install -m755 cpetpet.so $(DESTDIR)/lib + install -m644 share/cpetpet/* $(DESTDIR)/share/cpetpet + +clean: + $(RM) *.a *.o *.so + +cleanall: clean + $(RM) config.* config.* + +.PHONY: all clean install diff --git a/README b/README new file mode 100644 index 0000000..d2bb695 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +cpetpet +------- +Library for petting some pictures + +For usage check include/cpetpet.c, it's not so big ;) + +This library depends on the imagemagick of version 7 diff --git a/configure b/configure new file mode 100755 index 0000000..b6b0736 --- /dev/null +++ b/configure @@ -0,0 +1,46 @@ +#!/bin/sh + +usage() +{ + echo "Use environment variables to pass values: + CC - compiler (default: cc) + CFLAGS - flags for compiler + LDFLAGS - flags for linker + DESTDIR - path to make install (default: /usr/local)" + exit 1 +} + +while test $# -gt 0; do + case "$1" in + -h) usage + ;; + --help) usage + ;; + esac + shift +done + +CC=${CC:-cc} +CFLAGS=${CFLAGS:-} +LDFLAGS=${LDFLAGS:-} +DESTDIR=${DESTDIR:-/usr/local} + +echo "Configuration: + Compiler: $CC + CFLAGS: $CFLAGS + LDFLAGS: $LDFLAGS + DESTDIR: $DESTDIR" + +echo " +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#define SHAREDIR \"$DESTDIR/share/cpetpet\" +#define FRAMES 10 + +#endif +" > config.h + +echo " +DESTDIR=$DESTDIR +" > config.mk diff --git a/cpetpet.c b/cpetpet.c new file mode 100644 index 0000000..668116a --- /dev/null +++ b/cpetpet.c @@ -0,0 +1,74 @@ +#include <stdarg.h> +#include <stdio.h> + +#include <MagickWand/MagickWand.h> +#include <MagickWand/magick-image.h> +#include <MagickCore/resample.h> +#include <MagickCore/composite.h> +#include <MagickWand/pixel-wand.h> +#include <MagickCore/layer.h> + +#include "config.h" + + +int main(int argc, char **argv) +{ + MagickWand *result, *concat, *hand, *avatar, *edited; + PixelWand *empty; + char filenamebuf[128]; + double squeeze; + double width, height; + double offset_x, offset_y; + + MagickWandGenesis(); + + empty = NewPixelWand(); + + result = NewMagickWand(); + concat = NewMagickWand(); + avatar = NewMagickWand(); + concat = NewMagickWand(); + hand = NewMagickWand(); + + PixelSetColor(empty, "none"); + + MagickSetImageDispose(result, BackgroundDispose); + + MagickReadImage(avatar, "naki.png"); + MagickResizeImage(avatar, 128, 128, Lanczos2Filter); + + for (int i = 0; i < FRAMES; ++i) + { + squeeze = (i < FRAMES/2) ? i : FRAMES - i; + width = 0.8 + squeeze * 0.02; + height = 0.8 - squeeze * 0.05; + offset_x = (1 - width) * 0.5 + 0.1; + offset_y = (1 - height) - 0.08; + snprintf(filenamebuf, sizeof(filenamebuf), SHAREDIR "/pet%d.gif", i); + + edited = CloneMagickWand(avatar); + MagickNewImage(concat, MagickGetImageWidth(avatar), MagickGetImageHeight(avatar), empty); + MagickSetImageDispose(concat, BackgroundDispose); + MagickSetImageDelay(concat, 2); + MagickResizeImage(edited, (double)MagickGetImageWidth(avatar)*width, (double)MagickGetImageHeight(avatar)*height, Lanczos2Filter); + MagickReadImage(hand, filenamebuf); + + MagickCompositeImage(concat, edited, OverCompositeOp, MagickTrue, MagickGetImageWidth(concat)*offset_x, MagickGetImageHeight(concat)*offset_y); + MagickCompositeImage(concat, hand, OverCompositeOp, MagickTrue, 0, 0); + MagickAddImage(result, concat); + + ClearMagickWand(concat); + ClearMagickWand(hand); + } + MagickWriteImages(result, "petpet.gif", MagickTrue); + + DestroyMagickWand(result); + DestroyMagickWand(concat); + DestroyMagickWand(avatar); + DestroyMagickWand(edited); + DestroyMagickWand(hand); + + DestroyPixelWand(empty); + + MagickWandTerminus(); +} diff --git a/cpetpet.h b/cpetpet.h new file mode 100644 index 0000000..cbd3ced --- /dev/null +++ b/cpetpet.h @@ -0,0 +1,9 @@ +#ifndef __PETPET_C__ +#define __PETPET_C__ + +#include <stddef.h> + + +void CPetPet(const char *in, const char *out, const size_t speed); + +#endif /* __PETPET_C__ */ diff --git a/share/cpetpet/pet0.gif b/share/cpetpet/pet0.gif new file mode 100644 index 0000000..09c40d4 --- /dev/null +++ b/share/cpetpet/pet0.gif Binary files differdiff --git a/share/cpetpet/pet1.gif b/share/cpetpet/pet1.gif new file mode 100644 index 0000000..f3f1fdc --- /dev/null +++ b/share/cpetpet/pet1.gif Binary files differdiff --git a/share/cpetpet/pet2.gif b/share/cpetpet/pet2.gif new file mode 100644 index 0000000..ee33972 --- /dev/null +++ b/share/cpetpet/pet2.gif Binary files differdiff --git a/share/cpetpet/pet3.gif b/share/cpetpet/pet3.gif new file mode 100644 index 0000000..e70c930 --- /dev/null +++ b/share/cpetpet/pet3.gif Binary files differdiff --git a/share/cpetpet/pet4.gif b/share/cpetpet/pet4.gif new file mode 100644 index 0000000..4d09c16 --- /dev/null +++ b/share/cpetpet/pet4.gif Binary files differdiff --git a/share/cpetpet/pet5.gif b/share/cpetpet/pet5.gif new file mode 100644 index 0000000..e250e13 --- /dev/null +++ b/share/cpetpet/pet5.gif Binary files differdiff --git a/share/cpetpet/pet6.gif b/share/cpetpet/pet6.gif new file mode 100644 index 0000000..09dedb3 --- /dev/null +++ b/share/cpetpet/pet6.gif Binary files differdiff --git a/share/cpetpet/pet7.gif b/share/cpetpet/pet7.gif new file mode 100644 index 0000000..a467e92 --- /dev/null +++ b/share/cpetpet/pet7.gif Binary files differdiff --git a/share/cpetpet/pet8.gif b/share/cpetpet/pet8.gif new file mode 100644 index 0000000..f9fb14c --- /dev/null +++ b/share/cpetpet/pet8.gif Binary files differdiff --git a/share/cpetpet/pet9.gif b/share/cpetpet/pet9.gif new file mode 100644 index 0000000..f9fb14c --- /dev/null +++ b/share/cpetpet/pet9.gif Binary files differ |