-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReaderWriterPCX.hpp
97 lines (84 loc) · 2.9 KB
/
ReaderWriterPCX.hpp
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
/*
* osgdb_pcx is plugin for OpenSceneGraph engine
* Copyright (C) 2015 by darkprof
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef PCX_CLASS_H
#define PCX_CLASS_H
#include <osg/Image>
#include <osg/Notify>
#include <osg/Image>
#include <osg/GL>
#include <osg/Endian>
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <tr1/memory>
#include "../global.hpp"
//#define PCX_RGB 3
/*
* PCX header
*/
#pragma pack(push, 1)
struct PCXHEADER {
BYTE Identifier; /* PCX Id Number (Always 0x0A) */
BYTE Version; /* Version Number */
BYTE Encoding; /* Encoding Format */
BYTE BitsPerPixel; /* Bits per Pixel */
WORD XStart; /* Left of image */
WORD YStart; /* Top of Image */
WORD XEnd; /* Right of Image */
WORD YEnd; /* Bottom of image */
WORD HorzRes; /* Horizontal Resolution */
WORD VertRes; /* Vertical Resolution */
BYTE Palette[48]; /* 16-Color EGA Palette */
BYTE Reserved1; /* Reserved (Always 0) */
BYTE NumBitPlanes; /* Number of Bit Planes */
WORD BytesPerLine; /* Bytes per Scan-line */
WORD PaletteType; /* Palette Type */
WORD HorzScreenSize; /* Horizontal Screen Size */
WORD VertScreenSize; /* Vertical Screen Size */
BYTE Reserved2[54]; /* Reserved (Always 0) */
};
#pragma pack(pop)
#pragma pack(push, 1)
struct COLORS {
uint8_t red;
uint8_t green;
uint8_t blue;
};
#pragma pack(pop)
class ReaderWriterPCX : public osgDB::ReaderWriter
{
public:
ReaderWriterPCX();
const char* className() const;
ReadResult readObject(std::istream& fin, const Options* options = 0) const;
ReadResult readObject(const std::string& file, const Options* options = 0) const;
ReadResult readImage(std::istream& fin, const Options* options = 0) const;
ReadResult readImage(const std::string& file, const Options* options = 0) const;
WriteResult writeImage(const osg::Image& image, std::ostream& fout, const Options* = 0) const;
WriteResult writeImage(const osg::Image& img, const std::string& fileName, const Options* options = 0) const;
private:
static ReadResult readPCXStream(std::istream& fin);
};
#endif