From 96ef16db4f4a6ca8b5ab711b93e194d3952875e1 Mon Sep 17 00:00:00 2001 From: b Date: Sun, 13 Nov 2022 22:25:59 +0000 Subject: [PATCH] build new picture --- bluenh.c | 2 +- core.c | 102 +++++++++++++++++++++++++++ core.h | 2 + info.c | 4 +- nofading.c | 2 +- reveal.c | 197 +---------------------------------------------------- 6 files changed, 109 insertions(+), 200 deletions(-) diff --git a/bluenh.c b/bluenh.c index 3a99ba4..db32f55 100644 --- a/bluenh.c +++ b/bluenh.c @@ -72,7 +72,7 @@ int subtool_bluenh (int argc, char **argv, int argi, char **err) return EINVAL; } - r = create_pictures(1); + r = reserve_pictures(1); if (r) { *err = CREATE_FAILED; diff --git a/core.c b/core.c index 9481898..c8ac693 100644 --- a/core.c +++ b/core.c @@ -207,6 +207,9 @@ int convert_picture (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *fla if (id >= n_pictures) return EINVAL; + if (!(picture[id].open)) + return EINVAL; + r = get_info (id, &info_c, 0); if (r!=0) return r; @@ -450,6 +453,9 @@ int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_ if (id >= n_pictures) return EINVAL; + // if(!(picture[id].open)) + create_picture(id); + ilBindImage(picture[id].handle); if (!ilLoadImage(path)) return EIO; @@ -457,6 +463,99 @@ int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_ 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; @@ -553,6 +652,9 @@ int action_1picture ( if (id >= n_pictures) return EINVAL; + if (!(picture[id].open)) + return EINVAL; + ilBindImage(picture[id].handle); get_info(id, &(p.info), 0); diff --git a/core.h b/core.h index 94ca197..a97c98e 100644 --- a/core.h +++ b/core.h @@ -176,6 +176,8 @@ void get_flags (struct IL_full_info *info, FLAG_TYPE *flags); 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); diff --git a/info.c b/info.c index 0fa6d36..d1ae427 100644 --- a/info.c +++ b/info.c @@ -1,7 +1,7 @@ /* info.c Get information -12.11.2022 +13.11.2022 Copyright (C) 2022 Balthasar Szczepański @@ -175,7 +175,7 @@ int subtool_info (int argc, char **argv, int argi, char **err) return EINVAL; } - r = create_pictures(1); + r = reserve_pictures(1); if (r) { *err = CREATE_FAILED; diff --git a/nofading.c b/nofading.c index 9343e1a..52df73c 100644 --- a/nofading.c +++ b/nofading.c @@ -165,7 +165,7 @@ int subtool_nofading (int argc, char **argv, int argi, char **err) else flags |= CANNOT_BE_INDEXED | IN_WINDOW; - r = create_pictures(1); + r = reserve_pictures(1); if (r) { *err = CREATE_FAILED; diff --git a/reveal.c b/reveal.c index 5b411ef..6d70a27 100644 --- a/reveal.c +++ b/reveal.c @@ -52,7 +52,7 @@ int subtool_reveal (int argc, char **argv, int argi, char **err) return EINVAL; } - r = create_pictures(1); + r = reserve_pictures(1); if (r) { *err = CREATE_FAILED; @@ -162,198 +162,3 @@ static inline ILubyte reveal_swap4(ILubyte x) 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 -#include -#include -#include - -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;k1)?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); -} -*/ -- 2.30.2