Debian Codegraph @

src/bin/geomutil/vrml2oogl/lib/QvSFImage.c++

raw
1 #include <QvSFImage.h>
2
3 // Can't use macro, since we define a constructor.
4
5 QvSFImage::QvSFImage()
6 {
7 size[0] = size[1] = 0;
8 numComponents = 0;
9 bytes = NULL;
10 }
11
12 QvSFImage::~QvSFImage()
13 {
14 if (bytes != NULL)
15 delete [] bytes;
16 }
17 QvBool
18 QvSFImage::readValue(QvInput *in)
19 {
20 if (! in->read(size[0]) ||
21 ! in->read(size[1]) ||
22 ! in->read(numComponents))
23 return FALSE;
24
25 if (bytes != NULL)
26 delete [] bytes;
27 bytes = new unsigned char[size[0] * size[1] * numComponents];
28
29 int byte = 0;
30 for (int i = 0; i < size[0] * size[1]; i++) {
31 unsigned long l;
32 if (! in->read(l))
33 return FALSE;
34 for (int j = 0; j < numComponents; j++)
35 bytes[byte++] =
36 (unsigned char) ((l >> (8*(numComponents-j-1))) & 0xFF);
37 }
38 return TRUE;
39 }