Skip to content

Commit

Permalink
Refactor|Resources: Represent image_t dimensions as de::Vector2ui, cl…
Browse files Browse the repository at this point in the history
…eanup
  • Loading branch information
danij-deng committed Dec 13, 2013
1 parent 5a60fcc commit b5e0ff0
Show file tree
Hide file tree
Showing 17 changed files with 296 additions and 329 deletions.
14 changes: 7 additions & 7 deletions doomsday/api/api_resource.h
Expand Up @@ -41,7 +41,7 @@ DENG_API_TYPEDEF(R)
* @param info Extend info will be written here if found.
* @return @c true: Extended info for this patch was found.
*/
boolean (*GetPatchInfo)(patchid_t id, patchinfo_t* info);
boolean (*GetPatchInfo)(patchid_t id, patchinfo_t *info);

/// @return Uri for the patch associated with @a id. Should be released with Uri_Delete()
Uri* (*ComposePatchUri)(patchid_t id);
Expand All @@ -64,7 +64,7 @@ DENG_API_TYPEDEF(R)
* @param tics Base duration of the new frame in tics.
* @param randomTics Extra frame duration in tics (randomized on each cycle).
*/
void (*AddAnimGroupFrame)(int groupNum, const Uri* texture, int tics, int randomTics);
void (*AddAnimGroupFrame)(int groupNum, Uri const *texture, int tics, int randomTics);

/**
* Add a new (named) color palette.
Expand All @@ -80,23 +80,23 @@ DENG_API_TYPEDEF(R)
*
* @return Color palette id.
*/
colorpaletteid_t (*CreateColorPalette)(const char* fmt, const char* name, const uint8_t* colorData, int colorCount);
colorpaletteid_t (*CreateColorPalette)(char const *fmt, char const *name, uint8_t const *colorData, int colorCount);

/**
* Given a color palette name, look up the associated identifier.
*
* @param name Unique name of the palette to locate.
* @return Identifier of the palette associated with this name, else @c 0
*/
colorpaletteid_t (*GetColorPaletteNumForName)(const char* name);
colorpaletteid_t (*GetColorPaletteNumForName)(char const *name);

/**
* Given a color palette id, look up the specified unique name.
*
* @param id Id of the color palette to locate.
* @return Pointer to the unique name associated with the specified id else @c NULL
*/
const char* (*GetColorPaletteNameForNum)(colorpaletteid_t id);
char const* (*GetColorPaletteNameForNum)(colorpaletteid_t id);

/**
* Given a color palette index, calculate the equivalent RGB color.
Expand All @@ -118,8 +118,8 @@ DENG_API_TYPEDEF(R)
*/
void (*GetColorPaletteRGBubv)(colorpaletteid_t id, int colorIdx, uint8_t rgb[3], boolean applyTexGamma);

int (*TextureUniqueId)(const Uri* uri); /*quiet=false*/
int (*TextureUniqueId2)(const Uri* uri, boolean quiet);
int (*TextureUniqueId)(Uri const *uri); /*quiet=false*/
int (*TextureUniqueId2)(Uri const *uri, boolean quiet);
}
DENG_API_T(R);

Expand Down
6 changes: 5 additions & 1 deletion doomsday/client/include/resource/colorpalettes.h
Expand Up @@ -32,6 +32,10 @@ DENG_EXTERN_C byte *translationTables;
void R_InitTranslationTables();
void R_UpdateTranslationTables();

byte const *R_TranslationTable(int tclass, int tmap);
/// Returns a linear palette translation index for the given class and map.
/// Note that @c -1 is returned when @a tclass =0 and @a tmap =0
int R_ToPaletteTranslation(int tclass, int tmap);

byte const *R_TranslationTable(int trans);

#endif // DENG_RESOURCE_COLORPALETTES_H
8 changes: 5 additions & 3 deletions doomsday/client/include/resource/image.h
Expand Up @@ -64,14 +64,16 @@ namespace res

