ecere: Initial Emscripten support
[sdk] / ecere / src / gfx / bitmaps / JPEGFormat.ec
index 2fa496d..8e17ff9 100644 (file)
@@ -1,8 +1,10 @@
 namespace gfx::bitmaps;
 
+#define _Noreturn
 import "Display"
 
 #include <setjmp.h>
+#include <stdio.h>
 
 #include "jpeglib.h"
 #include "jerror.h"
@@ -178,7 +180,7 @@ static void JPEG_SetDestination(j_compress_ptr cinfo, File outfile)
 }
 
 // BITMAP DRIVER
-static char * extensions[] = { "jpg", "jpeg", null };
+static const char * extensions[] = { "jpg", "jpeg", null };
 
 class JPGFormat : BitmapFormat
 {
@@ -214,7 +216,16 @@ class JPGFormat : BitmapFormat
                jpeg_read_scanlines(&cinfo, buffer, 1);
                for(c = 0; c<cinfo.image_width; c++)
                {
-                  if(cinfo.output_components == 1)
+                  if(cinfo.out_color_space == JCS_CMYK && cinfo.output_components == 4)
+                  {
+                     int cyan = 255-buffer[0][c*4+0];
+                     int m = 255-buffer[0][c*4+1];
+                     int y = 255-buffer[0][c*4+2];
+                     int k = 255-buffer[0][c*4+3];
+                     //picture[c] = ColorAlpha { 255, { cinfo.sample_range_limit[(255 - (cyan + k))], cinfo.sample_range_limit[(255 - (m + k))], cinfo.sample_range_limit[(255 - (y + k))] } };
+                     picture[c] = ColorCMYK { cyan * 100.0f / 255, m * 100.0f / 255, y * 100.0f / 255, k * 100.0f / 255 };
+                  }
+                  else if(cinfo.output_components == 1)
                      picture[c] = ColorAlpha { 255, { buffer[0][c], buffer[0][c], buffer[0][c] } };
                   else
                      picture[c] = ColorAlpha { 255, { buffer[0][c*3], buffer[0][c*3+1], buffer[0][c*3+2] } };
@@ -232,7 +243,7 @@ class JPGFormat : BitmapFormat
       return result;
    }
 
-   bool Save(Bitmap bitmap, char *filename, void * options)
+   bool Save(Bitmap bitmap, const char *filename, void * options)
    {
       bool result = false;
       if(bitmap.pixelFormat == pixelFormat888)
@@ -296,7 +307,7 @@ class JPGFormat : BitmapFormat
       return result;
    }
 
-   ColorAlpha * LoadPalette(char * fileName, char * type)
+   ColorAlpha * LoadPalette(const char * fileName, const char * type)
    {
       ColorAlpha * result = null;
       return result;