From: b Date: Wed, 30 Nov 2022 01:00:49 +0000 (+0000) Subject: back to npb X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=640debd660fb301f3eb6d94f0047eaf754b0b5b9;p=ott%2Fenhance back to npb --- diff --git a/403.png b/403.png deleted file mode 100644 index c6bc7de..0000000 Binary files a/403.png and /dev/null differ diff --git a/core.c b/core.c index f79c6ad..4283561 100644 --- a/core.c +++ b/core.c @@ -201,7 +201,7 @@ int reserve_pictures (uint_fast16_t n) void get_flags (struct IL_full_info *info, FLAG_TYPE *flags) { - *flags &= ~(HAS_ALPHA | IS_GRAY | IS_INDEXED | IS_MULTIPLE | IS_OVER_8BIT); + *flags &= ~(HAS_ALPHA | IS_GRAY | IS_INDEXED | IS_MULTIPLE | IS_OVER_8BIT | EFF_ALPHA | EFF_GRAY | EFF_INDEXED); if (info->num_images > 0) *flags |= IS_MULTIPLE; @@ -212,7 +212,7 @@ void get_flags (struct IL_full_info *info, FLAG_TYPE *flags) switch (info->image_format) { case IL_COLOUR_INDEX: - *flags |= IS_INDEXED; + *flags |= IS_INDEXED | EFF_INDEXED; switch (info->palette_type) { case IL_PAL_BGR32: @@ -221,7 +221,7 @@ void get_flags (struct IL_full_info *info, FLAG_TYPE *flags) break; case IL_PAL_BGRA32: case IL_PAL_RGBA32: - *flags |= HAS_ALPHA; + *flags |= HAS_ALPHA | EFF_ALPHA; break; case IL_PAL_RGB24: case IL_PAL_BGR24: @@ -230,13 +230,13 @@ void get_flags (struct IL_full_info *info, FLAG_TYPE *flags) } break; case IL_LUMINANCE_ALPHA: - *flags |= HAS_ALPHA; + *flags |= HAS_ALPHA | EFF_ALPHA; case IL_LUMINANCE: - *flags |= IS_GRAY; + *flags |= IS_GRAY | EFF_GRAY; break; case IL_RGBA: case IL_BGRA: - *flags |= HAS_ALPHA; + *flags |= HAS_ALPHA | EFF_ALPHA; case IL_RGB: case IL_BGR: default: @@ -817,7 +817,7 @@ int perform_action ( if (r!=0) break; - p[i].flags &= ~(IS_GRAY|IS_INDEXED|IS_OVER_8BIT|IS_PALETTE_ONLY); + p[i].flags &= ~(HAS_ALPHA|IS_GRAY|IS_INDEXED|IS_OVER_8BIT|IS_PALETTE_ONLY|EFF_ALPHA|EFF_GRAY|EFF_INDEXED); if (palette_only) p[i].flags |= IS_PALETTE_ONLY; @@ -837,7 +837,7 @@ int perform_action ( switch (p[i].info.image_format) { case IL_COLOUR_INDEX: - p[i].flags |= IS_INDEXED; + p[i].flags |= IS_INDEXED | EFF_INDEXED; r = get_palette(p[i].id, &(p[i].palette), p[i].f_pict); if (r!=0) break; @@ -848,7 +848,7 @@ int perform_action ( p[i].flags |= IS_OVER_8BIT; break; case IL_PAL_BGRA32: - p[i].flags |= HAS_ALPHA; + p[i].flags |= HAS_ALPHA | EFF_ALPHA; p[i].alpha_offset = 3; case IL_PAL_BGR24: p[i].red_offset = 2; @@ -856,7 +856,7 @@ int perform_action ( p[i].blue_offset = 0; break; case IL_PAL_RGBA32: - p[i].flags |= HAS_ALPHA; + p[i].flags |= HAS_ALPHA | EFF_ALPHA; p[i].alpha_offset = 3; case IL_PAL_RGB24: default: @@ -867,14 +867,14 @@ int perform_action ( } break; case IL_LUMINANCE_ALPHA: - p[i].flags |= HAS_ALPHA; + p[i].flags |= HAS_ALPHA | EFF_ALPHA; p[i].alpha_offset = 1 * p[i].info.image_bpc; case IL_LUMINANCE: - p[i].flags |= IS_GRAY; + p[i].flags |= IS_GRAY | EFF_GRAY; p[i].value_offset = 0 * p[i].info.image_bpc; break; case IL_BGRA: - p[i].flags |= HAS_ALPHA; + p[i].flags |= HAS_ALPHA | EFF_ALPHA; p[i].alpha_offset = 3 * p[i].info.image_bpc; case IL_BGR: p[i].red_offset = 2 * p[i].info.image_bpc; @@ -882,7 +882,7 @@ int perform_action ( p[i].blue_offset = 0 * p[i].info.image_bpc; break; case IL_RGBA: - p[i].flags |= HAS_ALPHA; + p[i].flags |= HAS_ALPHA | EFF_ALPHA; p[i].alpha_offset = 3 * p[i].info.image_bpc; case IL_RGB: default: @@ -893,6 +893,17 @@ int perform_action ( } if (p[i].info.image_bpc > 1) p[i].flags |= IS_OVER_8BIT; + + if ((p[i].flags & IS_INDEXED) && (p[i].flags & CANNOT_BE_INDEXED)) + p[i].flags &= ~EFF_INDEXED; + if ((p[i].flags & IS_GRAY) && (p[i].flags & CANNOT_BE_GRAY)) + p[i].flags &= ~EFF_GRAY; + else if (!(p[i].flags & IS_GRAY) && (p[i].flags & MUST_BE_GRAY)) + p[i].flags |= EFF_GRAY; + if ((!(p[i].flags & HAS_ALPHA)) && (p[i].flags & MUST_HAVE_ALPHA)) + p[i].flags |= EFF_ALPHA; + else if ((p[i].flags & HAS_ALPHA) && (p[i].flags & CANNOT_HAVE_ALPHA)) + p[i].flags &= ~EFF_ALPHA; } if (!skip_frame) { @@ -1303,10 +1314,8 @@ int perform_action_palette_mix ( { case IL_PAL_BGR32: case IL_PAL_RGB32: - p[i].flags |= IS_OVER_8BIT; break; case IL_PAL_BGRA32: - p[i].flags |= HAS_ALPHA; p[i].alpha_offset = 3; case IL_PAL_BGR24: p[i].red_offset = 2; @@ -1314,7 +1323,6 @@ int perform_action_palette_mix ( p[i].blue_offset = 0; break; case IL_PAL_RGBA32: - p[i].flags |= HAS_ALPHA; p[i].alpha_offset = 3; case IL_PAL_RGB24: default: @@ -1323,6 +1331,15 @@ int perform_action_palette_mix ( p[i].blue_offset = 2; break; } + + if ((p[i].flags & IS_GRAY) && (p[i].flags & CANNOT_BE_GRAY)) + p[i].flags &= ~EFF_GRAY; + else if (!(p[i].flags & IS_GRAY) && (p[i].flags & MUST_BE_GRAY)) + p[i].flags |= EFF_GRAY; + if ((!(p[i].flags & HAS_ALPHA)) && (p[i].flags & MUST_HAVE_ALPHA)) + p[i].flags |= EFF_ALPHA; + else if ((p[i].flags & HAS_ALPHA) && (p[i].flags & CANNOT_HAVE_ALPHA)) + p[i].flags &= ~EFF_ALPHA; } if (!skip_frame) { @@ -1415,6 +1432,94 @@ ILubyte downscale_value (ILuint x, ILint bytes) return (ILubyte)(x >> (8 * (bytes-1))); } +int copy_pixels (ILuint n, struct PixelInfo *p, void *data) +{ + ILuint max = *((ILuint *)data); + + if (n < 2) + return EINVAL; + + if (p[0].flags & EFF_INDEXED) + { + if (!(p[1].flags & EFF_INDEXED)) + return EINVAL; + p[1].index = p[0].index; + } + else if (p[0].flags & EFF_ALPHA) + { + if (p[0].flags & EFF_GRAY) + { + if (!(p[1].flags & EFF_GRAY)) + return EINVAL; + p[1].value = copy_1p_alpha(p[0].value, p[1].value, p[0].alpha, max); + } + else + { + if (p[1].flags & EFF_GRAY) + return EINVAL; + p[1].red = copy_1p_alpha(p[0].red, p[1].red, p[0].alpha, max); + p[1].green = copy_1p_alpha(p[0].green, p[1].green, p[0].alpha, max); + p[1].blue = copy_1p_alpha(p[0].blue, p[1].blue, p[0].alpha, max); + } + if (p[1].flags & EFF_ALPHA) + p[1].alpha = copy_1p_alpha(max, p[1].alpha, p[0].alpha, max); + } + else + { + if (p[0].flags & EFF_GRAY) + { + if (!(p[1].flags & EFF_GRAY)) + return EINVAL; + p[1].value = p[0].value + } + else + { + if (p[1].flags & EFF_GRAY) + return EINVAL; + p[1].red = p[0].red; + p[1].green = p[0].green; + p[1].blue = p[0].blue; + } + if (p[1].flags & EFF_ALPHA) + p[1].alpha = max; + } + + return 0; +} + +int fill_color (ILuint n, struct PixelInfo *p, void *data) +{ + struct ColorInfo *d = data; + + if (p->flags & EFF_INDEXED) + { + p->index = d->index; + } + else + { + if (p->flags & EFF_ALPHA) + p->alpha = d->alpha; + if (p->flags & EFF_GRAY) + p->value = d->value; + else + { + p->red = d->red; + p->green = d->green; + p->blue = d->blue; + } + } + + return 0; +} + + +ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, iILint64 max) +{ + ILint64 v = (src * alpha + dst * (max - alpha)) / max; + return (ILuint)v; +} + + // int action( // ILuint n, struct PixelInfo *info, void *data // ) diff --git a/core.h b/core.h index 144979d..15af406 100644 --- a/core.h +++ b/core.h @@ -34,28 +34,32 @@ on Pentium III libdevil must be recompiled with #define FLAG_TYPE uint_fast32_t -#define MUST_HAVE_ALPHA 0x00001 -#define CANNOT_HAVE_ALPHA 0x00002 -#define MUST_BE_GRAY 0x00004 -#define CANNOT_BE_GRAY 0x00008 -#define MUST_BE_INDEXED 0x00010 -#define CANNOT_BE_INDEXED 0x00020 +#define MUST_HAVE_ALPHA 0x000001 +#define CANNOT_HAVE_ALPHA 0x000002 +#define MUST_BE_GRAY 0x000004 +#define CANNOT_BE_GRAY 0x000008 +#define MUST_BE_INDEXED 0x000010 +#define CANNOT_BE_INDEXED 0x000020 -#define OK_PALETTE_ONLY 0x00040 -#define CAN_BE_MULTIPLE 0x00080 -#define CAN_BE_OVER_8BIT 0x00100 +#define OK_PALETTE_ONLY 0x000040 +#define CAN_BE_MULTIPLE 0x000080 +#define CAN_BE_OVER_8BIT 0x000100 -#define IN_WINDOW 0x00200 +#define IN_WINDOW 0x000200 -#define HAS_ALPHA 0x00400 -#define IS_GRAY 0x00800 -#define IS_INDEXED 0x01000 -#define IS_MULTIPLE 0x02000 -#define IS_OVER_8BIT 0x04000 -#define IS_PALETTE_ONLY 0x08000 +#define HAS_ALPHA 0x000400 +#define IS_GRAY 0x000800 +#define IS_INDEXED 0x001000 +#define IS_MULTIPLE 0x002000 +#define IS_OVER_8BIT 0x004000 +#define IS_PALETTE_ONLY 0x008000 -#define NOT_WRITABLE 0x10000 -#define NOT_READABLE 0x20000 +#define NOT_WRITABLE 0x010000 +#define NOT_READABLE 0x020000 + +#define EFF_ALPHA 0x040000 +#define EFF_GRAY 0x080000 +#define EFF_INDEXED 0x100000 extern char NO_STR[]; extern char INIT_FAILED[]; @@ -167,13 +171,19 @@ struct PixelInfo struct IL_full_info info; }; -typedef int (ACTION_F)(ILuint n, struct PixelInfo *info, void *data); +struct ColorInfo +{ + ILuint red; + ILuint green; + ILuint blue; + ILuint value; + ILuint alpha; + ILuint index; +} +typedef int (ACTION_F)(ILuint n, struct PixelInfo *info, void *data); typedef int (SUBTOOL_F)(int argc, char **argv, int argi, char **err); - - - void finish (int const returnvalue, char const * const returntext); @@ -225,4 +235,8 @@ int perform_action_palette_mix ( void *data ); -//ACTION_F action; \ No newline at end of file + + +int copy_pixels (ILuint n, struct PixelInfo *p, void *data); +ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, iILint64 max); +int fill_color (ILuint n, struct PixelInfo *p, void *data); \ No newline at end of file diff --git a/data/npb-ong1.png b/data/npb-ong1.png deleted file mode 100644 index 36db7c7..0000000 Binary files a/data/npb-ong1.png and /dev/null differ diff --git a/diff.c b/diff.c index 23b7054..4f44997 100644 --- a/diff.c +++ b/diff.c @@ -276,7 +276,7 @@ int difference (ILuint n, struct PixelInfo *p, void *data) p[2].red = diff_1ch(p[0].red, p[1].red, d->r_a, d->r_b, d->max); p[2].green = diff_1ch(p[0].green, p[1].green, d->g_a, d->g_b, d->max); p[2].blue = diff_1ch(p[0].blue, p[1].blue, d->b_a, d->b_b, d->max); - if (p[2].flags & HAS_ALPHA) + if (p[2].flags & EFF_ALPHA) p[2].alpha = (p[0].alpha + p[1].alpha) / 2; /* no better idea */ return 0; diff --git a/enhance.c b/enhance.c index be6a6b5..7fc3a75 100644 --- a/enhance.c +++ b/enhance.c @@ -34,6 +34,7 @@ on Pentium III libdevil must be recompiled with #include "bluenh.h" #include "reveal.h" #include "diff.h" +#include "npb.h" int main (int argc, char **argv) { diff --git a/f2h.c b/f2h.c new file mode 100644 index 0000000..32fb519 --- /dev/null +++ b/f2h.c @@ -0,0 +1,104 @@ +/* +f2h.c +make file into h +29.11.2022 + +Copyright (C) 2022 Balthasar Szczepański + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +*/ + +#include +#include +#include +#include + +char DEFAULT_NAME[] = "data"; +FILE *infile, *outfile; +uint_fast8_t in_open = 0; +uint_fast8_t out_open = 0; + +int cleanup(int r) +{ + if (out_open) + fclose(outfile); + if (in_open) + fclose(infile); + return r; +} + +int main (int argc, char **argv) +{ + char *name; + uint_fast8_t i; + uint8_t x; + uint_fast64_t size=0; + + if (argc >= 2) + name = argv[1]; + else + name = DEFAULT_NAME; + if (argc >= 3) + { + infile = fopen(argv[2], "rb"); + if (infile==NULL) + return cleanup(EIO); + in_open = 1; + } + else + infile = stdin; + if (argc >= 4) + { + outfile = fopen(argv[3], "wt"); + if (outfile==NULL) + return cleanup(EIO); + out_open = 1; + } + else + outfile = stdout; + + fprintf( + outfile, + "/* %s is autogenerated%s%s. */\n", + out_open ? argv[3] : "File", + in_open ? " from " : "", + in_open ? argv[2] : "" + ); + fputs ("#include \n", outfile); + fprintf( + outfile, + "const uint8_t %s[] = {", + name + ); + for (i=0; fread(&x, 1, 1, infile)!=0;i=(i+1)&7) + { + fprintf( + outfile, + "%s0x%02" PRIX8 ",", + (i==0) ? "\n\t" : " ", + x + ); + ++size + } + fputs ("\n};\n", outfile); + fprintf( + outfile, + "#define %s_size %" PRIu64 "\n", + name, + size + ); + + return cleanup(0); +} diff --git a/makefile b/makefile index 16f61c1..2d65650 100644 --- a/makefile +++ b/makefile @@ -42,28 +42,45 @@ nofading\ info\ bluenh\ reveal\ -diff +diff\ +npb C_STANDALONE=\ standalone-nofading.c\ standalone-info.c\ standalone-bluenh.c\ standalone-reveal.c\ -standalone-diff.c +standalone-diff.c\ +standalone-npb.c C_SUBTOOL=\ nofading.c\ info.c\ bluenh.c\ reveal.c\ -diff.c +diff.c\ +npb.c H_SUBTOOL=\ nofading.h\ info.h\ bluenh.h\ reveal.h\ -diff.h +diff.h\ +npb.h + +H_PNG=\ +npb0.h\ +npb1.h\ +npb2.h\ +npb_ong1.h\ +npb_403.h + +# keep these 2 lists in the same order!: +GENERATE_FROM= + +TO_GENERATE= + #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd @@ -74,21 +91,30 @@ makefile: makefile.1.mak $(CONFIGFILE) $(CONFIGURE_CMD) < makefile.1.mak > makefile -enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL) +enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL) $(H_PNG) $(CC) $(CF) -o enhance enhance.c core.c $(C_SUBTOOL) $(L_IL) -$(STANDALONE): %: standalone-%.c %.c %.h core.c core.h +$(STANDALONE): %: standalone-%.c %.c %.h core.c core.h $(H_PNG) $(CC) $(CF) -o $@ standalone-$*.c $*.c core.c $(L_IL) $(C_STANDALONE): standalone-%.c: settings-standalone.txt standalone.c $(CONFIGURE) subtool=$* settings-standalone.txt --in standalone.c --out $@ +$(TO_GENERATE): $(GENERATE_FROM) $(CONFIGFILE) + $(CONFIGURE_CMD) --in $(GENERATE_FROM) --out $(TO_GENERATE) + +$(H_PNG): %.h: %.png f2h + ./f2h $* $*.png $@ + +f2h: f2h.c + $(CC) $(CF) -o f2h f2h.c + #test: test.c core.h core.c # $(CC) $(CF) -o test test.c core.c $(LF) clean: - $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) + $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) PHONY: all clean diff --git a/makefile.1.mak b/makefile.1.mak index fd5f631..169e127 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -42,28 +42,45 @@ nofading\ info\ bluenh\ reveal\ -diff +diff\ +npb C_STANDALONE=\ standalone-nofading.c\ standalone-info.c\ standalone-bluenh.c\ standalone-reveal.c\ -standalone-diff.c +standalone-diff.c\ +standalone-npb.c C_SUBTOOL=\ nofading.c\ info.c\ bluenh.c\ reveal.c\ -diff.c +diff.c\ +npb.c H_SUBTOOL=\ nofading.h\ info.h\ bluenh.h\ reveal.h\ -diff.h +diff.h\ +npb.h + +H_PNG=\ +npb0.h\ +npb1.h\ +npb2.h\ +npb_ong1.h\ +npb_403.h + +# keep these 2 lists in the same order!: +GENERATE_FROM= + +TO_GENERATE= + #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd @@ -74,21 +91,30 @@ makefile: makefile.1.mak $(CONFIGFILE) $(CONFIGURE_CMD) < makefile.1.mak > makefile -enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL) +enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL) $(H_PNG) $(CC) $(CF) -o enhance enhance.c core.c $(C_SUBTOOL) $(L_IL) -$(STANDALONE): %: standalone-%.c %.c %.h core.c core.h +$(STANDALONE): %: standalone-%.c %.c %.h core.c core.h $(H_PNG) $(CC) $(CF) -o $@ standalone-$*.c $*.c core.c $(L_IL) $(C_STANDALONE): standalone-%.c: settings-standalone.txt standalone.c $(CONFIGURE) subtool=$* settings-standalone.txt --in standalone.c --out $@ +$(TO_GENERATE): $(GENERATE_FROM) $(CONFIGFILE) + $(CONFIGURE_CMD) --in $(GENERATE_FROM) --out $(TO_GENERATE) + +$(H_PNG): %.h: %.png f2h + ./f2h $* $*.png $@ + +f2h: f2h.c + $(CC) $(CF) -o f2h f2h.c + #test: test.c core.h core.c # $(CC) $(CF) -o test test.c core.c $(LF) clean: - $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) + $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) PHONY: all clean diff --git a/nofading.c b/nofading.c index 877eaf4..acd888f 100644 --- a/nofading.c +++ b/nofading.c @@ -1,7 +1,7 @@ /* nofading.c The tool to remove fading from an image -15.11.2022 +29.11.2022 Copyright (C) 2015, 2022 Balthasar Szczepański @@ -251,7 +251,7 @@ int find_fading_range (ILuint n, struct PixelInfo *p, void *data) d = data; - if (p->flags & IS_GRAY) + if (p->flags & EFF_GRAY) { UPDATE_RANGE(p->value, d->green_low, d->green_high); } @@ -267,7 +267,7 @@ int find_fading_range (ILuint n, struct PixelInfo *p, void *data) UPDATE_RANGE(p->green, d->green_low, d->green_high); UPDATE_RANGE(p->blue, d->green_low, d->green_high); } - if ((p->flags & HAS_ALPHA) && (d->enhance_alpha)) + if ((p->flags & EFF_ALPHA) && (d->enhance_alpha)) { UPDATE_RANGE(p->alpha, d->alpha_low, d->alpha_high); } @@ -292,7 +292,7 @@ int enhance_fading (ILuint n, struct PixelInfo *p, void *data) d = data; - if (p->flags & IS_GRAY) + if (p->flags & EFF_GRAY) p->value = enhance_fading_1ch(p->value, d->green_low, d->green_high, d->max); else if (d->individual_channels) { @@ -306,7 +306,7 @@ int enhance_fading (ILuint n, struct PixelInfo *p, void *data) p->green = enhance_fading_1ch(p->green, d->green_low, d->green_high, d->max); p->blue = enhance_fading_1ch(p->blue , d->green_low, d->green_high, d->max); } - if ((p->flags & HAS_ALPHA) && (d->enhance_alpha)) + if ((p->flags & EFF_ALPHA) && (d->enhance_alpha)) p->alpha = enhance_fading_1ch(p->alpha, d->alpha_low, d->alpha_high, d->max); return 0; diff --git a/npb.cpp b/npb.c similarity index 64% rename from npb.cpp rename to npb.c index a08e577..1c03b99 100644 --- a/npb.cpp +++ b/npb.c @@ -1,11 +1,183 @@ - // //It's NewpixbOTTification Time! - // // Take a picture and add a newpixbot to it! - // // - // // Requires Dev Image Library, -// // //on Pentium III libdevil must be - // // recompiled with --disable-ssl2 --disable-ssl3 - // // - // // ~~bicyclesonthemoon +/* +npb.c +Take a picture and add a newpixbot to it! +29.11.2022 + +Copyright (C) 2013 - 2015, 2022 Balthasar Szczepański + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + + +Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) +on Pentium III libdevil must be recompiled with +--disable-ssl2 --disable-ssl3 +(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) + +*/ + +#include +#include + +#include "core.h" +#include "npb.h" + +#include "npb0.h" +#include "npb1.h" +#include "npb2.h" +#include "npb_ong1.h" +#include "npb_403.h" + +#define NPB0_L 21 +#define NPB0_R 116 +#define NPB0_T 122 +#define NPB0_B 189 + +#define NPB1_L 22 +#define NPB1_R 154 +#define NPB1_T 69 +#define NPB1_B 162 + + +char NPB_MISSING_ARGS[] = "Missing parameters.\nnpb [-o -4 -r -b -c] inPix outPix\n"; + +int subtool_npb (int argc, char **argv, int argi, char **err) +{ + uint_fast8_t ong1 = 0; + uint_fast8_t t403 = 0; + uint_fast8_t corners = 0; + uint_fast8_t fullsize = 0; + uint_fast8_t fill_white = 0; + uint_fast8_t expand_left = 0; + uint_fast8_t expand_right = 0; + uint_fast8_t expand_up = 0; + uint_fast8_t expand_down = 0; + uint_fast8_t border_outside = 0; + + ILuint cut_border = 0; + ILuint new_border = 2; + ILuint max = 0xFF; //upscale_value(0xFF, info[0].image_bpc); // bpc=1 + ILuint effective_width, effective_height; + const uint8_t *npb_pix; + uint_fast32_t npb_size; + ILuint x_l, x_r, y_t, y_b; + + struct ColorInfo color; + struct IL_full_info info[3]; + FLAG_TYPE flags [3] = { + CANNOT_BE_GRAY | CANNOT_BE_INDEXED | NOT_WRITABLE, + CANNOT_BE_GRAY | CANNOT_BE_INDEXED | NOT_WRITABLE | MUST_HAVE_ALPHA, + CANNOT_BE_GRAY | CANNOT_BE_INDEXED | NOT_READABLE | MUST_HAVE_ALPHA, + } + ILuint x0[3]; + ILuint y0[3]; + + struct option long_options[] = { + {"ong1", no_argument, NULL, 'o'}, + {"403", no_argument, NULL, '4'}, + {"remove-border", required_argument, NULL, 'r'}, + {"new-border", required_argument, NULL, 'b'}, + {"corners", no_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0} + }; + char short_options[] = "o4r:b:ch"; + + int opt; + int r; + + optind = argi; + while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) + { + switch (opt) + { + case 'o': + ong1 = 1; + break; + case '4': + t403 = 1; + break; + case 'r': + sscanf(optarg, "%lu, &cut_border); + break; + case 'b': + sscanf(optarg, "%lu, &new_border); + fullsize = 1; + break; + case 'c': + corners = 1; + break; + case 'h': + /* help */ + break; + } + } + + if (argc < optind + 2) + { + *err = NPB_MISSING_ARGS; + return EINVAL; + } + + r = reserve_pictures(1); + if (r) + { + *err = CREATE_FAILED; + return r; + } + + r = load_picture(0, argv[optind], &(info[0]), &(flags[0]); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + effective_width = (info[0].image_width > (2*cut_border)) ? (info[0].image_width - (2*cut_border)) : 0; + effective_height = (info[0].image_height > (2*cut_border)) ? (info[0].image_height - (2*cut_border)) : 0; + + if (t403) + { + npb_pix = npb_403; + npb_size = npb_403_size; + } + else if (ong1) + { + npb_pix = npb_ong1; + npb_size = npb_ong1_size; + } + else if ((effective_width <= NPB0_X_MAX) && (effective_height <= NPB0_Y_MAX) && (!fullsize)) + { + npb_pix = npb0; + npb_size = npb0_size; + fill_white = 1; + new_border = 0; + } + else if ((effective_width <= NPB1_X_MAX) && (effective_height <= NPB1_Y_MAX) && (!fullsize)) + { + npb_pix = npb1; + npb_size = npb1_size; + fill_white = 1; + new_border = 0; + } + else + { + npb_pix = npb2; + npb_size = npb2_size; + } + + +} #define INPIX_MUSTARD 1 #define OUTPIX_MUSTARD 2 @@ -322,4 +494,4 @@ void mustard(int mustard) ilDeleteImages(1, &npbPix); exit(mustard); } - + */ diff --git a/npb.h b/npb.h new file mode 100644 index 0000000..c2c95f3 --- /dev/null +++ b/npb.h @@ -0,0 +1,28 @@ +/* +npb.h +Take a picture and add a newpixbot to it! +29.11.2022 + +Copyright (C) 2022 Balthasar Szczepański + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + + +Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) +on Pentium III libdevil must be recompiled with +--disable-ssl2 --disable-ssl3 +(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) +*/ + +int subtool_npb (int argc, char **argv, int argi, char **err); diff --git a/npb_403.png b/npb_403.png new file mode 100644 index 0000000..326a198 Binary files /dev/null and b/npb_403.png differ diff --git a/npb_ong1.png b/npb_ong1.png new file mode 100644 index 0000000..2ef8a15 Binary files /dev/null and b/npb_ong1.png differ diff --git a/reveal.c b/reveal.c index f4769bb..8e7adde 100644 --- a/reveal.c +++ b/reveal.c @@ -1,7 +1,7 @@ /* reveal.c reveal hidden details -15.11.2022 +29.11.2022 Copyright (C) 2014 - 2019, 2022 Balthasar Szczepański @@ -91,7 +91,7 @@ int subtool_reveal (int argc, char **argv, int argi, char **err) int reveal (ILuint n, struct PixelInfo *p, void *data) { - if (p->flags & IS_GRAY) + if (p->flags & EFF_GRAY) p->value = reveal_swap2(p->value); else {