From 6605dc7cb26c14db24677823d89cbb2c265c6f38 Mon Sep 17 00:00:00 2001 From: b Date: Mon, 14 Nov 2022 23:13:00 +0000 Subject: [PATCH] perform action on multiple pictures at once. NOT FINISHED! --- core.c | 492 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- core.h | 6 +- 2 files changed, 496 insertions(+), 2 deletions(-) diff --git a/core.c b/core.c index c8ac693..71d514d 100644 --- a/core.c +++ b/core.c @@ -1,7 +1,7 @@ /* core.c The tool with multiple enhancements and manipulations of pictures -13.11.2022 +14.11.2022 Copyright (C) 2014, 2015, 2022 Balthasar Szczepański @@ -1026,6 +1026,496 @@ int action_1picture ( return r; } +int perform_action ( + uint_fast16_t n, + uint_fast16_t *id, + ILint *x0, ILint *y0, *ILint f0, ILint width, ILint height, ILint frames, + ACTION_F *function, + FLAG_TYPE *flags, + void *data +) +{ + uint_fast16_t i, j; + uint_fast8_t palette_only = 1; + uint_fast8_t skip_frame; + uint_fast8_t skip_line; + uint_fast8_t skip_pixel; + ILint actual_frames = 0xFFFFFFFF; + ILint actual_width = 0xFFFFFFFF; + ILint actual_height = 0xFFFFFFFF; + ILint actual_colours= 0xFFFFFFFF; + ILint x, y, f; + struct PixelInfo *p; + int r = 0; + + if (n==0) + return 0; + + p = malloc((sizeof (struct PixelInfo)) * n); + if (p == NULL) + { + perror("perform_action(): malloc():"); + return (r=errno); + } + + for (i=0; i= n_pictures) + { + free(p); + return EINVAL; + } + if (!(picture[id].open)) + { + free(p); + return EINVAL; + } + + get_info(id[i], &(p[i].info), 0); + + if (p[i].info.num_images > 0) + p[i].flags |= IS_MULTIPLE; + if (p[i].flags & CAN_BE_MULTIPLE) + { + if (p[i].num_images+1 < actual_frames) + actual_frames = p[i].num_images+1; + } + else + actual_frames = 1; + + if (p[i].info.image_width < actual_width) + actual_width = p[i].info.image_width; + if (p[i].info.image_height < actual_height) + actual_height = p[i].info.image_height; + + if (*flags & IN_WINDOW) /* check first flags only! */ + { + p[i].f0 = f0[i]; + p[i].x0 = x0[i]; + p[i].y0 = y0[i]; + } + else + { + p[i].f0 = 0; + p[i].x0 = 0; + p[i].y0 = 0; + } + + if ((p[i].info.image_format != IL_COLOUR_INDEX) || (!(p[i].flags & OK_PALETTE_ONLY))) + palette_only = 0; + } + + if (!(*flags & IN_WINDOW)) /* check first flags only! */ + { + width = actual_width; + height = actual_height; + frames = actual_frames; + } + + for (f = 0; (f < frames) && (r == 0); ++f) + { + skip_frame = 0; + for (i=0; i p[i].info.num_images)) + { + skip_frame = 1; + break; + } + + ilBindImage(picture[id[i]].handle); + ilActiveImage(p[i].f_pict); + p[i].data = ilGetData(); + p[i].flags &= ~(IS_GRAY|IS_INDEXED|IS_OVER_8BIT|IS_PALETTE_ONLY); + if (palette_only) + p[i].flags |= IS_PALETTE_ONLY; + + p[i].alpha_offset = 0; + p[i].value_offset = 0; + p[i].index_offset = 0; + p[i].red_offset = 0; + p[i].green_offset = 0; + p[i].blue_offset = 0; + + if (palette_only) + { + if (p[i].palette_num_cols < actual_colours) + actual_colours = p[i].palette_num_cols; + } + + switch (p[i].info.image_format) + { + case IL_COLOUR_INDEX: + p[i].flags |= IS_INDEXED; + p[i].palette = ilGetPalette(); + switch (p[i].info.palette_type) + { + 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; + p[i].green_offset = 1; + 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: + p[i].red_offset = 0; + p[i].green_offset = 1; + p[i].blue_offset = 2; + break; + } + break; + case IL_LUMINANCE_ALPHA: + p[i].flags |= HAS_ALPHA; + p[i].alpha_offset = 1 * p[i].info.image_bpc; + case IL_LUMINANCE: + p[i].flags |= IS_GRAY; + p[i].value_offset = 0 * p[i].info.image_bpc; + break; + case IL_BGRA: + p[i].flags |= HAS_ALPHA; + p[i].alpha_offset = 3 * p[i].info.image_bpc; + case IL_BGR: + p[i].red_offset = 2 * p[i].info.image_bpc; + p[i].green_offset = 1 * p[i].info.image_bpc; + p[i].blue_offset = 0 * p[i].info.image_bpc; + break; + case IL_RGBA: + p[i].flags |= HAS_ALPHA; + p[i].alpha_offset = 3 * p[i].info.image_bpc; + case IL_RGB: + default: + p[i].red_offset = 0 * p[i].info.image_bpc; + p[i].green_offset = 1 * p[i].info.image_bpc; + p[i].blue_offset = 2 * p[i].info.image_bpc; + break; + } + if (p[i].info.image_bpc > 1) + p[i].flags |= IS_OVER_8BIT; + } + if (!skip_frame) + { + if (palette_only) + { + for (i=0; i= p[i]info.image_height)) + { + skip_line = 1; + break; + } + + p[i].x_window = 0; + p[i].x_pict = p[i].x0; + p[i].pixel_offset = p[i].line_offset + (p[i].x_pict * p[i].info.image_bytes_per_pixel); + } + if (!skip_line) + { + for (x=0; x= p[i]info.image_width)) + { + skip_pixel = 1; + break; + } + } + if (!skip_pixel) + { + for (i=0; i