Revision: 18647
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18647
Author:   campbellbarton
Date:     2009-01-24 11:19:29 +0100 (Sat, 24 Jan 2009)

Log Message:
-----------
jpeg2000 commit missed the 2 most important files.

Added Paths:
-----------
    trunk/blender/source/blender/imbuf/intern/IMB_jp2.h
    trunk/blender/source/blender/imbuf/intern/jp2.c

Added: trunk/blender/source/blender/imbuf/intern/IMB_jp2.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/IMB_jp2.h                         
(rev 0)
+++ trunk/blender/source/blender/imbuf/intern/IMB_jp2.h 2009-01-24 10:19:29 UTC 
(rev 18647)
@@ -0,0 +1,49 @@
+/*
+ * IMB_jp2.h
+ *
+ * $Id: IMB_bmp.h 14444 2008-04-16 22:40:48Z hos $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+/**
+ * \file IMB_jp2.h
+ * \ingroup imbuf
+ * \brief Function declarations for jp2.c
+ */
+
+#ifndef IMB_JP2_H
+#define IMB_JP2_H
+
+#ifdef WITH_OPENJPEG
+struct ImBuf;
+
+int imb_is_a_jp2(void *buf);
+struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags);
+short imb_savejp2(struct ImBuf *ibuf, char *name, int flags);
+#endif /* WITH_OPENJPEG */
+
+#endif
+

