Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package babl for openSUSE:Factory checked in 
at 2023-03-05 20:07:57
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/babl (Old)
 and      /work/SRC/openSUSE:Factory/.babl.new.31432 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "babl"

Sun Mar  5 20:07:57 2023 rev:62 rq:1068536 version:0.1.102

Changes:
--------
--- /work/SRC/openSUSE:Factory/babl/babl.changes        2022-11-24 
12:22:39.253078302 +0100
+++ /work/SRC/openSUSE:Factory/.babl.new.31432/babl.changes     2023-03-05 
20:07:59.636703350 +0100
@@ -1,0 +2,9 @@
+Wed Mar  1 07:35:32 UTC 2023 - Paolo Stivanin <[email protected]>
+
+- update to 0.1.102:
+  * LUT code-paths now disabled by default.
+  * Stop double processing with LUT+normal fishes.
+  * Support for non-ASCII characters in file paths on windows.
+    Improved wrap build support.
+
+-------------------------------------------------------------------

Old:
----
  babl-0.1.98.tar.xz

New:
----
  babl-0.1.102.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ babl.spec ++++++
--- /var/tmp/diff_new_pack.diDDpL/_old  2023-03-05 20:08:00.184705883 +0100
+++ /var/tmp/diff_new_pack.diDDpL/_new  2023-03-05 20:08:00.184705883 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package babl
 #
-# Copyright (c) 2022 SUSE LLC
+# Copyright (c) 2023 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -19,7 +19,7 @@
 %define debug_package_requires libbabl-0_1-0 = %{version}-%{release}
 
 Name:           babl
-Version:        0.1.98
+Version:        0.1.102
 Release:        0
 Summary:        Dynamic Pixel Format Translation Library
 License:        GPL-3.0-or-later AND LGPL-3.0-or-later

++++++ babl-0.1.98.tar.xz -> babl-0.1.102.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/NEWS new/babl-0.1.102/NEWS
--- old/babl-0.1.98/NEWS        2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/NEWS       2023-02-25 20:01:55.000000000 +0100
@@ -3,6 +3,13 @@
 the news section both in the README and the webpage.
                                                                           -->
 
+2023-02-25 babl-0.1.102                                             </dt><dd>
+Brown paper bag release - LUT code-paths now disabled by default.
+2023-02-20 babl-0.1.100                                             </dt><dd>
+Stop double processing with LUT+normal fishes.
+Support for non-ASCII characters in file paths on windows. Improved wrap build
+support. 
+                                                                    </dd><dt>
 2022-11-13 babl-0.1.98                                              </dt><dd>
 More robust bounds protection in ICC handling, avoid garbage collecting lookup
 tables in-line with processing.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl-cache.c 
new/babl-0.1.102/babl/babl-cache.c
--- old/babl-0.1.98/babl/babl-cache.c   2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/babl/babl-cache.c  2023-02-25 20:01:55.000000000 +0100
@@ -35,72 +35,112 @@
 static int
 mk_ancestry_iter (const char *path)
 {
-  char copy[4096];
-  strncpy (copy, path, 4096);
-  copy[sizeof (copy) - 1] = '\0';
-  if (strrchr (copy, '/'))
+  char *copy = babl_strdup (path);
+  char *rchr = NULL;
+  int result = 0;
+
+  if (!copy)
+    return -1;
+
+  rchr = strrchr (copy, '/');
+  if (rchr)
     {
-      *strrchr (copy, '/') = '\0';
+      *rchr = '\0';
+
       if (copy[0])
         {
-          struct stat stat_buf;
-          if ( ! (stat (copy, &stat_buf)==0 && S_ISDIR(stat_buf.st_mode)))
-            {
-              if (mk_ancestry_iter (copy) != 0)
-                return -1;
-#ifndef _WIN32
-              return mkdir (copy, S_IRWXU);
-#else
-              return mkdir (copy);
-#endif
-            }
+          BablStat stat_buf;
+          if ( ! (_babl_stat (copy, &stat_buf)==0 && 
S_ISDIR(stat_buf.st_mode)))
+            result = mk_ancestry_iter (copy) == 0 ? _babl_mkdir (copy, 
S_IRWXU) : -1;
         }
     }
-  return 0;
+
+  babl_free (copy);
+  return result;
 }
 
 static int
 mk_ancestry (const char *path)
 {
-  char copy[4096];
-  strncpy (copy, path, 4096);
-  copy[sizeof (copy) - 1] = '\0';
+  char *copy = babl_strdup (path);
+  int result = 0;
+
+  if (!copy)
+    return -1;
+
 #ifdef _WIN32
   for (char *c = copy; *c; c++)
     if (*c == '\\')
       *c = '/';
 #endif
-  return mk_ancestry_iter (copy);
+
+  result = mk_ancestry_iter (copy);
+
+  babl_free (copy);
+  return result;
 }
 
