OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRpfColorGrayscaleTable.cpp
Go to the documentation of this file.
2 #include <string.h> // for memcpy
5 
7  const ossimRpfColorGrayscaleTable& data)
8 {
9  out << "theNumberOfElements: " << data.theNumberOfElements
10  << "\ntheTotalNumberOfBytes: " << data.theTotalNumberOfBytes
11  << "\ntheTableId: " << data.theTableId;
12 
13  return out;
14 }
15 
17  :theNumberOfElements(0),
18  theTotalNumberOfBytes(0),
19  theTableId(0),
20  theData(NULL)
21 {
22 }
23 
25  :theNumberOfElements(0),
26  theTotalNumberOfBytes(0),
27  theTableId(0),
28  theData(NULL)
29 {
30  *this = rhs;
31 }
32 
33 
35 {
36  if(theData)
37  {
38  delete [] theData;
39  theData = NULL;
40  }
41 }
42 
44  ossimByteOrder /* byteOrder */)
45 {
46  if(in)
47  {
49  {
50  in.read((char*)theData, theTotalNumberOfBytes);
51  }
52  }
53  else
54  {
56  }
57 
59 }
60 
61 const unsigned char* ossimRpfColorGrayscaleTable::getStartOfData(unsigned long entry)const
62 {
63  unsigned long offset = 0;
64 
65  switch(theTableId)
66  {
67  case 1: // this is in format RGB
68  {
69  offset = 3*entry;
70  break;
71  }
72  case 2: // format RGBM
73  case 4: // format CMYK
74  {
75  offset = 4*entry;
76  break;
77  }
78  case 3: // format M
79  {
80  offset = entry;
81  break;
82  }
83  }
84 
85  return (const unsigned char*)(theData + offset);
86 }
87 
89  unsigned long numberOfElements)
90 {
91  if(theData)
92  {
93  delete theData;
94  theData = NULL;
95  }
96 
97  unsigned long totalBytes = 0;
98 
99  switch(id)
100  {
101  case 1: // this is in format RGB
102  {
103  totalBytes = 3*numberOfElements;
104  break;
105  }
106  case 2: // format RGBM
107  case 4: // format CMYK
108  {
109  totalBytes = 4*numberOfElements;
110  break;
111  }
112  case 3: // format M
113  {
114  totalBytes = numberOfElements;
115  break;
116  }
117  }
118 
119  if(totalBytes > 0)
120  {
121  theTableId = id;
122  theNumberOfElements = numberOfElements;
123  theTotalNumberOfBytes = totalBytes;
124 
125  theData = new unsigned char[totalBytes];
126  }
127 }
128 
129 
130 
132 {
133 
134  if(&rhs != this)
135  {
138  theTableId = rhs.theTableId;
139  if(theData)
140  {
141  delete theData;
142  theData = NULL;
143  }
145  {
146  theData = new unsigned char[theTotalNumberOfBytes];
147 
148  memcpy(theData, rhs.theData, theTotalNumberOfBytes);
149  }
150  }
151 
152  return *this;
153 }
ossim_int32 ossimErrorCode
static const ossimErrorCode OSSIM_OK
const unsigned char * getStartOfData(unsigned long entry) const
static const ossimErrorCode OSSIM_ERROR
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
void setTableData(unsigned short id, unsigned long numberOfElements)
ossimByteOrder
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
std::ostream & operator<<(std::ostream &out, const ossimRpfColorGrayscaleTable &data)
const ossimRpfColorGrayscaleTable & operator=(const ossimRpfColorGrayscaleTable &)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23