Added: trunk/blender/source/blender/imbuf/intern/jp2.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/jp2.c                             
(rev 0)
+++ trunk/blender/source/blender/imbuf/intern/jp2.c     2009-01-24 10:19:29 UTC 
(rev 18647)
@@ -0,0 +1,736 @@
+/**
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifdef WITH_OPENJPEG
+
+#include "BLI_blenlib.h"
+
+#include "imbuf.h"
+#include "imbuf_patch.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+#include "IMB_allocimbuf.h"
+#include "IMB_jp2.h"
+
+#include "openjpeg.h"
+
+#define JP2_FILEHEADER_SIZE 14
+
+static char JP2_HEAD[]= {0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 
0x0A, 0x87, 0x0A};
+
+/* We only need this because of how the presets are set */
+typedef struct img_folder{
+       /** The directory path of the folder containing input images*/
+       char *imgdirpath;
+       /** Output format*/
+       char *out_format;
+       /** Enable option*/
+       char set_imgdir;
+       /** Enable Cod Format for output*/
+       char set_out_format;
+       /** User specified rate stored in case of cinema option*/
+       float *rates;
+}img_fol_t;
+
+static int checkj2p(unsigned char *mem) /* J2K_CFMT */
+{
+       return memcmp(JP2_HEAD, mem, 12) ? 0 : 1;
+}
+
+int imb_is_a_jp2(void *buf)
+{      
+       return checkj2p(buf);
+}
+
+
+/**
+sample error callback expecting a FILE* client object
+*/
+void error_callback(const char *msg, void *client_data) {
+       FILE *stream = (FILE*)client_data;
+       fprintf(stream, "[ERROR] %s", msg);
+}
+/**
+sample warning callback expecting a FILE* client object
+*/
+void warning_callback(const char *msg, void *client_data) {
+       FILE *stream = (FILE*)client_data;
+       fprintf(stream, "[WARNING] %s", msg);
+}
+/**
+sample debug callback expecting no client object
+*/
+void info_callback(const char *msg, void *client_data) {
+       (void)client_data;
+       fprintf(stdout, "[INFO] %s", msg);
+}
+
+
+
+struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
+{
+       struct ImBuf *ibuf = 0;
+       int use_float = 0; /* for precissions higher then 8 use float */
+       unsigned char *rect= NULL;
+       float *rect_float= NULL;
+       
+       long signed_offsets[4] = {0,0,0,0};
+       int float_divs[4];
+       
+       int index;
+       
+       int w, h, depth;
+       
+       opj_dparameters_t parameters;   /* decompression parameters */
+       
+       opj_event_mgr_t event_mgr;              /* event manager */
+       opj_image_t *image = NULL;
+       
+       int i;
+       
+       opj_dinfo_t* dinfo = NULL;      /* handle to a decompressor */
+       opj_cio_t *cio = NULL;
+
+       if (checkj2p(mem) == 0) return(0);
+
+       /* configure the event callbacks (not required) */
+       memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+       event_mgr.error_handler = error_callback;
+       event_mgr.warning_handler = warning_callback;
+       event_mgr.info_handler = info_callback;
+
+
+       /* set decoding parameters to default values */
+       opj_set_default_decoder_parameters(&parameters);
+
+
+       /* JPEG 2000 compressed image data */
+
+       /* get a decoder handle */
+       dinfo = opj_create_decompress(CODEC_JP2);
+
+       /* catch events using our callbacks and give a local context */
+       opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
+
+       /* setup the decoder decoding parameters using the current image and 
user parameters */
+       opj_setup_decoder(dinfo, &parameters);
+
+       /* open a byte stream */
+       cio = opj_cio_open((opj_common_ptr)dinfo, mem, size);
+
+       /* decode the stream and fill the image structure */
+       image = opj_decode(dinfo, cio);
+       
+       if(!image) {
+               fprintf(stderr, "ERROR -> j2k_to_image: failed to decode 
image!\n");
+               opj_destroy_decompress(dinfo);
+               opj_cio_close(cio);
+               return NULL;
+       }
+
+       /* close the byte stream */
+       opj_cio_close(cio);
+
+
+       if((image->numcomps * image->x1 * image->y1) == 0)
+       {
+               fprintf(stderr,"\nError: invalid raw image parameters\n");
+               return NULL;
+       }
+       
+       w = image->comps[0].w;      
+       h = image->comps[0].h;
+       
+       switch (image->numcomps) {
+       case 1: /* Greyscale */
+       case 3: /* Color */
+               depth= 24; 
+               break;
+       default: /* 2 or 4 - Greyscale or Color + alpha */
+               depth= 32; /* greyscale + alpha */
+               break;
+       }
+       
+       
+       i = image->numcomps;
+       if (i>4) i= 4;
+       
+       while (i) {
+               i--;
+               
+               if (image->comps[i].prec > 8)
+                       use_float = 1;
+               
+               if (image->comps[i].sgnd)
+                       signed_offsets[i]=  1 << (image->comps[i].prec - 1); 
+               
+               /* only needed for float images but dosnt hurt to calc this */
+               float_divs[i]= (1<<image->comps[i].prec)-1;
+       }
+       
+       if (use_float) {
+               ibuf= IMB_allocImBuf(w, h, depth, IB_rectfloat, 0);
+               rect_float = ibuf->rect_float;
+       } else {
+               ibuf= IMB_allocImBuf(w, h, depth, IB_rect, 0);
+               rect = (unsigned char *) ibuf->rect;
+       }
+       
+       if (ibuf==NULL) {
+               if(dinfo)
+                       opj_destroy_decompress(dinfo);
+               return NULL;
+       }
+       
+       ibuf->ftype = JP2;
+       
+       if (use_float) {
+               rect_float = ibuf->rect_float;
+               
+               if (image->numcomps < 3) {
+                       /* greyscale 12bits+ */
+                       for (i = 0; i < w * h; i++, rect_float+=4) {
+                               index = w * h - ((i) / (w) + 1) * w + (i) % (w);
+                               
+                               rect_float[0]= rect_float[1]= rect_float[2]= 
(float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
+                               
+                               if (image->numcomps == 2)
+                                       rect_float[3]= 
(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
+                               else
+                                       rect_float[3]= 1.0f;
+                       }
+               } else {
+                       /* rgb or rgba 12bits+ */
+                       for (i = 0; i < w * h; i++, rect_float+=4) {
+                               index = w * h - ((i) / (w) + 1) * w + (i) % (w);
+                               
+                               rect_float[0]= 
(float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
+                               rect_float[1]= 
(float)(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
+                               rect_float[2]= 
(float)(image->comps[2].data[index] + signed_offsets[2]) / float_divs[2];
+                               
+                               if (image->numcomps >= 4)
+                                       rect_float[3]= 
(float)(image->comps[2].data[index] + signed_offsets[3]) / float_divs[3];
+                               else
+                                       rect_float[3]= 1.0f;
+                       }
+               }
+               
+       } else {
+               
+               if (image->numcomps < 3) {
+                       /* greyscale */
+                       for (i = 0; i < w * h; i++, rect+=4) {
+                               index = w * h - ((i) / (w) + 1) * w + (i) % (w);
+                               
+                               rect_float[0]= rect_float[1]= rect_float[2]= 
(image->comps[0].data[index] + signed_offsets[0]);
+                               
+                               if (image->numcomps == 2)
+                                       rect[3]= image->comps[1].data[index] + 
signed_offsets[1];
+                               else
+                                       rect[3]= 255;
+                       }
+               } else {
+                       /* 8bit rgb or rgba */
+                       for (i = 0; i < w * h; i++, rect+=4) {
+                               int index = w * h - ((i) / (w) + 1) * w + (i) % 
(w);
+                               
+                               rect[0]= image->comps[0].data[index] + 
signed_offsets[0];
+                               rect[1]= image->comps[1].data[index] + 
signed_offsets[1];
+                               rect[2]= image->comps[2].data[index] + 
signed_offsets[2];
+                               
+                               if (image->numcomps >= 4)
+                                       rect[3]= image->comps[2].data[index] + 
signed_offsets[3];
+                               else
+                                       rect[3]= 255;
+                       }
+               }
+       }
+       
+       /* free remaining structures */
+       if(dinfo) {
+               opj_destroy_decompress(dinfo);
+       }
+       
+       /* free image data structure */
+       opj_image_destroy(image);
+       
+       if (flags & IB_rect) {
+               IMB_rect_from_float(ibuf);
+       }
+       
+       return(ibuf);
+}
+
+//static opj_image_t* rawtoimage(const char *filename, opj_cparameters_t 
*parameters, raw_cparameters_t *raw_cp) {
+/* prec can be 8, 12, 16 */
+
+#define UPSAMPLE_8_TO_12(_val) ((_val<<4) | (_val & ((1<<4)-1)))
+#define UPSAMPLE_8_TO_16(_val) ((_val<<8)+_val)
+
+#define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val)<=0.0f?0: ((_val)>=1.0f?255: 
(int)(255.0f*(_val)))
+#define DOWNSAMPLE_FLOAT_TO_12BIT(_val)        (_val)<=0.0f?0: 
((_val)>=1.0f?4095: (int)(4095.0f*(_val)))
+#define DOWNSAMPLE_FLOAT_TO_16BIT(_val)        (_val)<=0.0f?0: 
((_val)>=1.0f?65535: (int)(65535.0f*(_val)))
+
+
+/*
+2048x1080 (2K) at 24 fps or 48 fps, or 4096x2160 (4K) at 24 fps; 3\xD712 bits 
per pixel, XYZ color space
+
+    * In 2K, for Scope (2.39:1) presentation 2048x858 pixels of the imager is 
used
+    * In 2K, for Flat (1.85:1) presentation 1998x1080 pixels of the imager is 
used
+*/
+
+/* ****************************** COPIED FROM image_to_j2k.c */
+
+/* ----------------------------------------------------------------------- */

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to