/*
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
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)
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;
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);
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 (
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:
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;
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)
{
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
){
}
}
}
-
+ return 0;
}
int action(
ILint x, ILint y, ILint z,
/*
core.h
The tool with multiple enhancements and manipulations of pictures
-05.11.2022
+06.11.2022
Copyright (C) 2022 Balthasar Szczepański
#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[];
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;
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);
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,
/*
enhance.c
The tool with multiple enhancements and manipulations of pictures
-21.10.2022
+06.11.2022
Copyright (C) 2022 Balthasar Szczepański
#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);
/*
info.c
Get information
-05.11.2022
+06.11.2022
Copyright (C) 2022 Balthasar Szczepański
{
int r;
int i;
+ ILint j;
+ ILint frames=1;
struct IL_full_info info;
if (argc<1)
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;
}
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
#
#
#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
/*
nofading.c
The tool to remove fading from an image
-05.11.2022
+06.11.2022
Copyright (C) 2015, 2022 Balthasar Szczepański
return r;
}
- r = load_picture(0, argv[0], 0);
+ r = load_picture(0, argv[0], CAN_BE_MULTIPLE);
if (r)
{
*err = LOAD_FAILED;
0,
0,0,0,0,
&action,
- 0,
+ CAN_BE_MULTIPLE,
NULL
);