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