remove useless unittest.pl
[openc2e.git] / blkImage.cpp
blobbea30be1d8a6a190195db8f8ccbe8dd9e0f86064
1 /*
2 * blkImage.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "openc2e.h"
21 #include "blkImage.h"
22 #include <iostream>
24 void blkImage::readHeader(std::istream &in) {
25 uint32 flags; uint16 width, height, spritecount;
26 in.read((char *)&flags, 4); flags = swapEndianLong(flags);
27 is_565 = (flags & 0x01);
28 in.read((char *)&width, 2); width = swapEndianShort(width);
29 in.read((char *)&height, 2); height = swapEndianShort(height);
30 totalwidth = width * 128; totalheight = height * 128;
31 in.read((char *)&spritecount, 2); m_numframes = swapEndianShort(spritecount);
33 assert(m_numframes == (unsigned int) (width * height));
35 widths = new uint16[m_numframes];
36 heights = new uint16[m_numframes];
37 offsets = new uint32[m_numframes];
39 for (unsigned int i = 0; i < m_numframes; i++) {
40 in.read((char *)&offsets[i], 4); offsets[i] = swapEndianLong(offsets[i]) + 4;
41 in.read((char *)&widths[i], 2); widths[i] = swapEndianShort(widths[i]); assert(widths[i] == 128);
42 in.read((char *)&heights[i], 2); heights[i] = swapEndianShort(heights[i]); assert(heights[i] == 128);
46 void blkImage::writeHeader(std::ostream &s) {
47 unsigned int dw; unsigned short w;
49 dw = (is_565 ? 1 : 0);
50 dw = swapEndianLong(dw); s.write((char *)&dw, 4);
51 w = totalwidth / 128; assert((unsigned int)(w * 128) == totalwidth);
52 w = swapEndianShort(w); s.write((char *)&w, 2);
53 w = totalheight / 128; assert((unsigned int)(w * 128) == totalheight);
54 w = swapEndianShort(w); s.write((char *)&w, 2);
55 w = m_numframes; assert(m_numframes == (unsigned int) ((totalwidth / 128) * (totalheight / 128)));
56 w = swapEndianShort(w); s.write((char *)&w, 2);
58 for (unsigned int i = 0; i < m_numframes; i++) {
59 dw = offsets[i] - 4;
60 dw = swapEndianLong(dw); s.write((char *)&dw, 4);
61 w = widths[i]; assert(w == 128);
62 w = swapEndianShort(w); s.write((char *)&w, 2);
63 w = heights[i]; assert(w == 128);
64 w = swapEndianShort(w); s.write((char *)&w, 2);
68 blkImage::blkImage(mmapifstream *in, std::string n) : creaturesImage(n) {
69 stream = in;
70 imgformat = if_16bit;
72 readHeader(*in);
74 buffers = new void *[m_numframes];
76 for (unsigned int i = 0; i < m_numframes; i++)
77 buffers[i] = in->map + offsets[i];
80 blkImage::~blkImage() {
81 delete[] widths;
82 delete[] heights;
83 delete[] buffers;
84 delete[] offsets;
87 /* vim: set noet: */