#include <gdcmPixelReadConvert.h>
Inheritance diagram for gdcm::PixelReadConvert:
Public Member Functions | |
void | SetPrintLevel (int level) |
Sets the print level for the Dicom Header Elements. | |
int | GetPrintLevel () |
Gets the print level for the Dicom Entries. | |
Protected Attributes | |
int | PrintLevel |
Amount of printed details for each Dicom Entries : 0 : stands for the least detail level. | |
Private Member Functions | |
PixelReadConvert () | |
Constructor. | |
virtual | ~PixelReadConvert () |
Canonical Destructor. | |
void | Print (std::ostream &os=std::cout, std::string const &indent="") |
Print self. | |
uint8_t * | GetRGB () |
returns pixel area holding RGB Pixels, made from Grey level + LUT | |
size_t | GetRGBSize () |
returns pixel area length -RGB Pixels, (from Grey level + LUT)- | |
uint8_t * | GetRaw () |
returns pixel area holding native RGB Pixels or Grey level | |
size_t | GetRawSize () |
returns pixel area size -native RGB Pixels or Grey level- | |
uint8_t * | GetLutRGBA () |
returns Red Green Blue Alpha LUT | |
int | GetLutItemNumber () |
returns Lut Item Number | |
int | GetLutItemSize () |
returns Lut Item Size | |
bool | IsRawRGB () |
Predicate to know whether the image[s] (once Raw) is RGB. | |
void | GrabInformationsFromFile (File *file) |
Gets various usefull informations from the file header. | |
bool | ReadAndDecompressPixelData (std::ifstream *fp) |
Reads from disk and decompresses Pixels. | |
void | Squeeze () |
Deletes Pixels Area. | |
bool | BuildRGBImage () |
Build the RGB image from the Raw image and the LUTs. | |
void | BuildLUTRGBA () |
Build Red/Green/Blue/Alpha LUT from File when :
| |
void | SetUserFunction (VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc) |
Allow user to pass his own function to modify pixels (e.g; mirror, upsidedown, ...) just after reading. | |
void | ReadAndDecompress12BitsTo16Bits (std::ifstream *fp) throw ( FormatError ) |
Read from file a 12 bits per pixel image and decompress it into a 16 bits per pixel image. | |
bool | ReadAndDecompressJPEGFile (std::ifstream *fp) |
Reads from disk the Pixel Data of JPEG Dicom encapsulated file and decompress it. | |
void | ConvertSwapZone () |
Swap the bytes, according to SwapCode. | |
void | ConvertReorderEndianity () |
Deal with endianness i.e. re-arange bytes inside the integer. | |
bool | ConvertReArrangeBits () throw ( FormatError ) |
Re-arrange the bits within the bytes. | |
void | ConvertFixGreyLevels () |
Deal with Grey levels i.e. re-arange them to have low values = dark, high values = bright. | |
void | ConvertRGBPlanesToRGBPixels () |
Convert (Red plane, Green plane, Blue plane) to RGB pixels. | |
void | ConvertYcBcRPlanesToRGBPixels () |
Convert (cY plane, cB plane, cR plane) to RGB pixels. | |
void | ConvertHandleColor () |
Deals with the color decoding i.e. handle:
| |
void | ComputeRawAndRGBSizes () |
Computes the Pixels Size. | |
void | AllocateRGB () |
Allocates room for RGB Pixels. | |
void | AllocateRaw () |
Allocates room for RAW Pixels. | |
Private Attributes | |
uint8_t * | RGB |
Pixel data represented as RGB after LUT color interpretation. 'uint8_t' is just to avoid warnings at compile time. feel free to cast it as uint16_t if you need. | |
size_t | RGBSize |
Size of RGB image. | |
uint8_t * | Raw |
Pixel data after decompression and bit/byte rearrangement. | |
size_t | RawSize |
Size of Decompressed image. | |
uint8_t * | LutRGBA |
Red/Green/Blue/Alpha LookUpTable build out of the Red/Green/Blue LUT descriptors (see BuildLUTRGBA ). | |
int | LutItemNumber |
int | LutItemSize |
size_t | PixelOffset |
size_t | PixelDataLength |
int | XSize |
int | YSize |
int | ZSize |
int | BitsAllocated |
int | BitsStored |
int | HighBitPosition |
int | SamplesPerPixel |
bool | PixelSign |
int | SwapCode |
bool | IsRaw |
bool | IsPrivateGETransferSyntax |
bool | IsJPEG2000 |
bool | IsJPEGLS |
bool | IsJPEGLossless |
bool | IsJPEGLossy |
bool | IsJPEG |
bool | IsRLELossless |
bool | IsMPEG |
RLEFramesInfo * | RLEInfo |
JPEGFragmentsInfo * | JPEGInfo |
int | PlanarConfiguration |
bool | IsMonochrome |
bool | IsMonochrome1 |
bool | IsPaletteColor |
bool | IsYBRFull |
bool | HasLUT |
std::string | LutRedDescriptor |
std::string | LutGreenDescriptor |
std::string | LutBlueDescriptor |
uint8_t * | LutRedData |
uint8_t * | LutGreenData |
uint8_t * | LutBlueData |
File * | FileInternal |
VOID_FUNCTION_PUINT8_PFILE_POINTER | UserFunction |
Friends | |
class | FileHelper |
Definition at line 41 of file gdcmPixelReadConvert.h.
|
Constructor.
Definition at line 43 of file gdcmPixelReadConvert.cxx. References FileInternal, JPEGInfo, LutBlueData, LutGreenData, LutRedData, LutRGBA, Raw, RawSize, RGB, RGBSize, RLEInfo, and UserFunction. 00044 { 00045 RGB = 0; 00046 RGBSize = 0; 00047 Raw = 0; 00048 RawSize = 0; 00049 LutRGBA = 0; 00050 LutRedData = 0; 00051 LutGreenData = 0; 00052 LutBlueData = 0; 00053 RLEInfo = 0; 00054 JPEGInfo = 0; 00055 UserFunction = 0; 00056 FileInternal = 0; 00057 }
|
|
Canonical Destructor.
Definition at line 60 of file gdcmPixelReadConvert.cxx. References Squeeze(). 00061 { 00062 Squeeze(); 00063 }
|
|
Allocates room for RAW Pixels.
Definition at line 1319 of file gdcmPixelReadConvert.cxx. Referenced by ReadAndDecompressPixelData().
|
|
Allocates room for RGB Pixels.
Definition at line 1311 of file gdcmPixelReadConvert.cxx. Referenced by BuildRGBImage().
|
|
Build Red/Green/Blue/Alpha LUT from File when :
Definition at line 576 of file gdcmPixelReadConvert.cxx. References BitsAllocated, gdcm::GDCM_UNFOUND, gdcmDebugMacro, gdcmWarningMacro, IsPaletteColor, LutBlueData, LutBlueDescriptor, LutGreenData, LutGreenDescriptor, LutItemNumber, LutItemSize, LutRedData, LutRedDescriptor, and LutRGBA. Referenced by BuildRGBImage(), and gdcm::FileHelper::GetLutRGBA(). 00577 { 00578 00579 // Note to code reviewers : 00580 // The problem is *much more* complicated, since a lot of manufacturers 00581 // Don't follow the norm : 00582 // have a look at David Clunie's remark at the end of this .cxx file. 00583 if ( LutRGBA ) 00584 00585 { 00586 return; 00587 } 00588 // Not so easy : see 00589 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables 00590 00591 if ( ! IsPaletteColor ) 00592 { 00593 return; 00594 } 00595 00596 if ( LutRedDescriptor == GDCM_UNFOUND 00597 || LutGreenDescriptor == GDCM_UNFOUND 00598 || LutBlueDescriptor == GDCM_UNFOUND ) 00599 { 00600 gdcmWarningMacro( "(At least) a LUT Descriptor is missing" ); 00601 return; 00602 } 00603 00605 // Extract the info from the LUT descriptors 00606 int lengthR; // Red LUT length in Bytes 00607 int debR; // Subscript of the first Lut Value 00608 int nbitsR; // Lut item size (in Bits) 00609 int nbRead; // nb of items in LUT descriptor (must be = 3) 00610 00611 nbRead = sscanf( LutRedDescriptor.c_str(), 00612 "%d\\%d\\%d", 00613 &lengthR, &debR, &nbitsR ); 00614 if ( nbRead != 3 ) 00615 { 00616 gdcmWarningMacro( "Wrong Red LUT descriptor" ); 00617 } 00618 int lengthG; // Green LUT length in Bytes 00619 int debG; // Subscript of the first Lut Value 00620 int nbitsG; // Lut item size (in Bits) 00621 00622 nbRead = sscanf( LutGreenDescriptor.c_str(), 00623 "%d\\%d\\%d", 00624 &lengthG, &debG, &nbitsG ); 00625 if ( nbRead != 3 ) 00626 { 00627 gdcmWarningMacro( "Wrong Green LUT descriptor" ); 00628 } 00629 00630 int lengthB; // Blue LUT length in Bytes 00631 int debB; // Subscript of the first Lut Value 00632 int nbitsB; // Lut item size (in Bits) 00633 nbRead = sscanf( LutRedDescriptor.c_str(), 00634 "%d\\%d\\%d", 00635 &lengthB, &debB, &nbitsB ); 00636 if ( nbRead != 3 ) 00637 { 00638 gdcmWarningMacro( "Wrong Blue LUT descriptor" ); 00639 } 00640 00641 gdcmDebugMacro(" lengthR " << lengthR << " debR " 00642 << debR << " nbitsR " << nbitsR); 00643 gdcmDebugMacro(" lengthG " << lengthG << " debG " 00644 << debG << " nbitsG " << nbitsG); 00645 gdcmDebugMacro(" lengthB " << lengthB << " debB " 00646 << debB << " nbitsB " << nbitsB); 00647 00648 if ( !lengthR ) // if = 2^16, this shall be 0 see : CP-143 00649 lengthR=65536; 00650 if ( !lengthG ) // if = 2^16, this shall be 0 00651 lengthG=65536; 00652 if ( !lengthB ) // if = 2^16, this shall be 0 00653 lengthB=65536; 00654 00656 00657 if ( ( ! LutRedData ) || ( ! LutGreenData ) || ( ! LutBlueData ) ) 00658 { 00659 gdcmWarningMacro( "(At least) a LUT is missing" ); 00660 return; 00661 } 00662 00663 // ------------------------------------------------------------- 00664 00665 if ( BitsAllocated <= 8 ) 00666 { 00667 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT 00668 LutRGBA = new uint8_t[ 1024 ]; // 256 * 4 (R, G, B, Alpha) 00669 if ( !LutRGBA ) 00670 return; 00671 LutItemNumber = 256; 00672 LutItemSize = 8; 00673 memset( LutRGBA, 0, 1024 ); 00674 00675 int mult; 00676 if ( ( nbitsR == 16 ) && ( BitsAllocated == 8 ) ) 00677 { 00678 // when LUT item size is different than pixel size 00679 mult = 2; // high byte must be = low byte 00680 } 00681 else 00682 { 00683 // See PS 3.3-2003 C.11.1.1.2 p 619 00684 mult = 1; 00685 } 00686 00687 // if we get a black image, let's just remove the '+1' 00688 // from 'i*mult+1' and check again 00689 // if it works, we shall have to check the 3 Palettes 00690 // to see which byte is ==0 (first one, or second one) 00691 // and fix the code 00692 // We give up the checking to avoid some (useless ?) overhead 00693 // (optimistic asumption) 00694 int i; 00695 uint8_t *a; 00696 00697 //take "Subscript of the first Lut Value" (debR,debG,debB) into account! 00698 00699 //FIXME : +1 : to get 'low value' byte 00700 // Trouble expected on Big Endian Processors ? 00701 // 16 BIts Per Pixel Palette Color to be swapped? 00702 00703 a = LutRGBA + 0 + debR; 00704 for( i=0; i < lengthR; ++i ) 00705 { 00706 *a = LutRedData[i*mult+1]; 00707 a += 4; 00708 } 00709 00710 a = LutRGBA + 1 + debG; 00711 for( i=0; i < lengthG; ++i) 00712 { 00713 *a = LutGreenData[i*mult+1]; 00714 a += 4; 00715 } 00716 00717 a = LutRGBA + 2 + debB; 00718 for(i=0; i < lengthB; ++i) 00719 { 00720 *a = LutBlueData[i*mult+1]; 00721 a += 4; 00722 } 00723 00724 a = LutRGBA + 3 ; 00725 for(i=0; i < 256; ++i) 00726 { 00727 *a = 1; // Alpha component 00728 a += 4; 00729 } 00730 } 00731 else 00732 { 00733 // Probabely the same stuff is to be done for 16 Bits Pixels 00734 // with 65536 entries LUT ?!? 00735 // Still looking for accurate info on the web :-( 00736 00737 gdcmWarningMacro( "Sorry Palette Color Lookup Tables not yet dealt with" 00738 << " for 16 Bits Per Pixel images" ); 00739 00740 // forge the 4 * 16 Bits Red/Green/Blue/Alpha LUT 00741 00742 LutRGBA = (uint8_t *)new uint16_t[ 65536*4 ]; // 2^16 * 4 (R, G, B, Alpha) 00743 if ( !LutRGBA ) 00744 return; 00745 memset( LutRGBA, 0, 65536*4*2 ); // 16 bits = 2 bytes ;-) 00746 00747 LutItemNumber = 65536; 00748 LutItemSize = 16; 00749 00750 int i; 00751 uint16_t *a16; 00752 00753 //take "Subscript of the first Lut Value" (debR,debG,debB) into account! 00754 00755 a16 = (uint16_t*)LutRGBA + 0 + debR; 00756 for( i=0; i < lengthR; ++i ) 00757 { 00758 *a16 = ((uint16_t*)LutRedData)[i]; 00759 a16 += 4; 00760 } 00761 00762 a16 = (uint16_t*)LutRGBA + 1 + debG; 00763 for( i=0; i < lengthG; ++i) 00764 { 00765 *a16 = ((uint16_t*)LutGreenData)[i]; 00766 a16 += 4; 00767 } 00768 00769 a16 = (uint16_t*)LutRGBA + 2 + debB; 00770 for(i=0; i < lengthB; ++i) 00771 { 00772 *a16 = ((uint16_t*)LutBlueData)[i]; 00773 a16 += 4; 00774 } 00775 00776 a16 = (uint16_t*)LutRGBA + 3 ; 00777 for(i=0; i < 65536; ++i) 00778 { 00779 *a16 = 1; // Alpha component 00780 a16 += 4; 00781 } 00782 /* Just to 'see' the LUT, at debug time 00783 // Don't remove this commented out code. 00784 00785 a16=(uint16_t*)LutRGBA; 00786 for (int j=0;j<65536;j++) 00787 { 00788 std::cout << *a16 << " " << *(a16+1) << " " 00789 << *(a16+2) << " " << *(a16+3) << std::endl; 00790 a16+=4; 00791 } 00792 */ 00793 } 00794 }
|
|
Build the RGB image from the Raw image and the LUTs.
Definition at line 349 of file gdcmPixelReadConvert.cxx. References AllocateRGB(), BitsAllocated, BuildLUTRGBA(), gdcmDebugMacro, LutRGBA, Raw, RawSize, and RGB. Referenced by gdcm::FileHelper::GetImageData(), and gdcm::FileHelper::SetWriteToRGB(). 00350 { 00351 if ( RGB ) 00352 { 00353 // The job is already done. 00354 return true; 00355 } 00356 00357 if ( ! Raw ) 00358 { 00359 // The job can't be done 00360 return false; 00361 } 00362 00363 BuildLUTRGBA(); 00364 if ( ! LutRGBA ) 00365 { 00366 // The job can't be done 00367 return false; 00368 } 00369 00370 gdcmDebugMacro( "--> BuildRGBImage" ); 00371 00372 // Build RGB Pixels 00373 AllocateRGB(); 00374 00375 int j; 00376 if ( BitsAllocated <= 8 ) 00377 { 00378 uint8_t *localRGB = RGB; 00379 for (size_t i = 0; i < RawSize; ++i ) 00380 { 00381 j = Raw[i] * 4; 00382 *localRGB++ = LutRGBA[j]; 00383 *localRGB++ = LutRGBA[j+1]; 00384 *localRGB++ = LutRGBA[j+2]; 00385 } 00386 } 00387 00388 else // deal with 16 bits pixels and 16 bits Palette color 00389 { 00390 uint16_t *localRGB = (uint16_t *)RGB; 00391 for (size_t i = 0; i < RawSize/2; ++i ) 00392 { 00393 j = ((uint16_t *)Raw)[i] * 4; 00394 *localRGB++ = ((uint16_t *)LutRGBA)[j]; 00395 *localRGB++ = ((uint16_t *)LutRGBA)[j+1]; 00396 *localRGB++ = ((uint16_t *)LutRGBA)[j+2]; 00397 } 00398 } 00399 00400 return true; 00401 }
|
|
Computes the Pixels Size.
Definition at line 1286 of file gdcmPixelReadConvert.cxx. References BitsAllocated, HasLUT, RawSize, RGBSize, SamplesPerPixel, XSize, YSize, and ZSize. Referenced by GrabInformationsFromFile(). 01287 { 01288 int bitsAllocated = BitsAllocated; 01289 // Number of "Bits Allocated" is fixed to 16 when it's 12, since 01290 // in this case we will expand the image to 16 bits (see 01291 // \ref ReadAndDecompress12BitsTo16Bits() ) 01292 if ( BitsAllocated == 12 ) 01293 { 01294 bitsAllocated = 16; 01295 } 01296 01297 RawSize = XSize * YSize * ZSize 01298 * ( bitsAllocated / 8 ) 01299 * SamplesPerPixel; 01300 if ( HasLUT ) 01301 { 01302 RGBSize = 3 * RawSize; // works for 8 and 16 bits per Pixel 01303 } 01304 else 01305 { 01306 RGBSize = RawSize; 01307 } 01308 }
|
|
Deal with Grey levels i.e. re-arange them to have low values = dark, high values = bright.
Definition at line 944 of file gdcmPixelReadConvert.cxx. References BitsAllocated, BitsStored, IsMonochrome1, PixelSign, Raw, and RawSize. Referenced by ReadAndDecompressPixelData(). 00945 { 00946 if (!IsMonochrome1) 00947 return; 00948 00949 uint32_t i; // to please M$VC6 00950 int16_t j; 00951 00952 if (!PixelSign) 00953 { 00954 if ( BitsAllocated == 8 ) 00955 { 00956 uint8_t *deb = (uint8_t *)Raw; 00957 for (i=0; i<RawSize; i++) 00958 { 00959 *deb = 255 - *deb; 00960 deb++; 00961 } 00962 return; 00963 } 00964 00965 if ( BitsAllocated == 16 ) 00966 { 00967 uint16_t mask =1; 00968 for (j=0; j<BitsStored-1; j++) 00969 { 00970 mask = (mask << 1) +1; // will be fff when BitsStored=12 00971 } 00972 00973 uint16_t *deb = (uint16_t *)Raw; 00974 for (i=0; i<RawSize/2; i++) 00975 { 00976 *deb = mask - *deb; 00977 deb++; 00978 } 00979 return; 00980 } 00981 } 00982 else 00983 { 00984 if ( BitsAllocated == 8 ) 00985 { 00986 uint8_t smask8 = 255; 00987 uint8_t *deb = (uint8_t *)Raw; 00988 for (i=0; i<RawSize; i++) 00989 { 00990 *deb = smask8 - *deb; 00991 deb++; 00992 } 00993 return; 00994 } 00995 if ( BitsAllocated == 16 ) 00996 { 00997 uint16_t smask16 = 65535; 00998 uint16_t *deb = (uint16_t *)Raw; 00999 for (i=0; i<RawSize/2; i++) 01000 { 01001 *deb = smask16 - *deb; 01002 deb++; 01003 } 01004 return; 01005 } 01006 } 01007 }
|
|
Deals with the color decoding i.e. handle:
Definition at line 1206 of file gdcmPixelReadConvert.cxx. References ConvertRGBPlanesToRGBPixels(), ConvertYcBcRPlanesToRGBPixels(), gdcmDebugMacro, IsRawRGB(), IsRLELossless, IsYBRFull, and PlanarConfiguration. Referenced by ReadAndDecompressPixelData(). 01207 { 01209 // Deal with the color decoding i.e. handle: 01210 // - R, G, B planes (as opposed to RGB pixels) 01211 // - YBR (various) encodings. 01212 // - LUT[s] (or "PALETTE COLOR"). 01213 // 01214 // The classification in the color decoding schema is based on the blending 01215 // of two Dicom tags values: 01216 // * "Photometric Interpretation" for which we have the cases: 01217 // - [Photo A] MONOCHROME[1|2] pictures, 01218 // - [Photo B] RGB or YBR_FULL_422 (which acts as RGB), 01219 // - [Photo C] YBR_* (with the above exception of YBR_FULL_422) 01220 // - [Photo D] "PALETTE COLOR" which indicates the presence of LUT[s]. 01221 // * "Planar Configuration" for which we have the cases: 01222 // - [Planar 0] 0 then Pixels are already RGB 01223 // - [Planar 1] 1 then we have 3 planes : R, G, B, 01224 // - [Planar 2] 2 then we have 1 gray Plane and 3 LUTs 01225 // 01226 // Now in theory, one could expect some coherence when blending the above 01227 // cases. For example we should not encounter files belonging at the 01228 // time to case [Planar 0] and case [Photo D]. 01229 // Alas, this was only theory ! Because in practice some odd (read ill 01230 // formated Dicom) files (e.g. gdcmData/US-PAL-8-10x-echo.dcm) we encounter: 01231 // - "Planar Configuration" = 0, 01232 // - "Photometric Interpretation" = "PALETTE COLOR". 01233 // Hence gdcm will use the folowing "heuristic" in order to be tolerant 01234 // towards Dicom-non-conformant files: 01235 // << whatever the "Planar Configuration" value might be, a 01236 // "Photometric Interpretation" set to "PALETTE COLOR" forces 01237 // a LUT intervention >> 01238 // 01239 // Now we are left with the following handling of the cases: 01240 // - [Planar 0] OR [Photo A] no color decoding (since respectively 01241 // Pixels are already RGB and monochrome pictures have no color :), 01242 // - [Planar 1] AND [Photo B] handled with ConvertRGBPlanesToRGBPixels() 01243 // - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels() 01244 // - [Planar 2] OR [Photo D] requires LUT intervention. 01245 01246 gdcmDebugMacro("--> ConvertHandleColor " 01247 << "Planar Configuration " << PlanarConfiguration ); 01248 01249 if ( ! IsRawRGB() ) 01250 { 01251 // [Planar 2] OR [Photo D]: LUT intervention done outside 01252 gdcmDebugMacro("--> RawRGB : LUT intervention done outside"); 01253 return; 01254 } 01255 01256 if ( PlanarConfiguration == 1 ) 01257 { 01258 if ( IsYBRFull ) 01259 { 01260 // [Planar 1] AND [Photo C] (remember YBR_FULL_422 acts as RGB) 01261 gdcmDebugMacro("--> YBRFull"); 01262 ConvertYcBcRPlanesToRGBPixels(); 01263 } 01264 else 01265 { 01266 // [Planar 1] AND [Photo C] 01267 gdcmDebugMacro("--> YBRFull"); 01268 ConvertRGBPlanesToRGBPixels(); 01269 } 01270 return; 01271 } 01272 01273 // When planarConf is 0, and RLELossless (forbidden by Dicom norm) 01274 // pixels need to be RGB-fyied anyway 01275 01276 if (IsRLELossless) 01277 { 01278 gdcmDebugMacro("--> RLE Lossless"); 01279 ConvertRGBPlanesToRGBPixels(); 01280 } 01281 01282 // In *normal *case, when planarConf is 0, pixels are already in RGB 01283 }
|
|
Re-arrange the bits within the bytes.
Definition at line 1013 of file gdcmPixelReadConvert.cxx. References BitsAllocated, BitsStored, gdcmWarningMacro, HighBitPosition, PixelSign, Raw, and RawSize. Referenced by ReadAndDecompressPixelData(). 01014 { 01015 01016 if ( BitsStored != BitsAllocated ) 01017 { 01018 int l = (int)( RawSize / ( BitsAllocated / 8 ) ); 01019 if ( BitsAllocated == 16 ) 01020 { 01021 // pmask : to mask the 'unused bits' (may contain overlays) 01022 uint16_t pmask = 0xffff; 01023 pmask = pmask >> ( BitsAllocated - BitsStored ); 01024 01025 uint16_t *deb = (uint16_t*)Raw; 01026 01027 if ( !PixelSign ) // Pixels are unsigned 01028 { 01029 for(int i = 0; i<l; i++) 01030 { 01031 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & pmask; 01032 deb++; 01033 } 01034 } 01035 else // Pixels are signed 01036 { 01037 // smask : to check the 'sign' when BitsStored != BitsAllocated 01038 uint16_t smask = 0x0001; 01039 smask = smask << ( 16 - (BitsAllocated - BitsStored + 1) ); 01040 // nmask : to propagate sign bit on negative values 01041 int16_t nmask = (int16_t)0x8000; 01042 nmask = nmask >> ( BitsAllocated - BitsStored - 1 ); 01043 01044 for(int i = 0; i<l; i++) 01045 { 01046 *deb = *deb >> (BitsStored - HighBitPosition - 1); 01047 if ( *deb & smask ) 01048 { 01049 *deb = *deb | nmask; 01050 } 01051 else 01052 { 01053 *deb = *deb & pmask; 01054 } 01055 deb++; 01056 } 01057 } 01058 } 01059 else if ( BitsAllocated == 32 ) 01060 { 01061 // pmask : to mask the 'unused bits' (may contain overlays) 01062 uint32_t pmask = 0xffffffff; 01063 pmask = pmask >> ( BitsAllocated - BitsStored ); 01064 01065 uint32_t *deb = (uint32_t*)Raw; 01066 01067 if ( !PixelSign ) 01068 { 01069 for(int i = 0; i<l; i++) 01070 { 01071 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & pmask; 01072 deb++; 01073 } 01074 } 01075 else 01076 { 01077 // smask : to check the 'sign' when BitsStored != BitsAllocated 01078 uint32_t smask = 0x00000001; 01079 smask = smask >> ( 32 - (BitsAllocated - BitsStored +1 )); 01080 // nmask : to propagate sign bit on negative values 01081 int32_t nmask = 0x80000000; 01082 nmask = nmask >> ( BitsAllocated - BitsStored -1 ); 01083 01084 for(int i = 0; i<l; i++) 01085 { 01086 *deb = *deb >> (BitsStored - HighBitPosition - 1); 01087 if ( *deb & smask ) 01088 *deb = *deb | nmask; 01089 else 01090 *deb = *deb & pmask; 01091 deb++; 01092 } 01093 } 01094 } 01095 else 01096 { 01097 gdcmWarningMacro("Weird image (BitsAllocated !=8, 12, 16, 32)"); 01098 throw FormatError( "Weird image !?" ); 01099 } 01100 } 01101 return true; 01102 }
|
|
Deal with endianness i.e. re-arange bytes inside the integer.
Definition at line 915 of file gdcmPixelReadConvert.cxx. References BitsAllocated, BitsStored, ConvertSwapZone(), PixelSign, Raw, and RawSize. Referenced by ReadAndDecompressPixelData(). 00916 { 00917 if ( BitsAllocated != 8 ) 00918 { 00919 ConvertSwapZone(); 00920 } 00921 00922 // Special kludge in order to deal with xmedcon broken images: 00923 if ( BitsAllocated == 16 00924 && BitsStored < BitsAllocated 00925 && !PixelSign ) 00926 { 00927 int l = (int)( RawSize / ( BitsAllocated / 8 ) ); 00928 uint16_t *deb = (uint16_t *)Raw; 00929 for(int i = 0; i<l; i++) 00930 { 00931 if ( *deb == 0xffff ) 00932 { 00933 *deb = 0; 00934 } 00935 deb++; 00936 } 00937 } 00938 }
|
|
Convert (Red plane, Green plane, Blue plane) to RGB pixels.
Definition at line 1108 of file gdcmPixelReadConvert.cxx. References gdcmWarningMacro, Raw, RawSize, XSize, YSize, and ZSize. Referenced by ConvertHandleColor(). 01109 { 01110 gdcmWarningMacro("--> ConvertRGBPlanesToRGBPixels"); 01111 01112 uint8_t *localRaw = Raw; 01113 uint8_t *copyRaw = new uint8_t[ RawSize ]; 01114 memmove( copyRaw, localRaw, RawSize ); 01115 01116 int l = XSize * YSize * ZSize; 01117 01118 uint8_t *a = copyRaw; 01119 uint8_t *b = copyRaw + l; 01120 uint8_t *c = copyRaw + l + l; 01121 01122 for (int j = 0; j < l; j++) 01123 { 01124 *(localRaw++) = *(a++); 01125 *(localRaw++) = *(b++); 01126 *(localRaw++) = *(c++); 01127 } 01128 delete[] copyRaw; 01129 }
|
|
Swap the bytes, according to SwapCode.
Definition at line 799 of file gdcmPixelReadConvert.cxx. References BitsAllocated, gdcmWarningMacro, IsPrivateGETransferSyntax, Raw, RawSize, and SwapCode. Referenced by ConvertReorderEndianity(). 00800 { 00801 unsigned int i; 00802 uint16_t localSwapCode = SwapCode; 00803 00804 // If this file is 'ImplicitVR BigEndian PrivateGE Transfer Syntax', 00805 // then the header is in little endian format and the pixel data is in 00806 // big endian format. When reading the header, GDCM has already established 00807 // a byte swapping code suitable for this machine to read the 00808 // header. In TS::ImplicitVRBigEndianPrivateGE, this code will need 00809 // to be switched in order to read the pixel data. This must be 00810 // done REGARDLESS of the processor endianess! 00811 // 00812 // Example: Assume we are on a little endian machine. When 00813 // GDCM reads the header, the header will match the machine 00814 // endianess and the swap code will be established as a no-op. 00815 // When GDCM reaches the pixel data, it will need to switch the 00816 // swap code to do big endian to little endian conversion. 00817 // 00818 // Now, assume we are on a big endian machine. When GDCM reads the 00819 // header, the header will be recognized as a different endianess 00820 // than the machine endianess, and a swap code will be established 00821 // to convert from little endian to big endian. When GDCM readers 00822 // the pixel data, the pixel data endianess will now match the 00823 // machine endianess. But we currently have a swap code that 00824 // converts from little endian to big endian. In this case, we 00825 // need to switch the swap code to a no-op. 00826 // 00827 // Therefore, in either case, if the file is in 00828 // 'ImplicitVR BigEndian PrivateGE Transfer Syntax', then GDCM needs to switch 00829 // the byte swapping code when entering the pixel data. 00830 00831 if ( IsPrivateGETransferSyntax ) 00832 { 00833 // PrivateGETransferSyntax only exists for 'true' Dicom images 00834 // we assume there is no 'exotic' 32 bits endianess! 00835 switch (localSwapCode) 00836 { 00837 case 1234: 00838 localSwapCode = 4321; 00839 break; 00840 case 4321: 00841 localSwapCode = 1234; 00842 break; 00843 } 00844 } 00845 00846 if ( BitsAllocated == 16 ) 00847 { 00848 uint16_t *im16 = (uint16_t*)Raw; 00849 switch( localSwapCode ) 00850 { 00851 case 1234: 00852 break; 00853 case 3412: 00854 case 2143: 00855 case 4321: 00856 for( i = 0; i < RawSize / 2; i++ ) 00857 { 00858 im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); 00859 } 00860 break; 00861 default: 00862 gdcmWarningMacro("SwapCode value (16 bits) not allowed."); 00863 } 00864 } 00865 else if ( BitsAllocated == 32 ) 00866 { 00867 uint32_t s32; 00868 uint16_t high; 00869 uint16_t low; 00870 uint32_t *im32 = (uint32_t*)Raw; 00871 switch ( localSwapCode ) 00872 { 00873 case 1234: 00874 break; 00875 case 4321: 00876 for( i = 0; i < RawSize / 4; i++ ) 00877 { 00878 low = im32[i] & 0x0000ffff; // 4321 00879 high = im32[i] >> 16; 00880 high = ( high >> 8 ) | ( high << 8 ); 00881 low = ( low >> 8 ) | ( low << 8 ); 00882 s32 = low; 00883 im32[i] = ( s32 << 16 ) | high; 00884 } 00885 break; 00886 case 2143: 00887 for( i = 0; i < RawSize / 4; i++ ) 00888 { 00889 low = im32[i] & 0x0000ffff; // 2143 00890 high = im32[i] >> 16; 00891 high = ( high >> 8 ) | ( high << 8 ); 00892 low = ( low >> 8 ) | ( low << 8 ); 00893 s32 = high; 00894 im32[i] = ( s32 << 16 ) | low; 00895 } 00896 break; 00897 case 3412: 00898 for( i = 0; i < RawSize / 4; i++ ) 00899 { 00900 low = im32[i] & 0x0000ffff; // 3412 00901 high = im32[i] >> 16; 00902 s32 = low; 00903 im32[i] = ( s32 << 16 ) | high; 00904 } 00905 break; 00906 default: 00907 gdcmWarningMacro("SwapCode value (32 bits) not allowed." ); 00908 } 00909 } 00910 }
|
|
Convert (cY plane, cB plane, cR plane) to RGB pixels.
Definition at line 1135 of file gdcmPixelReadConvert.cxx. References gdcmWarningMacro, Raw, RawSize, XSize, YSize, and ZSize. Referenced by ConvertHandleColor(). 01136 { 01137 // Remarks for YBR newbees : 01138 // YBR_FULL works very much like RGB, i.e. three samples per pixel, 01139 // just the color space is YCbCr instead of RGB. This is particularly useful 01140 // for doppler ultrasound where most of the image is grayscale 01141 // (i.e. only populates the Y components) and Cb and Cr are mostly zero, 01142 // except for the few patches of color on the image. 01143 // On such images, RLE achieves a compression ratio that is much better 01144 // than the compression ratio on an equivalent RGB image. 01145 01146 gdcmWarningMacro("--> ConvertYcBcRPlanesToRGBPixels"); 01147 01148 uint8_t *localRaw = Raw; 01149 uint8_t *copyRaw = new uint8_t[ RawSize ]; 01150 memmove( copyRaw, localRaw, RawSize ); 01151 01152 // to see the tricks about YBR_FULL, YBR_FULL_422, 01153 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at : 01154 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf 01155 // and be *very* affraid 01156 // 01157 int l = XSize * YSize; 01158 int nbFrames = ZSize; 01159 01160 uint8_t *a = copyRaw + 0; 01161 uint8_t *b = copyRaw + l; 01162 uint8_t *c = copyRaw + l+ l; 01163 int32_t R, G, B; 01164 01170 01171 for ( int i = 0; i < nbFrames; i++ ) 01172 { 01173 for ( int j = 0; j < l; j++ ) 01174 { 01175 R = 38142 *(*a-16) + 52298 *(*c -128); 01176 G = 38142 *(*a-16) - 26640 *(*c -128) - 12845 *(*b -128); 01177 B = 38142 *(*a-16) + 66093 *(*b -128); 01178 01179 R = (R+16384)>>15; 01180 G = (G+16384)>>15; 01181 B = (B+16384)>>15; 01182 01183 if (R < 0) R = 0; 01184 if (G < 0) G = 0; 01185 if (B < 0) B = 0; 01186 if (R > 255) R = 255; 01187 if (G > 255) G = 255; 01188 if (B > 255) B = 255; 01189 01190 *(localRaw++) = (uint8_t)R; 01191 *(localRaw++) = (uint8_t)G; 01192 *(localRaw++) = (uint8_t)B; 01193 a++; 01194 b++; 01195 c++; 01196 } 01197 } 01198 delete[] copyRaw; 01199 }
|
|
returns Lut Item Number
Definition at line 63 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetLutItemNumber(). 00063 { return LutItemNumber; }
|
|
returns Lut Item Size
Definition at line 65 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetLutItemSize(). 00065 { return LutItemSize; }
|
|
returns Red Green Blue Alpha LUT
Definition at line 61 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetLutRGBA(). 00061 { return LutRGBA; }
|
|
Gets the print level for the Dicom Entries.
Definition at line 50 of file gdcmBase.h. 00050 { return PrintLevel; }
|
|
returns pixel area holding native RGB Pixels or Grey level
Definition at line 57 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetImageData(), gdcm::FileHelper::GetRaw(), gdcm::FileHelper::GetRawData(), gdcm::FileHelper::SetWriteToRaw(), gdcm::FileHelper::SetWriteToRGB(), and gdcm::FileHelper::WriteRawData(). 00057 { return Raw; }
|
|
returns pixel area size -native RGB Pixels or Grey level-
Definition at line 59 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetImageDataRawSize(), gdcm::FileHelper::GetRawDataSize(), gdcm::FileHelper::SetWriteToRaw(), gdcm::FileHelper::SetWriteToRGB(), and gdcm::FileHelper::WriteRawData(). 00059 { return RawSize; }
|
|
returns pixel area holding RGB Pixels, made from Grey level + LUT
Definition at line 53 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetImageData(), gdcm::FileHelper::GetRGBData(), gdcm::FileHelper::SetWriteToRGB(), and gdcm::FileHelper::WriteRawData(). 00053 { return RGB; }
|
|
returns pixel area length -RGB Pixels, (from Grey level + LUT)-
Definition at line 55 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetImageDataSize(), gdcm::FileHelper::GetRGBDataSize(), gdcm::FileHelper::SetWriteToRGB(), and gdcm::FileHelper::WriteRawData(). 00055 { return RGBSize; }
|
|
Gets various usefull informations from the file header.
Definition at line 85 of file gdcmPixelReadConvert.cxx. References BitsAllocated, BitsStored, ComputeRawAndRGBSizes(), FileInternal, gdcmWarningMacro, gdcm::File::GetBitsAllocated(), gdcm::File::GetBitsStored(), gdcm::DocEntrySet::GetEntryBinArea(), gdcm::DocEntrySet::GetEntryString(), gdcm::File::GetHighBitPosition(), gdcm::File::GetJPEGInfo(), gdcm::File::GetPixelAreaLength(), gdcm::File::GetPixelOffset(), gdcm::File::GetPlanarConfiguration(), gdcm::File::GetRLEInfo(), gdcm::File::GetSamplesPerPixel(), gdcm::Document::GetSwapCode(), gdcm::Document::GetTransferSyntax(), gdcm::Global::GetTS(), gdcm::File::GetXSize(), gdcm::File::GetYSize(), gdcm::File::GetZSize(), gdcm::File::HasLUT(), HasLUT, HighBitPosition, gdcm::Document::IsDicomV3(), IsJPEG2000, IsJPEGLossless, IsJPEGLossy, IsJPEGLS, gdcm::File::IsMonochrome(), IsMonochrome, gdcm::File::IsMonochrome1(), IsMonochrome1, IsMPEG, gdcm::File::IsPaletteColor(), IsPaletteColor, IsPrivateGETransferSyntax, IsRaw, IsRLELossless, gdcm::File::IsSignedPixelData(), gdcm::File::IsYBRFull(), IsYBRFull, JPEGInfo, gdcm::Document::LoadEntryBinArea(), LutBlueData, LutBlueDescriptor, LutGreenData, LutGreenDescriptor, LutRedData, LutRedDescriptor, PixelDataLength, PixelOffset, PixelSign, PlanarConfiguration, RLEInfo, SamplesPerPixel, SwapCode, XSize, YSize, and ZSize. Referenced by gdcm::FileHelper::FileHelper(), and gdcm::FileHelper::Load(). 00086 { 00087 // Number of Bits Allocated for storing a Pixel is defaulted to 16 00088 // when absent from the file. 00089 BitsAllocated = file->GetBitsAllocated(); 00090 if ( BitsAllocated == 0 ) 00091 { 00092 BitsAllocated = 16; 00093 } 00094 00095 // Number of "Bits Stored", defaulted to number of "Bits Allocated" 00096 // when absent from the file. 00097 BitsStored = file->GetBitsStored(); 00098 if ( BitsStored == 0 ) 00099 { 00100 BitsStored = BitsAllocated; 00101 } 00102 00103 // High Bit Position, defaulted to "Bits Allocated" - 1 00104 HighBitPosition = file->GetHighBitPosition(); 00105 if ( HighBitPosition == 0 ) 00106 { 00107 HighBitPosition = BitsAllocated - 1; 00108 } 00109 00110 XSize = file->GetXSize(); 00111 YSize = file->GetYSize(); 00112 ZSize = file->GetZSize(); 00113 SamplesPerPixel = file->GetSamplesPerPixel(); 00114 //PixelSize = file->GetPixelSize(); Useless 00115 PixelSign = file->IsSignedPixelData(); 00116 SwapCode = file->GetSwapCode(); 00117 00118 if (! file->IsDicomV3() ) // Should be ACR-NEMA file 00119 { 00120 IsRaw = true; 00121 // Don't loose time checking unexistant Transfer Syntax ! 00122 IsPrivateGETransferSyntax = IsMPEG 00123 = IsJPEG2000 = IsJPEGLS = IsJPEGLossy 00124 = IsJPEGLossless = IsRLELossless 00125 = false; 00126 } 00127 else 00128 { 00129 std::string ts = file->GetTransferSyntax(); 00130 00131 IsRaw = false; 00132 while (true) 00133 { 00134 // mind the order : check the most usual first. 00135 if( IsRaw = Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian) break; 00136 if( IsRaw = Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian ) break; 00137 if( IsRaw = Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian) break; 00138 if( IsRaw = Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRBigEndianPrivateGE) break; 00139 if( IsRaw = Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian) break; 00140 break; 00141 } 00142 00143 IsPrivateGETransferSyntax = 00144 ( Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRBigEndianPrivateGE ); 00145 00146 IsMPEG = IsJPEG2000 = IsJPEGLS = IsJPEGLossy = IsJPEGLossless = IsRLELossless = false; 00147 00148 if (!IsRaw) 00149 { 00150 while(true) 00151 { 00152 // mind the order : check the most usual first. 00153 if( IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts) ) break; 00154 if( IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts) ) break; 00155 if( IsRLELossless = Global::GetTS()->IsRLELossless(ts) ) break; 00156 if( IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts) ) break; 00157 if( IsMPEG = Global::GetTS()->IsMPEG(ts) ) break; 00158 if( IsJPEGLS = Global::GetTS()->IsJPEGLS(ts) ) break; 00159 gdcmWarningMacro("Unexepected Transfer Syntax :[" << ts << "]"); 00160 break; 00161 } 00162 } 00163 } 00164 00165 PixelOffset = file->GetPixelOffset(); 00166 PixelDataLength = file->GetPixelAreaLength(); 00167 RLEInfo = file->GetRLEInfo(); 00168 JPEGInfo = file->GetJPEGInfo(); 00169 00170 IsMonochrome = file->IsMonochrome(); 00171 IsMonochrome1 = file->IsMonochrome1(); 00172 IsPaletteColor = file->IsPaletteColor(); 00173 IsYBRFull = file->IsYBRFull(); 00174 00175 PlanarConfiguration = file->GetPlanarConfiguration(); 00176 00178 // LUT section: 00179 HasLUT = file->HasLUT(); 00180 if ( HasLUT ) 00181 { 00182 // Just in case some access to a File element requires disk access. 00183 LutRedDescriptor = file->GetEntryString( 0x0028, 0x1101 ); 00184 LutGreenDescriptor = file->GetEntryString( 0x0028, 0x1102 ); 00185 LutBlueDescriptor = file->GetEntryString( 0x0028, 0x1103 ); 00186 00187 // FIXME : The following comment is probabely meaningless, since LUT are *always* 00188 // loaded at parsing time, whatever their length is. 00189 00190 // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE 00191 // [ refer to invocation of Document::SetMaxSizeLoadEntry() in 00192 // Document::Document() ], the loading of the value (content) of a 00193 // [Bin|Val]Entry occurence migth have been hindered (read simply NOT 00194 // loaded). Hence, we first try to obtain the LUTs data from the file 00195 // and when this fails we read the LUTs data directly from disk. 00196 // \TODO Reading a [Bin|Val]Entry directly from disk is a kludge. 00197 // We should NOT bypass the [Bin|Val]Entry class. Instead 00198 // an access to an UNLOADED content of a [Bin|Val]Entry occurence 00199 // (e.g. DataEntry::GetBinArea()) should force disk access from 00200 // within the [Bin|Val]Entry class itself. The only problem 00201 // is that the [Bin|Val]Entry is unaware of the FILE* is was 00202 // parsed from. Fix that. FIXME. 00203 00204 // //// Red round 00205 file->LoadEntryBinArea(0x0028, 0x1201); 00206 LutRedData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1201 ); 00207 if ( ! LutRedData ) 00208 { 00209 gdcmWarningMacro("Unable to read Red Palette Color Lookup Table data"); 00210 } 00211 00212 // //// Green round: 00213 file->LoadEntryBinArea(0x0028, 0x1202); 00214 LutGreenData = (uint8_t*)file->GetEntryBinArea(0x0028, 0x1202 ); 00215 if ( ! LutGreenData) 00216 { 00217 gdcmWarningMacro("Unable to read Green Palette Color Lookup Table data"); 00218 } 00219 00220 // //// Blue round: 00221 file->LoadEntryBinArea(0x0028, 0x1203); 00222 LutBlueData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1203 ); 00223 if ( ! LutBlueData ) 00224 { 00225 gdcmWarningMacro("Unable to read Blue Palette Color Lookup Table data"); 00226 } 00227 } 00228 FileInternal = file; 00229 00230 ComputeRawAndRGBSizes(); 00231 }
|
|
Predicate to know whether the image[s] (once Raw) is RGB.
Definition at line 71 of file gdcmPixelReadConvert.cxx. References IsMonochrome, IsPaletteColor, and PlanarConfiguration. Referenced by ConvertHandleColor(). 00072 { 00073 if ( IsMonochrome 00074 || PlanarConfiguration == 2 00075 || IsPaletteColor ) 00076 { 00077 return false; 00078 } 00079 return true; 00080 }
|
|
Print self.
Reimplemented from gdcm::Base. Definition at line 1333 of file gdcmPixelReadConvert.cxx. References gdcmWarningMacro, IsJPEG2000, IsJPEGLossless, IsJPEGLossy, IsJPEGLS, IsRLELossless, JPEGInfo, PixelDataLength, PixelOffset, and RLEInfo. Referenced by gdcm::FileHelper::Print(). 01334 { 01335 os << indent 01336 << "--- Pixel information -------------------------" 01337 << std::endl; 01338 os << indent 01339 << "Pixel Data: offset " << PixelOffset 01340 << " x(" << std::hex << PixelOffset << std::dec 01341 << ") length " << PixelDataLength 01342 << " x(" << std::hex << PixelDataLength << std::dec 01343 << ")" << std::endl; 01344 01345 if ( IsRLELossless ) 01346 { 01347 if ( RLEInfo ) 01348 { 01349 RLEInfo->Print( os, indent ); 01350 } 01351 else 01352 { 01353 gdcmWarningMacro("Set as RLE file but NO RLEinfo present."); 01354 } 01355 } 01356 01357 if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS ) 01358 { 01359 if ( JPEGInfo ) 01360 { 01361 JPEGInfo->Print( os, indent ); 01362 } 01363 else 01364 { 01365 gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present."); 01366 } 01367 } 01368 }
|
|
Read from file a 12 bits per pixel image and decompress it into a 16 bits per pixel image.
Definition at line 412 of file gdcmPixelReadConvert.cxx. Referenced by ReadAndDecompressPixelData(). 00414 { 00415 int nbPixels = XSize * YSize; 00416 uint16_t *localDecompres = (uint16_t*)Raw; 00417 00418 for( int p = 0; p < nbPixels; p += 2 ) 00419 { 00420 uint8_t b0, b1, b2; 00421 00422 fp->read( (char*)&b0, 1); 00423 if ( fp->fail() || fp->eof() ) 00424 { 00425 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()", 00426 "Unfound first block" ); 00427 } 00428 00429 fp->read( (char*)&b1, 1 ); 00430 if ( fp->fail() || fp->eof()) 00431 { 00432 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()", 00433 "Unfound second block" ); 00434 } 00435 00436 fp->read( (char*)&b2, 1 ); 00437 if ( fp->fail() || fp->eof()) 00438 { 00439 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()", 00440 "Unfound second block" ); 00441 } 00442 00443 // Two steps are necessary to please VC++ 00444 // 00445 // 2 pixels 12bit = [0xABCDEF] 00446 // 2 pixels 16bit = [0x0ABD] + [0x0FCE] 00447 // A B D 00448 *localDecompres++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f); 00449 // F C E 00450 *localDecompres++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4); 00451 00453 } 00454 }
|
|
Reads from disk the Pixel Data of JPEG Dicom encapsulated file and decompress it.
Definition at line 462 of file gdcmPixelReadConvert.cxx. References BitsAllocated, BitsStored, gdcm::JPEGFragmentsInfo::DecompressFromFile(), gdcm::gdcm_read_JPEG2000_file(), gdcmAssertMacro, gdcmWarningMacro, gdcm::JPEGFragmentsInfo::GetFirstFragment(), gdcm::JPEGFragmentsInfo::GetFragmentCount(), gdcm::JPEGFragment::GetLength(), gdcm::JPEGFragmentsInfo::GetNextFragment(), gdcm::JPEGFragment::GetOffset(), IsJPEG2000, IsJPEGLossless, IsJPEGLossy, IsJPEGLS, JPEGInfo, Raw, SamplesPerPixel, XSize, and YSize. Referenced by ReadAndDecompressPixelData(). 00463 { 00464 if ( IsJPEG2000 ) 00465 { 00466 // make sure this is the right JPEG compression 00467 assert( !IsJPEGLossless || !IsJPEGLossy || !IsJPEGLS ); 00468 // FIXME this is really ugly but it seems I have to load the complete 00469 // jpeg2000 stream to use jasper: 00470 // I don't think we'll ever be able to deal with multiple fragments properly 00471 00472 unsigned long inputlength = 0; 00473 JPEGFragment *jpegfrag = JPEGInfo->GetFirstFragment(); 00474 while( jpegfrag ) 00475 { 00476 inputlength += jpegfrag->GetLength(); 00477 jpegfrag = JPEGInfo->GetNextFragment(); 00478 } 00479 gdcmAssertMacro( inputlength != 0); 00480 uint8_t *inputdata = new uint8_t[inputlength]; 00481 char *pinputdata = (char*)inputdata; 00482 jpegfrag = JPEGInfo->GetFirstFragment(); 00483 while( jpegfrag ) 00484 { 00485 fp->seekg( jpegfrag->GetOffset(), std::ios::beg); 00486 fp->read(pinputdata, jpegfrag->GetLength()); 00487 pinputdata += jpegfrag->GetLength(); 00488 jpegfrag = JPEGInfo->GetNextFragment(); 00489 } 00490 // Warning the inputdata buffer is delete in the function 00491 if ( ! gdcm_read_JPEG2000_file( Raw, 00492 (char*)inputdata, inputlength ) ) 00493 { 00494 return true; 00495 } 00496 // wow what happen, must be an error 00497 gdcmWarningMacro( "gdcm_read_JPEG2000_file() failed "); 00498 return false; 00499 } 00500 else if ( IsJPEGLS ) 00501 { 00502 // make sure this is the right JPEG compression 00503 assert( !IsJPEGLossless || !IsJPEGLossy || !IsJPEG2000 ); 00504 // WARNING : JPEG-LS is NOT the 'classical' Jpeg Lossless : 00505 // [JPEG-LS is the basis for new lossless/near-lossless compression 00506 // standard for continuous-tone images intended for JPEG2000. The standard 00507 // is based on the LOCO-I algorithm (LOw COmplexity LOssless COmpression 00508 // for Images) developed at Hewlett-Packard Laboratories] 00509 // 00510 // see http://datacompression.info/JPEGLS.shtml 00511 // 00512 #if 0 00513 std::cerr << "count:" << JPEGInfo->GetFragmentCount() << std::endl; 00514 unsigned long inputlength = 0; 00515 JPEGFragment *jpegfrag = JPEGInfo->GetFirstFragment(); 00516 while( jpegfrag ) 00517 { 00518 inputlength += jpegfrag->GetLength(); 00519 jpegfrag = JPEGInfo->GetNextFragment(); 00520 } 00521 gdcmAssertMacro( inputlength != 0); 00522 uint8_t *inputdata = new uint8_t[inputlength]; 00523 char *pinputdata = (char*)inputdata; 00524 jpegfrag = JPEGInfo->GetFirstFragment(); 00525 while( jpegfrag ) 00526 { 00527 fp->seekg( jpegfrag->GetOffset(), std::ios::beg); 00528 fp->read(pinputdata, jpegfrag->GetLength()); 00529 pinputdata += jpegfrag->GetLength(); 00530 jpegfrag = JPEGInfo->GetNextFragment(); 00531 } 00532 00533 //fp->read((char*)Raw, PixelDataLength); 00534 00535 std::ofstream out("/tmp/jpegls.jpg"); 00536 out.write((char*)inputdata, inputlength); 00537 out.close(); 00538 delete[] inputdata; 00539 #endif 00540 00541 gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" ); 00542 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg); 00543 // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) ) 00544 return false; 00545 } 00546 else 00547 { 00548 // make sure this is the right JPEG compression 00549 assert( !IsJPEGLS || !IsJPEG2000 ); 00550 // Precompute the offset localRaw will be shifted with 00551 int length = XSize * YSize * SamplesPerPixel; 00552 int numberBytes = BitsAllocated / 8; 00553 00554 JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length ); 00555 return true; 00556 } 00557 }
|
|
Reads from disk and decompresses Pixels.
Definition at line 234 of file gdcmPixelReadConvert.cxx. References AllocateRaw(), BitsAllocated, ConvertFixGreyLevels(), ConvertHandleColor(), ConvertReArrangeBits(), ConvertReorderEndianity(), gdcm::RLEFramesInfo::DecompressRLEFile(), FileInternal, gdcmWarningMacro, IsMPEG, IsRaw, IsRLELossless, PixelDataLength, PixelOffset, Raw, RawSize, ReadAndDecompress12BitsTo16Bits(), ReadAndDecompressJPEGFile(), RLEInfo, Squeeze(), UserFunction, XSize, YSize, and ZSize. Referenced by gdcm::FileHelper::GetRaw(). 00235 { 00236 // ComputeRawAndRGBSizes is already made by 00237 // ::GrabInformationsFromfile. So, the structure sizes are 00238 // correct 00239 Squeeze(); 00240 00243 if ( !fp ) 00244 { 00245 gdcmWarningMacro( "Unavailable file pointer." ); 00246 return false; 00247 } 00248 00249 fp->seekg( PixelOffset, std::ios::beg ); 00250 if ( fp->fail() || fp->eof() ) 00251 { 00252 gdcmWarningMacro( "Unable to find PixelOffset in file." ); 00253 return false; 00254 } 00255 00256 AllocateRaw(); 00257 00260 if ( BitsAllocated == 12 ) 00261 { 00262 ReadAndDecompress12BitsTo16Bits( fp); 00263 } 00264 else if ( IsRaw ) 00265 { 00266 // This problem can be found when some obvious informations are found 00267 // after the field containing the image data. In this case, these 00268 // bad data are added to the size of the image (in the PixelDataLength 00269 // variable). But RawSize is the right size of the image ! 00270 if ( PixelDataLength != RawSize ) 00271 { 00272 gdcmWarningMacro( "Mismatch between PixelReadConvert : " 00273 << PixelDataLength << " and RawSize : " << RawSize ); 00274 } 00275 if ( PixelDataLength > RawSize ) 00276 { 00277 fp->read( (char*)Raw, RawSize); 00278 } 00279 else 00280 { 00281 fp->read( (char*)Raw, PixelDataLength); 00282 } 00283 00284 if ( fp->fail() || fp->eof()) 00285 { 00286 gdcmWarningMacro( "Reading of Raw pixel data failed." ); 00287 return false; 00288 } 00289 } 00290 else if ( IsRLELossless ) 00291 { 00292 if ( ! RLEInfo->DecompressRLEFile 00293 ( fp, Raw, XSize, YSize, ZSize, BitsAllocated ) ) 00294 { 00295 gdcmWarningMacro( "RLE decompressor failed." ); 00296 return false; 00297 } 00298 } 00299 else if ( IsMPEG ) 00300 { 00301 //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" ); 00302 //return false; 00303 // fp has already been seek to start of mpeg 00304 //ReadMPEGFile(fp, (char*)Raw, PixelDataLength); 00305 return true; 00306 } 00307 else 00308 { 00309 // Default case concerns JPEG family 00310 if ( ! ReadAndDecompressJPEGFile( fp ) ) 00311 { 00312 gdcmWarningMacro( "JPEG decompressor ( ReadAndDecompressJPEGFile()" 00313 << " method ) failed." ); 00314 return false; 00315 } 00316 } 00317 00320 ConvertReorderEndianity(); 00321 ConvertReArrangeBits(); 00322 ConvertFixGreyLevels(); 00323 if (UserFunction) // user is allowed to Mirror, TopDown, Rotate,...the image 00324 UserFunction( Raw, FileInternal); 00325 ConvertHandleColor(); 00326 00327 return true; 00328 }
|
|
Sets the print level for the Dicom Header Elements.
Definition at line 47 of file gdcmBase.h. Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print(). 00047 { PrintLevel = level; }
|
|
Allow user to pass his own function to modify pixels (e.g; mirror, upsidedown, ...) just after reading.
Definition at line 77 of file gdcmPixelReadConvert.h. Referenced by gdcm::FileHelper::GetRaw(). 00078 { UserFunction = userFunc; }
|
|
Deletes Pixels Area.
Definition at line 331 of file gdcmPixelReadConvert.cxx. References LutRGBA, Raw, and RGB. Referenced by ReadAndDecompressPixelData(), and ~PixelReadConvert(). 00332 { 00333 if ( RGB ) 00334 delete [] RGB; 00335 RGB = 0; 00336 00337 if ( Raw ) 00338 delete [] Raw; 00339 Raw = 0; 00340 00341 if ( LutRGBA ) 00342 delete [] LutRGBA; 00343 LutRGBA = 0; 00344 }
|
|
Definition at line 43 of file gdcmPixelReadConvert.h. |
|
Definition at line 126 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), BuildRGBImage(), ComputeRawAndRGBSizes(), ConvertFixGreyLevels(), ConvertReArrangeBits(), ConvertReorderEndianity(), ConvertSwapZone(), GrabInformationsFromFile(), ReadAndDecompressJPEGFile(), and ReadAndDecompressPixelData(). |
|
Definition at line 127 of file gdcmPixelReadConvert.h. Referenced by ConvertFixGreyLevels(), ConvertReArrangeBits(), ConvertReorderEndianity(), GrabInformationsFromFile(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 162 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), PixelReadConvert(), and ReadAndDecompressPixelData(). |
|
Definition at line 153 of file gdcmPixelReadConvert.h. Referenced by ComputeRawAndRGBSizes(), and GrabInformationsFromFile(). |
|
Definition at line 128 of file gdcmPixelReadConvert.h. Referenced by ConvertReArrangeBits(), and GrabInformationsFromFile(). |
|
Definition at line 140 of file gdcmPixelReadConvert.h. |
|
Definition at line 136 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 138 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 139 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 137 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 149 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), and IsRawRGB(). |
|
Definition at line 150 of file gdcmPixelReadConvert.h. Referenced by ConvertFixGreyLevels(), and GrabInformationsFromFile(). |
|
Definition at line 142 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), and ReadAndDecompressPixelData(). |
|
Definition at line 151 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), GrabInformationsFromFile(), and IsRawRGB(). |
|
Definition at line 135 of file gdcmPixelReadConvert.h. Referenced by ConvertSwapZone(), and GrabInformationsFromFile(). |
|
Definition at line 134 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), and ReadAndDecompressPixelData(). |
|
Definition at line 141 of file gdcmPixelReadConvert.h. Referenced by ConvertHandleColor(), GrabInformationsFromFile(), Print(), and ReadAndDecompressPixelData(). |
|
Definition at line 152 of file gdcmPixelReadConvert.h. Referenced by ConvertHandleColor(), and GrabInformationsFromFile(). |
|
Definition at line 145 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), PixelReadConvert(), Print(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 160 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), GrabInformationsFromFile(), and PixelReadConvert(). |
|
Definition at line 157 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), and GrabInformationsFromFile(). |
|
Definition at line 159 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), GrabInformationsFromFile(), and PixelReadConvert(). |
|
Definition at line 156 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), and GrabInformationsFromFile(). |
|
Definition at line 115 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(). |
|
Definition at line 116 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(). |
|
Definition at line 158 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), GrabInformationsFromFile(), and PixelReadConvert(). |
|
Definition at line 155 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), and GrabInformationsFromFile(). |
|
Red/Green/Blue/Alpha LookUpTable build out of the Red/Green/Blue LUT descriptors (see BuildLUTRGBA ).
Definition at line 114 of file gdcmPixelReadConvert.h. Referenced by BuildLUTRGBA(), BuildRGBImage(), PixelReadConvert(), and Squeeze(). |
|
Definition at line 122 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressPixelData(). |
|
Definition at line 121 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), Print(), and ReadAndDecompressPixelData(). |
|
Definition at line 131 of file gdcmPixelReadConvert.h. Referenced by ConvertFixGreyLevels(), ConvertReArrangeBits(), ConvertReorderEndianity(), and GrabInformationsFromFile(). |
|
Definition at line 148 of file gdcmPixelReadConvert.h. Referenced by ConvertHandleColor(), GrabInformationsFromFile(), and IsRawRGB(). |
|
Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.
Definition at line 55 of file gdcmBase.h. Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), gdcm::DocEntry::Print(), gdcm::DictEntry::Print(), gdcm::DicomDirStudy::Print(), gdcm::DicomDirSerie::Print(), gdcm::DicomDirPatient::Print(), gdcm::DicomDirMeta::Print(), gdcm::DicomDir::Print(), and gdcm::DataEntry::Print(). |
|
Pixel data after decompression and bit/byte rearrangement.
Definition at line 109 of file gdcmPixelReadConvert.h. Referenced by AllocateRaw(), BuildRGBImage(), ConvertFixGreyLevels(), ConvertReArrangeBits(), ConvertReorderEndianity(), ConvertRGBPlanesToRGBPixels(), ConvertSwapZone(), ConvertYcBcRPlanesToRGBPixels(), PixelReadConvert(), ReadAndDecompressJPEGFile(), ReadAndDecompressPixelData(), and Squeeze(). |
|
Size of Decompressed image.
Definition at line 111 of file gdcmPixelReadConvert.h. Referenced by AllocateRaw(), BuildRGBImage(), ComputeRawAndRGBSizes(), ConvertFixGreyLevels(), ConvertReArrangeBits(), ConvertReorderEndianity(), ConvertRGBPlanesToRGBPixels(), ConvertSwapZone(), ConvertYcBcRPlanesToRGBPixels(), PixelReadConvert(), and ReadAndDecompressPixelData(). |
|
Pixel data represented as RGB after LUT color interpretation. 'uint8_t' is just to avoid warnings at compile time. feel free to cast it as uint16_t if you need.
Definition at line 105 of file gdcmPixelReadConvert.h. Referenced by AllocateRGB(), BuildRGBImage(), PixelReadConvert(), and Squeeze(). |
|
Size of RGB image.
Definition at line 107 of file gdcmPixelReadConvert.h. Referenced by AllocateRGB(), ComputeRawAndRGBSizes(), and PixelReadConvert(). |
|
Definition at line 144 of file gdcmPixelReadConvert.h. Referenced by GrabInformationsFromFile(), PixelReadConvert(), Print(), and ReadAndDecompressPixelData(). |
|
Definition at line 129 of file gdcmPixelReadConvert.h. Referenced by ComputeRawAndRGBSizes(), GrabInformationsFromFile(), and ReadAndDecompressJPEGFile(). |
|
Definition at line 132 of file gdcmPixelReadConvert.h. Referenced by ConvertSwapZone(), and GrabInformationsFromFile(). |
|
Definition at line 163 of file gdcmPixelReadConvert.h. Referenced by PixelReadConvert(), and ReadAndDecompressPixelData(). |
|
Definition at line 123 of file gdcmPixelReadConvert.h. Referenced by ComputeRawAndRGBSizes(), ConvertRGBPlanesToRGBPixels(), ConvertYcBcRPlanesToRGBPixels(), GrabInformationsFromFile(), ReadAndDecompressJPEGFile(), and ReadAndDecompressPixelData(). |
|
Definition at line 124 of file gdcmPixelReadConvert.h. Referenced by ComputeRawAndRGBSizes(), ConvertRGBPlanesToRGBPixels(), ConvertYcBcRPlanesToRGBPixels(), GrabInformationsFromFile(), ReadAndDecompressJPEGFile(), and ReadAndDecompressPixelData(). |
|
Definition at line 125 of file gdcmPixelReadConvert.h. Referenced by ComputeRawAndRGBSizes(), ConvertRGBPlanesToRGBPixels(), ConvertYcBcRPlanesToRGBPixels(), GrabInformationsFromFile(), and ReadAndDecompressPixelData(). |