void delta_decode(const unsigned char *data_in, size_t data_size,
std::vector<unsigned char> &new_stream, unsigned short pc, size_t w, size_t h)
{
const size_t plane_size = h * w;
const size_t outputlen = 3 * plane_size;
new_stream.resize( outputlen );
assert( data_size != outputlen );
if( data_size == outputlen )
{
return;
}
typedef unsigned char byte;
enum {
COLORMODE = 0x81,
ESCMODE = 0x82,
REPEATMODE = 0x83
};
const byte* src = (const byte*)data_in;
byte* dest = (byte*)new_stream.data();
union { byte gray; byte rgb[3]; } pixel;
pixel.rgb[0] = pixel.rgb[1] = pixel.rgb[2] = 0;
bool graymode = true;
size_t dx = 1;
size_t dy = 3;
if (pc)
{
dx = plane_size;
dy = 1;
}
size_t ps = plane_size;
while (ps)
{
byte b = *src++;
assert( src < data_in + data_size );
switch ( b )
{
case ESCMODE:
if (graymode)
{
pixel.gray += *src++;
dest[0*dx] = pixel.gray;
dest[1*dx] = pixel.gray;
dest[2*dx] = pixel.gray;
}
else
{
pixel.rgb[0] += *src++;
pixel.rgb[1] += *src++;
pixel.rgb[2] += *src++;
dest[0*dx] = pixel.rgb[0];
dest[1*dx] = pixel.rgb[1];
dest[2*dx] = pixel.rgb[2];
}
dest += dy;
ps--;
break;
case REPEATMODE:
b = *src++;
ps -= b;
if (graymode)
{
while (b-- > 0)
{
dest[0*dx] = pixel.gray;
dest[1*dx] = pixel.gray;
dest[2*dx] = pixel.gray;
dest += dy;
}
}
else
{
while (b-- > 0)
{
dest[0*dx] = pixel.rgb[0];
dest[1*dx] = pixel.rgb[1];
dest[2*dx] = pixel.rgb[2];
dest += dy;
}
}
break;
case COLORMODE:
if (graymode)
{
graymode = false;
pixel.rgb[0] = pixel.rgb[1] = pixel.rgb[2] = 0;
}
else
{
graymode = true;
pixel.gray = 0;
}
break;
default:
if (graymode)
{
pixel.gray += b;
dest[0*dx] = pixel.gray;
dest[1*dx] = pixel.gray;
dest[2*dx] = pixel.gray;
}
else
{
pixel.rgb[0] += b;
pixel.rgb[1] += *src++;
pixel.rgb[2] += *src++;
dest[0*dx] = pixel.rgb[0];
dest[1*dx] = pixel.rgb[1];
dest[2*dx] = pixel.rgb[2];
}
dest += dy;
ps--;
break;
}
}
}
int main(int argc, char *argv [])
{
if( argc < 2 ) return 1;
const char *filename = argv[1];
{
std::cerr << "Failed to read: " << filename << std::endl;
return 1;
}
if ( compressiontype.
IsEmpty() )
return 1;
std::string comprle = "PMSCT_RLE1";
std::string comprgb = "PMSCT_RGB1";
bool isrle = false;
bool isrgb = false;
if( strncmp( bv->
GetPointer(), comprle.c_str(), comprle.size() ) == 0 )
{
isrle = true;
return 1;
}
if( strncmp( bv->
GetPointer(), comprgb.c_str(), comprgb.size() ) == 0 )
{
isrgb = true;
}
if( !isrgb && !isrle ) return 1;
if ( compressionpixeldata.
IsEmpty() )
return 1;
std::vector<unsigned char> buffer;
pixeldata.SetByteValue( (char*)buffer.data(), (uint32_t)buffer.size() );
std::string outfilename;
if (argc > 2)
outfilename = argv[2];
else
outfilename = "outrgb.dcm";
{
std::cerr << "Failed to write" << std::endl;
return 1;
}
std::cout << "success !" << std::endl;
return 0;
}
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:154
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:229
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
const char * GetPointer() const
Definition gdcmByteValue.h:110
VL GetLength() const override
Definition gdcmByteValue.h:77
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
const Tag & GetTag() const
Get Tag.
Definition gdcmDataElement.h:67
const ByteValue * GetByteValue() const
Definition gdcmDataElement.h:133
bool IsEmpty() const
Check if Data Element is empty.
Definition gdcmDataElement.h:106
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
SizeType Remove(const Tag &tag)
Completely remove a dataelement from the dataset.
Definition gdcmDataSet.h:172
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner)
Definition gdcmPrivateTag.h:39
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
virtual bool Read()
Main function to read a file.
void SetFileName(const char *filename_native)
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
@ OW
Definition gdcmVR.h:77
Writer ala DOM (Document Object Model)
Definition gdcmWriter.h:49
File & GetFile()
Definition gdcmWriter.h:67
virtual bool Write()
Main function to tell the writer to write.
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header)
Definition gdcmWriter.h:66
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write: