*Patch from Callum Lewick. Clean up of j2klib.h for the aligned malloc stuff.
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Wed, 10 Oct 2007 06:17:28 +0000 (06:17 +0000)
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Wed, 10 Oct 2007 06:17:28 +0000 (06:17 +0000)
*convert.c: Changed some error comments for TIFF images

ChangeLog
codec/convert.c
libopenjpeg/j2k_lib.h

index 636bac851364563c4cecb3b8b5e393a7a14a4503..2dd8c9eb13be0fc141ecc5407e68e7abf193abdb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,11 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+October 10, 2007
+* [FOD] Patch from Callum Lewick. Clean up of j2klib.h for the aligned malloc stuff. 
+        It makes it work right with mingw, as _mm_malloc() isn't a macro, attempts to pave the way to using cmake to check for this stuff and combines a patch from Dana Fagerstrom at Sun that makes it use memalign() on Solaris
+        convert.c: Changed some error comments for TIFF images
+
 September 27, 2007
 * [FOD] Patch from Callum Lewick. Fixed dwt.c where an alignment in buffer was problematic under x86_64.
 
index ff95001f1c593b06a60d1d7d022d03f941d68275..c120c2492ccbef55b4ba6b3a692dfa40615ee992 100644 (file)
@@ -1714,7 +1714,7 @@ int imagetotif(opj_image_t * image, const char *outfile) {
                                                        break; 
                                        }
                                }else{
-                                       fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
+                                       fprintf(stderr,"TIFF file creation. Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
                                        fprintf(stderr,"Aborting\n");
                                        return 1;
                                }
@@ -1723,7 +1723,7 @@ int imagetotif(opj_image_t * image, const char *outfile) {
                        _TIFFfree(buf);
                        TIFFClose(tif);
                }else{
-                       fprintf(stderr,"False color format. Only RGB & Grayscale has been implemented\n");
+                       fprintf(stderr,"TIFF file creation. Bad color format. Only RGB & Grayscale has been implemented\n");
                        fprintf(stderr,"Aborting\n");
                        return 1;
                }
@@ -1858,7 +1858,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
                                }
                        }
                        else{
-                               fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
+                               fprintf(stderr,"TIFF file creation. Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
                                fprintf(stderr,"Aborting\n");
                                return NULL;
                        }
@@ -1936,7 +1936,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
                                }
                        }
                        else{
-                               fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
+                               fprintf(stderr,"TIFF file creation. Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
                                fprintf(stderr,"Aborting\n");
                                return NULL;
                        }
@@ -1945,7 +1945,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
                _TIFFfree(buf);
                TIFFClose(tif);
        }else{
-               fprintf(stderr,"False color format. Only RGB & Grayscale has been implemented\n");
+               fprintf(stderr,"TIFF file creation. Bad color format. Only RGB & Grayscale has been implemented\n");
                fprintf(stderr,"Aborting\n");
                return NULL;
        }
index bb936c8b4dc75c5e33a721a1fd26191847f92b7e..99f061962ec62693f385460453fe3c198d420bb0 100644 (file)
@@ -61,43 +61,57 @@ Allocate memory aligned to a 16 byte boundry
 @param size Bytes to allocate
 @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
 */
+/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
 #ifdef WIN32
-
-#ifdef __GNUC__
-#include <mm_malloc.h>
-#else /* MSVC, Intel C++ */
-#include <malloc.h>
-#endif
-
-#ifdef _mm_malloc
-  #define opj_aligned_malloc(size) _mm_malloc(size, 16)
-  #else
-  #define opj_aligned_malloc(size) malloc(size)
- #endif
- #ifdef _mm_free
-  #define opj_aligned_free(m) _mm_free(m)
-  #else
-  #define opj_aligned_free(m) free(m)
- #endif
-
+       /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
+       #ifdef __GNUC__
+               #include <mm_malloc.h>
+               #define HAVE_MM_MALLOC
+       #else /* MSVC, Intel C++ */
+               #include <malloc.h>
+               #ifdef _mm_malloc
+                       #define HAVE_MM_MALLOC
+               #endif
+       #endif
 #else /* Not WIN32 */
+       #if defined(__sun)
+               #define HAVE_MEMALIGN
+       /* Linux x86_64 and OSX always align allocations to 16 bytes */
+       #elif !defined(__amd64__) && !defined(__APPLE__)
+               /* FIXME: Yes, this is a big assumption */
+               #define HAVE_POSIX_MEMALIGN
+       #endif
+#endif
 
-/* Linux x86_64 and OSX always align allocations to 16 bytes */
-#if defined(__amd64__) || defined(__APPLE__)
 #define opj_aligned_malloc(size) malloc(size)
-#else
-extern int posix_memalign (void **, size_t, size_t);
-
-static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
-       void* mem = NULL;
-       posix_memalign(&mem, 16, size);
-       return mem;
-}
+#define opj_aligned_free(m) free(m)
+
+#ifdef HAVE_MM_MALLOC
+       #undef opj_aligned_malloc
+       #define opj_aligned_malloc(size) _mm_malloc(size, 16)
+       #undef opj_aligned_free
+       #define opj_aligned_free(m) _mm_free(m)
 #endif
 
-#define opj_aligned_free(m) free(m)
+#ifdef HAVE_MEMALIGN
+       extern void* memalign(size_t, size_t);
+       #undef opj_aligned_malloc
+       #define opj_aligned_malloc(size) memalign(16, (size))
+       #undef opj_aligned_free
+       #define opj_aligned_free(m) free(m)
+#endif
 
+#ifdef HAVE_POSIX_MEMALIGN
+       #undef opj_aligned_malloc
+       extern int posix_memalign(void**, size_t, size_t);
+
+       static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
+               void* mem = NULL;
+               posix_memalign(&mem, 16, size);
+               return mem;
+       }
+       #undef opj_aligned_free
+       #define opj_aligned_free(m) free(m)
 #endif
 
 /**