From: b Date: Sat, 5 Nov 2022 18:19:25 +0000 (+0000) Subject: more towards general action X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=308177604bbf28979bd85f3a1d8f8349d20e5fae;p=ott%2Fenhance more towards general action --- diff --git a/core.c b/core.c index 93d9714..9b9f1ce 100644 --- a/core.c +++ b/core.c @@ -1,7 +1,7 @@ /* core.c The tool with multiple enhancements and manipulations of pictures -01.11.2022 +05.11.2022 Copyright (C) 2014, 2015, 2022 Balthasar Szczepański @@ -36,6 +36,9 @@ on Pentium III libdevil must be recompiled with uint_fast16_t n_pictures = 0; struct Picture * picture; +char LOAD_FAILED[] = "Failed to load picture.\n"; +char CREATE_FAILED[] = "Failed to create picture(s).\n"; + void init (void) { ilInit(); @@ -414,19 +417,20 @@ void get_info (uint_fast16_t id, struct IL_full_info *info) int action_1picture ( uint_fast16_t id, ILint x0, ILint y0, ILint width, ILint height, - void *function, + ACTION_F *function, FLAG_TYPE flags, - void *data + void *f_data ) { ILint x, y, z; ILint frames; - IL_full_info *info; - ILuint r, g, b, a, y, i; + struct IL_full_info info; + ILuint r, g, b, a, v, i; ILint line_bytes, line_start, frame_bytes; ILint frame_offset, line_offset, pixel_offset; - ILint r_offset, g_offset, b_offset, a_offset, y_offset, i_offset; + ILint r_offset, g_offset, b_offset, a_offset, v_offset, i_offset; void *data; + int re; flags &= ~(IS_GRAY|IS_INDEXED|IS_MULTIPLE|IS_OVER_8BIT|IS_PALETTE_ONLY); @@ -440,31 +444,30 @@ int action_1picture ( switch (info.image_format) { case IL_COLOUR_INDEX: - info_flag |= IS_INDEXED; + flags |= IS_INDEXED; switch (info.palette_type) { case IL_PAL_BGR32: case IL_PAL_RGB32: - info_flag |= IS_OVER_8BIT; + flags |= IS_OVER_8BIT; break; case IL_PAL_BGRA32: case IL_PAL_RGBA32: - info_flag |= HAS_ALPHA; + flags |= HAS_ALPHA; break; case IL_PAL_BGR24: case IL_PAL_RGB24: default: break; } - } case IL_LUMINANCE_ALPHA: - info_flag |= HAS_ALPHA; + flags |= HAS_ALPHA; case IL_LUMINANCE: - info_flag |= IS_GRAY; + flags |= IS_GRAY; break; case IL_BGRA: case IL_RGBA: - info_flag |= HAS_ALPHA; + flags |= HAS_ALPHA; case IL_BGR: case IL_RGB: default: @@ -476,11 +479,11 @@ int action_1picture ( case IL_UNSIGNED_BYTE: break; default: - info_flag |= IS_OVER_8BIT; + flags |= IS_OVER_8BIT; } frames = info.num_images; if (frames > 1) - info_flag |= IS_MULTIPLE; + flags |= IS_MULTIPLE; else if (frames < 1) frames = 1; @@ -495,7 +498,7 @@ int action_1picture ( height = info.image_height; } - line_bytes = info.bytes_per_pixel * info.image_width; + line_bytes = info.image_bytes_per_pixel * info.image_width; frame_bytes = line_bytes * info.image_height; if (info.origin_mode == IL_ORIGIN_UPPER_LEFT) @@ -516,7 +519,7 @@ int action_1picture ( g_offset = -1; b_offset = -1; a_offset = -1; - y_offset = -1; + v_offset = -1; i_offset = -1; switch (info.image_type) { @@ -541,7 +544,7 @@ int action_1picture ( case IL_LUMINANCE_ALPHA: a_offset = 4; case IL_LUMINANCE: - y_offset = 0; + v_offset = 0; break; case IL_COLOUR_INDEX: i_offset = 0; @@ -570,7 +573,7 @@ int action_1picture ( case IL_LUMINANCE_ALPHA: a_offset = 2; case IL_LUMINANCE: - y_offset = 0; + v_offset = 0; break; case IL_COLOUR_INDEX: i_offset = 0; @@ -599,7 +602,7 @@ int action_1picture ( case IL_LUMINANCE_ALPHA: a_offset = 1; case IL_LUMINANCE: - y_offset = 0; + v_offset = 0; break; case IL_COLOUR_INDEX: i_offset = 0; @@ -619,29 +622,27 @@ int action_1picture ( for ( y=y0, line_offset=frame_offset+line_start+(y0*line_bytes); y < y0 + height; - ++y, line_offset += line_bytes; + ++y, line_offset += line_bytes ){ if ((y>=0)&&(y=0)&&(x rgb + } + if ((flags & IS_GRAY) && (flags & CANNOT_BE_GRAY)) + { + r = v; + g = v; + b = v; + } + else if (!(flags & IS_GRAY) && (flags & MUST_BE_GRAY)) + { + y = (r+g+b)/3; + } + + re = function(x,y,z,&r,&g,&b,&a,&v,&i,flags,f_data); + if (re) + return re; //!!!!!!!! } } } @@ -675,8 +717,20 @@ int action_1picture ( } } -void action( +} +int action( ILint x, ILint y, ILint z, - ILuint *r, ILuint *g, ILuint *b, ILuint *a, ILuint *y, ILuint *i, + ILuint *r, ILuint *g, ILuint *b, ILuint *a, ILuint *v, ILuint *i, FLAG_TYPE flags, - void *data \ No newline at end of file + void *data +) +{ + printf( + "%04lu %04lu %04lu: %03lu %03lu %03lu %03lu %03lu %03lu\n", + (unsigned long)x, (unsigned long)y, (unsigned long)z, + (unsigned long)(*r), (unsigned long)(*g), (unsigned long)(*b), + (unsigned long)(*a), (unsigned long)(*v), (unsigned long)(*i) + ); + return 0; +} + diff --git a/core.h b/core.h index e8fed75..93a62b3 100644 --- a/core.h +++ b/core.h @@ -1,7 +1,7 @@ /* core.h The tool with multiple enhancements and manipulations of pictures -01.11.2022 +05.11.2022 Copyright (C) 2022 Balthasar Szczepański @@ -54,6 +54,8 @@ on Pentium III libdevil must be recompiled with #define IS_OVER_8BIT 0x4000 #define IS_PALETTE_ONLY 0x8000 +extern char LOAD_FAILED[]; +extern char CREATE_FAILED[]; struct Picture { uint_fast8_t open; @@ -88,6 +90,15 @@ struct IL_full_info { ILint version_num; }; +typedef int (ACTION_F)( + ILint x, ILint y, ILint z, + ILuint *r, ILuint *g, ILuint *b, ILuint *a, ILuint *v, ILuint *i, + FLAG_TYPE flags, void *data +); + + + + void finish (int const returnvalue, char const * const returntext); void init (void); @@ -100,3 +111,15 @@ int reserve_pictures (uint_fast16_t n); int convert_picture (uint_fast16_t id, FLAG_TYPE flags); int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags); void get_info (uint_fast16_t id, struct IL_full_info *info); + +int action_1picture ( + uint_fast16_t id, + ILint x0, ILint y0, ILint width, ILint height, + ACTION_F *function, + FLAG_TYPE flags, + void *f_data +); + + + +ACTION_F action; \ No newline at end of file diff --git a/enhance b/enhance deleted file mode 100755 index e4c44cd..0000000 Binary files a/enhance and /dev/null differ diff --git a/info.c b/info.c index 3c3060c..023c35d 100644 --- a/info.c +++ b/info.c @@ -1,7 +1,7 @@ /* info.c Get information -01.11.2022 +05.11.2022 Copyright (C) 2022 Balthasar Szczepański @@ -34,7 +34,6 @@ on Pentium III libdevil must be recompiled with #include "info.h" char INFO_MISSING_ARGS[] = "Missing parameters.\ninfo inPix\n"; -char INFO_LOAD_FAILED[] = "Failed to load picture.\n"; void print_info_uint (char *name, long unsigned value) { @@ -176,7 +175,7 @@ int info (int argc, char **argv, char **err) r = create_pictures(1); if (r) { - *err = INFO_LOAD_FAILED; + *err = CREATE_FAILED; return r; } diff --git a/nofading.c b/nofading.c index 2079ce6..ab64505 100644 --- a/nofading.c +++ b/nofading.c @@ -1,7 +1,7 @@ /* nofading.c The tool to remove fading from an image -01.11.2022 +05.11.2022 Copyright (C) 2015, 2022 Balthasar Szczepański @@ -43,6 +43,7 @@ int nofading (int argc, char **argv, char **err) uint_fast16_t frame_l = 0; uint_fast16_t frame_r = 0; uint_fast8_t palette_only = 0; + int r; if (argc<2) { @@ -87,7 +88,27 @@ int nofading (int argc, char **argv, char **err) if ((frame_t==0) && (frame_b==0) && (frame_l==0) && (frame_r==0)) palette_only = OK_PALETTE_ONLY; - create_pictures(2); + r = create_pictures(1); + if (r) + { + *err = CREATE_FAILED; + return r; + } + + r = load_picture(0, argv[0], 0); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + r = action_1picture ( + 0, + 0,0,0,0, + &action, + 0, + NULL + ); return 0; } diff --git a/testimg/4x4.png b/testimg/4x4.png new file mode 100644 index 0000000..08c5812 Binary files /dev/null and b/testimg/4x4.png differ