1 /*=========================================================================
4 Module: $RCSfile: gdcmJpeg2000.cxx,v $
6 Date: $Date: 2005/05/30 01:30:39 $
7 Version: $Revision: 1.21 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmFileHelper.h"
19 #include "gdcmDebug.h"
23 #include <jasper/jasper.h>
27 //-----------------------------------------------------------------------------
29 * \brief routine for JPEG decompression
30 * @param fp pointer to an already open file descriptor
31 * JPEG2000 encoded image
32 * @param image_buffer to receive uncompressed pixels
33 * @return 1 on success, 0 on error
34 * @warning : not yet made
37 bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength)
39 jas_init(); //important...
40 jas_stream_t *jasStream =
41 jas_stream_memopen((char *)inputdata, inputlength);
44 if ((fmtid = jas_image_getfmt(jasStream)) < 0)
46 gdcmErrorMacro("unknown image format");
51 jas_image_t *jasImage = NULL;
52 if (!(jasImage = jas_image_decode(jasStream, fmtid, 0)))
54 gdcmErrorMacro("cannot decode image");
59 jas_stream_close(jasStream);
60 int numcmpts = jas_image_numcmpts(jasImage);
61 int width = jas_image_cmptwidth(jasImage, 0);
62 int height = jas_image_cmptheight(jasImage, 0);
63 int prec = jas_image_cmptprec(jasImage, 0);
65 char *fmtname = jas_image_fmttostr(fmtid);
66 printf("%s %d %d %d %d %ld\n", fmtname, numcmpts, width, height, prec, (long) jas_image_rawsize(jasImage));
68 // The following should serioulsy be rewritten I cannot belive we need to
69 // do a per pixel decompression, there should be a way to read a full
73 uint8_t *data8 = (uint8_t*)raw;
74 for ( i = 0; i < height; i++)
75 for ( j = 0; j < width; j++)
76 for ( k= 0; k < numcmpts; k++)
78 (uint8_t)(jas_image_readcmptsample(jasImage, k, j ,i ));
82 uint16_t *data16 = (uint16_t*)raw;
83 for ( i = 0; i < height; i++)
84 for ( j = 0; j < width; j++)
85 for ( k= 0; k < numcmpts; k++)
87 (uint16_t)(jas_image_readcmptsample(jasImage, k, j ,i ));
91 uint32_t *data32 = (uint32_t*)raw;
92 for ( i = 0; i < height; i++)
93 for ( j = 0; j < width; j++)
94 for ( k= 0; k < numcmpts; k++)
96 (uint32_t)(jas_image_readcmptsample(jasImage, k, j ,i ));
99 jas_image_destroy(jasImage);
100 jas_image_clearfmts();
103 //delete the jpeg temp buffer
109 //-----------------------------------------------------------------------------
110 } // end namespace gdcm