OpenGTA/util/image_loader.h

84 lines
3.5 KiB
C
Raw Normal View History

2015-12-03 00:37:37 +00:00
/************************************************************************
* Copyright (c) 2005-2007 tok@openlinux.org.uk *
* *
* This software is provided as-is, without any express or implied *
* warranty. In no event will the authors be held liable for any *
* damages arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute *
* it freely, subject to the following restrictions: *
* *
* 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 in a product, an acknowledgment in the product documentation *
* would be appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must *
* not be misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
************************************************************************/
2015-12-03 00:37:02 +00:00
#ifndef UTIL_IMAGE_LOADER_H
#define UTIL_IMAGE_LOADER_H
#include <SDL_opengl.h>
#include <string>
#include "gl_pagedtexture.h"
namespace ImageUtil {
2015-12-03 00:38:22 +00:00
/** Helper to calculate 2^k texture sizes.
*/
2015-12-03 00:37:02 +00:00
struct NextPowerOfTwo {
NextPowerOfTwo(uint32_t _w, uint32_t _h) {
w = 1; h = 1;
while (w < _w) { w <<= 1; }
while (h < _h) { h <<= 1; }
}
uint32_t w;
uint32_t h;
};
2015-12-03 00:38:22 +00:00
/** Run scale2x on 32bit input image.
*
* \note Uses Util::BufferCache for dst memory; lock 'src' before calling
* if it also is a BufferCache buffer.
*/
uint8_t* scale2x_32bit(const uint8_t* src, const int src_width, const int src_height);
uint8_t* scale2x_24bit(const uint8_t* src, const int src_width, const int src_height);
typedef std::pair<uint16_t, uint16_t> WidthHeightPair;
2015-12-03 00:37:02 +00:00
// hardcoded data for known images
WidthHeightPair lookupImageSize(const std::string & name, const uint32_t size);
// load a rgb image
OpenGL::PagedTexture loadImageRAW(const std::string & name);
// load a palette image and guess the palette filename
2015-12-03 00:38:22 +00:00
//OpenGL::PagedTexture loadImageRAT(const std::string & name);
2015-12-03 00:37:02 +00:00
// load a palette image using palette file
OpenGL::PagedTexture loadImageRATWithPalette(const std::string & name,
const std::string & palette_file);
2015-12-03 00:38:22 +00:00
#ifdef WITH_SDL_IMAGE
OpenGL::PagedTexture loadImageSDL(const std::string & name);
#endif
extern bool mipmapTextures;
extern GLfloat supportedMaxAnisoDegree;
// plain simple garden-variety create-a-texture; needs to be 2^k
GLuint createGLTexture(GLsizei w, GLsizei h, bool rgba,
const void* pixels);
2015-12-03 00:37:02 +00:00
2015-12-03 00:38:22 +00:00
// blitting a buffer into another; no checks done!
2015-12-03 00:37:02 +00:00
void copyImage2Image(uint8_t *dest, const uint8_t *src, const uint16_t
srcWidth, const uint16_t srcHeight, const uint16_t destWidth);
2015-12-03 00:38:22 +00:00
// texture-class instance from pixel data; does transform to 2^k if required
2015-12-03 00:37:02 +00:00
OpenGL::PagedTexture createEmbeddedTexture(GLsizei w, GLsizei h, bool rgba,
const void *pixels);
}
#endif