Skip to content

Commit

Permalink
Refactor: Renamed Image methods and moved the module under "resource"
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 13, 2012
1 parent 901b6b5 commit 2d1792e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/engine.pro
Expand Up @@ -198,7 +198,6 @@ DENG_HEADERS += \
include/gl_tex.h \
include/gl_texmanager.h \
include/gridmap.h \
include/image.h \
include/json.h \
include/kdtree.h \
include/library.h \
Expand Down Expand Up @@ -294,6 +293,7 @@ DENG_HEADERS += \
include/resource/colorpalette.h \
include/resource/font.h \
include/resource/fonts.h \
include/resource/image.h \
include/resource/material.h \
include/resource/materials.h \
include/resource/materialvariant.h \
Expand Down Expand Up @@ -488,7 +488,6 @@ SOURCES += \
src/gl_tex.c \
src/gl_texmanager.c \
src/gridmap.c \
src/image.cpp \
src/json.cpp \
src/kdtree.c \
src/library.cpp \
Expand Down Expand Up @@ -580,6 +579,7 @@ SOURCES += \
src/resource/bitmapfont.c \
src/resource/colorpalette.c \
src/resource/fonts.cpp \
src/resource/image.cpp \
src/resource/material.cpp \
src/resource/materialarchive.c \
src/resource/materials.cpp \
Expand Down
@@ -1,6 +1,6 @@
/**
* @file image.h
* Image objects and relates routines. @ingroup gl
* Image objects and relates routines. @ingroup resource
*
* @authors Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2012 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -65,9 +65,19 @@ typedef struct image_s {
uint8_t* pixels;
} image_t;

void GL_InitImage(image_t* image);
/**
* Initializes the previously allocated @a image for use.
* @param image Image instance.
*/
void Image_Init(image_t* image);

/**
* Releases image pixel data, but does not delete @a image.
* @param image Image instance.
*/
void Image_Destroy(image_t* image);

void GL_PrintImageMetadata(const image_t* image);
void Image_PrintMetadata(const image_t* image);

/**
* Loads PCX, TGA and PNG images. The returned buffer must be freed
Expand All @@ -81,9 +91,6 @@ boolean Image_LoadFromFileWithFormat(image_t* img, const char* format, FileHandl

boolean Image_Save(const image_t *image, const char* filePath);

/// Release image pixel data.
void GL_DestroyImage(image_t* image);

/// @return @c true if the image pixel data contains alpha information.
boolean Image_HasAlpha(const image_t* image);

Expand Down
38 changes: 19 additions & 19 deletions doomsday/engine/src/gl_texmanager.c
Expand Up @@ -1405,7 +1405,7 @@ void GL_PruneTextureVariantSpecifications(void)
#endif
}

void GL_InitImage(image_t* img)
void Image_Init(image_t* img)
{
assert(img);
img->size.width = 0;
Expand All @@ -1416,7 +1416,7 @@ void GL_InitImage(image_t* img)
img->pixels = 0;
}

void GL_PrintImageMetadata(const image_t* image)
void Image_PrintMetadata(const image_t* image)
{
assert(image);
Con_Printf("dimensions:[%ix%i] flags:%i %s:%i\n", image->size.width, image->size.height,
Expand All @@ -1427,7 +1427,7 @@ void GL_PrintImageMetadata(const image_t* image)
static boolean tryLoadPCX(image_t* img, FileHandle* file)
{
assert(img && file);
GL_InitImage(img);
Image_Init(img);
img->pixels = PCX_Load(file, &img->size.width, &img->size.height, &img->pixelSize);
return (0 != img->pixels);
}
Expand All @@ -1442,7 +1442,7 @@ static boolean tryLoadPNG(image_t* img, FileHandle* file)
{
assert(img && file);
/*
GL_InitImage(img);
Image_Init(img);
img->pixels = PNG_Load(file, &img->size.width, &img->size.height, &img->pixelSize);
return (0 != img->pixels);
*/
Expand All @@ -1452,7 +1452,7 @@ static boolean tryLoadPNG(image_t* img, FileHandle* file)
static boolean tryLoadTGA(image_t* img, FileHandle* file)
{
assert(img && file);
GL_InitImage(img);
Image_Init(img);
img->pixels = TGA_Load(file, &img->size.width, &img->size.height, &img->pixelSize);
return (0 != img->pixels);
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ uint8_t* Image_LoadFromFile(image_t* img, FileHandle* file)
const char* fileName;
assert(img && file);

GL_InitImage(img);
Image_Init(img);

fileName = Str_Text(F_ComposePath(FileHandle_File_const(file)));

Expand Down Expand Up @@ -1571,7 +1571,7 @@ uint8_t* GL_LoadImageStr(image_t* img, const ddstring_t* filePath)
return GL_LoadImage(img, Str_Text(filePath));
}

