]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
introduce more order in big action runner, not finished.
authorb <rowerynaksiezycu@gmail.com>
Tue, 8 Nov 2022 22:48:47 +0000 (23:48 +0100)
committerb <rowerynaksiezycu@gmail.com>
Tue, 8 Nov 2022 22:48:47 +0000 (23:48 +0100)
core.c
core.h
makefile
testimg/4_3_2_t.gif [new file with mode: 0644]

diff --git a/core.c b/core.c
index 97301df4f1e7bafbed9c973b74f7e295900880fe..20a5f4bd80d9f36b1f4482aa1278c4dbe5cf6b7f 100644 (file)
--- a/core.c
+++ b/core.c
@@ -1,7 +1,7 @@
 /*
 core.c
 The tool with multiple enhancements and manipulations of pictures
-06.11.2022
+08.11.2022
 
 Copyright (C) 2014, 2015, 2022  Balthasar Szczepański
 
@@ -60,6 +60,14 @@ void finish (int const returnvalue, char const * const returntext)
        exit(returnvalue);
 }
 
+ILuint get_handle (uint_fast16_t id)
+{
+       if (id<n_pictures)
+               return picture[id].handle;
+       else  /* invalid but must return something */
+               return -1;
+}
+
 void create_picture (uint_fast16_t id)
 {
        if (id<n_pictures)
@@ -457,232 +465,147 @@ int action_1picture (
        ILint x0, ILint y0, ILint width, ILint height,
        ACTION_F *function,
        FLAG_TYPE flags,
-       void *f_data
+       void *data
 )
 {
-       ILint x, y, z;
+       ILint f;
        ILint frames;
-       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, v_offset, i_offset;
-       void *data;
-       int re;
+       struct PixelInfo p;
+       int r;
        
-       flags &= ~(IS_GRAY|IS_INDEXED|IS_MULTIPLE|IS_OVER_8BIT|IS_PALETTE_ONLY);
+       p.flags = flags & ~(IS_MULTIPLE);
        
        if (id >= n_pictures)
                return EINVAL;
-       ilBindImage(picture[id].handle);
-       
-       // data = ilGetData();
-       
-       get_info(id, &info, 0);
-       switch (info.image_format)
-       {
-       case IL_COLOUR_INDEX:
-               flags |= IS_INDEXED;
-               switch (info.palette_type)
-               {
-               case IL_PAL_BGR32:
-               case IL_PAL_RGB32:
-                       flags |= IS_OVER_8BIT;
-                       break;
-               case IL_PAL_BGRA32:
-               case IL_PAL_RGBA32:
-                       flags |= HAS_ALPHA;
-                       break;
-               case IL_PAL_BGR24:
-               case IL_PAL_RGB24:
-               default:
-                       break;
-               }
-       case IL_LUMINANCE_ALPHA:
-               flags |= HAS_ALPHA;
-       case IL_LUMINANCE:
-               flags |= IS_GRAY;
-               break;
-       case IL_BGRA:
-       case IL_RGBA:
-               flags |= HAS_ALPHA;
-       case IL_BGR:
-       case IL_RGB:
-       default:
-               break;
-       }
-       switch(info.image_type)
-       {
-       case IL_BYTE:
-       case IL_UNSIGNED_BYTE:
-               break;
-       default:
-               flags |= IS_OVER_8BIT;
-       }
-       frames = info.num_images + 1;
-       if (frames > 1)
-               flags |= IS_MULTIPLE;
-       
-       if ((flags & IS_INDEXED) && (flags & OK_PALETTE_ONLY))
-               flags |= IS_PALETTE_ONLY;
        
-       if (!(flags & IN_WINDOW))
-       {
-               x0 = 0;
-               y0 = 0;
-               width = info.image_width;
-               height = info.image_height;
-       }
-       
-       line_bytes = info.image_bytes_per_pixel * info.image_width;
-       frame_bytes = line_bytes * info.image_height;
+       ilBindImage(picture[id].handle);
+       get_info(id, &(p.info), 0);
        
-       // if (info.origin_mode == IL_ORIGIN_UPPER_LEFT)
-       // {
-               // line_start = frame_bytes;
-               // line_bytes = 0 - line_bytes;
-       // }
-       // else
-               // line_start = 0;
+       if (p.info.num_images > 0)
+               p.flags |= IS_MULTIPLE;
+       frames = (p.flags & CAN_BE_MULTIPLE) ? (p.info.num_images+1) : 1;
        
-       if (flags & IS_PALETTE_ONLY)
-       {
+       for (
+               f = 0;
+               f < frames;
+               ++f
+       ){
+               p.f_window = f;
+               p.f_pict = f;
                
-       }
-       else
-       {
-               r_offset = -1;
-               g_offset = -1;
-               b_offset = -1;
-               a_offset = -1;
-               v_offset = -1;
-               i_offset = -1;
-               switch (info.image_type)
+               ilBindImage(picture[id].handle);
+               ilActiveImage(z);
+               p.data = ilGetData();
+               p.flags &= ~(IS_GRAY|IS_INDEXED|IS_OVER_8BIT|IS_PALETTE_ONLY);
+               
+               p.alpha_offset = -1;
+               p.value_offset = -1;
+               p.index_offset = -1;
+               p.red_offset = -1;
+               p.green_offset = -1;
+               p.blue_offset = -1;
+               
+               switch (p.info.image_format)
                {
-               case IL_INT:
-               case IL_UNSIGNED_INT:
-                       switch (info.image_format)
+               case IL_COLOUR_INDEX:
+                       p.flags |= IS_INDEXED;
+                       p.palette = ilGetPalette();
+                       switch (p.info.palette_type)
                        {
-                       case IL_BGRA:
-                               a_offset = 12;
-                       case IL_BGR:
-                               r_offset = 8;
-                               g_offset = 4;
-                               b_offset = 0;
-                               break;
-                       case IL_RGBA:
-                               a_offset = 12;
-                       case IL_RGB:
-                               r_offset = 0;
-                               g_offset = 4;
-                               b_offset = 8;
+                       case IL_PAL_BGR32:
+                       case IL_PAL_RGB32:
+                               p.flags |= IS_OVER_8BIT;
                                break;
-                       case IL_LUMINANCE_ALPHA:
-                               a_offset = 4;
-                       case IL_LUMINANCE:
-                               v_offset = 0;
+                       case IL_PAL_BGRA32:
+                               p.flags |= HAS_ALPHA;
+                               p.alpha_offset = 3;
+                       case IL_PAL_BGR24:
+                               p.red_offset = 2;
+                               p.green_offset = 1;
+                               p.blue_offset = 0;
                                break;
-                       case IL_COLOUR_INDEX:
-                               i_offset = 0;
+                       case IL_PAL_RGBA32:
+                               p.flags |= HAS_ALPHA;
+                               p.alpha_offset = 3;
+                       case IL_PAL_RGB24:
                        default:
+                               p.red_offset = 0;
+                               p.green_offset = 1;
+                               p.blue_offset = 2;
                                break;
                        }
                        break;
-               case IL_SHORT:
-               case IL_UNSIGNED_SHORT:
-                       switch (info.image_format)
-                       {
-                       case IL_BGRA:
-                               a_offset = 6;
-                       case IL_BGR:
-                               r_offset = 4;
-                               g_offset = 2;
-                               b_offset = 0;
-                               break;
-                       case IL_RGBA:
-                               a_offset = 6;
-                       case IL_RGB:
-                               r_offset = 0;
-                               g_offset = 2;
-                               b_offset = 8;
-                               break;
-                       case IL_LUMINANCE_ALPHA:
-                               a_offset = 2;
-                       case IL_LUMINANCE:
-                               v_offset = 0;
-                               break;
-                       case IL_COLOUR_INDEX:
-                               i_offset = 0;
-                       default:
-                               break;
-                       }
+               case IL_LUMINANCE_ALPHA:
+                       p.flags |= HAS_ALPHA;
+                       p.alpha_offset = 1 * p.info.image_bpc;
+               case IL_LUMINANCE:
+                       p.flags |= IS_GRAY;
+                       p.value_offset = 0 * p.info.image_bpc;
                        break;
-               case IL_BYTE:
-               case IL_UNSIGNED_BYTE:
-                       switch (info.image_format)
-                       {
-                       case IL_BGRA:
-                               a_offset = 3;
-                       case IL_BGR:
-                               r_offset = 2;
-                               g_offset = 1;
-                               b_offset = 0;
-                               break;
-                       case IL_RGBA:
-                               a_offset = 3;
-                       case IL_RGB:
-                               r_offset = 0;
-                               g_offset = 1;
-                               b_offset = 2;
-                               break;
-                       case IL_LUMINANCE_ALPHA:
-                               a_offset = 1;
-                       case IL_LUMINANCE:
-                               v_offset = 0;
-                               break;
-                       case IL_COLOUR_INDEX:
-                               i_offset = 0;
-                       default:
-                               break;
-                       }
+               case IL_BGRA:
+                       p.flags |= HAS_ALPHA;
+                       p.alpha_offset = 3 * p.info.image_bpc;
+               case IL_BGR:
+                       p.red_offset = 2 * p.info.image_bpc;
+                       p.green_offset = 1 * p.info.image_bpc;
+                       p.blue_offset = 0 * p.info.image_bpc;
                        break;
+               case IL_RGBA:
+                       p.flags |= HAS_ALPHA;
+                       p.alpha.offset = 3 * p.info.image_bpc;
+               case IL_RGB:
                default:
+                       p.red_offset = 0 * p.info.image_bpc;
+                       p.green_offset = 1 * p.info.image_bpc;
+                       p.blue_offset = 2 * p.info.image_bpc;
                        break;
                }
+               if (p.info.image_bpc > 1);
+                       p.flags |= IS_OVER_8BIT;
                
-               // for (
-                       // z=0, frame_offset=0;
-                       // z<frames;
-                       // ++z, frame_offset += frame_bytes
-               // ){
-               for (
-                       z = 0;
-                       z < frames;
-                       ++z
-               ){
-                       // for (
-                               // y=y0, line_offset=frame_offset+line_start+(y0*line_bytes);
-                               // y < y0 + height;
-                               // ++y, line_offset += line_bytes
-                       // ){
-                       ilBindImage(picture[id].handle);
-                       // ilActiveImage(0);
-                       ilActiveImage(z);
-                       data = ilGetData();
+               if ((p.flags & IS_INDEXED) && (p.flags & OK_PALETTE_ONLY))
+               {
+                       p.flags |= IS_PALETTE_ONLY;
+                       /* TODO */
+               }
+               else
+               {
+                       p.line_bytes = p.info.image_bytes_per_pixel * p.info.image_width;
+                       p.frame_bytes = p.line_bytes * p.info.image_height;
+                       
+                       if (info.origin_mode == IL_ORIGIN_LOWER_LEFT)
+                       {
+                               p.line_start = p.frame_bytes - p.line_bytes;
+                               p.line_bytes = 0 - p.line_bytes;
+                       }
+                       else
+                               p.line_start = 0;
+                       
+                       if (!(flags & IN_WINDOW))
+                       {
+                               x0 = 0;
+                               y0 = 0;
+                               width = p.info.image_width;
+                               height = p.info.image_height;
+                       }
+
                        for (
-                               y = y0, line_offset = y0 * line_bytes;
-                               y < y0 + height;
-                               ++y, line_offset += line_bytes
+                               p.y_window = 0, p.y_pict = y0, p.line_offset = p.line_start + (p.y_pict * p.line_bytes);
+                               p.y_window < height,
+                               ++p.y_window, ++p.y_pict, p.line_offset += p.line_bytes
                        ){
-                               if ((y>=0)&&(y<info.image_height))
+                               if ((p.y_pict >= 0) && (p.y_pict < p.info.image_height))
                                {
                                        for (
-                                               x = x0, pixel_offset = line_offset + (x0 * info.image_bytes_per_pixel);
-                                               x < x0 + width;
-                                               ++x, pixel_offset += info.image_bytes_per_pixel
+                                               p.x_window = 0, p.x_pict = x0, p.pixel_offset = p.line_offset + (p.x_pict * p.info.image_bytes_per_pixel);
+                                               p.x_window < width;
+                                               ++p.x_window, ++p.x_pict, p.pixel_offset += p.info.image_bytes_per_pixel
                                        ){
-                                               if ((x>=0)&&(x<info.image_width))
+                                               if ((p.x_pict >=0) && (p.x_pict < p.info.image_width))
                                                {
+                                                       
+                                                       
+                                                       
                                                        switch (info.image_type)
                                                        {
                                                        case IL_INT:
@@ -769,17 +692,14 @@ int action_1picture (
        return 0;
 }
 int action(
-       ILint x, ILint y, ILint z,
-       ILuint *r, ILuint *g, ILuint *b, ILuint *a, ILuint *v, ILuint *i,
-       FLAG_TYPE flags,
-       void *data
+       ILuint n, struct PixelInfo *info, 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)
+               (unsigned long)(info->x_pict), (unsigned long)(info->y_pict), (unsigned long)(info->f_pict),
+               (unsigned long)(info->red), (unsigned long)(info->green), (unsigned long)(info->blue),
+               (unsigned long)(info->alpha), (unsigned long)(info->value), (unsigned long)(info->index)
        );
        return 0;
 }
diff --git a/core.h b/core.h
index c02677a48e82efdb43bbe121b03c7e2767fdb2fc..29dfd29301310e9f647b2924c06c2d1f28de38c8 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,7 +1,7 @@
  /*
 core.h
 The tool with multiple enhancements and manipulations of pictures
-06.11.2022
+08.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -64,6 +64,44 @@ struct Picture {
        ILuint handle;
 };
 
+struct PixelInfo
+{
+       ILint x_window;
+       ILint y_window;
+       ILint f_window;
+       
+       ILint x_pict;
+       ILint y_pict;
+       ILint f_pict;
+       
+       ILuint red;
+       ILuint green;
+       ILuint blue;
+       ILuint value;
+       ILuint alpha;
+       ILuint index;
+       
+       ILint red_offset;
+       ILint green_offset;
+       ILint blue_offset;
+       ILint value_offset;
+       ILint alpha_offset;
+       ILint index_offset;
+       
+       ILint line_start;
+       ILint line_bytes;
+       ILint frame_bytes;
+       
+       ILint line_offset;
+       ILint pixel_offset;
+       
+       FLAG_TYPE flags;
+       void *data;
+       void *palette;
+       
+       struct IL_full_info info;
+}
+
 struct IL_full_info {
        ILint active_image;
        ILint active_layer;
@@ -111,9 +149,7 @@ struct IL_full_info {
 };
 
 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
+       ILuint n, struct PixelInfo *info, void *data
 );
 
 
@@ -121,7 +157,7 @@ typedef int (ACTION_F)(
 
 void finish (int const returnvalue, char const * const returntext);
 int init (void);
-
+ILuint get_handle (uint_fast16_t id);
 void create_picture (uint_fast16_t id);
 int create_pictures (uint_fast16_t n);
 void close_picture (uint_fast16_t id);
index 38774681901507bd765e95b29264d01841786023..aab5b132775252cb6d19bc3c3c5582efcfde09df 100644 (file)
--- a/makefile
+++ b/makefile
@@ -9,6 +9,9 @@ all: enhance
 enhance: enhance.c core.h core.c nofading.h nofading.c info.h info.c
        $(CC) $(CF) -o enhance enhance.c core.c nofading.c info.c $(LF)
 
+#test: test.c core.h core.c
+#      $(CC) $(CF) -o test test.c core.c $(LF)
+
 clean:
        rm enhance
 
diff --git a/testimg/4_3_2_t.gif b/testimg/4_3_2_t.gif
new file mode 100644 (file)
index 0000000..caecdab
Binary files /dev/null and b/testimg/4_3_2_t.gif differ