-static const char *
+static char *
 fish_cache_path (void)
 {
-  struct stat stat_buf;
-  static char path[4096];
+  char *path = NULL;
+  char buf[4096];
+  BablStat stat_buf;
 
-  strncpy (path, FALLBACK_CACHE_PATH, 4096);
-  path[sizeof (path) - 1] = '\0';
 #ifndef _WIN32
+
+  strncpy (buf, FALLBACK_CACHE_PATH, 4096);
+  buf[sizeof (buf) - 1] = '\0';
+
   if (getenv ("XDG_CACHE_HOME"))
-    snprintf (path, sizeof (path), "%s/babl/babl-fishes", 
getenv("XDG_CACHE_HOME"));
+    snprintf (buf, sizeof (buf), "%s/babl/babl-fishes", 
getenv("XDG_CACHE_HOME"));
   else if (getenv ("HOME"))
-    snprintf (path, sizeof (path), "%s/.cache/babl/babl-fishes", 
getenv("HOME"));
+    snprintf (buf, sizeof (buf), "%s/.cache/babl/babl-fishes", getenv("HOME"));
+
+  path = babl_strdup (buf);
+
 #else
-{
-  char win32path[4096];
-  if (SHGetFolderPathA (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, 
win32path) == S_OK)
-    snprintf (path, sizeof (path), "%s\\%s\\babl-fishes.txt", win32path, 
BABL_LIBRARY);
+
+  wchar_t *appdata_utf16 = NULL;
+
+  if (SHGetKnownFolderPath (&FOLDERID_LocalAppData, KF_FLAG_DEFAULT, NULL, 
&appdata_utf16) == S_OK)
+    {
+      char *appdata = babl_convert_utf16_to_utf8 (appdata_utf16);
+
+      if (appdata && appdata[0])
+        {
+          const char *fmt = "%s\\%s\\babl-fishes.txt";
+          size_t sz = add_check_overflow (3, strlen (fmt), strlen (appdata), 
strlen (BABL_LIBRARY));
+
+          if (sz > 0 && (path = babl_malloc (sz)) != NULL)
+            _snprintf_s (path, sz, sz, fmt, appdata, BABL_LIBRARY);
+        }
+
+      if (appdata)
+        babl_free (appdata);
+    }
   else if (getenv ("TEMP"))
-    snprintf (path, sizeof (path), "%s\\babl-fishes.txt", getenv("TEMP"));
-}
+    {
+      snprintf (buf, sizeof (buf), "%s\\babl-fishes.txt", getenv("TEMP"));
+      path = babl_strdup (buf);
+    }
+
+  if (appdata_utf16)
+    {
+      CoTaskMemFree (appdata_utf16);
+      appdata_utf16 = NULL;
+    }
+
 #endif
 
-  if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
+  if (!path)
+    return babl_strdup (FALLBACK_CACHE_PATH);
+
+  if (_babl_stat (path, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode))
     return path;
 
   if (mk_ancestry (path) != 0)
-    return FALLBACK_CACHE_PATH;
+    return babl_strdup (FALLBACK_CACHE_PATH);
 
   return path;
 }
@@ -177,23 +217,23 @@
   return buf;
 }
 
