]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
build new picture
authorb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 22:25:59 +0000 (22:25 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 22:25:59 +0000 (22:25 +0000)
bluenh.c
core.c
core.h
info.c
nofading.c
reveal.c

index 3a99ba46e0bb908f0c3b9e123fe0f79572d9f430..db32f5535c6a9acc88e912c4c5aa59ca1e1d36a3 100644 (file)
--- 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 948189840184b0ae5e9c29d33880a3c651ff0141..c8ac6930bccf3889fd8fc4e99c008988567cc340 100644 (file)
--- 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 94ca1977bfea5d6567c70571cce0767431c7231c..a97c98e9a8a831450c7251d1de954cf00c05f21d 100644 (file)
--- 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 0fa6d36f7a59159a6a10eedc186cebefb0f55f9a..d1ae427e447450bc61f800c65787830b6b52d9d5 100644 (file)
--- 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;
index 9343e1a42fb34f4da445f1f0b9ef7684d8809b32..52df73c9796f227801edaaea0cd4225f46eb9a17 100644 (file)
@@ -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;
index 5b411efae07fb5c7af1b0736b51ba2d6ceecbb1d..6d70a27284b34f46472493a1d9cd0bcba8b0d723 100644 (file)
--- 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 <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);
-}
-*/