#include <fstream>
#include "gdcm_charls.h"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
{
return 1;
}
if( !sf )
{
std::cerr << "No pixel data (or not encapsulated)" << std::endl;
return 1;
}
{
std::cerr << "Unsupported" << std::endl;
return 1;
}
std::vector<BYTE> rgbyteOutall;
{
if( !bv ) return 1;
std::vector<char> vbuffer;
vbuffer.resize( totalLen );
char *buffer = &vbuffer[0];
const BYTE* pbyteCompressed0 = (const BYTE*)buffer;
while( totalLen > 0 && pbyteCompressed0[totalLen-1] != 0xd9 )
{
totalLen--;
}
JlsParameters metadata;
if (JpegLsReadHeader(buffer, totalLen, &metadata) != OK)
{
std::cerr << "Cant parse jpegls" << std::endl;
return false;
}
std::cout << metadata.width << std::endl;
std::cout << metadata.height << std::endl;
std::cout << metadata.bitspersample << std::endl;
std::cout << pf << std::endl;
unsigned char marker_lse_13[] = {
0xFF, 0xF8, 0x00, 0x0D,
0x01,
0x1F, 0xFF,
0x00, 0x22,
0x00, 0x83,
0x02, 0x24,
0x00, 0x40
};
unsigned char marker_lse_14[] = {
0xFF, 0xF8, 0x00, 0x0D,
0x01,
0x3F, 0xFF,
0x00, 0x42,
0x01, 0x03,
0x04, 0x44,
0x00, 0x40
};
unsigned char marker_lse_15[] = {
0xFF, 0xF8, 0x00, 0x0D,
0x01,
0x7F, 0xFF,
0x00, 0x82,
0x02, 0x03,
0x08, 0x84,
0x00, 0x40
};
unsigned char marker_lse_16[] = {
0xFF, 0xF8, 0x00, 0x0D,
0x01,
0xFF, 0xFF,
0x01, 0x02,
0x04, 0x03,
0x11, 0x04,
0x00, 0x40
};
const unsigned char *marker_lse = NULL;
switch( metadata.bitspersample )
{
case 13:
marker_lse = marker_lse_13;
break;
case 14:
marker_lse = marker_lse_14;
break;
case 15:
marker_lse = marker_lse_15;
break;
case 16:
marker_lse = marker_lse_16;
break;
}
if( !marker_lse )
{
std::cerr << "Cant handle: " << metadata.bitspersample << std::endl;
return 1;
}
vbuffer.insert (vbuffer.begin() + 0x0F, marker_lse, marker_lse+15);
#if 0
std::ofstream of( "/tmp/d.jls", std::ios::binary );
of.write( &vbuffer[0], vbuffer.size() );
of.close();
#endif
const char *pbyteCompressed = &vbuffer[0];
size_t cbyteCompressed = vbuffer.size();
JlsParameters params;
JpegLsReadHeader(pbyteCompressed, cbyteCompressed, ¶ms);
std::vector<BYTE> rgbyteOut;
rgbyteOut.resize(params.height *params.width * ((params.bitspersample + 7)
/ 8) * params.components);
JLS_ERROR result =
JpegLsDecode(&rgbyteOut[0], rgbyteOut.size(), pbyteCompressed, cbyteCompressed, ¶ms );
if (result != OK)
{
std::cerr << "Could not patch JAI-JPEGLS" << std::endl;
return 1;
}
rgbyteOutall.insert( rgbyteOutall.end(), rgbyteOut.begin(), rgbyteOut.end() );
}
pixeldata.
SetByteValue( (
char*)&rgbyteOutall[0], (uint32_t)rgbyteOutall.size() );
std::cout << "Success !" << std::endl;
return 0;
}