-void 
+void
 babl_store_db (void)
 {
   BablDb *db = babl_fish_db ();
-  int i;
+  char *cache_path = fish_cache_path ();
   char *tmpp = calloc(8000,1);
-  FILE *dbfile;
+  FILE *dbfile = NULL;
+  int i;
+
+  if (!cache_path || !tmpp)
+    goto cleanup;
 
-  if (!tmpp)
-    return;
-  snprintf (tmpp, 8000, "%s~", fish_cache_path ());
-  dbfile  = fopen (tmpp, "w");
+  snprintf (tmpp, 8000, "%s~", cache_path);
+  dbfile  = _babl_fopen (tmpp, "w");
   if (!dbfile)
-  {
-    free (tmpp);
-    return;
-  }
+    goto cleanup;
+
   fprintf (dbfile, "%s\n", cache_header ());
 
   /* sort the list of fishes by usage, making next run more efficient -
@@ -209,13 +249,24 @@
     if (babl_fish_serialize (fish, tmp, 4096))
       fprintf (dbfile, "%s----\n", tmp);
   }
+
   fclose (dbfile);
+  dbfile = NULL;
 
 #ifdef _WIN32
-  remove (fish_cache_path ());
+  _babl_remove (cache_path);
 #endif
-  rename (tmpp, fish_cache_path());
-  free (tmpp);
+  _babl_rename (tmpp, cache_path);
+
+cleanup:
+  if (dbfile)
+    fclose (dbfile);
+
+  if (cache_path)
+    babl_free (cache_path);
+
+  if (tmpp)
+    free (tmpp);
 }
 
 int
@@ -230,7 +281,7 @@
 void 
 babl_init_db (void)
 {
-  const char *path = fish_cache_path ();
+  char *path = fish_cache_path ();
   long  length = -1;
   char  seps[] = "\n\r";
   Babl *babl   = NULL;
@@ -242,11 +293,11 @@
   time_t tim = time (NULL);
 
   if (getenv ("BABL_DEBUG_CONVERSIONS"))
-    return;
+    goto cleanup;
 
   _babl_file_get_contents (path, &contents, &length, NULL);
   if (!contents)
-    return;
+    goto cleanup;
 
   token = strtok_r (contents, seps, &tokp);
   while( token != NULL )
@@ -274,10 +325,7 @@
           /* if babl has changed in git .. drop whole cache */
           {
             if (strcmp ( token, cache_header ()))
-            {
-              free (contents);
-              return;
-            }
+              goto cleanup;
           }
           break;
         case '\t':
@@ -294,8 +342,7 @@
             {
               fprintf (stderr, "%s:%i: loading of cache failed\n",
                               __FUNCTION__, __LINE__);
-              free (contents);
-              return;
+              goto cleanup;
             }
 
             if (strstr (token, "[reference]"))
@@ -384,6 +431,11 @@
       }
       token = strtok_r (NULL, seps, &tokp);
     }
+
+cleanup:
   if (contents)
     free (contents);
+
+  if (path)
+    babl_free (path);
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl-extension.c 
new/babl-0.1.102/babl/babl-extension.c
--- old/babl-0.1.98/babl/babl-extension.c       2022-11-13 15:45:36.000000000 
+0100
+++ new/babl-0.1.102/babl/babl-extension.c      2023-02-25 20:01:55.000000000 
+0100
@@ -33,7 +33,6 @@
 #include "babl-base.h"
 
 #include <string.h>
-#include <stdarg.h>
 
 
 static Babl *babl_extension_current_extender = NULL;
@@ -176,7 +175,22 @@
 #include <windows.h>
 #define HLIB    HINSTANCE
 
-#define dlopen(a, b)    LoadLibrary (a)
+static HLIB
+LoadLibraryWrap (const char *filename)
+{
+  wchar_t *filename_utf16 = babl_convert_utf8_to_utf16 (filename);
+  HLIB module = NULL;
+
+  if (!filename_utf16)
+    return NULL;
+
+  module = LoadLibraryW (filename_utf16);
+
+  babl_free (filename_utf16);
+  return module;
+}
+
+#define dlopen(a, b)    LoadLibraryWrap (a)
 #define dlsym(l, s)     GetProcAddress (l, s)
 #define dlclose(l)      FreeLibrary (l)
 #define dlerror()       GetLastError ()
@@ -246,45 +260,53 @@
     }
 }
 
+struct dir_foreach_ctx
+{
+  const char **exclusion_patterns;
+};
+
 static void
