]> bicyclesonthemoon.info Git - ott/enhance/blobdiff - core.c
newpixbot online
[ott/enhance] / core.c
diff --git a/core.c b/core.c
index 42835617d6e69c756a5cf76bc756e87a6e4d14f8..0a3d1c41da19d3670bb4bd1a238113063a1f8384 100644 (file)
--- a/core.c
+++ b/core.c
@@ -1,7 +1,7 @@
 /*
 core.c
 The tool with multiple enhancements and manipulations of pictures
-26.11.2022
+03.12.2022
 
 Copyright (C) 2014, 2015, 2022  Balthasar SzczepaƄski
 
@@ -89,7 +89,7 @@ int get_data (uint_fast16_t id, void **data, ILuint frame)
        return 0;
 }
 
-int get_palette (uint_fast16_t id, void **palette, ILuint frame)
+int get_palette (uint_fast16_t id, void *palette, ILuint frame)
 {
        if (id >= n_pictures)
                return EINVAL;
@@ -101,7 +101,7 @@ int get_palette (uint_fast16_t id, void **palette, ILuint frame)
        ilActiveImage(frame);
        if (ilGetInteger(IL_IMAGE_FORMAT) != IL_COLOUR_INDEX)
                return EINVAL;
-       *palette = ilGetPalette();
+       *((void **)palette) = ilGetPalette();
        return 0;
 }
 
@@ -514,6 +514,21 @@ int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_
        return convert_picture(id, info, flags);
 }
 
+int load_picture_mem (uint_fast16_t id, const void *address, ILuint size, struct IL_full_info *info, FLAG_TYPE *flags)
+{
+       if (id >= n_pictures)
+               return EINVAL;
+       
+       // if(!(picture[id].open))
+               create_picture(id);
+       
+       ilBindImage(picture[id].handle);
+       if (!ilLoadL(IL_TYPE_UNKNOWN, address, size))
+               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)
 {
        struct IL_full_info reference_info;
@@ -702,6 +717,24 @@ int perform_action_1picture (
        );
 }
 
+int perform_action_1picture_1pixel (
+       uint_fast16_t id,
+       ILint x, ILint y, ILint f,
+       ACTION_F *function,
+       FLAG_TYPE flags,
+       void *data
+)
+{
+       return perform_action_1picture (
+               id,
+               x, y, f,
+               1, 1, 1,
+               function,
+               flags | IN_WINDOW,
+               data
+       );
+}
+
 int perform_action (
        uint_fast16_t n,
        uint_fast16_t *id,
@@ -1470,7 +1503,7 @@ int copy_pixels (ILuint n, struct PixelInfo *p, void *data)
                {
                        if (!(p[1].flags & EFF_GRAY))
                                return EINVAL;
-                       p[1].value = p[0].value
+                       p[1].value = p[0].value;
                }
                else
                {
@@ -1512,13 +1545,84 @@ int fill_color (ILuint n, struct PixelInfo *p, void *data)
        return 0;
 }
 
-
-ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, iILint64 max)
+ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, ILint64 max)
 {
        ILint64 v = (src * alpha + dst * (max - alpha)) / max;
        return (ILuint)v;
 }
 
+int palette_mix_index (ILuint n, struct PixelInfo *p, void *data)
+{
+       if (n < 3)
+               return EIO;
+       
+       p[2].index = p[0].index * p[1].info.palette_num_cols + p[1].index;
+       
+       return 0;
+}
+
+ILuint tsqrt(ILuint s)
+{
+       switch(s)
+       {
+       case 256:
+               return 16;
+       case 225:
+               return 15;
+       case 196:
+               return 14;
+       case 169:
+               return 13;
+       case 144:
+               return 12;
+       case 121:
+               return 11;
+       case 100:
+               return 10;
+       case 81:
+               return 9;
+       case 64:
+               return 8;
+       case 49:
+               return 7;
+       case 36:
+               return 6;
+       case 25:
+               return 5;
+       case 16:
+               return 4;
+       case 9:
+               return 3;
+       case 4:
+               return 2;
+       case 1:
+               return 1;
+       default: // not a square - please fail
+               return 0;
+       }
+}
+
+//unsigned short isqrt(unsigned s)
+//{
+//      unsigned short r;
+//      unsigned short b=0x0040;
+//      
+//      while(b>s)
+//           b>>=2;
+//      while(b)
+//      {
+//           if(s>=r+b)
+//           {
+//                   s-=r+b;
+//                   r=(r>>1)+b;
+//           }
+//           else
+//                   r>>1;
+//           b>>2;
+//      }
+//      return r;
+//}
+
 
 // int action(
        // ILuint n, struct PixelInfo *info, void *data