/*
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
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)
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:
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;
}