return EINVAL;
}
- r = create_pictures(1);
+ r = reserve_pictures(1);
if (r)
{
*err = CREATE_FAILED;
if (id >= n_pictures)
return EINVAL;
+ if (!(picture[id].open))
+ return EINVAL;
+
r = get_info (id, &info_c, 0);
if (r!=0)
return r;
if (id >= n_pictures)
return EINVAL;
+ // if(!(picture[id].open))
+ create_picture(id);
+
ilBindImage(picture[id].handle);
if (!ilLoadImage(path))
return EIO;
return convert_picture(id, info, flags);
}
+int build_picture (uint_fast16_t id, ILint width, ILint height, ILint frames, struct IL_full_info *info, FLAG_TYPE *flags)
+{
+ info->image_width = width;
+ info->image_height = height;
+ if (*flags & CAN_BE_MULTIPLE)
+ info->num_images = frames-1;
+ else
+ info->num_images = 0;
+
+ if (*flags & MUST_BE_INDEXED)
+ {
+ info->image_format = IL_COLOUR_INDEX;
+ info->image_type = IL_UNSIGNED_BYTE;
+ info->image_channels = 1;
+ }
+ else
+ {
+ if (*flags & MUST_BE_GRAY)
+ {
+ if (*flags & MUST_HAVE_ALPHA)
+ {
+ info->image_format = IL_LUMINANCE_ALPHA;
+ info->image_channels = 2;
+ }
+ else
+ {
+ info->image_format = IL_LUMINANCE;
+ info->image_channels = 1;
+ }
+ }
+ else
+ {
+ if (*flags & MUST_HAVE_ALPHA)
+ {
+ info->image_format = IL_RGBA;
+ info->image_channels = 4;
+ }
+ else
+ {
+ info->image_format = IL_RGB;
+ info->image_channels = 3;
+ }
+ }
+ if (*flags & CAN_BE_OVER_8BIT)
+ info->image_type = IL_UNSIGNED_SHORT;
+ else
+ info->image_type = IL_UNSIGNED_BYTE;
+ }
+ return build_picture_from_info(id, info, flags);
+}
+
+int build_picture_from_info (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags)
+{
+ ILint i;
+ int r;
+
+ if (id >= n_pictures)
+ return EINVAL;
+
+ // if(!(picture[id].open))
+ create_picture(id);
+
+ ilBindImage(picture[id].handle);
+ if (info->num_images > 0)
+ {
+ if (!ilCreateSubImage(IL_SUB_NEXT, info->num_images))
+ return EIO;
+ }
+
+ for (i=0; i<=info->num_images; ++i)
+ {
+ ilBindImage(picture[id].handle);
+ ilActiveImage(i);
+ if (!ilTexImage(
+ info->image_width,
+ info->image_height,
+ 0,
+ info->image_channels,
+ info->image_format,
+ info->image_type,
+ NULL
+ ))
+ return EIO;
+ }
+
+ r = get_info(id, info, 0);
+ if (r!=0)
+ return r;
+ get_flags(info, flags);
+
+ return 0;
+}
+
int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
{
int r;
if (id >= n_pictures)
return EINVAL;
+ if (!(picture[id].open))
+ return EINVAL;
+
ilBindImage(picture[id].handle);
get_info(id, &(p.info), 0);
int convert_picture (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags);
int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_TYPE *flags);
int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags);
+int build_picture (uint_fast16_t id, ILint width, ILint height, ILint frames, struct IL_full_info *info, FLAG_TYPE *flags);
+int build_picture_from_info (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags);
int get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame);
ILuint upscale_value (ILubyte x, ILint bytes);
/*
info.c
Get information
-12.11.2022
+13.11.2022
Copyright (C) 2022 Balthasar SzczepaĆski
return EINVAL;
}
- r = create_pictures(1);
+ r = reserve_pictures(1);
if (r)
{
*err = CREATE_FAILED;
else
flags |= CANNOT_BE_INDEXED | IN_WINDOW;
- r = create_pictures(1);
+ r = reserve_pictures(1);
if (r)
{
*err = CREATE_FAILED;
return EINVAL;
}
- r = create_pictures(1);
+ r = reserve_pictures(1);
if (r)
{
*err = CREATE_FAILED;
return y;
}
-
-/*
-#define INPIX_MUSTARD 1
-#define OUTPIX_MUSTARD 2
-
-#define ARGUMENT_MUSTARD 4
-
-#define ANIMATED_MUSTARD 6
-#define FAIL 900
-#define OK 0
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <IL/il.h>
-#include <IL/ilu.h>
-
-void mustard(int mustard);
-ILubyte swap1(ILubyte x);
-ILubyte swap2(ILubyte x);
-ILubyte swap4(ILubyte x);
-int main (int argc, const char *argv[]);
-
-ILuint pix;
-ILboolean q=true;
-ILboolean pixOpen=false;
-
-
-ILubyte swap1(ILubyte x)
-{
- ILubyte y=0;
-
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
- x >>= 1;
- y <<= 1;
- y |= x&0x01;
-
- return y;
-}
-
-ILubyte swap2(ILubyte x)
-{
- ILubyte y=0;
-
- y |= x&0x03;
- x >>= 2;
- y <<= 2;
- y |= x&0x03;
- x >>= 2;
- y <<= 2;
- y |= x&0x03;
- x >>= 2;
- y <<= 2;
- y |= x&0x03;
-
- return y;
-}
-
-ILubyte swap4(ILubyte x)
-{
- ILubyte y=0;
-
- y |= x&0x0f;
- x >>= 4;
- y <<= 4;
- y |= x&0x0f;
-
- return y;
-}
-
-int main (int argc, const char *argv[])
-{
- ILuint inX, inY, inZ, inC;
- ILubyte *newdata, *pal;
- unsigned char indexed;
-
- if(argc<3)
- mustard(ARGUMENT_MUSTARD);
- if (argc>=4)
- {
- if (argv[3][0]=='q' || argv[3][0]=='Q')
- q=false;
- }
-
- if(q) printf("%s -> %s ",argv[1],argv[2]);
-
- ilInit();
- iluInit();
- if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
- if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
- ilClearColour(255,255,0,0);
- ilGenImages(1, &pix);
- pixOpen=true;
- ilBindImage(pix);
- if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
- indexed=(ilGetInteger(IL_IMAGE_FORMAT)==IL_COLOUR_INDEX)?1:0;
-
- if (indexed)
- {
- ilConvertPal(IL_PAL_RGB24);
- inC=ilGetInteger(IL_PALETTE_NUM_COLS);
- pal=ilGetPalette();
-
- for(unsigned long k=0;k<inC;++k)
- {
- pal[k*3 ]=swap4(pal[k*3 ]);
- pal[k*3+1]=swap2(pal[k*3+1]);
- pal[k*3+2]=swap1(pal[k*3+2]);
- }
- printf("e\n");
- }
- else
- {
-
- if(!ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
-
- inX=ilGetInteger(IL_IMAGE_WIDTH);
- inY=ilGetInteger(IL_IMAGE_HEIGHT);
- inZ=ilGetInteger(IL_NUM_IMAGES);
- if(!inZ)
- inZ=1;
-
- // printf("%d %d %d\n", inX, inY, inZ);
-
- newdata=ilGetData();
- for(unsigned long k=0;k<inZ;++k)
- {
- for(unsigned long i=0;i<inX;++i)
- {
- for(unsigned long j=0;j<inY;++j)
- {
- newdata[(k*inX*inY+j*inX+i)*3 ]=swap4(newdata[(k*inX*inY+j*inX+i)*3 ]);
- newdata[(k*inX*inY+j*inX+i)*3+1]=swap2(newdata[(k*inX*inY+j*inX+i)*3+1]);
- newdata[(k*inX*inY+j*inX+i)*3+2]=swap1(newdata[(k*inX*inY+j*inX+i)*3+2]);
- }
- }
- }
- }
- if(!ilSave((inZ>1)?IL_GIF:IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
- // no mustard
- mustard(0);
-}
-
-void mustard(int mustard)
-{
- ILenum error;
- while((error=ilGetError())!=IL_NO_ERROR)
- printf("%d: %s\n",error,iluErrorString(error));
- switch(mustard)
- {
- case 0:
- if(q) printf("ENHANCED!\n");
- break;
- case ARGUMENT_MUSTARD:
- if(q)
- printf("enhance inPix outPix [q]\n");
- break;
- case INPIX_MUSTARD:
- if(q)
- printf("inPIX mustard.\n");
- break;
- case OUTPIX_MUSTARD:
- if(q)
- printf("outPIX mustard.\n");
- break;
- case ANIMATED_MUSTARD:
- if(q)
- printf("Animation is mustard.\n");
- break;
- default:
- if (q)
- printf("Ch*rpin* mustard mustaard!\n");
- }
- if(pixOpen)
- ilDeleteImages(1, &pix);
- exit(mustard);
-}
-*/