/*
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
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();
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);
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:
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;
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)
g_offset = -1;
b_offset = -1;
a_offset = -1;
- y_offset = -1;
+ v_offset = -1;
i_offset = -1;
switch (info.image_type)
{
case IL_LUMINANCE_ALPHA:
a_offset = 4;
case IL_LUMINANCE:
- y_offset = 0;
+ v_offset = 0;
break;
case IL_COLOUR_INDEX:
i_offset = 0;
case IL_LUMINANCE_ALPHA:
a_offset = 2;
case IL_LUMINANCE:
- y_offset = 0;
+ v_offset = 0;
break;
case IL_COLOUR_INDEX:
i_offset = 0;
case IL_LUMINANCE_ALPHA:
a_offset = 1;
case IL_LUMINANCE:
- y_offset = 0;
+ v_offset = 0;
break;
case IL_COLOUR_INDEX:
i_offset = 0;
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)));
}
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; //!!!!!!!!
}
}
}
}
}
-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;
+}
+
/*
core.h
The tool with multiple enhancements and manipulations of pictures
-01.11.2022
+05.11.2022
Copyright (C) 2022 Balthasar Szczepański
#define IS_OVER_8BIT 0x4000
#define IS_PALETTE_ONLY 0x8000
+extern char LOAD_FAILED[];
+extern char CREATE_FAILED[];
struct Picture {
uint_fast8_t open;
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);
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