X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmJpeg2000.cxx;h=ff585e751acf560a45a7b9350ba7a1de65f11d72;hb=3842530aeeb5ab67f9d7b0f1754108fd176ee51a;hp=4a33f3a187ff71156ac3330aa1f3d65a6f0bb40e;hpb=b8ce88766307f0197209797c4a1fc49a1045ad3a;p=gdcm.git diff --git a/src/gdcmJpeg2000.cxx b/src/gdcmJpeg2000.cxx index 4a33f3a1..ff585e75 100644 --- a/src/gdcmJpeg2000.cxx +++ b/src/gdcmJpeg2000.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmJpeg2000.cxx,v $ Language: C++ - Date: $Date: 2005/07/05 20:58:27 $ - Version: $Revision: 1.25 $ + Date: $Date: 2005/10/24 21:21:09 $ + Version: $Revision: 1.32 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,7 +20,10 @@ #include #include -#include + +extern "C" { + #include +} namespace gdcm { @@ -35,8 +38,86 @@ namespace gdcm bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength) { + j2k_image_t img; + j2k_cp_t cp; + + // default blindly copied + cp.layer=0; + cp.reduce=0; + cp.decod_format=-1; + cp.cod_format=-1; + + cp.cod_format=J2K_CFMT; + cp.decod_format = PGX_DFMT; + int len = inputlength; + unsigned char *src = (unsigned char*)inputdata; + + // Decompression + if (!j2k_decode(src, len, &img, &cp)) + { + gdcmErrorMacro( "ERROR -> j2k_to_image: failed to decode image!" ); + return false; + } + + // Copy buffer + for (int compno = 0; compno < img.numcomps; compno++) + { + j2k_comp_t *comp = &img.comps[compno]; + int nbytes = 0; + + int w = img.comps[compno].w; + int wr = int_ceildivpow2(img.comps[compno].w, img.comps[compno].factor); + + //int h = img.comps[compno].h; + int hr = int_ceildivpow2(img.comps[compno].h, img.comps[compno].factor); + + if (comp->prec <= 8) + { + nbytes = 1; + uint8_t *data8 = (uint8_t*)raw; + for (int i = 0; i < wr * hr; i++) + { + int v = img.comps[compno].data[i / wr * w + i % wr]; + *data8++ = (uint8_t)v; + } + } + else if (comp->prec <= 16) + { + nbytes = 2; + uint16_t *data16 = (uint16_t*)raw; + for (int i = 0; i < wr * hr; i++) + { + int v = img.comps[compno].data[i / wr * w + i % wr]; + *data16++ = (uint16_t)v; + } + } + else + { + nbytes = 4; + uint32_t *data32 = (uint32_t*)raw; + for (int i = 0; i < wr * hr; i++) + { + int v = img.comps[compno].data[i / wr * w + i % wr]; + *data32++ = (uint32_t)v; + } + } + free(img.comps[compno].data); + } + + // Free remaining structures + j2k_dec_release(); + // FIXME + delete[] inputdata; + + return true; +} + #if 0 - std::ofstream out("/tmp/jpeg2000.jpc"); +bool gdcm_read_JASPER_file (void* raw, char *inputdata, size_t inputlength) +{ +#if 0 + std::cerr << "Inputlenght=" << inputlength << std::endl; + std::ofstream out("/tmp/jpeg2000.jpc", std::ios::binary); out.write((char*)inputdata,inputlength); out.close(); #endif @@ -52,7 +133,7 @@ bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength) } // Decode the image. - jas_image_t *jasImage = NULL; + jas_image_t *jasImage /* = NULL*/; // Useless assignation if (!(jasImage = jas_image_decode(jasStream, fmtid, 0))) { gdcmErrorMacro("cannot decode image"); @@ -67,7 +148,7 @@ bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength) int prec = jas_image_cmptprec(jasImage, 0); int i, j, k; - // The following should serioulsy be rewritten I cannot belive we need to + // The following should serioulsy be rewritten I cannot believe we need to // do a per pixel decompression, there should be a way to read a full // scanline... if (prec == 8) @@ -100,10 +181,16 @@ bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength) //FIXME //delete the jpeg temp buffer +#if 0 + std::ofstream rawout("/tmp/jpeg2000.raw"); + rawout.write((char*)raw,height*width*numcmpts*((prec+4)/8)); + rawout.close(); +#endif delete[] inputdata; return true; } +#endif //----------------------------------------------------------------------------- } // end namespace gdcm