Mercurial > fife-parpg
comparison utils/frminfo/frm_raw_loader.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2006 by the FIFE Team * | |
3 * fife-public@lists.sourceforge.net * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 | |
26 // FIFE includes | |
27 #include "map/loaders/fallout/frm.h" | |
28 #include "map/loaders/fallout/pal.h" | |
29 #include "map/loaders/fallout/animatedpal.h" | |
30 #include "vfs/raw/rawdata.h" | |
31 | |
32 #include "frm_raw_loader.h" | |
33 | |
34 namespace FIFE { | |
35 RawFRM::RawFRM(const std::string & fname, map::loaders::fallout::AnimatedPalette* palette) : map::loaders::fallout::FRM(fname, palette) { | |
36 } | |
37 | |
38 std::pair<uint16_t, uint16_t> RawFRM::getFrameDimension(uint16_t dir, uint16_t frame) { | |
39 FrameInfo & fi = m_frame_info[dir][frame]; | |
40 return std::make_pair(fi.width, fi.height); | |
41 } | |
42 | |
43 uint8_t* RawFRM::getFrameRaw(uint16_t dir, uint16_t frame) { | |
44 FrameInfo & fi = m_frame_info[dir][frame]; | |
45 uint32_t size = fi.width * fi.height; | |
46 m_data->setIndex(fi.fpos); | |
47 uint8_t* raw_data = new uint8_t[size]; | |
48 uint8_t* buff = raw_data; | |
49 m_data->readInto(raw_data, size); | |
50 return buff; | |
51 } | |
52 | |
53 uint8_t* RawFRM::getFrameRGBA(uint16_t dir, uint16_t frame) { | |
54 uint8_t* _data = getFrameRaw(dir, frame); | |
55 map::loaders::fallout::PAL palette("color.pal"); | |
56 int id = 0; | |
57 uint8_t* dataCopy = _data; | |
58 | |
59 FrameInfo &fi = m_frame_info[dir][frame]; | |
60 | |
61 uint32_t size = fi.width * fi.height * 4; | |
62 uint8_t* rgba_data = new uint8_t[size]; | |
63 uint32_t* pixeldata = reinterpret_cast<uint32_t*>(rgba_data); | |
64 for (uint32_t y = 0; y < fi.height; ++y) { | |
65 for (uint32_t x = 0; x < fi.width; ++x) { | |
66 uint8_t index = *(_data++); | |
67 if (index == 0) { | |
68 *pixeldata = 0x00000000; | |
69 } else { | |
70 //id |= palutil->checkPixel(index); | |
71 | |
72 uint8_t alpha = 0xff; | |
73 if( index == 108 ) { // 108 is the transparent window pixel index | |
74 alpha = 0x80; | |
75 } | |
76 /** @todo: find solution: 13 should be yellow/red and transparent only for specific objects. | |
77 else | |
78 if( 13 == index ) { ///< 13 is transparent force-field | |
79 alpha = 0x80; | |
80 } | |
81 */ | |
82 | |
83 /* | |
84 uint8_t red = std::min(palette.getRed(index) * m_custom_gamma, 0xff) & 0xff; | |
85 uint8_t green = std::min(palette.getGreen(index) * m_custom_gamma, 0xff) & 0xff; | |
86 uint8_t blue = std::min(palette.getBlue(index) * m_custom_gamma, 0xff) & 0xff; | |
87 | |
88 *pixeldata = (red << 24) | (green << 16) | (blue << 8) | alpha; | |
89 */ | |
90 *pixeldata = (palette.getRed(index) << 24) | (palette.getGreen(index) << 16) | (palette.getBlue(index) << 8) | alpha; | |
91 } | |
92 ++pixeldata; | |
93 } | |
94 } | |
95 delete [] dataCopy; | |
96 return rgba_data; | |
97 } | |
98 | |
99 } |