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

pixelformat.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 "graphics/pixelformat.h"
00024 #include "common/algorithm.h"
00025 
00026 namespace Graphics {
00027 
00028 Common::String PixelFormat::toString() const {
00029     if (bytesPerPixel == 1)
00030         return "CLUT8";
00031 
00032     // We apply a trick to simplify the code here. We encode all the shift,
00033     // loss, and component name in the component entry. By having the shift as
00034     // highest entry we can sort according to shift.
00035     // This works because in valid RGB PixelFormats shift values needs to be
00036     // distinct except when the loss is 8. However, components with loss value
00037     // of 8 are not printed, thus their position does not matter.
00038     int component[4];
00039     component[0] = (rShift << 16) | (rLoss << 8) | 'R';
00040     component[1] = (gShift << 16) | (gLoss << 8) | 'G';
00041     component[2] = (bShift << 16) | (bLoss << 8) | 'B';
00042     component[3] = (aShift << 16) | (aLoss << 8) | 'A';
00043 
00044     // Sort components according to descending shift value.
00045     Common::sort(component, component + ARRAYSIZE(component), Common::Greater<int>());
00046 
00047     Common::String letters, digits;
00048     for (int i = 0; i < ARRAYSIZE(component); ++i) {
00049         const int componentLoss = (component[i] >> 8) & 0xFF;
00050         // A loss of 8 means that the component does not exist.
00051         if (componentLoss == 8) {
00052             continue;
00053         }
00054 
00055         const char componentName = component[i] & 0xFF;
00056 
00057         letters += componentName;
00058         digits += '0' + 8 - componentLoss;
00059     }
00060 
00061     return letters + digits + '@' + ('0' + bytesPerPixel);
00062 }
00063 
00064 } // End of namespace Graphics


Generated on Sat May 18 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge