From 13feee2e6c44417f9f5a1a9560eccc463aaef449 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sun, 22 Sep 2024 16:05:27 +0300 Subject: Add files --- .gitignore | 5 ++++ LICENSE | 9 ++++++ Makefile | 37 +++++++++++++++++++++++++ README | 7 +++++ configure | 46 ++++++++++++++++++++++++++++++ cpetpet.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ cpetpet.h | 9 ++++++ share/cpetpet/pet0.gif | Bin 0 -> 2764 bytes share/cpetpet/pet1.gif | Bin 0 -> 2745 bytes share/cpetpet/pet2.gif | Bin 0 -> 3042 bytes share/cpetpet/pet3.gif | Bin 0 -> 3042 bytes share/cpetpet/pet4.gif | Bin 0 -> 2934 bytes share/cpetpet/pet5.gif | Bin 0 -> 2934 bytes share/cpetpet/pet6.gif | Bin 0 -> 2936 bytes share/cpetpet/pet7.gif | Bin 0 -> 2936 bytes share/cpetpet/pet8.gif | Bin 0 -> 2598 bytes share/cpetpet/pet9.gif | Bin 0 -> 2598 bytes 17 files changed, 187 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100755 configure create mode 100644 cpetpet.c create mode 100644 cpetpet.h create mode 100644 share/cpetpet/pet0.gif create mode 100644 share/cpetpet/pet1.gif create mode 100644 share/cpetpet/pet2.gif create mode 100644 share/cpetpet/pet3.gif create mode 100644 share/cpetpet/pet4.gif create mode 100644 share/cpetpet/pet5.gif create mode 100644 share/cpetpet/pet6.gif create mode 100644 share/cpetpet/pet7.gif create mode 100644 share/cpetpet/pet8.gif create mode 100644 share/cpetpet/pet9.gif 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 +#include + +#include +#include +#include +#include +#include +#include + +#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 + + +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 Binary files /dev/null and b/share/cpetpet/pet0.gif differ diff --git a/share/cpetpet/pet1.gif b/share/cpetpet/pet1.gif new file mode 100644 index 0000000..f3f1fdc Binary files /dev/null and b/share/cpetpet/pet1.gif differ diff --git a/share/cpetpet/pet2.gif b/share/cpetpet/pet2.gif new file mode 100644 index 0000000..ee33972 Binary files /dev/null and b/share/cpetpet/pet2.gif differ diff --git a/share/cpetpet/pet3.gif b/share/cpetpet/pet3.gif new file mode 100644 index 0000000..e70c930 Binary files /dev/null and b/share/cpetpet/pet3.gif differ diff --git a/share/cpetpet/pet4.gif b/share/cpetpet/pet4.gif new file mode 100644 index 0000000..4d09c16 Binary files /dev/null and b/share/cpetpet/pet4.gif differ diff --git a/share/cpetpet/pet5.gif b/share/cpetpet/pet5.gif new file mode 100644 index 0000000..e250e13 Binary files /dev/null and b/share/cpetpet/pet5.gif differ diff --git a/share/cpetpet/pet6.gif b/share/cpetpet/pet6.gif new file mode 100644 index 0000000..09dedb3 Binary files /dev/null and b/share/cpetpet/pet6.gif differ diff --git a/share/cpetpet/pet7.gif b/share/cpetpet/pet7.gif new file mode 100644 index 0000000..a467e92 Binary files /dev/null and b/share/cpetpet/pet7.gif differ diff --git a/share/cpetpet/pet8.gif b/share/cpetpet/pet8.gif new file mode 100644 index 0000000..f9fb14c Binary files /dev/null and b/share/cpetpet/pet8.gif differ diff --git a/share/cpetpet/pet9.gif b/share/cpetpet/pet9.gif new file mode 100644 index 0000000..f9fb14c Binary files /dev/null and b/share/cpetpet/pet9.gif differ -- cgit 1.4.1