]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
more towards general action
authorb <rowerynaksiezycu@gmail.com>
Sat, 5 Nov 2022 18:19:25 +0000 (18:19 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 5 Nov 2022 18:19:25 +0000 (18:19 +0000)
core.c
core.h
enhance [deleted file]
info.c
nofading.c
testimg/4x4.png [new file with mode: 0644]

diff --git a/core.c b/core.c
index 93d9714ec7bcd534ed144a72ee3fb7a2d98944bb..9b9f1ce0cbef15adf57bd4e0a0a0a3c730c53c55 100644 (file)
--- 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<info.image_height))
                                {
                                        for (
-                                               x=x0, pixel_offset=line_offset+(x0*info.bytes_per_pixel);
+                                               x=x0, pixel_offset=line_offset+(x0*info.image_bytes_per_pixel);
                                                x < x0 + width;
                                                ++x
                                        ){
                                                if ((x>=0)&&(x<info.image_width))
                                                {
-                                                       if (flags & IS_INDEXED)
-                                                       {
-                                                               
-                                                       }
-                                                       else
+                                                       switch (info.image_type)
                                                        {
-                                                               switch (info.image_type)
+                                                       case IL_INT:
+                                                       case IL_UNSIGNED_INT:
+                                                               if(flags & IS_INDEXED)
+                                                                       i = (ILuint)(*((ILuint*)(data+pixel_offset+i_offset)));
+                                                               else
                                                                {
-                                                               case IL_INT:
-                                                               case IL_UNSIGNED_INT:
                                                                        if(flags & IS_GRAY)
-                                                                               y = (ILuint)(*((ILuint*)(data+pixel_offset+y_offset)));
+                                                                               v = (ILuint)(*((ILuint*)(data+pixel_offset+v_offset)));
                                                                        else
                                                                        {
                                                                                r = (ILuint)(*((ILuint*)(data+pixel_offset+r_offset)));
@@ -650,24 +651,65 @@ int action_1picture (
                                                                        }
                                                                        if(flags & HAS_ALPHA)
                                                                                a = (ILuint)(*((ILuint*)(data+pixel_offset+a_offset)));
-                                                                       break;
-                                                               case IL_SHORT:
-                                                               case IL_UNSIGNED_SHORT:
+                                                               }
+                                                               break;
+                                                       case IL_SHORT:
+                                                       case IL_UNSIGNED_SHORT:
+                                                               if(flags & IS_INDEXED)
+                                                                       i = (ILushort)(*((ILuint*)(data+pixel_offset+i_offset)));
+                                                               else
+                                                               {
                                                                        if(flags & IS_GRAY)
-                                                                               y = (ILuint)(*((ILuint*)(data+pixel_offset+y_offset)));
+                                                                               v = (ILushort)(*((ILuint*)(data+pixel_offset+v_offset)));
                                                                        else
                                                                        {
-                                                                               r = (ILuint)(*((ILuint*)(data+pixel_offset+r_offset)));
-                                                                               g = (ILuint)(*((ILuint*)(data+pixel_offset+g_offset)));
-                                                                               b = (ILuint)(*((ILuint*)(data+pixel_offset+b_offset)));
+                                                                               r = (ILushort)(*((ILuint*)(data+pixel_offset+r_offset)));
+                                                                               g = (ILushort)(*((ILuint*)(data+pixel_offset+g_offset)));
+                                                                               b = (ILushort)(*((ILuint*)(data+pixel_offset+b_offset)));
                                                                        }
                                                                        if(flags & HAS_ALPHA)
-                                                                               a = (ILuint)(*((ILuint*)(data+pixel_offset+a_offset)));
-                                                                       break;
+                                                                               a = (ILushort)(*((ILuint*)(data+pixel_offset+a_offset)));
+                                                               }
+                                                               break;
+                                                       case IL_BYTE:
+                                                       case IL_UNSIGNED_BYTE:
+                                                               if(flags & IS_INDEXED)
+                                                                       i = (ILushort)(*((ILubyte*)(data+pixel_offset+i_offset)));
+                                                               else
+                                                               {
+                                                                       if(flags & IS_GRAY)
+                                                                               v = (ILushort)(*((ILubyte*)(data+pixel_offset+v_offset)));
+                                                                       else
+                                                                       {
+                                                                               r = (ILushort)(*((ILubyte*)(data+pixel_offset+r_offset)));
+                                                                               g = (ILushort)(*((ILubyte*)(data+pixel_offset+g_offset)));
+                                                                               b = (ILushort)(*((ILubyte*)(data+pixel_offset+b_offset)));
+                                                                       }
+                                                                       if(flags & HAS_ALPHA)
+                                                                               a = (ILushort)(*((ILubyte*)(data+pixel_offset+a_offset)));
                                                                }
-                                                               
-                                                                       
-                                                                       
+                                                               break;
+                                                       default:
+                                                               break;
+                                                       }
+                                                       if ((flags & IS_INDEXED) && (flags & CANNOT_BE_INDEXED))
+                                                       {
+                                                               // TODO: i -> 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 e8fed75cdf4be1dc650d003c61ee82763f1ad700..93a62b3f09ce5fe04028896d985029e17be3c37b 100644 (file)
--- 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 (executable)
index e4c44cd..0000000
Binary files a/enhance and /dev/null differ
diff --git a/info.c b/info.c
index 3c3060c44361f527e96230f744d6c0cc16f96ee2..023c35d88fb94e7c3fe765f7df5da45a5b20649b 100644 (file)
--- 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;
        }
        
index 2079ce6ba8a88e4ebf390cd552f1c89fe8982f31..ab6450551af25e4d166e84bf0bb97a6613a7195e 100644 (file)
@@ -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 (file)
index 0000000..08c5812
Binary files /dev/null and b/testimg/4x4.png differ