void GL_DestroyImage(image_t* img)
void Image_Destroy(image_t* img)
{
assert(img);
if(!img->pixels) return;
Expand Down Expand Up @@ -2367,7 +2367,7 @@ TexSource GL_LoadDetailTextureLump(image_t* image, FileHandle* file)
{ // It must be an old-fashioned "raw" image.
size_t bufSize, fileLength = FileHandle_Length(file);

GL_InitImage(image);
Image_Init(image);

/**
* @todo Do not fatal error here if the not a known format!
Expand Down Expand Up @@ -2418,7 +2418,7 @@ TexSource GL_LoadFlatLump(image_t* image, FileHandle* file)

size_t bufSize, fileLength = FileHandle_Length(file);

GL_InitImage(image);
Image_Init(image);

/// @todo not all flats are 64x64!
image->size.width = FLAT_WIDTH;
Expand Down Expand Up @@ -2463,7 +2463,7 @@ static TexSource loadPatchLump(image_t* image, FileHandle* file, int tclass, int

if(validPatch((const uint8_t*)patch, fileLength))
{
GL_InitImage(image);
Image_Init(image);
image->size.width = SHORT(patch->width) + border*2;
image->size.height = SHORT(patch->height) + border*2;
image->pixelSize = 1;
Expand Down Expand Up @@ -2531,7 +2531,7 @@ DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap,
0, (useMipmap ? glmode[mipmapping] : GL_LINEAR),
magFilter, texAniso, wrapS, wrapT);

GL_DestroyImage(&image);
Image_Destroy(&image);
}

return texture;
Expand All @@ -2550,7 +2550,7 @@ TexSource GL_LoadPatchComposite(image_t* image, Texture* tex)
texDef = (patchcompositetex_t*)Texture_UserDataPointer(tex);
assert(texDef);

GL_InitImage(image);
Image_Init(image);
image->pixelSize = 1;
image->size.width = texDef->size.width;
image->size.height = texDef->size.height;
Expand Down Expand Up @@ -2626,7 +2626,7 @@ TexSource GL_LoadPatchCompositeAsSky(image_t* image, Texture* tex, boolean zeroM
F_UnlockLump(file, lumpIdx);
}

GL_InitImage(image);
Image_Init(image);
image->pixelSize = 1;
image->size.width = width;
image->size.height = height;
Expand Down Expand Up @@ -2705,7 +2705,7 @@ TexSource GL_LoadRawTex(image_t* image, const rawtex_t* r)
size_t fileLength = FileHandle_Length(file);
size_t bufSize = 3 * RAW_WIDTH * RAW_HEIGHT;

GL_InitImage(image);
Image_Init(image);
image->pixels = malloc(bufSize);
if(fileLength < bufSize)
memset(image->pixels, 0, bufSize);
Expand Down Expand Up @@ -2764,7 +2764,7 @@ DGLuint GL_PrepareRawTexture(rawtex_t* raw)

raw->width = image.size.width;
raw->height = image.size.height;
GL_DestroyImage(&image);
Image_Destroy(&image);
}

return raw->tex;
Expand Down Expand Up @@ -3356,7 +3356,7 @@ static boolean tryLoadImageAndPrepareVariant(Texture* tex,
}

// We're done with the image data.
GL_DestroyImage(&image);
Image_Destroy(&image);

#ifdef _DEBUG
VERBOSE(
Expand All @@ -3369,7 +3369,7 @@ static boolean tryLoadImageAndPrepareVariant(Texture* tex,
)
VERBOSE2(
Con_Printf(" Content: ");
GL_PrintImageMetadata(&image);
Image_PrintMetadata(&image);
Con_Printf(" Specification: ");
GL_PrintTextureVariantSpecification(spec);
)
Expand Down Expand Up @@ -3660,7 +3660,7 @@ boolean GL_DumpImage(const image_t* origImg, const char* filePath)
const image_t* img = origImg;
if(img->pixelSize != 4 || img->paletteId)
{
GL_InitImage(&imgABGR32);
Image_Init(&imgABGR32);
imgABGR32.pixels = GL_ConvertBuffer(img->pixels, img->size.width, img->size.height,
((img->flags & IMGF_IS_MASKED)? 2 : 1),
R_ToColorPalette(img->paletteId), 4);
Expand All @@ -3674,7 +3674,7 @@ boolean GL_DumpImage(const image_t* origImg, const char* filePath)

if(img == &imgABGR32)
{
GL_DestroyImage(&imgABGR32);
Image_Destroy(&imgABGR32);
}
return savedOK;
}}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/render/rend_particle.c
Expand Up @@ -135,7 +135,7 @@ static byte loadParticleTexture(uint particleTex, boolean silent)
TXCF_NO_COMPRESSION);

// Free the buffer.
GL_DestroyImage(&image);
Image_Destroy(&image);
}
else if(!silent)
{
Expand Down
Expand Up @@ -145,7 +145,7 @@ boolean Image_LoadFromFileWithFormat(image_t* img, const char* format, FileHandl
// It is assumed that file's position stays the same (could be trying multiple loaders).
size_t initPos = hndl.tell();

GL_InitImage(img);
Image_Init(img);

// Load the file contents to a memory buffer.
QByteArray data;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/ui/busyvisual.c
Expand Up @@ -153,13 +153,13 @@ void BusyVisual_LoadTextures(void)
if(GL_LoadImage(&image, "}data/graphics/loading1.png"))
{
texLoading[0] = GL_NewTextureWithParams(DGL_RGBA, image.size.width, image.size.height, image.pixels, TXCF_NEVER_DEFER);
GL_DestroyImage(&image);
Image_Destroy(&image);
}

if(GL_LoadImage(&image, "}data/graphics/loading2.png"))
{
texLoading[1] = GL_NewTextureWithParams(DGL_RGBA, image.size.width, image.size.height, image.pixels, TXCF_NEVER_DEFER);
GL_DestroyImage(&image);
Image_Destroy(&image);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/ui/canvas.cpp
Expand Up @@ -235,7 +235,7 @@ void Canvas::grab(image_t* img, const QSize& outputSize)
{
QImage grabbed = grabImage(outputSize);

GL_InitImage(img);
Image_Init(img);
img->size.width = grabbed.width();
img->size.height = grabbed.height();
img->pixels = (uint8_t*) malloc(grabbed.byteCount());
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/ui/ui_main.c
Expand Up @@ -281,7 +281,7 @@ void UI_LoadTextures(void)
TXCF_NO_COMPRESSION, 0, GL_LINEAR, GL_LINEAR,
0 /*no anisotropy*/, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

GL_DestroyImage(&image);
Image_Destroy(&image);
}
else
uiTextures[i] = 0;
Expand Down

0 comments on commit 2d1792e

Please sign in to comment.