struct image_t
{
typedef de::Vector2ui Size;

/// @ref imageFlags
int flags;

/// Indentifier of the color palette used/assumed or @c 0 if none (1-based).
uint paletteId;

/// Size of the image in pixels.
Size2Raw size;
Size size;

/// Bytes per pixel in the data buffer.
int pixelSize;
Expand All @@ -93,9 +95,9 @@ void Image_Init(image_t &image);
void Image_ClearPixelData(image_t &image);

/**
* Returns the dimensions of the image in pixels.
* Returns the size of the image in pixels.
*/
de::Vector2i Image_Dimensions(image_t const &image);
image_t::Size Image_Size(image_t const &image);

/**
* Returns a textual description of the image.
Expand Down
32 changes: 11 additions & 21 deletions doomsday/client/include/resource/pcx.h
@@ -1,11 +1,10 @@
/**
* @file pcx.h PCX image reader
/** @file pcx.h PCX image reader.
*
* Originally derived from the Q2 utils source (lbmlib.c).
*
* @author Copyright &copy; 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 1997-2006 id Software, Inc
* @authors Copyright © 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 1997-2006 id Software, Inc
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -22,35 +21,26 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_GRAPHICS_PCX_H
#define LIBDENG_GRAPHICS_PCX_H
#ifndef DENG_RESOURCE_PCX_H
#define DENG_RESOURCE_PCX_H

#include "filehandle.h"

#ifdef __cplusplus
extern "C" {
#endif
#include <de/Vector>

/// @addtogroup resource
///@{

/**
* Reads the given PCX image and returns a pointer to a planar
* RGBA buffer. Width and height are set, and pixelSize is 4 (RGBA).
* Reads the given PCX image and returns a pointer to a planar RGBA buffer.
* The caller must free the allocated buffer with Z_Free.
* Width, height and pixelSize can't be NULL.
*/
uint8_t *PCX_Load(FileHandle *file, int *width, int *height, int *pixelSize);
uint8_t *PCX_Load(de::FileHandle &file, de::Vector2ui &outSize, int &pixelSize);

/**
* @return Textual message detailing the last error encountered else @c 0.
*/
char const *PCX_LastError(void);
char const *PCX_LastError();

///@}

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_GRAPHICS_PCX_H */
#endif // DENG_RESOURCE_PCX_H
26 changes: 9 additions & 17 deletions doomsday/client/include/resource/tga.h
@@ -1,8 +1,7 @@
/**
* @file tga.h Truevision TGA (a.k.a Targa) image reader/writer
/** @file tga.h Truevision TGA (a.k.a Targa) image reader/writer
*
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2009-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -19,14 +18,11 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_GRAPHICS_TGA_H
#define LIBDENG_GRAPHICS_TGA_H
#ifndef DENG_RESOURCE_TGA_H
#define DENG_RESOURCE_TGA_H

#include "filehandle.h"

#ifdef __cplusplus
extern "C" {
#endif
#include <de/Vector>

/// @addtogroup resource
///@{
Expand Down Expand Up @@ -87,17 +83,13 @@ int TGA_Save16_rgb888(FILE *file, int w, int h, uint8_t const *buf);
*
* @return Non-zero iff the image is loaded successfully.
*/
uint8_t *TGA_Load(FileHandle *file, int *width, int *height, int *pixelSize);
uint8_t *TGA_Load(de::FileHandle &file, de::Vector2ui &outSize, int &pixelSize);

/**
* @return Textual message detailing the last error encountered else @c 0.
*/
char const *TGA_LastError(void);
char const *TGA_LastError();

///@}

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_GRAPHICS_TGA_H */
#endif // DENG_RESOURCE_TGA_H
15 changes: 7 additions & 8 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -175,7 +175,7 @@ GLuint GL_PrepareLSTexture(lightingtexid_t which)
( image.pixelSize == 2 ? DGL_LUMINANCE_PLUS_A8 :
image.pixelSize == 3 ? DGL_RGB :
image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ),
image.size.width, image.size.height, image.pixels,
image.size.x, image.size.y, image.pixels,
TXCF_NO_COMPRESSION, 0, GL_LINEAR, GL_LINEAR, -1 /*best anisotropy*/,
( which == LST_GRADIENT? GL_REPEAT : GL_CLAMP_TO_EDGE ), GL_CLAMP_TO_EDGE);

Expand Down Expand Up @@ -237,7 +237,7 @@ GLuint GL_PrepareSysFlaremap(flaretexid_t which)
( image.pixelSize == 2 ? DGL_LUMINANCE_PLUS_A8 :
image.pixelSize == 3 ? DGL_RGB :
image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ),
image.size.width, image.size.height, image.pixels,
image.size.x, image.size.y, image.pixels,
TXCF_NO_COMPRESSION, 0, GL_LINEAR, GL_LINEAR, 0 /*no anisotropy*/,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

Expand Down Expand Up @@ -317,8 +317,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)

// Load the raw image data.
FileHandle_Read(file, image.pixels, fileLength);
image.size.width = RAW_WIDTH;
image.size.height = int(fileLength / image.size.width);
image.size = Vector2ui(RAW_WIDTH, fileLength / image.size.x);
image.pixelSize = 1;

F_Delete(file);
Expand All @@ -345,7 +344,7 @@ GLuint GL_PrepareRawTexture(rawtex_t &raw)
{
// Loaded an external raw texture.
raw.tex = GL_NewTextureWithParams(image.pixelSize == 4? DGL_RGBA : DGL_RGB,
image.size.width, image.size.height, image.pixels, 0, 0,
image.size.x, image.size.y, image.pixels, 0, 0,
GL_NEAREST, (filterUI ? GL_LINEAR : GL_NEAREST), 0 /*no anisotropy*/,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
}
Expand All @@ -355,14 +354,14 @@ GLuint GL_PrepareRawTexture(rawtex_t &raw)
(image.flags & IMGF_IS_MASKED)? DGL_COLOR_INDEX_8_PLUS_A8 :
image.pixelSize == 4? DGL_RGBA :
image.pixelSize == 3? DGL_RGB : DGL_COLOR_INDEX_8,
image.size.width, image.size.height, image.pixels, 0, 0,
image.size.x, image.size.y, image.pixels, 0, 0,
GL_NEAREST, (filterUI? GL_LINEAR:GL_NEAREST), 0 /*no anisotropy*/,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

}

raw.width = image.size.width;
raw.height = image.size.height;
raw.width = image.size.x;
raw.height = image.size.y;
Image_ClearPixelData(image);
}

Expand Down

0 comments on commit b5e0ff0

Please sign in to comment.