File: TestPixelFormat.cxx

package info (click to toggle)
gdcm 3.0.24-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 27,560 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (150 lines) | stat: -rw-r--r-- 4,289 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmPixelFormat.h"

struct frame_info {
  gdcm::PixelFormat pixeltype;
};

int TestPixelFormat(int , char *[])
{
  using gdcm::PixelFormat;
  gdcm::PixelFormat pf;
  pf.SetScalarType( gdcm::PixelFormat::UNKNOWN );
  if( pf.GetScalarType() != gdcm::PixelFormat::UNKNOWN )
    {
    return 1;
    }
  pf.SetScalarType( gdcm::PixelFormat::UINT32 );
  //pf.SetScalarType( gdcm::PixelFormat::UINT64 );
  static const int64_t values[][2] = {
     { 0LL,255LL },
     { 0LL,4095LL },
     { 0LL,65535LL },
     { 0LL,4294967295LL },
     { -128LL,127LL },
     { -2048LL,2047LL },
     { -32768LL,32767LL },
     { -2147483648LL,2147483647LL },
//     { -2147483648LL,2147483647LL }
  };
  static const size_t n = sizeof( values ) / sizeof( *values );
  size_t c = 0;
  pf.SetBitsStored( 8 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 12 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 16 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 32 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
//  ++c;
//  pf.SetBitsStored( 64 );
//  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
//    {
//    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
//    return 1;
//    }

  pf.SetPixelRepresentation( 1 );

  ++c;
  pf.SetBitsStored( 8 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 12 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 16 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
  ++c;
  pf.SetBitsStored( 32 );
  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
    {
    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
    return 1;
    }
//  ++c;
//  pf.SetBitsStored( 64 );
//  if( pf.GetMin() != values[c][0] || pf.GetMax() != values[c][1] )
//    {
//    std::cerr << pf.GetMin() << "," << pf.GetMax() << std::endl;
//    return 1;
//    }
  ++c;
  if ( c != n ) return 1;

  for(unsigned int i = 0; i < PixelFormat::UNKNOWN; ++i)
    {
    PixelFormat::ScalarType st = (PixelFormat::ScalarType)i;
    pf.SetScalarType( st );
    gdcm::PixelFormat pf2 = st;
    std::cout << pf << std::endl;
    std::cout << pf.GetPixelRepresentation() << std::endl;
    std::cout << pf.GetScalarTypeAsString() << std::endl;
    if( pf2 != pf ) return 1;
    }

  // make to avoid user mistakes:
  gdcm::PixelFormat pf3 = PixelFormat::UINT8;
  if( pf3.GetBitsStored() != 8 ) return 1;
  pf3.SetBitsStored( 32 );
  // previous call should not execute
  if( pf3.GetBitsStored() != 8 ) return 1;
  pf3.SetHighBit( 8 );
  if( pf3.GetHighBit() != 7 ) return 1;

  gdcm::PixelFormat pf4 = PixelFormat::UINT16;
  pf4.SetBitsStored(8);
  if( pf4.GetScalarType() != gdcm::PixelFormat::UINT16 ) return 1;
  pf4.SetPixelRepresentation(1);
  if( pf4.GetScalarType() != gdcm::PixelFormat::INT16 ) return 1;

  frame_info fi = {};
  (void)fi;

  return 0;
}