]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
more order to this
authorb <rowerynaksiezycu@gmail.com>
Sun, 6 Nov 2022 18:13:22 +0000 (19:13 +0100)
committerb <rowerynaksiezycu@gmail.com>
Sun, 6 Nov 2022 18:13:22 +0000 (19:13 +0100)
core.c
core.h
enhance.c
info.c
makefile
nofading.c
testimg/4_3_2.gif [new file with mode: 0644]
testimg/4x4x4.gif [new file with mode: 0644]

diff --git a/core.c b/core.c
index b39df1c7a1d7347c79c3abd787a4dbb49e7a549f..97301df4f1e7bafbed9c973b74f7e295900880fe 100644 (file)
--- a/core.c
+++ b/core.c
@@ -1,7 +1,7 @@
 /*
 core.c
 The tool with multiple enhancements and manipulations of pictures
-05.11.2022
+06.11.2022
 
 Copyright (C) 2014, 2015, 2022  Balthasar Szczepański
 
@@ -36,13 +36,21 @@ on Pentium III libdevil must be recompiled with
 uint_fast16_t n_pictures = 0;
 struct Picture * picture;
 
+char INIT_FAILED[]   = "Failae to set up library.\n";
 char LOAD_FAILED[]   = "Failed to load picture.\n";
 char CREATE_FAILED[] = "Failed to create picture(s).\n";
+char NO_STR[] = "";
 
-void init (void)
+int init (void)
 {
        ilInit();
-       ilEnable(IL_FILE_OVERWRITE);
+       if (!ilEnable(IL_FILE_OVERWRITE))
+               return EIO;
+       // if(!ilEnable(IL_ORIGIN_SET))
+               // return EIO;
+       // if(!ilOriginFunc(IL_ORIGIN_UPPER_LEFT))
+               // return EIO;
+       return 0;
 }
 
 void finish (int const returnvalue, char const * const returntext)
@@ -151,7 +159,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
        
        if (!(flags & CAN_BE_MULTIPLE))
        {
-               if (ilGetInteger(IL_NUM_IMAGES) > 1)
+               if (ilGetInteger(IL_NUM_IMAGES) > 0)
                {
                        fputs("Picture is not allowed to have multiple frames.\n", stderr);
                        return EINVAL;
@@ -382,29 +390,56 @@ int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
        return convert_picture(id, flags);
 }
 
-void get_info (uint_fast16_t id, struct IL_full_info *info)
+int get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame)
 {
+       int r = 0;
+       
        if (id < n_pictures)
+       {
                ilBindImage(picture[id].handle);
+               if (frame <= ilGetInteger(IL_NUM_IMAGES))
+               {
+                       if(!ilActiveImage(frame))
+                               r = EIO;
+               }
+       }
        
        info->active_image          = ilGetInteger(IL_ACTIVE_IMAGE);
        info->active_layer          = ilGetInteger(IL_ACTIVE_LAYER);
        info->active_mipmap         = ilGetInteger(IL_ACTIVE_MIPMAP);
+       info->blit_blend            = ilGetInteger(IL_BLIT_BLEND);
+       info->compress_mode         = ilGetInteger(IL_COMPRESS_MODE);
        info->conv_pal              = ilGetInteger(IL_CONV_PAL);
        info->cur_image             = ilGetInteger(IL_CUR_IMAGE);
+       info->default_on_fail       = ilGetInteger(IL_DEFAULT_ON_FAIL);
+       info->dxtc_data_format      = ilGetInteger(IL_DXTC_DATA_FORMAT);
        info->file_mode             = ilGetInteger(IL_FILE_MODE);
        info->format_mode           = ilGetInteger(IL_FORMAT_MODE);
        info->format_set            = ilGetInteger(IL_FORMAT_SET);
        info->image_bits_per_pixel  = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
+       info->image_bpc             = ilGetInteger(IL_IMAGE_BPC);
        info->image_bytes_per_pixel = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
+       info->image_channels        = ilGetInteger(IL_IMAGE_CHANNELS);
+       info->image_cubeflags       = ilGetInteger(IL_IMAGE_CUBEFLAGS);
+       info->image_depth           = ilGetInteger(IL_IMAGE_DEPTH);
+       info->image_duration        = ilGetInteger(IL_IMAGE_DURATION);
        info->image_format          = ilGetInteger(IL_IMAGE_FORMAT);
        info->image_height          = ilGetInteger(IL_IMAGE_HEIGHT);
+       info->image_offx            = ilGetInteger(IL_IMAGE_OFFX);
+       info->image_offy            = ilGetInteger(IL_IMAGE_OFFY);
+       info->image_origin          = ilGetInteger(IL_IMAGE_ORIGIN);
+       info->image_planesize       = ilGetInteger(IL_IMAGE_PLANESIZE);
+       info->image_size_of_data    = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
        info->image_type            = ilGetInteger(IL_IMAGE_TYPE);
        info->image_width           = ilGetInteger(IL_IMAGE_WIDTH);
+       info->keep_dxtc_data        = ilGetInteger(IL_KEEP_DXTC_DATA);
+       info->num_faces             = ilGetInteger(IL_NUM_FACES);
        info->num_images            = ilGetInteger(IL_NUM_IMAGES);
+       info->num_layers            = ilGetInteger(IL_NUM_LAYERS);
        info->num_mipmaps           = ilGetInteger(IL_NUM_MIPMAPS);
        info->origin_mode           = ilGetInteger(IL_ORIGIN_MODE);
        info->origin_set            = ilGetInteger(IL_ORIGIN_SET);
+       info->palette_base_type     = ilGetInteger(IL_PALETTE_BASE_TYPE);
        info->palette_bpp           = ilGetInteger(IL_PALETTE_BPP);
        info->palette_num_cols      = ilGetInteger(IL_PALETTE_NUM_COLS);
        info->palette_type          = ilGetInteger(IL_PALETTE_TYPE);
@@ -412,6 +447,9 @@ void get_info (uint_fast16_t id, struct IL_full_info *info)
        info->type_set              = ilGetInteger(IL_TYPE_SET);
        info->use_key_colour        = ilGetInteger(IL_USE_KEY_COLOUR);
        info->version_num           = ilGetInteger(IL_VERSION_NUM);
+       
+
+       return r;
 }
 
 int action_1picture (
@@ -438,9 +476,9 @@ int action_1picture (
                return EINVAL;
        ilBindImage(picture[id].handle);
        
-       data = ilGetData();
+       // data = ilGetData();
        
-       get_info(id, &info);
+       get_info(id, &info, 0);
        switch (info.image_format)
        {
        case IL_COLOUR_INDEX:
@@ -481,11 +519,9 @@ int action_1picture (
        default:
                flags |= IS_OVER_8BIT;
        }
-       frames = info.num_images;
+       frames = info.num_images + 1;
        if (frames > 1)
                flags |= IS_MULTIPLE;
-       else if (frames < 1)
-               frames = 1;
        
        if ((flags & IS_INDEXED) && (flags & OK_PALETTE_ONLY))
                flags |= IS_PALETTE_ONLY;
@@ -501,13 +537,13 @@ int action_1picture (
        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)
-       {
-               line_start = frame_bytes;
-               line_bytes = 0 - line_bytes;
-       }
-       else
-               line_start = 0;
+       // if (info.origin_mode == IL_ORIGIN_UPPER_LEFT)
+       // {
+               // line_start = frame_bytes;
+               // line_bytes = 0 - line_bytes;
+       // }
+       // else
+               // line_start = 0;
        
        if (flags & IS_PALETTE_ONLY)
        {
@@ -614,20 +650,34 @@ int action_1picture (
                        break;
                }
                
+               // for (
+                       // z=0, frame_offset=0;
+                       // z<frames;
+                       // ++z, frame_offset += frame_bytes
+               // ){
                for (
-                       z=0, frame_offset=0;
-                       z<frames;
-                       ++z, frame_offset += frame_bytes
+                       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();
                        for (
-                               y=y0, line_offset=frame_offset+line_start+(y0*line_bytes);
+                               y = y0, line_offset = y0 * line_bytes;
                                y < y0 + height;
                                ++y, line_offset += line_bytes
                        ){
                                if ((y>=0)&&(y<info.image_height))
                                {
                                        for (
-                                               x=x0, pixel_offset=line_offset+(x0*info.image_bytes_per_pixel);
+                                               x = x0, pixel_offset = line_offset + (x0 * info.image_bytes_per_pixel);
                                                x < x0 + width;
                                                ++x, pixel_offset += info.image_bytes_per_pixel
                                        ){
@@ -716,7 +766,7 @@ int action_1picture (
                        }
                }
        }
-       
+       return 0;
 }
 int action(
        ILint x, ILint y, ILint z,
diff --git a/core.h b/core.h
index 93a62b3f09ce5fe04028896d985029e17be3c37b..c02677a48e82efdb43bbe121b03c7e2767fdb2fc 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,7 +1,7 @@
  /*
 core.h
 The tool with multiple enhancements and manipulations of pictures
-05.11.2022
+06.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 NO_STR[];
+extern char INIT_FAILED[];
 extern char LOAD_FAILED[];
 extern char CREATE_FAILED[];
 
@@ -66,21 +68,39 @@ struct IL_full_info {
        ILint active_image;
        ILint active_layer;
        ILint active_mipmap;
+       ILint blit_blend; //b
+       ILint compress_mode; //
        ILint conv_pal;
        ILint cur_image;
+       ILint default_on_fail; //b
+       ILint dxtc_data_format; //
        ILint file_mode;
        ILint format_mode;
        ILint format_set;
        ILint image_bits_per_pixel;
+       ILint image_bpc; //
        ILint image_bytes_per_pixel;
+       ILint image_channels; //
+       ILint image_cubeflags; //
+       ILint image_depth; //
+       ILint image_duration; //
        ILint image_format;
        ILint image_height;
+       ILint image_offx; //
+       ILint image_offy; //
+       ILint image_origin; //
+       ILint image_planesize; //
+       ILint image_size_of_data; //
        ILint image_type;
        ILint image_width;
+       ILint keep_dxtc_data; //
+       ILint num_faces; //
        ILint num_images;
+       ILint num_layers; //
        ILint num_mipmaps;
        ILint origin_mode;
        ILint origin_set;
+       ILint palette_base_type; //
        ILint palette_bpp;
        ILint palette_num_cols;
        ILint palette_type;
@@ -100,7 +120,7 @@ typedef int (ACTION_F)(
 
 
 void finish (int const returnvalue, char const * const returntext);
-void init (void);
+int init (void);
 
 void create_picture (uint_fast16_t id);
 int create_pictures (uint_fast16_t n);
@@ -110,7 +130,7 @@ void clear_pictures (void);
 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 get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame);
 
 int action_1picture (
        uint_fast16_t id,
index f4c87294dc016b2944267c0a8dfccceac7d004c7..0f8eca69cddb420ec620150979b1eae52f82d54d 100644 (file)
--- a/enhance.c
+++ b/enhance.c
@@ -1,7 +1,7 @@
 /*
 enhance.c
 The tool with multiple enhancements and manipulations of pictures
-21.10.2022
+06.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -32,16 +32,17 @@ on Pentium III libdevil must be recompiled with
 #include "info.h"
 #include "nofading.h"
 
-
 int main (int argc, char **argv)
 {
        int r;
-       char *error_text;
+       char *error_text = NO_STR;
        
        if (argc < 2)
                finish(EINVAL, "No mode selected.\n");
        
-       init();
+       r = init();
+       if (r !=0)
+               finish(r, INIT_FAILED);
        
        if (strcmp(argv[1], "nofading")==0)
                r = nofading(argc-2, argv+2, &error_text);
diff --git a/info.c b/info.c
index 023c35d88fb94e7c3fe765f7df5da45a5b20649b..1817104ba1ef11aef62de652c230b722d49234b2 100644 (file)
--- a/info.c
+++ b/info.c
@@ -1,7 +1,7 @@
 /*
 info.c
 Get information
-05.11.2022
+06.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -164,6 +164,8 @@ int info (int argc, char **argv, char **err)
 {
        int r;
        int i;
+       ILint j;
+       ILint frames=1;
        struct IL_full_info info;
        
        if (argc<1)
@@ -190,32 +192,57 @@ int info (int argc, char **argv, char **err)
                        continue;
                }
                
-               get_info(0, &info);
-               print_info_uint       ("active_image",          info.active_image);
-               print_info_uint       ("active_layer",          info.active_layer);
-               print_info_uint       ("active_mipmap",         info.active_mipmap);
-               print_info_bool       ("conv_pal",              info.conv_pal);
-               print_info_uint       ("cur_image",             info.cur_image);
-               print_info_bool       ("file_mode",             info.file_mode);
-               print_info_dataformat ("format_mode",           info.format_mode);
-               print_info_bool       ("format_set",            info.format_set);
-               print_info_uint       ("image_bits_per_pixel",  info.image_bits_per_pixel);
-               print_info_uint       ("image_bytes_per_pixel", info.image_bytes_per_pixel);
-               print_info_dataformat ("image_format",          info.image_format);
-               print_info_uint       ("image_height",          info.image_height);
-               print_info_datatype   ("image_type",            info.image_type);
-               print_info_uint       ("image_width",           info.image_width);
-               print_info_uint       ("num_images",            info.num_images);
-               print_info_uint       ("num_mipmaps",           info.num_mipmaps);
-               print_info_originmode ("origin_mode",           info.origin_mode);
-               print_info_bool       ("origin_set",            info.origin_set);
-               print_info_uint       ("palette_bpp",           info.palette_bpp);
-               print_info_uint       ("palette_num_cols",      info.palette_num_cols);
-               print_info_palettetype("palette_type",          info.palette_type);
-               print_info_datatype   ("type_mode",             info.type_mode);
-               print_info_bool       ("type_set",              info.type_set);
-               print_info_bool       ("use_key_colour",        info.use_key_colour);
-               print_info_uint       ("version_num",           info.palette_num_cols);
+               for (j=0; j<frames; ++j)
+               {
+                       get_info(0, &info, j);
+                       if (j==0)
+                               frames = info.num_images+1;
+                       else
+                               fprintf(stdout, "--- %lu ---\n", (unsigned long)j);
+                       print_info_uint       ("active_image",          info.active_image);
+                       print_info_uint       ("active_layer",          info.active_layer);
+                       print_info_uint       ("active_mipmap",         info.active_mipmap);
+                       print_info_bool       ("blit_blend",            info.blit_blend);
+                       print_info_uint       ("compress_mode",         info.compress_mode);
+                       print_info_bool       ("conv_pal",              info.conv_pal);
+                       print_info_uint       ("cur_image",             info.cur_image);
+                       print_info_bool       ("default_on_fail",       info.default_on_fail);
+                       print_info_uint /*?*/ ("dxtc_data_format",      info.dxtc_data_format);
+                       print_info_bool       ("file_mode",             info.file_mode);
+                       print_info_dataformat ("format_mode",           info.format_mode);
+                       print_info_bool       ("format_set",            info.format_set);
+                       print_info_uint       ("image_bits_per_pixel",  info.image_bits_per_pixel);
+                       print_info_uint       ("image_bpc",             info.image_bpc);
+                       print_info_uint       ("image_bytes_per_pixel", info.image_bytes_per_pixel);
+                       print_info_uint       ("image_channels",        info.image_channels);
+                       print_info_uint       ("image_cubeflags",       info.image_cubeflags);
+                       print_info_uint       ("image_depth",           info.image_depth);
+                       print_info_uint       ("image_duration",        info.image_duration);
+                       print_info_dataformat ("image_format",          info.image_format);
+                       print_info_uint       ("image_height",          info.image_height);
+                       print_info_uint       ("image_offx",            info.image_offx);
+                       print_info_uint       ("image_offy",            info.image_offy);
+                       print_info_originmode ("image_origin",          info.image_origin);
+                       print_info_uint       ("image_planesize",       info.image_planesize);
+                       print_info_uint       ("image_size_of_data",    info.image_size_of_data);
+                       print_info_datatype   ("image_type",            info.image_type);
+                       print_info_uint       ("image_width",           info.image_width);
+                       print_info_uint /*?*/ ("keep_dxtc_data",        info.keep_dxtc_data);
+                       print_info_uint       ("num_faces",             info.num_faces);
+                       print_info_uint       ("num_images",            info.num_images);
+                       print_info_uint       ("num_layers",            info.num_layers);
+                       print_info_uint       ("num_mipmaps",           info.num_mipmaps);
+                       print_info_originmode ("origin_mode",           info.origin_mode);
+                       print_info_bool       ("origin_set",            info.origin_set);
+                       print_info_dataformat ("palette_base_type",     info.palette_base_type);
+                       print_info_uint       ("palette_bpp",           info.palette_bpp);
+                       print_info_uint       ("palette_num_cols",      info.palette_num_cols);
+                       print_info_palettetype("palette_type",          info.palette_type);
+                       print_info_datatype   ("type_mode",             info.type_mode);
+                       print_info_bool       ("type_set",              info.type_set);
+                       print_info_bool       ("use_key_colour",        info.use_key_colour);
+                       print_info_uint       ("version_num",           info.palette_num_cols);
+               }
        }
        return 0;
 }
