Skip to content

Commit

Permalink
Image::getMipMapPixels(int) is now just getPixels()
Browse files Browse the repository at this point in the history
No calling code ever made use of the mipmap level parameter, nor could it ever
do so since the RGBAImage implementation would assert if the requested level
were anything other than 0, making this parameter useless. The only class which
cares about mipmap levels is DDSImage, which continues to be populated by its
(non-interface) getMipMapPixels method inside dds.cpp.
  • Loading branch information
Matthew Mott committed Jun 18, 2020
1 parent 39471f9 commit 1828f91
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
34 changes: 16 additions & 18 deletions include/iimage.h
Expand Up @@ -61,29 +61,27 @@ class Image
{
public:

/**
* greebo: Returns the specified mipmap pixel data.
*/
virtual byte* getMipMapPixels(std::size_t mipMapIndex) const = 0;

/**
* greebo: Returns the dimension of the specified mipmap.
*/
virtual std::size_t getWidth(std::size_t mipMapIndex) const = 0;
virtual std::size_t getHeight(std::size_t mipMapIndex) const = 0;

// greebo: Returns TRUE whether this image is precompressed (DDS)
virtual bool isPrecompressed() const {
return false;
}
/// Return the start of the pixel data for this image
virtual uint8_t* getPixels() const = 0;

/**
* greebo: Returns the dimension of the specified mipmap.
*/
virtual std::size_t getWidth(std::size_t mipMapIndex) const = 0;
virtual std::size_t getHeight(std::size_t mipMapIndex) const = 0;

// greebo: Returns TRUE whether this image is precompressed (DDS)
virtual bool isPrecompressed() const {
return false;
}
};
typedef std::shared_ptr<Image> ImagePtr;

class ArchiveFile;

/// Module responsible for loading images from VFS or disk filesystem
class ImageLoader :
public RegisterableModule
public RegisterableModule
{
public:

Expand All @@ -100,11 +98,11 @@ class ImageLoader :
*/
virtual ImagePtr imageFromVFS(const std::string& vfsPath) const = 0;

/**
/**
* \brief
* Load an image from a filesystem path.
*/
virtual ImagePtr imageFromFile(const std::string& filename) const = 0;
virtual ImagePtr imageFromFile(const std::string& filename) const = 0;
};

typedef std::shared_ptr<ImageLoader> ImageLoaderPtr;
Expand Down
6 changes: 2 additions & 4 deletions libs/RGBAImage.h
Expand Up @@ -37,10 +37,8 @@ class RGBAImage :
delete[] pixels;
}

virtual byte* getMipMapPixels(std::size_t mipMapIndex) const
uint8_t* getPixels() const override
{
assert(mipMapIndex == 0); // only one mipmap is allowed here

return reinterpret_cast<byte*>(pixels);
}

Expand Down Expand Up @@ -77,7 +75,7 @@ class RGBAImage :
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,
static_cast<GLint>(getWidth(0)), static_cast<GLint>(getHeight(0)),
GL_RGBA, GL_UNSIGNED_BYTE,
getMipMapPixels(0)
getPixels()
);

// Un-bind the texture
Expand Down
8 changes: 7 additions & 1 deletion radiant/image/dds.cpp
Expand Up @@ -112,7 +112,7 @@ class DDSImage: public Image, public util::Noncopyable
/**
* greebo: Returns the specified mipmap pixel data.
*/
virtual byte* getMipMapPixels(std::size_t mipMapIndex) const {
byte* getMipMapPixels(std::size_t mipMapIndex) const {
assert(mipMapIndex < _mipMapInfo.size());

return _pixelData + _mipMapInfo[mipMapIndex].offset;
Expand All @@ -133,6 +133,12 @@ class DDSImage: public Image, public util::Noncopyable
return _mipMapInfo[mipMapIndex].height;
}

/* Image implementation */
uint8_t* getPixels() const override
{
return getMipMapPixels(0);
}

/* BindableTexture implementation */
TexturePtr bindTexture(const std::string& name) const
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/shaders/CameraCubeMapDecl.cpp
Expand Up @@ -42,7 +42,7 @@ void CameraCubeMapDecl::bindDirection(const std::string& dir,
0, //border
GL_RGBA, //format
GL_UNSIGNED_BYTE, //type
img->getMipMapPixels(0)
img->getPixels()
);
debug::assertNoGlErrors();
}
Expand Down
40 changes: 20 additions & 20 deletions radiant/shaders/MapExpression.cpp
Expand Up @@ -96,9 +96,9 @@ ImagePtr MapExpression::getResampled(const ImagePtr& input, std::size_t width, s

// Resample the texture to match the dimensions of the first image
TextureManipulator::instance().resampleTexture(
input->getMipMapPixels(0),
input->getPixels(),
input->getWidth(0), input->getHeight(0),
resampled->getMipMapPixels(0),
resampled->getPixels(),
width, height, 4
);
return resampled;
Expand Down Expand Up @@ -171,9 +171,9 @@ ImagePtr AddNormalsExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* pixOne = imgOne->getMipMapPixels(0);
byte* pixTwo = imgTwo->getMipMapPixels(0);
byte* pixOut = result->getMipMapPixels(0);
byte* pixOne = imgOne->getPixels();
byte* pixTwo = imgTwo->getPixels();
byte* pixOut = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; y++ )
Expand Down Expand Up @@ -237,8 +237,8 @@ ImagePtr SmoothNormalsExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = normalMap->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = normalMap->getPixels();
byte* out = result->getPixels();

