ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

maccursor.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/textconsole.h"
00024 
00025 #include "graphics/maccursor.h"
00026 
00027 namespace Graphics {
00028 
00029 MacCursor::MacCursor() {
00030     _surface = 0;
00031     memset(_palette, 0, 256 * 3);
00032 
00033     _hotspotX = 0;
00034     _hotspotY = 0;
00035 }
00036 
00037 MacCursor::~MacCursor() {
00038     clear();
00039 }
00040 
00041 void MacCursor::clear() {
00042     delete[] _surface; _surface = 0;
00043     memset(_palette, 0, 256 * 3);
00044 }
00045 
00046 bool MacCursor::readFromStream(Common::SeekableReadStream &stream, bool forceMonochrome) {
00047     clear();
00048 
00049     // Older Mac CURS monochrome cursors had a set size
00050     // All crsr cursors are larger than this
00051     if (stream.size() == 32 * 2 + 4)
00052         return readFromCURS(stream);
00053 
00054     return readFromCRSR(stream, forceMonochrome);
00055 }
00056 
00057 bool MacCursor::readFromCURS(Common::SeekableReadStream &stream) {
00058     // Grab B/W icon data
00059     _surface = new byte[16 * 16];
00060     for (int i = 0; i < 32; i++) {
00061         byte imageByte = stream.readByte();
00062         for (int b = 0; b < 8; b++)
00063             _surface[i * 8 + b] = (byte)((imageByte & (0x80 >> b)) > 0 ? 0 : 1);
00064     }
00065 
00066     // Apply mask data
00067     for (int i = 0; i < 32; i++) {
00068         byte imageByte = stream.readByte();
00069         for (int b = 0; b < 8; b++)
00070             if ((imageByte & (0x80 >> b)) == 0)
00071                 _surface[i * 8 + b] = 0xff;
00072     }
00073 
00074     _hotspotY = stream.readUint16BE();
00075     _hotspotX = stream.readUint16BE();
00076 
00077     // Setup a basic palette
00078     _palette[1 * 3 + 0] = 0xff;
00079     _palette[1 * 3 + 1] = 0xff;
00080     _palette[1 * 3 + 2] = 0xff;
00081 
00082     return !stream.eos();
00083 }
00084 
00085 bool MacCursor::readFromCRSR(Common::SeekableReadStream &stream, bool forceMonochrome) {
00086     stream.readUint16BE(); // type
00087     stream.readUint32BE(); // offset to pixel map
00088     stream.readUint32BE(); // offset to pixel data
00089     stream.readUint32BE(); // expanded cursor data
00090     stream.readUint16BE(); // expanded data depth
00091     stream.readUint32BE(); // reserved
00092 
00093     // Read the B/W data first
00094     if (!readFromCURS(stream))
00095         return false;
00096 
00097     // Use b/w cursor on backends which don't support cursor palettes
00098     if (forceMonochrome)
00099         return true;
00100 
00101     stream.readUint32BE(); // reserved
00102     stream.readUint32BE(); // cursorID
00103 
00104     // Color version of cursor
00105     stream.readUint32BE(); // baseAddr
00106 
00107     // Keep only lowbyte for now
00108     stream.readByte();
00109     int iconRowBytes = stream.readByte();
00110 
00111     if (!iconRowBytes)
00112         return false;
00113 
00114     int iconBounds[4];
00115     iconBounds[0] = stream.readUint16BE();
00116     iconBounds[1] = stream.readUint16BE();
00117     iconBounds[2] = stream.readUint16BE();
00118     iconBounds[3] = stream.readUint16BE();
00119 
00120     stream.readUint16BE(); // pmVersion
00121     stream.readUint16BE(); // packType
00122     stream.readUint32BE(); // packSize
00123 
00124     stream.readUint32BE(); // hRes
00125     stream.readUint32BE(); // vRes
00126 
00127     stream.readUint16BE(); // pixelType
00128     stream.readUint16BE(); // pixelSize
00129     stream.readUint16BE(); // cmpCount
00130     stream.readUint16BE(); // cmpSize
00131 
00132     stream.readUint32BE(); // planeByte
00133     stream.readUint32BE(); // pmTable
00134     stream.readUint32BE(); // reserved
00135 
00136     // Pixel data for cursor
00137     int iconDataSize =  iconRowBytes * (iconBounds[3] - iconBounds[1]);
00138     byte *iconData = new byte[iconDataSize];
00139 
00140     if (!iconData)
00141         error("Cannot allocate Mac color cursor iconData");
00142 
00143     stream.read(iconData, iconDataSize);
00144 
00145     // Color table
00146     stream.readUint32BE(); // ctSeed
00147     stream.readUint16BE(); // ctFlag
00148     uint16 ctSize = stream.readUint16BE() + 1;
00149 
00150     // Read just high byte of 16-bit color
00151     for (int c = 0; c < ctSize; c++) {
00152         stream.readUint16BE();
00153         _palette[c * 3 + 0] = stream.readUint16BE() >> 8;
00154         _palette[c * 3 + 1] = stream.readUint16BE() >> 8;
00155         _palette[c * 3 + 2] = stream.readUint16BE() >> 8;
00156     }
00157 
00158     int pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes;
00159     int bpp           = 8 / pixelsPerByte;
00160 
00161     // build a mask to make sure the pixels are properly shifted out
00162     int bitmask = 0;
00163     for (int m = 0; m < bpp; m++) {
00164         bitmask <<= 1;
00165         bitmask  |= 1;
00166     }
00167 
00168     // Extract pixels from bytes
00169     for (int j = 0; j < iconDataSize; j++) {
00170         for (int b = 0; b < pixelsPerByte; b++) {
00171             int idx = j * pixelsPerByte + (pixelsPerByte - 1 - b);
00172 
00173             if (_surface[idx] != 0xff) // if mask is not there
00174                 _surface[idx] = (byte)((iconData[j] >> (b * bpp)) & bitmask);
00175         }
00176     }
00177 
00178     delete[] iconData;
00179     return stream.pos() == stream.size();
00180 }
00181 
00182 } // End of namespace Common


Generated on Sat Mar 23 2019 05:01:49 for ResidualVM by doxygen 1.7.1
curved edge   curved edge