+2004-10-08 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+ * src/gdcmCommon.h now declares int8_t for non stdint.h plateforms.
+ * CLEANUP_ROUND (7) for gdcmPixelConvert (lost at sea)
+ - src/gdcmFile.h gdcmPixelConvert.cxx gdcmPixelConvert.h gdcmRLE.cxx:
+ clean up of RLE related code.
+
2004-10-07 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
* CLEANUP_ROUND (5) for gdcmPixelConvert (Upshit creek without a paddle)
- src/gdcmDocument.[cxx|h] Parse7Fe0 renamed to ComputeRLEInfo.
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/10/01 12:40:57 $
- Version: $Revision: 1.55 $
+ Date: $Date: 2004/10/08 08:56:48 $
+ Version: $Revision: 1.56 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// (would be static in C, or embedded in ADA)
// It's NOT a method, but a not user intended fonction.
// How do we write that in C++ ?)
- static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode,
- long uncompressedSegmentSize, FILE* fp);
+ static bool gdcm_read_RLE_fragment( uint8_t** decodedZone,
+ long fragmentSize,
+ long uncompressedSegmentSize, FILE* fp);
void SaveInitialValues(); // will belong to the future gdcmPixelData class
void RestoreInitialValues(); // will belong to the future gdcmPixelData class
Program: gdcm
Module: $RCSfile: gdcmPixelConvert.cxx,v $
Language: C++
- Date: $Date: 2004/09/29 17:33:17 $
- Version: $Revision: 1.1 $
+ Date: $Date: 2004/10/08 08:56:48 $
+ Version: $Revision: 1.2 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
-////// #include <stdio.h>
+////////////////// TEMPORARY NOT
+// look for "fixMem" and convert that to a member of this class
+// Removing the prefix fixMem and dealing with allocations should do the trick
#define str2num(str, typeNum) *((typeNum *)(str))
#include "gdcmDebug.h"
* High Byte 'Planes'...(for what it may mean)
* @return Boolean
*/
-bool gdcmPixelConvert::UncompressRLE16BitsFromRLE8Bits(
- size_t PixelNumber,
- int NumberOfFrames )
-
+uint8_t* gdcmPixelConvert::UncompressRLE16BitsFromRLE8Bits(
+ int XSize,
+ int YSize,
+ int NumberOfFrames,
+ uint8_t* fixMemUncompressed )
{
- /// We assumed Uncompressed contains the decoded RLE pixels but as
- /// 8 bits per pixel. In order to convert those pixels to 16 bits
- /// per pixel we need to double the space. Hence we cannot work in
- /// place within Uncompressed. So, here is how we handle things:
- /// - First stage: copy Uncompressed in a safe place, say OldUncompressed
- /// - Second stage: reallocate Uncompressed with the needed space
- /// - Third stage: expand from OldUncompressed to Uncompressed
- /// - Fourth stage: clean up OldUncompressed
+ size_t PixelNumber = XSize * YSize;
+ size_t fixMemUncompressedSize = XSize * YSize * NumberOfFrames;
+
+ // We assumed Uncompressed contains the decoded RLE pixels but as
+ // 8 bits per pixel. In order to convert those pixels to 16 bits
+ // per pixel we cannot work in place within Uncompressed.
+ // Here is how we handle things:
+ // - First stage: copy Uncompressed in a safe place, say OldUncompressed
+ // - Second stage: reallocate Uncompressed with the needed space
+ // - Third stage: expand from OldUncompressed to Uncompressed
+ // - Fourth stage: clean up OldUncompressed
/// First stage:
- uint8_t* OldUncompressed = new uint8_t[UncompressedSize * 2];
- memmove( OldUncompressed, Uncompressed, UncompressedSize);
+ uint8_t* OldUncompressed = new uint8_t[ fixMemUncompressedSize * 2 ];
+ memmove( OldUncompressed, fixMemUncompressed, fixMemUncompressedSize * 2);
/// Second stage:
- SetUncompressedSize( 2 * UncompressedSize );
- AllocateUncompressed();
+ //fixMem SetUncompressedSize( 2 * UncompressedSize );
+ //fixMem AllocateUncompressed();
+ uint8_t* fixMemNewUncompressed = new uint8_t[fixMemUncompressedSize * 2];
/// Third stage:
- uint8_t* x = Uncompressed;
+ uint8_t* x = fixMemNewUncompressed;
uint8_t* a = OldUncompressed;
uint8_t* b = a + PixelNumber;
delete[] OldUncompressed;
/// \todo check that operator new []didn't fail, and sometimes return false
- return true;
+ return fixMemNewUncompressed;
}
Program: gdcm
Module: $RCSfile: gdcmPixelConvert.h,v $
Language: C++
- Date: $Date: 2004/09/29 17:33:17 $
- Version: $Revision: 1.1 $
+ Date: $Date: 2004/10/08 08:56:48 $
+ Version: $Revision: 1.2 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
size_t expectedSize );
bool ConvertGrayAndLutToRGB( uint8_t *lutRGBA );
bool ReadAndUncompressRLE8Bits(FILE* fp, size_t uncompressedSize );
-bool UncompressRLE16BitsFromRLE8Bits( size_t PixelNumber, int NumberOfFrames );
-
-
-
-
+static uint8_t* UncompressRLE16BitsFromRLE8Bits(
+ int XSize,
+ int YSize,
+ int NumberOfFrames,
+ uint8_t* fixMemUncompressed );
+
};
Program: gdcm
Module: $RCSfile: gdcmRLE.cxx,v $
Language: C++
- Date: $Date: 2004/10/08 04:52:55 $
- Version: $Revision: 1.25 $
+ Date: $Date: 2004/10/08 08:56:48 $
+ Version: $Revision: 1.26 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmFile.h"
-
-#define str2num(str, typeNum) *((typeNum *)(str))
+#include "gdcmDebug.h"
+#include "gdcmPixelConvert.h"
+#include <stdio.h>
//-----------------------------------------------------------------------------
/**
* at which the pixel data should be copied
* @return Boolean
*/
-bool gdcmFile::gdcm_read_RLE_file (FILE* fp,void* image_buffer)
+bool gdcmFile::gdcm_read_RLE_file( FILE* fp, void* image_buffer )
{
- char * im = (char *)image_buffer;
+ char* im = (char *)image_buffer;
long uncompressedSegmentSize = Header->GetXSize() * Header->GetYSize();
for( unsigned int k = 1; k <= (*it)->NumberFragments; k++ )
{
fseek( fp, (*it)->Offset[k] ,SEEK_SET);
- gdcm_read_RLE_fragment( &im, (*it)->Length[k],
- uncompressedSegmentSize, fp );
+ (void)gdcm_read_RLE_fragment( (uint8_t**) (&im), (*it)->Length[k],
+ uncompressedSegmentSize, fp );
}
}
-
- if (Header->GetBitsAllocated()==16)
+
+ if ( Header->GetBitsAllocated() == 16 )
{
- // try to deal with RLE 16 Bits
-
+ // Try to deal with RLE 16 Bits
+ /*
+ image_buffer = (void*)gdcmPixelConvert::UncompressRLE16BitsFromRLE8Bits(
+ Header->GetXSize(),
+ Header->GetYSize(),
+ Header->GetZSize(),
+ (uint8_t*) im);
+ */
im = (char *)image_buffer;
- // need to make 16 Bits Pixels from Low Byte and Hight Byte 'Planes'
+ // need to make 16 Bits Pixels from Low Byte and Hight Byte 'Planes'
int l = Header->GetXSize()*Header->GetYSize();
int nbFrames = Header->GetZSize();
// ----------------------------------------------------------------------------
-// RLE LossLess Fragment
-int gdcmFile::gdcm_read_RLE_fragment(char** areaToRead, long lengthToDecode,
- long uncompressedSegmentSize, FILE* fp)
+/**
+ * \brief Implementation of the RLE decoding algorithm for uncompressing
+ * a RLE fragment. [refer to PS 3.5-2003, section G.3.2 p 86]
+ */
+bool gdcmFile::gdcm_read_RLE_fragment( uint8_t** decodedZone,
+ long fragmentSize,
+ long uncompressedSegmentSize,
+ FILE* fp )
{
- (void)lengthToDecode; //FIXME
- int count;
- long numberOfOutputBytes=0;
- char n, car;
+ int8_t count;
+ long numberOfOutputBytes = 0;
+ long numberOfReadBytes = 0;
while( numberOfOutputBytes < uncompressedSegmentSize )
{
- fread(&n,sizeof(char),1,fp);
- count=n;
- if (count >= 0 && count <= 127)
+ fread( &count, 1, 1, fp );
+ numberOfReadBytes += 1;
+ if ( count >= 0 )
+ // Note: count <= 127 comparison is always true due to limited range
+ // of data type int8_t [since the maximum of an exact width
+ // signed integer of width N is 2^(N-1) - 1, which for int8_t
+ // is 127].
{
- fread(*areaToRead,(count+1)*sizeof(char),1,fp);
- *areaToRead+=count+1;
- numberOfOutputBytes+=count+1;
+ fread( *decodedZone, count + 1, 1, fp);
+ numberOfReadBytes += count + 1;
+ *decodedZone += count + 1;
+ numberOfOutputBytes += count + 1;
}
else
{
- if (count <= -1 && count >= -127)
+ if ( ( count <= -1 ) && ( count >= -127 ) )
{
- fread(&car,sizeof(char),1,fp);
- for(int i=0; i<-count+1; i++)
+ int8_t newByte;
+ fread( &newByte, 1, 1, fp);
+ numberOfReadBytes += 1;
+ for( int i = 0; i < -count + 1; i++ )
{
- (*areaToRead)[i]=car;
+ (*decodedZone)[i] = newByte;
}
- *areaToRead+=(-count+1);
- numberOfOutputBytes+=(-count+1);
+ *decodedZone += -count + 1;
+ numberOfOutputBytes += -count + 1;
}
}
- // if count = 128 output nothing (See : PS 3.5-2003 Page 86)
+ // if count = 128 output nothing
+
+ if ( numberOfReadBytes > fragmentSize )
+ {
+ dbg.Verbose(0, "gdcmFile::gdcm_read_RLE_fragment: we read more "
+ "bytes than the segment size.");
+ return false;
+ }
}
- return 1;
+ return true;
}
// ----------------------------------------------------------------------------