Fixed up love.graphics.newScreenshot() to return a right-side up image without breaking abstraction layers.

This commit is contained in:
bill@Ixion
2009-09-02 20:42:38 -05:00
parent 623e701549
commit 4d2994e05f
2 changed files with 102 additions and 83 deletions
+21 -2
View File
@@ -1178,10 +1178,29 @@ namespace opengl
int w = getWidth(); int w = getWidth();
int h = getHeight(); int h = getHeight();
GLubyte * pixels = new GLubyte[4*w*h]; int row = 4*w;
int size = row*h;
GLubyte * pixels = new GLubyte[size];
GLubyte * screenshot = new GLubyte[size];
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// OpenGL sucks and reads pixels from the lower-left. Let's fix that.
GLubyte *src = pixels - row, *dst = screenshot + size;
for (int i = 0; i < h; ++i) {
memcpy(dst-=row, src+=row, row);
}
return image->newImageData(w, h, (void*)pixels); love::image::ImageData * img = image->newImageData(w, h, (void*)screenshot);
delete [] pixels;
delete [] screenshot;
return img;
} }
void Graphics::push() void Graphics::push()
+81 -81
View File
@@ -1,82 +1,82 @@
/** /**
* Copyright (c) 2006-2009 LOVE Development Team * Copyright (c) 2006-2009 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
* appreciated but is not required. * appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be * 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software. * misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#ifndef LOVE_DEVIL_IMAGE_DATA_H #ifndef LOVE_DEVIL_IMAGE_DATA_H
#define LOVE_DEVIL_IMAGE_DATA_H #define LOVE_DEVIL_IMAGE_DATA_H
// LOVE // LOVE
#include <filesystem/File.h> #include <filesystem/File.h>
#include <image/ImageData.h> #include <image/ImageData.h>
// DevIL // DevIL
#include <IL/il.h> #include <IL/il.h>
namespace love namespace love
{ {
namespace image namespace image
{ {
namespace devil namespace devil
{ {
class ImageData : public love::image::ImageData class ImageData : public love::image::ImageData
{ {
private: private:
// The width of the image data. // The width of the image data.
int width; int width;
// The height of the image data. // The height of the image data.
int height; int height;
// The origin of the image. // The origin of the image.
int origin; int origin;
// The bits per pixel. // The bits per pixel.
int bpp; int bpp;
// DevIL image identifier. // DevIL image identifier.
ILuint image; ILuint image;
void load(Data * data); void load(Data * data);
public: public:
ImageData(Data * data); ImageData(Data * data);
ImageData(love::filesystem::File * file); ImageData(love::filesystem::File * file);
ImageData(int width, int height); ImageData(int width, int height);
ImageData(int width, int height, void *data); ImageData(int width, int height, void *data);
virtual ~ImageData(); virtual ~ImageData();
// Implements Data. // Implements Data.
void * getData() const; void * getData() const;
int getSize() const; int getSize() const;
// Implements ImageData. // Implements ImageData.
int getWidth() const ; int getWidth() const ;
int getHeight() const ; int getHeight() const ;
void setPixel(int x, int y, pixel c); void setPixel(int x, int y, pixel c);
pixel getPixel(int x, int y) const; pixel getPixel(int x, int y) const;
}; // ImageData }; // ImageData
} // devil } // devil
} // image } // image
} // love } // love
#endif // LOVE_DEVIL_IMAGE_DATA_H #endif // LOVE_DEVIL_IMAGE_DATA_H