-babl_extension_load_dir (const char *base_path,
-                         const char **exclusion_patterns)
+dir_foreach (const char *base_path,
+             const char *entry,
+             void       *user_data)
 {
-  DIR *dir;
+  struct dir_foreach_ctx *ctx = (struct dir_foreach_ctx*) user_data;
 
-  if ((dir = opendir (base_path)))
+  if (entry[0] != '.')
     {
-      struct  dirent *dentry;
+      char       *path = NULL;
+      char       *extension;
 
-      while ((dentry = readdir (dir)) != NULL)
-        {
-          if (dentry->d_name[0] != '.')
-            {
-              char       *path = NULL;
-              char       *extension;
-
-              path = babl_strcat (path, base_path);
-              path = babl_strcat (path, BABL_DIR_SEPARATOR);
-              path = babl_strcat (path, dentry->d_name);
-
-              if ((extension = strrchr (dentry->d_name, '.')) != NULL &&
-                  !strcmp (extension, SHREXT))
-                {
-                  int excluded = 0;
-                  for (int i = 0; exclusion_patterns[i]; i++)
-                    if (strstr (path, exclusion_patterns[i]))
-                      excluded = 1;
-                  if (!excluded)
-                    babl_extension_load (path);
-                }
+      path = babl_strcat (path, base_path);
+      path = babl_strcat (path, BABL_DIR_SEPARATOR);
+      path = babl_strcat (path, entry);
 
-              babl_free (path);
-            }
+      if ((extension = strrchr (entry, '.')) != NULL &&
+          !strcmp (extension, SHREXT))
+        {
+          int excluded = 0;
+          for (int i = 0; ctx->exclusion_patterns[i]; i++)
+            if (strstr (path, ctx->exclusion_patterns[i]))
+              excluded = 1;
+          if (!excluded)
+            babl_extension_load (path);
         }
-      closedir (dir);
+
+      babl_free (path);
     }
 }
 
+static void
+babl_extension_load_dir (const char *base_path,
+                         const char **exclusion_patterns)
+{
+  struct dir_foreach_ctx ctx;
+
+  ctx.exclusion_patterns = exclusion_patterns;
+
+  _babl_dir_foreach (base_path, dir_foreach, &ctx);
+}
+
 static char *
 expand_path (char *path)
 {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl-fish-path.c 
new/babl-0.1.102/babl/babl-fish-path.c
--- old/babl-0.1.98/babl/babl-fish-path.c       2022-11-13 15:45:36.000000000 
+0100
+++ new/babl-0.1.102/babl/babl-fish-path.c      2023-02-25 20:01:55.000000000 
+0100
@@ -32,6 +32,8 @@
 #define MIN(a, b) (((a) > (b)) ? (b) : (a))
 #endif
 
+static int enable_lut = 0;
+
 typedef struct GcContext {
    long time;
 } GcContext;
@@ -127,7 +129,7 @@
 
 static float timings[256] = {0,};
 
-static inline void _do_lut (uint32_t *lut,
+static inline int _do_lut (uint32_t *lut,
                            int   source_bpp,
                            int   dest_bpp,
                            const void *__restrict__ source,
@@ -142,7 +144,7 @@
           {
              uint32_t col = *src++;
              uint32_t lut_offset = col & 0xffffff;
-             float alpha = (col>>24)/255.0;
+             float alpha = (col>>24)/255.0f;
 
              *dst++ = lut[lut_offset*4+0];
              *dst++ = lut[lut_offset*4+1];
@@ -160,7 +162,7 @@
           {
              uint32_t col = *src++;
              uint32_t lut_offset = col & 0xffffff;
-             uint16_t alpha = (col>>24) << 8;
+             uint16_t alpha = (col>>24) << 8; 
 
              dst[0] = lut16[lut_offset*2+0];
              dst[1] = lut16[lut_offset*2+1];
@@ -189,8 +191,7 @@
           while (n--)
           {
              uint32_t col = *src++;
-             *dst = col & 0xff000000;
-             *dst |= lut[col & 0xffffff];
+             *dst = (col & 0xff000000) | lut[col & 0xffffff];
              dst++;
           }
         }
@@ -200,8 +201,8 @@
           uint32_t *dst = (uint32_t*)destination;
           while (n--)
           {
-             *dst = lut[*src++];
-             dst++;
+            *dst = lut[*src++];
+            dst++;
           }
         }
         else if (source_bpp == 2 && dest_bpp == 2)
@@ -247,11 +248,16 @@
           while (n--)
           {
              uint32_t col = src[0]*256*256+src[1]*256+src[2];
-             *dst = lut[col];
+             *dst = lut[col] | 0xff000000;
              dst++;
              src+=3;
           }
         }
+        else
+        {
+          return 0;
+        }
+        return 1;
 }
 
 
@@ -450,8 +456,6 @@
                                   temp_lut, 2,
                                   lut, 4,
                                   256*256);
-         for (int o = 0; o < 256 * 256; o++)
-           lut[o] = lut[o] & 0x00ffffff;
          free (temp_lut);
        }
        else if (source_bpp == 2 && dest_bpp == 16)
@@ -503,8 +507,11 @@
      }
      if (lut)
      {
-        _do_lut (lut, source_bpp, dest_bpp, source, destination, n);
-        BABL(babl)->fish_path.last_lut_use = babl_ticks ();
+       if (_do_lut (lut, source_bpp, dest_bpp, source, destination, n))
+       {
+         BABL(babl)->fish_path.last_lut_use = babl_ticks ();
+         return 1;
+       }
      }
      return 0;
 }
@@ -600,6 +607,12 @@
   else
     debug_conversions = 0;
 
+  env = getenv ("BABL_LUT");
+  if (env && env[0] != '\0')
+    enable_lut = 1;
+  else
+    enable_lut = 0;
+
   return error;
 }
 
@@ -947,30 +960,64 @@
          babl_log ("-eeek{%i}\n", babl_dest->instance.class_type - BABL_MAGIC);
      }
 
