Use GetHeight/GetWidth() where appropriate instead of m_Width/m_Height

This commit is contained in:
Pavel Krajcevski 2013-09-18 18:02:35 -04:00
parent 4135e38f22
commit 16cc7f4a93

View file

@ -83,27 +83,27 @@ Image::Image(uint32 height, uint32 width, const Pixel *pixels)
} }
Image::Image(const Image &other) Image::Image(const Image &other)
: m_Width(other.m_Width) : m_Width(other.GetWidth())
, m_Height(other.m_Height) , m_Height(other.GetHeight())
, m_Pixels(new Pixel[other.m_Width * other.m_Height]) , m_Pixels(new Pixel[other.GetWidth() * other.GetHeight()])
, m_FractionalPixels(new Pixel[other.m_Width * other.m_Height]) { , m_FractionalPixels(new Pixel[other.GetWidth() * other.GetHeight()]) {
memcpy(m_Pixels, other.m_Pixels, m_Width * m_Height * sizeof(Pixel)); memcpy(m_Pixels, other.m_Pixels, GetWidth() * GetHeight() * sizeof(Pixel));
} }
Image &Image::operator=(const Image &other) { Image &Image::operator=(const Image &other) {
m_Width = other.m_Width; m_Width = other.GetWidth();
m_Height = other.m_Height; m_Height = other.GetHeight();
assert(m_Pixels); assert(m_Pixels);
delete m_Pixels; delete m_Pixels;
m_Pixels = new Pixel[other.m_Width * other.m_Height]; m_Pixels = new Pixel[other.GetWidth() * other.GetHeight()];
memcpy(m_Pixels, other.m_Pixels, m_Width * m_Height * sizeof(Pixel)); memcpy(m_Pixels, other.m_Pixels, GetWidth() * GetHeight() * sizeof(Pixel));
assert(m_FractionalPixels); assert(m_FractionalPixels);
delete m_FractionalPixels; delete m_FractionalPixels;
m_FractionalPixels = new Pixel[other.m_Width * other.m_Height]; m_FractionalPixels = new Pixel[other.GetWidth() * other.GetHeight()];
memcpy(m_FractionalPixels, other.m_FractionalPixels, memcpy(m_FractionalPixels, other.m_FractionalPixels,
m_Width * m_Height * sizeof(Pixel)); GetWidth() * GetHeight() * sizeof(Pixel));
return *this; return *this;
} }
@ -129,8 +129,8 @@ static bool CompareBitDepths(const uint8 (&depth1)[4],
void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes, void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes,
EWrapMode wrapMode) { EWrapMode wrapMode) {
const uint32 newWidth = m_Width << xtimes; const uint32 newWidth = GetWidth() << xtimes;
const uint32 newHeight = m_Height << ytimes; const uint32 newHeight = GetHeight() << ytimes;
const uint32 xscale = 1 << xtimes; const uint32 xscale = 1 << xtimes;
const uint32 xoffset = xscale >> 1; const uint32 xoffset = xscale >> 1;
@ -214,9 +214,9 @@ void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes,
} }
void Image::ChangeBitDepth(const uint8 (&depths)[4]) { void Image::ChangeBitDepth(const uint8 (&depths)[4]) {
for(uint32 j = 0; j < m_Height; j++) { for(uint32 j = 0; j < GetHeight(); j++) {
for(uint32 i = 0; i < m_Width; i++) { for(uint32 i = 0; i < GetWidth(); i++) {
uint32 pidx = j * m_Width + i; uint32 pidx = j * GetWidth() + i;
m_Pixels[pidx].ChangeBitDepth(depths); m_Pixels[pidx].ChangeBitDepth(depths);
} }
} }
@ -229,10 +229,10 @@ void Image::ExpandTo8888() {
uint8 fractionDepth[4]; uint8 fractionDepth[4];
const uint8 fullDepth[4] = { 8, 8, 8, 8 }; const uint8 fullDepth[4] = { 8, 8, 8, 8 };
for(uint32 j = 0; j < m_Height; j++) { for(uint32 j = 0; j < GetHeight(); j++) {
for(uint32 i = 0; i < m_Width; i++) { for(uint32 i = 0; i < GetWidth(); i++) {
uint32 pidx = j * m_Width + i; uint32 pidx = j * GetWidth() + i;
m_Pixels[pidx].ChangeBitDepth(fullDepth); m_Pixels[pidx].ChangeBitDepth(fullDepth);
m_FractionalPixels[pidx].GetBitDepth(fractionDepth); m_FractionalPixels[pidx].GetBitDepth(fractionDepth);
@ -257,15 +257,15 @@ const Pixel &Image::GetPixel(int32 i, int32 j, EWrapMode wrapMode) {
if(wrapMode == eWrapMode_Clamp) { if(wrapMode == eWrapMode_Clamp) {
i = 0; i = 0;
} else { } else {
i += m_Width; i += GetWidth();
} }
} }
while(i >= static_cast<int32>(m_Width)) { while(i >= static_cast<int32>(GetWidth())) {
if(wrapMode == eWrapMode_Clamp) { if(wrapMode == eWrapMode_Clamp) {
i = m_Width - 1; i = GetWidth() - 1;
} else { } else {
i -= m_Width; i -= GetWidth();
} }
} }
@ -273,46 +273,49 @@ const Pixel &Image::GetPixel(int32 i, int32 j, EWrapMode wrapMode) {
if(wrapMode == eWrapMode_Clamp) { if(wrapMode == eWrapMode_Clamp) {
j = 0; j = 0;
} else { } else {
j += m_Height; j += GetHeight();
} }
} }
while(j >= static_cast<int32>(m_Height)) { while(j >= static_cast<int32>(GetHeight())) {
if(wrapMode == eWrapMode_Clamp) { if(wrapMode == eWrapMode_Clamp) {
j = m_Height - 1; j = GetHeight() - 1;
} else { } else {
j -= m_Height; j -= GetHeight();
} }
} }
return m_Pixels[j * m_Width + i]; int32 idx = j * GetWidth() + i;
assert(idx >= 0);
assert(idx < GetWidth() * GetHeight());
return idx;
} }
Pixel & Image::operator()(uint32 i, uint32 j) { Pixel & Image::operator()(uint32 i, uint32 j) {
assert(i < m_Width); assert(i < GetWidth());
assert(j < m_Height); assert(j < GetHeight());
return m_Pixels[j * m_Width + i]; return m_Pixels[j * GetWidth() + i];
} }
const Pixel & Image::operator()(uint32 i, uint32 j) const { const Pixel & Image::operator()(uint32 i, uint32 j) const {
assert(i < m_Width); assert(i < GetWidth());
assert(j < m_Height); assert(j < GetHeight());
return m_Pixels[j * m_Width + i]; return m_Pixels[j * GetWidth() + i];
} }
void Image::DebugOutput(const char *filename) const { void Image::DebugOutput(const char *filename) const {
uint32 *outPixels = new uint32[m_Width * m_Height]; uint32 *outPixels = new uint32[GetWidth() * GetHeight()];
const uint8 fullDepth[4] = { 8, 8, 8, 8 }; const uint8 fullDepth[4] = { 8, 8, 8, 8 };
for(int j = 0; j < m_Height; j++) { for(uint32 j = 0; j < GetHeight(); j++) {
for(int i = 0; i < m_Width; i++) { for(uint32 i = 0; i < GetWidth(); i++) {
uint32 idx = j * m_Width + i; uint32 idx = j * GetWidth() + i;
Pixel p = m_Pixels[idx]; Pixel p = m_Pixels[idx];
p.ChangeBitDepth(fullDepth); p.ChangeBitDepth(fullDepth);
outPixels[idx] = p.PackRGBA(); outPixels[idx] = p.PackRGBA();
} }
} }
::Image img(m_Width, m_Height, outPixels); ::Image img(GetWidth(), GetHeight(), outPixels);
char debugFilename[256]; char debugFilename[256];
snprintf(debugFilename, sizeof(debugFilename), "%s.png", filename); snprintf(debugFilename, sizeof(debugFilename), "%s.png", filename);