index 41cc76561722c19ff0c044d2b4205dad271045ea..38774681901507bd765e95b29264d01841786023 100644 (file)
--- a/makefile
+++ b/makefile
@@ -9,6 +9,11 @@ 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)
 
+clean:
+       rm enhance
+
+PHONY: all clean
+
 #npb-ong1: npb-ong1.cpp makefile
 #      $(CC) $(CF) $(LF) -o npb-ong1 npb-ong1.cpp
 #
@@ -47,9 +52,10 @@ enhance: enhance.c core.h core.c nofading.h nofading.c info.h info.c
 #
 #compare: compare.c makefile
 #      $(CC) $(CF) $(LF) -o compare compare.c
-
-nofading: nofading.c makefile
-       $(CC) $(CF) $(LF) -o nofading nofading.c
-
-nofadingd: nofadingd.c makefile
-       $(CC) $(CF) $(LF) -o nofadingd nofadingd.c
+#
+#nofading: nofading.c makefile
+#      $(CC) $(CF) $(LF) -o nofading nofading.c
+#
+#nofadingd: nofadingd.c makefile
+#      $(CC) $(CF) $(LF) -o nofadingd nofadingd.c
+#
\ No newline at end of file
index ab6450551af25e4d166e84bf0bb97a6613a7195e..7d3afd69704973a68091380a7a4f2fde38ab655c 100644 (file)
@@ -1,7 +1,7 @@
 /*
 nofading.c
 The tool to remove fading from an image
-05.11.2022
+06.11.2022
 
 Copyright (C) 2015, 2022  Balthasar Szczepański
 
@@ -95,7 +95,7 @@ int nofading (int argc, char **argv, char **err)
                return r;
        }
        
-       r = load_picture(0, argv[0], 0);
+       r = load_picture(0, argv[0], CAN_BE_MULTIPLE);
        if (r)
        {
                *err = LOAD_FAILED;
@@ -106,7 +106,7 @@ int nofading (int argc, char **argv, char **err)
                0,
                0,0,0,0,
                &action,
-               0,
+               CAN_BE_MULTIPLE,
                NULL
        );
        
diff --git a/testimg/4_3_2.gif b/testimg/4_3_2.gif
new file mode 100644 (file)
index 0000000..5854fed
Binary files /dev/null and b/testimg/4_3_2.gif differ
diff --git a/testimg/4x4x4.gif b/testimg/4x4x4.gif
new file mode 100644 (file)
index 0000000..a2e6be8
Binary files /dev/null and b/testimg/4x4x4.gif differ