struct KernelElement {
// offset to the current pixel
Expand Down Expand Up @@ -327,9 +327,9 @@ ImagePtr AddExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* pixOne = imgOne->getMipMapPixels(0);
byte* pixTwo = imgTwo->getMipMapPixels(0);
byte* pixOut = result->getMipMapPixels(0);
byte* pixOne = imgOne->getPixels();
byte* pixTwo = imgTwo->getPixels();
byte* pixOut = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; y++)
Expand Down Expand Up @@ -398,8 +398,8 @@ ImagePtr ScaleExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = img->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = img->getPixels();
byte* out = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; ++y)
Expand Down Expand Up @@ -455,8 +455,8 @@ ImagePtr InvertAlphaExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = img->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = img->getPixels();
byte* out = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; ++y)
Expand Down Expand Up @@ -505,8 +505,8 @@ ImagePtr InvertColorExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = img->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = img->getPixels();
byte* out = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; y++) {
Expand Down Expand Up @@ -553,8 +553,8 @@ ImagePtr MakeIntensityExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = img->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = img->getPixels();
byte* out = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; ++y)
Expand Down Expand Up @@ -603,8 +603,8 @@ ImagePtr MakeAlphaExpression::getImage() const {

ImagePtr result (new RGBAImage(width, height));

byte* in = img->getMipMapPixels(0);
byte* out = result->getMipMapPixels(0);
byte* in = img->getPixels();
byte* out = result->getPixels();

// iterate through the pixels
for( std::size_t y = 0; y < height; y++)
Expand Down
4 changes: 2 additions & 2 deletions radiant/shaders/textures/HeightmapCreator.h
Expand Up @@ -22,8 +22,8 @@ ImagePtr createNormalmapFromHeightmap(ImagePtr heightMap, float scale) {

ImagePtr normalMap (new RGBAImage(width, height));

byte* in = heightMap->getMipMapPixels(0);
byte* out = normalMap->getMipMapPixels(0);
byte* in = heightMap->getPixels();
byte* out = normalMap->getPixels();

struct KernelElement
{
Expand Down
10 changes: 5 additions & 5 deletions radiant/shaders/textures/TextureManipulator.cpp
Expand Up @@ -70,7 +70,7 @@ Vector3 TextureManipulator::getFlatshadeColour(const ImagePtr& input) {
incr = 1;

// Set the pixel pointer to the very first pixel
byte* pixels = input->getMipMapPixels(0);
byte* pixels = input->getPixels();

Vector3 returnValue;
int pixelCount = 0;
Expand Down Expand Up @@ -110,7 +110,7 @@ ImagePtr TextureManipulator::getResized(const ImagePtr& input) {

std::size_t width = input->getWidth(0);
std::size_t height = input->getHeight(0);
byte* sourcePixels = input->getMipMapPixels(0);
byte* sourcePixels = input->getPixels();

ImagePtr output;

Expand All @@ -131,7 +131,7 @@ ImagePtr TextureManipulator::getResized(const ImagePtr& input) {

// Resample the texture into the allocated image
resampleTexture(sourcePixels, width, height,
output->getMipMapPixels(0), gl_width, gl_height, 4);
output->getPixels(), gl_width, gl_height, 4);
}
else {
// Nothing to do, return the source image
Expand Down Expand Up @@ -159,7 +159,7 @@ ImagePtr TextureManipulator::getResized(const ImagePtr& input) {
// Reduce the image to the next smaller power of two until it fits the openGL max texture size
while (gl_width > targetWidth || gl_height > targetHeight)
{
mipReduce(output->getMipMapPixels(0), output->getMipMapPixels(0),
mipReduce(output->getPixels(), output->getPixels(),
gl_width, gl_height, targetWidth, targetHeight);

if (gl_width > targetWidth)
Expand All @@ -183,7 +183,7 @@ ImagePtr TextureManipulator::processGamma(const ImagePtr& input) {
std::size_t numPixels = input->getWidth(0) * input->getHeight(0);

// Set the pixel pointer to the very first pixel
byte* pixels = input->getMipMapPixels(0);
byte* pixels = input->getPixels();

// Go over all the pixels and change their value accordingly
for (std::size_t i = 0; i < (numPixels*4); i += 4)
Expand Down

0 comments on commit 1828f91

Please sign in to comment.