+  if (enable_lut)
   {
-  int source_bpp = babl->fish_path.source_bpp;
-  int dest_bpp = babl->fish_path.dest_bpp;
-  if (//source->format.space != destination->format.space &&
-     (
-        (source_bpp == 2 && dest_bpp == 16)
-      ||(source_bpp == 4 && dest_bpp == 16)
-      ||(source_bpp == 4 && dest_bpp == 4)
-      ||(source_bpp == 4 && dest_bpp == 8)
-      ||(source_bpp == 3 && dest_bpp == 4)
-      ||(source_bpp == 2 && dest_bpp == 4)
-      ||(source_bpp == 2 && dest_bpp == 2)
-      ||(source_bpp == 1 && dest_bpp == 4)
-      ||(source_bpp == 3 && dest_bpp == 3)
+  int         source_bpp  = babl->fish_path.source_bpp;
+  int         dest_bpp    = babl->fish_path.dest_bpp;
+  const Babl *source_type = babl_format_get_type (babl_source,
+                                                  babl_format_get_n_components 
(babl_source) - 1);
+  const Babl *dest_type   = babl_format_get_type (babl_dest,
+                                                  babl_format_get_n_components 
(babl_dest) - 1);
+
+  int dest_not_associated = 
((babl->conversion.destination->format.model->flags &
+          BABL_MODEL_FLAG_ASSOCIATED)==0);
+
+  if (
+      (babl->conversion.source->format.type[0]->bits < 32)       
+
+      && (  (   source_bpp == 2
+             && dest_bpp   == 16)
+
+          ||(   source_bpp  == 4
+             && dest_bpp    == 16
+             && source_type == babl_type_from_id (BABL_U8)
+             && dest_type   == babl_type_from_id (BABL_FLOAT)
+             && dest_not_associated)
+
+          ||(   source_bpp == 4
+             && dest_bpp   == 4
+             && dest_type  == source_type
+             && dest_not_associated)
+
+          ||(   source_bpp  == 4
+             && dest_bpp    == 8
+             && source_type == babl_type_from_id (BABL_U8)
+             && dest_type   == babl_type_from_id (BABL_U16)
+             && dest_not_associated)
+
+          ||(   source_bpp == 3
+             && dest_bpp   == 4)
+
+          ||(   source_bpp == 2
+             && dest_bpp   == 4)
+
+          ||(   source_bpp == 2
+             && dest_bpp   == 2)
+
+          ||(   source_bpp == 1
+             && dest_bpp   == 4)
+
+          ||(   source_bpp == 3
+             && dest_bpp   == 3)
       )
      )
   {
      // as long as the highest 8bit of the 32bit of a 4 byte input is ignored
      // (alpha) - and it is not an associated color model. A 24 bit LUT 
provides
-     // exact data. Thus this is valid for instance for "YA half"
-
-     if ((babl->conversion.source->format.type[0]->bits < 32 &&
-          (source_bpp < 4 
-         || (babl->conversion.source->format.model->flags & 
BABL_MODEL_FLAG_ASSOCIATED)==0)))
+     // exact data. 
+     // Note that we can only copy alpha from source to complete when
+     // types are matching expectations - the source_bpp/dest_bpp pairs have
+     // currently have built-in expectation for what type alpha is filled in
      {
        static int measured_timings = 0;
        float scaling = 10.0;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl-util.c 
new/babl-0.1.102/babl/babl-util.c
--- old/babl-0.1.98/babl/babl-util.c    2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/babl/babl-util.c   2023-02-25 20:01:55.000000000 +0100
@@ -17,14 +17,22 @@
  */
 
 #include "config.h"
+#include <stdarg.h>
+#include <limits.h>
+#include <assert.h>
+#include <stdio.h>
 #include <math.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include "babl-internal.h"
 
 #ifdef __WIN32__
 #include <windows.h>
+#include <wchar.h>
 #else
 #include <sys/time.h>
 #include <time.h>
+#include <dirent.h>
 #endif
 
 #ifdef __WIN32__
@@ -101,6 +109,223 @@
   return error;
 }
 
+size_t
+add_check_overflow (size_t numbers_count, ...)
+{
+  size_t result = 0;
+  va_list args;
+
+  assert (numbers_count > 0);
+
+  va_start (args, numbers_count);
+  while (numbers_count--)
+    {
+      size_t addendum = va_arg (args, size_t);
+
+      if ((SIZE_MAX - result) < addendum)
+        {
+          result = 0;
+          break;
+        }
+
+      result += addendum;
+    }
+  va_end (args);
+
+  return result;
+}
+
+size_t
+mul_check_overflow (size_t numbers_count, ...)
+{
+  size_t result = 1;
+  va_list args;
+
+  assert (numbers_count > 0);
+
+  va_start (args, numbers_count);
+  while (numbers_count--)
+    {
+      size_t factor = va_arg (args, size_t);
+
+      if ((SIZE_MAX / result) < factor)
+        {
+          result = 0;
+          break;
+        }
+
+      result *= factor;
+    }
+  va_end (args);
+
+  return result;
+}
+
+FILE *
+_babl_fopen (const char *path,
+             const char *mode)
+{
+#ifndef _WIN32
+  return fopen (path, mode);
+#else
+  wchar_t *path_utf16 = babl_convert_utf8_to_utf16 (path);
+  wchar_t *mode_utf16 = babl_convert_utf8_to_utf16 (mode);
+  FILE *result = NULL;
+
+  result = _wfopen (path_utf16, mode_utf16);
+
+  if (path_utf16)
+    babl_free (path_utf16);
+
+  if (mode_utf16)
+    babl_free (mode_utf16);
+
+  return result;
+#endif
+}
+
+int
+_babl_remove (const char *path)
+{
+#ifndef _WIN32
+  return remove (path);
+#else
+  wchar_t *path_utf16 = babl_convert_utf8_to_utf16 (path);
+  int result = 0;
+
+  result = _wremove (path_utf16);
+
+  if (path_utf16)
+    babl_free (path_utf16);
+
+  return result;
+#endif
+}
+
+int
+_babl_rename (const char *oldname,
+              const char *newname)
+{
+#ifndef _WIN32
+  return rename (oldname, newname);
+#else
+  wchar_t *oldname_utf16 = babl_convert_utf8_to_utf16 (oldname);
+  wchar_t *newname_utf16 = babl_convert_utf8_to_utf16 (newname);
+  int result = 0;
+
+  result = _wrename (oldname_utf16, newname_utf16);
+
+  if (oldname_utf16)
+    babl_free (oldname_utf16);
+
+  if (newname_utf16)
+    babl_free (newname_utf16);
+
+  return result;
+#endif
+}
+
+int
+_babl_stat (const char *path,
+            BablStat   *buffer)
+{
+#ifndef _WIN32
+  return stat (path, buffer);
+#else
+  wchar_t *path_utf16 = babl_convert_utf8_to_utf16 (path);
+  int result = 0;
+
+  result = _wstat64 (path_utf16, buffer);
+
+  if (path_utf16)
+    babl_free (path_utf16);
+
+  return result;
+#endif
+}
+
+int
+_babl_mkdir (const char *path,
+             int         mode)
+{
+#ifndef _WIN32
+  return mkdir (path, (mode_t) mode);
+#else
+  wchar_t *path_utf16 = babl_convert_utf8_to_utf16 (path);
+  int result = 0;
+  (void) mode;
+
+  result = _wmkdir (path_utf16);
+
+  if (path_utf16)
+    babl_free (path_utf16);
+
+  return result;
+#endif
+}
+
+void
+_babl_dir_foreach (const char             *path,
+                   _babl_dir_foreach_cb_t  callback,
+                   void                   *user_data)
+{
+#ifndef _WIN32
+  DIR *dir = opendir (path);
+
+  if (!path)
+    return;
+
+  if (dir != NULL)
+    {
+      struct dirent *dentry;
+
+      while ((dentry = readdir (dir)))
+        callback (path, dentry->d_name, user_data);
+
+      closedir (dir);
+    }
+#else
+  char *search = NULL;
+  wchar_t *search_utf16 = NULL;
+  struct _wfinddata64_t info;
+  intptr_t search_id = 0;
+
+  if (!path)
+    return;
+
+  search = babl_strcat (search, path);
+  search = babl_strcat (search, "\\*");
+  search_utf16 = babl_convert_utf8_to_utf16 (search);
+  if (!search_utf16)
+    goto cleanup;
+
+  memset (&info, 0, sizeof (info));
+  if ((search_id = _wfindfirst64 (search_utf16, &info)) != (intptr_t)-1)
+    {
+      do
+        {
+          char *entry = babl_convert_utf16_to_utf8 (info.name);
+
+          if (entry)
+            {
+              callback (path, entry, user_data);
+              babl_free (entry);
+            }
+        }
+      while (_wfindnext64 (search_id, &info) == 0);
+
+      _findclose (search_id);
+    }
+
+cleanup:
+  if (search_utf16)
+    babl_free (search_utf16);
+
+  if (search)
+    babl_free (search);
+#endif
+}
+
 int
 _babl_file_get_contents (const char  *path,
                          char       **contents,
@@ -111,7 +336,7 @@
   long  size;
   char *buffer;
 
-  file = fopen (path,"rb");
+  file = _babl_fopen (path, "rb");
 
   if (!file)
     return -1;
@@ -148,3 +373,82 @@
   return 0;
 }
 
+#ifdef _WIN32
+
+wchar_t *
+babl_convert_utf8_to_utf16 (const char *str)
+{
+  int wchar_count = 0;
+  wchar_t *wstr = NULL;
+
+  if (!str)
+    return NULL;
+
+  wchar_count = MultiByteToWideChar (CP_UTF8,
+                                     MB_ERR_INVALID_CHARS,
+                                     str, -1,
+                                     NULL, 0);
+  if (wchar_count <= 0)
+    return NULL;
+
+  wstr = babl_malloc (wchar_count * sizeof (wchar_t));
+  if (!wstr)
+    return NULL;
+
+  wchar_count = MultiByteToWideChar (CP_UTF8,
+                                     MB_ERR_INVALID_CHARS,
+                                     str, -1,
+                                     wstr, wchar_count);
+  if (wchar_count <= 0)
+    {
+      babl_free (wstr);
+      return NULL;
+    }
+
+  return wstr;
+}
+
+char *
+babl_convert_utf16_to_utf8 (const wchar_t *wstr)
+{
+  int char_count = 0;
+  char *str = NULL;
+
+  if (!wstr)
+    return NULL;
+
+  char_count = WideCharToMultiByte (CP_UTF8,
+                                    WC_ERR_INVALID_CHARS,
+                                    wstr, -1,
+                                    NULL, 0,
+                                    NULL, NULL);
+  if (char_count <= 0)
+    return NULL;
+
+  str = babl_malloc (char_count);
+  if (!str)
+    return NULL;
+
+  char_count = WideCharToMultiByte (CP_UTF8,
+                                    WC_ERR_INVALID_CHARS,
+                                    wstr, -1,
+                                    str, char_count,
+                                    NULL, NULL);
+  if (char_count <= 0)
+    {
+      babl_free (str);
+      return NULL;
+    }
+
+  return str;
+}
+
+extern IMAGE_DOS_HEADER __ImageBase;
+
+void *
+get_libbabl_module (void)
+{
+  return &__ImageBase;
+}
+
+#endif /* _WIN32 */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl-util.h 
new/babl-0.1.102/babl/babl-util.h
--- old/babl-0.1.98/babl/babl-util.h    2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/babl/babl-util.h   2023-02-25 20:01:55.000000000 +0100
@@ -19,6 +19,17 @@
 #ifndef _BABL_UTIL_H
 #define _BABL_UTIL_H
 
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef _WIN32
+typedef struct stat BablStat;
+#else
+typedef struct _stat64 BablStat;
+#endif
+
 long
 babl_ticks     (void);
 
@@ -26,4 +37,53 @@
 babl_rel_avg_error (const double *imgA,
                     const double *imgB,
                     long          samples);
+
+size_t
+add_check_overflow (size_t numbers_count, ...);
+
+size_t
+mul_check_overflow (size_t numbers_count, ...);
+
+FILE *
+_babl_fopen (const char *path,
+             const char *mode);
+
+int
+_babl_remove (const char *path);
+
+int
+_babl_rename (const char *oldname,
+              const char *newname);
+
+int
+_babl_stat (const char *path,
+            BablStat   *buffer);
+
+int
+_babl_mkdir (const char *path,
+             int         mode);
+
+typedef void
+(*_babl_dir_foreach_cb_t) (const char *base_path,
+                           const char *entry,
+                           void       *data);
+
+void
+_babl_dir_foreach (const char             *path,
+                   _babl_dir_foreach_cb_t  callback,
+                   void                   *user_data);
+
+#ifdef _WIN32
+
+wchar_t *
+babl_convert_utf8_to_utf16 (const char *str);
+
+char *
+babl_convert_utf16_to_utf8 (const wchar_t *wstr);
+
+void *
+get_libbabl_module (void);
+
+#endif /* _WIN32 */
+
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl.c new/babl-0.1.102/babl/babl.c
--- old/babl-0.1.98/babl/babl.c 2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/babl/babl.c        2023-02-25 20:01:55.000000000 +0100
@@ -22,35 +22,9 @@
 
 static int ref_count = 0;
 
-#ifdef _WIN32
-static HMODULE libbabl_dll = NULL;
-
-/* Minimal DllMain that just stores the handle to this DLL */
-
-/* Avoid silly "no previous prototype" gcc warning */
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-         DWORD     fdwReason,
-         LPVOID    lpvReserved);
-
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-         DWORD     fdwReason,
-         LPVOID    lpvReserved)
-{
-  switch (fdwReason)
-    {
-      case DLL_PROCESS_ATTACH:
-        libbabl_dll = hinstDLL;
-        break;
-    }
-
-  return TRUE;
-}
-
-#else
+#ifndef _WIN32
 #define BABL_PATH              LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
-#endif /* _WIN32 */
+#endif
 
 /*
  * Returns a list of directories if the environment variable $BABL_PATH
@@ -70,21 +44,16 @@
     {
 #ifdef _WIN32
       /* Figure it out from the location of this DLL */
-      char *filename;
-      int filename_size;
-      char *sep1, *sep2;
-
       wchar_t w_filename[MAX_PATH];
+      char *filename = NULL;
+      char *sep1, *sep2;
       DWORD nSize = sizeof (w_filename) / sizeof ((w_filename)[0]);
 
-      if (GetModuleFileNameW (libbabl_dll, w_filename, nSize) == 0)
+      if (GetModuleFileNameW (get_libbabl_module (), w_filename, nSize) == 0)
         babl_fatal ("GetModuleFilenameW failed");
 
-      filename_size = WideCharToMultiByte (CP_UTF8, 0, w_filename, -1, NULL, 0,
-                                           NULL, NULL);
-      filename = babl_malloc (sizeof (char) * filename_size);
-      if (!WideCharToMultiByte (CP_UTF8, 0, w_filename, -1,
-                                filename, filename_size, NULL, NULL))
+      filename = babl_convert_utf16_to_utf8 (w_filename);
+      if (!filename)
         babl_fatal ("Converting module filename to UTF-8 failed");
 
       /* If the DLL file name is of the format
@@ -144,6 +113,7 @@
       babl_type_db ();
       babl_trc_class_init ();
       babl_space_class_init ();
+      _babl_legal_error ();
       babl_component_db ();
       babl_model_db ();
       babl_format_db ();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/babl/babl.h new/babl-0.1.102/babl/babl.h
--- old/babl-0.1.98/babl/babl.h 2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/babl/babl.h        2023-02-25 20:01:55.000000000 +0100
@@ -636,6 +636,11 @@
  * @blue_luminance: (out) (optional): Location for the blue luminance factor.
  *
  * Retrieve the relevant RGB luminance constants for a babl space.
+ *
+ * Note: these luminance coefficients should only ever be used on linear data.
+ * If your input @space is non-linear, you should convert your pixel values to
+ * the linearized variant of @space before making any computation with these
+ * coefficients. See #83.
  */
 void
 babl_space_get_rgb_luminance (const Babl *space,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/bin/babl.c new/babl-0.1.102/bin/babl.c
--- old/babl-0.1.98/bin/babl.c  2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/bin/babl.c 2023-02-25 20:01:55.000000000 +0100
@@ -210,7 +210,7 @@
   data_index   = 0;
 
   to_format    = babl_format_with_space (to, to_space);
-  dest         = malloc (babl_format_get_bytes_per_pixel (from_format));
+  dest         = malloc (babl_format_get_bytes_per_pixel (to_format));
 
   /* Re-looping through arguments, to be more flexible with argument orders.
    * In this second loop, we get the source components' values.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/git-version.h 
new/babl-0.1.102/git-version.h
--- old/babl-0.1.98/git-version.h       2022-11-13 15:46:30.724189500 +0100
+++ new/babl-0.1.102/git-version.h      2023-02-25 20:01:59.394290700 +0100
@@ -1,6 +1,6 @@
 #ifndef __BABL_GIT_VERSION_H__
 #define __BABL_GIT_VERSION_H__
 
-#define BABL_GIT_VERSION "BABL_0_1_98"
+#define BABL_GIT_VERSION "BABL_0_1_100-4-g47affe9"
 
 #endif /* __BABL_GIT_VERSION_H__ */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/babl-0.1.98/meson.build new/babl-0.1.102/meson.build
--- old/babl-0.1.98/meson.build 2022-11-13 15:45:36.000000000 +0100
+++ new/babl-0.1.102/meson.build        2023-02-25 20:01:55.000000000 +0100
@@ -1,6 +1,6 @@
 project('babl', 'c',
   license: 'LGPL3+',
-  version: '0.1.98',
+  version: '0.1.102',
   meson_version: '>=0.54.0',
   default_options: [
     'buildtype=debugoptimized'
@@ -515,7 +515,7 @@
 # pkg-config file
 pkgconfig.generate(
   babl,
-  filebase: 'babl',
+  filebase: 'babl-' + api_version,
   name: 'babl',
   description: 'Pixel encoding and color space conversion engine.',
   version: meson.project_version(),
@@ -539,7 +539,7 @@
     'babl_libdir' : babl_library_build_dir,
   },
 )
-meson.override_dependency('babl', babl_dep)
+meson.override_dependency('babl-' + api_version, babl_dep)
 
 
################################################################################
 # Build summary

Reply via email to