aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CImageWriterPCX.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CImageWriterPCX.cpp162
1 files changed, 162 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CImageWriterPCX.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CImageWriterPCX.cpp
new file mode 100644
index 0000000..5ace342
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CImageWriterPCX.cpp
@@ -0,0 +1,162 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "CImageWriterPCX.h"
6
7#ifdef _IRR_COMPILE_WITH_PCX_WRITER_
8
9#include "CImageLoaderPCX.h"
10#include "IWriteFile.h"
11#include "os.h" // for logging
12#include "irrString.h"
13
14namespace irr
15{
16namespace video
17{
18
19IImageWriter* createImageWriterPCX()
20{
21 return new CImageWriterPCX;
22}
23
24CImageWriterPCX::CImageWriterPCX()
25{
26#ifdef _DEBUG
27 setDebugName("CImageWriterPCX");
28#endif
29}
30
31bool CImageWriterPCX::isAWriteableFileExtension(const io::path& filename) const
32{
33 return core::hasFileExtension ( filename, "pcx" );
34}
35
36bool CImageWriterPCX::writeImage(io::IWriteFile *file, IImage *image,u32 param) const
37{
38 if (!file || !image)
39 return false;
40
41 u8 d1;
42 u16 d2;
43 u32 i;
44
45 d1 = 10; // Manufacturer
46 file->write(&d1, 1);
47 d1 = 5; // Version
48 file->write(&d1, 1);
49 d1 = 1; // Encoding
50 file->write(&d1, 1);
51 d1 = 8; // Bits per Pixel
52 file->write(&d1, 1);
53 d2 = 0; // pixel origin
54 file->write(&d2, 2);
55 file->write(&d2, 2);
56 d2 = image->getDimension().Width-1; // width
57#ifdef __BIG_ENDIAN__
58 d2 = os::Byteswap::byteswap(d2);
59#endif
60 file->write(&d2, 2);
61 d2 = image->getDimension().Height-1; // height
62#ifdef __BIG_ENDIAN__
63 d2 = os::Byteswap::byteswap(d2);
64#endif
65 file->write(&d2, 2);
66 d2 = 300; // dpi
67#ifdef __BIG_ENDIAN__
68 d2 = os::Byteswap::byteswap(d2);
69#endif
70 file->write(&d2, 2);
71 file->write(&d2, 2);
72 d2 = 0; // palette (not used)
73 for (i=0; i<24; ++i)
74 {
75 file->write(&d2, 2);
76 }
77 d1 = 0; // reserved
78 file->write(&d1, 1);
79 d1 = 3; // planes
80 file->write(&d1, 1);
81 d2 = image->getDimension().Width; // pitch
82 if (d2&0x0001) // must be even
83 ++d2;
84#ifdef __BIG_ENDIAN__
85 d2 = os::Byteswap::byteswap(d2);
86#endif
87 file->write(&d2, 2);
88 d2 = 1; // color mode
89#ifdef __BIG_ENDIAN__
90 d2 = os::Byteswap::byteswap(d2);
91#endif
92 file->write(&d2, 2);
93 d2 = 800; // screen width
94#ifdef __BIG_ENDIAN__
95 d2 = os::Byteswap::byteswap(d2);
96#endif
97 file->write(&d2, 2);
98 d2 = 600; // screen height
99#ifdef __BIG_ENDIAN__
100 d2 = os::Byteswap::byteswap(d2);
101#endif
102 file->write(&d2, 2);
103 d2 = 0; // filler (not used)
104 for (i=0; i<27; ++i)
105 {
106 file->write(&d2, 2);
107 }
108
109 u8 cnt, value;
110 for (i=0; i<image->getDimension().Height; ++i)
111 {
112 cnt = 0;
113 value = 0;
114 for (u32 j=0; j<3; ++j) // color planes
115 {
116 for (u32 k=0; k<image->getDimension().Width; ++k)
117 {
118 const SColor pix = image->getPixel(k,i);
119 if ((cnt!=0) && (cnt<63) &&
120 (((j==0) && (value==pix.getRed())) ||
121 ((j==1) && (value==pix.getGreen())) ||
122 ((j==2) && (value==pix.getBlue()))))
123 {
124 ++cnt;
125 }
126 else
127 {
128 if (cnt!=0)
129 {
130 if ((cnt>1) || ((value&0xc0)==0xc0))
131 {
132 cnt |= 0xc0;
133 file->write(&cnt, 1);
134 }
135 file->write(&value, 1);
136 }
137 cnt=1;
138 if (j==0)
139 value=(u8)pix.getRed();
140 else if (j==1)
141 value=(u8)pix.getGreen();
142 else if (j==2)
143 value=(u8)pix.getBlue();
144 }
145 }
146 }
147 if ((cnt>1) || ((value&0xc0)==0xc0))
148 {
149 cnt |= 0xc0;
150 file->write(&cnt, 1);
151 }
152 file->write(&value, 1);
153 }
154
155 return true;
156}
157
158} // namespace video
159} // namespace irr
160
161#endif
162