PSP: Improve const-correctness

This commit is contained in:
Colin Snover 2017-10-15 16:11:47 -05:00
parent 2ef10faa1e
commit ea2fa9093d
5 changed files with 36 additions and 34 deletions

View file

@ -40,10 +40,10 @@ public:
void clearBuffer();
void clearPalette();
void render() { _renderer.render(); }
uint32 getWidth() { return _buffer.getSourceWidth(); }
uint32 getHeight() { return _buffer.getSourceHeight(); }
uint32 getWidth() const { return _buffer.getSourceWidth(); }
uint32 getHeight() const { return _buffer.getSourceHeight(); }
void setPartialPalette(const byte *colors, uint start, uint num) { setDirty(); return _palette.setPartial(colors, start, num); }
void getPartialPalette(byte *colors, uint start, uint num) {
void getPartialPalette(byte *colors, uint start, uint num) const {
return _palette.getPartial(colors, start, num);
}
void copyFromRect(const byte *buf, int pitch, int destX, int destY, int recWidth, int recHeight);

View file

@ -204,7 +204,7 @@ void Palette::deallocate() {
// Copy some of the palette to an array of colors
//
void Palette::getPartial(byte *colors, uint start, uint num) {
void Palette::getPartial(byte *colors, uint start, uint num) const {
DEBUG_ENTER_FUNC();
assert(_values);
@ -286,13 +286,13 @@ void Palette::print(uint32 numToPrint /* = 0 */) {
}
}
uint32 Palette::getRawColorAt(uint32 position) {
uint32 Palette::getRawColorAt(uint32 position) const {
byte *pcolor = &_values[_pixelFormat.pixelsToBytes(position)];
uint32 color = _pixelFormat.getColorValueAt(pcolor);
return color;
}
uint32 Palette::getRGBAColorAt(uint32 position) {
uint32 Palette::getRGBAColorAt(uint32 position) const {
uint32 color = getRawColorAt(position);
uint32 r, g, b, a;
_pixelFormat.colorToRgba(color, r, g, b, a);

View file

@ -85,18 +85,19 @@ public:
void clear();
void setPixelFormats(PSPPixelFormat::Type paletteType, PSPPixelFormat::Type bufferType, bool swapRedBlue = false);
void setNumOfEntries(uint32 num) { _numOfEntries = num; }
uint32 getNumOfEntries() { return _numOfEntries; }
uint32 getSizeInBytes() { return _pixelFormat.pixelsToBytes(_numOfEntries); }
uint32 getNumOfEntries() const { return _numOfEntries; }
uint32 getSizeInBytes() const { return _pixelFormat.pixelsToBytes(_numOfEntries); }
void set(byte *values) { setPartial(values, 0, _numOfEntries); }
void setPartial(const byte *colors, uint start, uint num, bool supportsAlpha = false);
void getPartial(byte *colors, uint start, uint num);
uint32 getRawColorAt(uint32 position);
uint32 getRGBAColorAt(uint32 position);
void getPartial(byte *colors, uint start, uint num) const;
uint32 getRawColorAt(uint32 position) const;
uint32 getRGBAColorAt(uint32 position) const;
void setSingleColorRGBA(uint32 num, byte r, byte g, byte b, byte a);
void setColorPositionAlpha(uint32 position, bool alpha);
const byte *getRawValues() const { return _values; }
byte *getRawValues() { return _values; }
bool isAllocated() { return (_values != 0); }
PSPPixelFormat::Type getPixelFormat() { return _pixelFormat.format; }
bool isAllocated() const { return (_values != 0); }
PSPPixelFormat::Type getPixelFormat() const { return _pixelFormat.format; }
void print(uint32 numToPrint = 0); // print to screen
protected:
@ -127,19 +128,20 @@ public:
void setPixelFormat(PSPPixelFormat::Type type, bool swapRedBlue = false);
// getters
uint32 getWidth() { return _width; }
uint32 getWidthInBytes() { return _pixelFormat.pixelsToBytes(getWidth()); }
uint32 getHeight() { return _height; }
uint32 getSourceWidth() { return _sourceSize.width; }
uint32 getSourceWidthInBytes() { return _pixelFormat.pixelsToBytes(_sourceSize.width); }
uint32 getSourceHeight() { return _sourceSize.height; }
uint32 getTextureWidth() { return _textureSize.width; }
uint32 getTextureHeight() { return _textureSize.height; }
PSPPixelFormat::Type getPixelFormat() { return _pixelFormat.format; }
uint32 getBitsPerPixel() { return _pixelFormat.bitsPerPixel; }
uint32 getBytesPerPixel() { return getBitsPerPixel() >> 3; } /* won't work for 4-bit */
uint32 getWidth() const { return _width; }
uint32 getWidthInBytes() const { return _pixelFormat.pixelsToBytes(getWidth()); }
uint32 getHeight() const { return _height; }
uint32 getSourceWidth() const { return _sourceSize.width; }
uint32 getSourceWidthInBytes() const { return _pixelFormat.pixelsToBytes(_sourceSize.width); }
uint32 getSourceHeight() const { return _sourceSize.height; }
uint32 getTextureWidth() const { return _textureSize.width; }
uint32 getTextureHeight() const { return _textureSize.height; }
PSPPixelFormat::Type getPixelFormat() const { return _pixelFormat.format; }
uint32 getBitsPerPixel() const { return _pixelFormat.bitsPerPixel; }
uint32 getBytesPerPixel() const { return getBitsPerPixel() >> 3; } /* won't work for 4-bit */
const byte *getPixels() const { return _pixels; }
byte *getPixels() { return _pixels; }
uint32 getSizeInBytes() { return _pixelFormat.pixelsToBytes(_width * _height); }
uint32 getSizeInBytes() const { return _pixelFormat.pixelsToBytes(_width * _height); }
bool hasPalette();
void copyFromArray(const byte *buffer, int pitch);
@ -147,7 +149,7 @@ public:
void copyToArray(byte *dst, int pitch);
bool allocate(bool inVram = false);
void deallocate();
bool isAllocated() { return (_pixels != 0) ; }
bool isAllocated() const { return (_pixels != 0) ; }
void clear();
void flipNibbles(); // To handle peculiarities of PSP's 4 bit textures
static uint32 scaleUpToPowerOfTwo(uint32 size);

View file

@ -173,7 +173,7 @@ Graphics::PixelFormat PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat
return pf;
}
uint32 PSPPixelFormat::convertTo32BitColor(uint32 color) {
uint32 PSPPixelFormat::convertTo32BitColor(uint32 color) const {
DEBUG_ENTER_FUNC();
uint32 r, g, b, a, output;

View file

@ -55,9 +55,9 @@ struct PSPPixelFormat {
PSPPixelFormat::Type &paletteType,
bool &swapRedBlue);
static Graphics::PixelFormat convertToScummvmPixelFormat(PSPPixelFormat::Type type);
uint32 convertTo32BitColor(uint32 color);
uint32 convertTo32BitColor(uint32 color) const;
inline uint32 rgbaToColor(uint32 r, uint32 g, uint32 b, uint32 a) {
inline uint32 rgbaToColor(uint32 r, uint32 g, uint32 b, uint32 a) const {
uint32 color;
switch (format) {
@ -80,7 +80,7 @@ struct PSPPixelFormat {
return color;
}
inline void colorToRgba(uint32 color, uint32 &r, uint32 &g, uint32 &b, uint32 &a) {
inline void colorToRgba(uint32 color, uint32 &r, uint32 &g, uint32 &b, uint32 &a) const {
switch (format) {
case Type_4444:
a = (color >> 12) & 0xF; // Interpolate to get true colors
@ -140,7 +140,7 @@ struct PSPPixelFormat {
return color;
}
inline uint32 pixelsToBytes(uint32 pixels) {
inline uint32 pixelsToBytes(uint32 pixels) const {
switch (bitsPerPixel) {
case 4:
pixels >>= 1;
@ -160,7 +160,7 @@ struct PSPPixelFormat {
return pixels;
}
inline uint16 swapRedBlue16(uint16 color) {
inline uint16 swapRedBlue16(uint16 color) const {
uint16 output;
switch (format) {
@ -181,7 +181,7 @@ struct PSPPixelFormat {
return output;
}
inline uint32 swapRedBlue32(uint32 color) {
inline uint32 swapRedBlue32(uint32 color) const {
uint32 output;
switch (format) {
@ -211,7 +211,7 @@ struct PSPPixelFormat {
}
// Return whatever color we point at
inline uint32 getColorValueAt(byte *pointer) {
inline uint32 getColorValueAt(byte *pointer) const {
uint32 result;
switch (bitsPerPixel) {