libwld: Now compiles without errors or warnings
This commit is contained in:
parent
6bad8f7676
commit
b1fea5ec10
@ -58,7 +58,7 @@ wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
|
|||||||
/* This is the palette to use for the selected world */
|
/* This is the palette to use for the selected world */
|
||||||
|
|
||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
RGBColor worldPalette[256];
|
color_rgb_t worldPalette[256];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is the maximum value + 1 of a texture code. */
|
/* This is the maximum value + 1 of a texture code. */
|
||||||
|
@ -78,20 +78,15 @@ enum
|
|||||||
* Public Type Definitions
|
* Public Type Definitions
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
typedef struct rgb_color_t
|
struct wld_bitmap_s
|
||||||
{
|
|
||||||
uint8_t red; /* red component of color 0-63 */
|
|
||||||
uint8_t green; /* green component of color 0-63 */
|
|
||||||
uint8_t blue; /* blue component of color 0-63 */
|
|
||||||
} RGBColor;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
{
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint16_t h;
|
uint16_t h;
|
||||||
uint8_t log2h;
|
uint8_t log2h;
|
||||||
trv_pixel_t *bm;
|
trv_pixel_t *bm;
|
||||||
} wld_bitmap_t;
|
};
|
||||||
|
|
||||||
|
typedef struct wld_bitmap_s wld_bitmap_t;
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Global Variables
|
* Global Variables
|
||||||
@ -109,7 +104,7 @@ extern wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
|
|||||||
/* This is the palette to use for the selected world */
|
/* This is the palette to use for the selected world */
|
||||||
|
|
||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
extern RGBColor worldPalette[256];
|
extern color_rgb_t worldPalette[256];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is the maximum value + 1 of a texture code */
|
/* This is the maximum value + 1 of a texture code */
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
* Included files
|
* Included files
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
|
#include "wld_color.h"
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Compilation switches
|
* Compilation switches
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
@ -64,46 +66,44 @@
|
|||||||
* Public Type Definitions
|
* Public Type Definitions
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
typedef enum
|
enum graphic_file_format_e
|
||||||
{
|
{
|
||||||
formatGIF87,
|
formatGIF87,
|
||||||
formatGIF89,
|
formatGIF89,
|
||||||
formatPPM,
|
formatPPM,
|
||||||
formatPCX,
|
formatPCX,
|
||||||
formatUnknown
|
formatUnknown
|
||||||
} graphic_file_format_t;
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum graphic_file_format_e graphic_file_format_t;
|
||||||
|
|
||||||
|
enum graphic_file_enum_e
|
||||||
{
|
{
|
||||||
gfTrueColor,
|
gfTrueColor,
|
||||||
gfPaletted
|
gfPaletted
|
||||||
} graphic_file_enum_t;
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef enum graphic_file_enum_e graphic_file_enum_t;
|
||||||
|
|
||||||
|
struct graphic_file_e
|
||||||
{
|
{
|
||||||
graphic_file_enum_t type;
|
graphic_file_enum_t type;
|
||||||
uint16_t height, width;
|
uint16_t height, width;
|
||||||
int palette_entries;
|
int palette_entries;
|
||||||
long transparent_entry;
|
long transparent_entry;
|
||||||
RGBColor *palette;
|
color_rgb_t *palette;
|
||||||
uint8_t *bitmap;
|
uint8_t *bitmap;
|
||||||
} graphic_file_t;
|
};
|
||||||
|
|
||||||
|
typedef struct graphic_file_e graphic_file_t;
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Global Function Prototypes
|
* Public Function Prototypes
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Global Variables
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Private Variables
|
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
graphic_file_t *wld_new_graphicfile(void);
|
graphic_file_t *wld_new_graphicfile(void);
|
||||||
void wld_free_graphicfile(graphic_file_t *gFile);
|
void wld_free_graphicfile(graphic_file_t *gFile);
|
||||||
RGBColor wld_graphicfile_pixel(graphic_file_t *gFile,
|
color_rgb_t wld_graphicfile_pixel(graphic_file_t *gFile,
|
||||||
int x, int y);
|
int x, int y);
|
||||||
graphic_file_t *wld_readgraphic_file(char *filename);
|
graphic_file_t *wld_readgraphic_file(char *filename);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
* Description:
|
* Description:
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
RGBColor wld_graphicfile_pixel(graphic_file_t *gfile, int x, int y)
|
color_rgb_t wld_graphicfile_pixel(graphic_file_t *gfile, int x, int y)
|
||||||
{
|
{
|
||||||
if (gfile->type == gfPaletted)
|
if (gfile->type == gfPaletted)
|
||||||
{
|
{
|
||||||
@ -62,7 +62,7 @@ RGBColor wld_graphicfile_pixel(graphic_file_t *gfile, int x, int y)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char *pixel = gfile->bitmap + (y * gfile->width + x) * 3;
|
unsigned char *pixel = gfile->bitmap + (y * gfile->width + x) * 3;
|
||||||
RGBColor rgb;
|
color_rgb_t rgb;
|
||||||
|
|
||||||
rgb.red = *pixel++;
|
rgb.red = *pixel++;
|
||||||
rgb.green = *pixel++;
|
rgb.green = *pixel++;
|
||||||
|
@ -129,12 +129,12 @@ static bool wld_read_filename(FILE * fp, char *fileName)
|
|||||||
static uint8_t wld_load_bitmaps(FILE * fp)
|
static uint8_t wld_load_bitmaps(FILE * fp)
|
||||||
{
|
{
|
||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
volatile pcxPicture workPCX;
|
volatile pcx_picture_t pcx;
|
||||||
RGBColor *palette;
|
color_rgb_t *palette;
|
||||||
#endif
|
#endif
|
||||||
uint16_t bMapIndex;
|
uint16_t mapndx;
|
||||||
uint8_t result = BMAP_SUCCESS;
|
uint8_t result = BMAP_SUCCESS;
|
||||||
uint8_t graphicsFileName[FILE_NAME_SIZE];
|
char filename[FILE_NAME_SIZE];
|
||||||
|
|
||||||
/* Discard any bitmaps that we may currently have buffered */
|
/* Discard any bitmaps that we may currently have buffered */
|
||||||
|
|
||||||
@ -160,13 +160,12 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
|
|
||||||
/* Load each bitmap file */
|
/* Load each bitmap file */
|
||||||
|
|
||||||
for (bMapIndex = 0;
|
for (mapndx = 0; (mapndx < g_nbitmaps && result == BMAP_SUCCESS); mapndx++)
|
||||||
((bMapIndex < g_nbitmaps) && (result == BMAP_SUCCESS)); bMapIndex++)
|
|
||||||
{
|
{
|
||||||
/* Load the even bitmap */
|
/* Load the even bitmap */
|
||||||
/* Get the name of the file which contains the even bitmap */
|
/* Get the name of the file which contains the even bitmap */
|
||||||
|
|
||||||
if (!wld_read_filename(fp, graphicsFileName))
|
if (!wld_read_filename(fp, filename))
|
||||||
{
|
{
|
||||||
return BMAP_BML_READ_ERROR;
|
return BMAP_BML_READ_ERROR;
|
||||||
}
|
}
|
||||||
@ -174,7 +173,7 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
/* Setup to load the PCX bitmap from the file for the event bitmap */
|
/* Setup to load the PCX bitmap from the file for the event bitmap */
|
||||||
|
|
||||||
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
|
result = wld_pcx_init(&pcx, BITMAP_HEIGHT, BITMAP_WIDTH,
|
||||||
palette, NULL);
|
palette, NULL);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
@ -183,14 +182,14 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
|
|
||||||
/* Put the bitmap buffer into the evenBitmap list */
|
/* Put the bitmap buffer into the evenBitmap list */
|
||||||
|
|
||||||
g_even_bitmaps[bMapIndex].w = BITMAP_WIDTH;
|
g_even_bitmaps[mapndx].w = BITMAP_WIDTH;
|
||||||
g_even_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
g_even_bitmaps[mapndx].h = BITMAP_HEIGHT;
|
||||||
g_even_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
g_even_bitmaps[mapndx].log2h = BITMAP_LOG2H;
|
||||||
g_even_bitmaps[bMapIndex].bm = workPCX.buffer;
|
g_even_bitmaps[mapndx].bm = pcx.buffer;
|
||||||
|
|
||||||
/* Load the PCX bitmap from the file for the event bitmap */
|
/* Load the PCX bitmap from the file for the event bitmap */
|
||||||
|
|
||||||
result = wld_loadpcx(graphicsFileName, &workPCX);
|
result = wld_loadpcx(filename, &pcx);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
@ -201,8 +200,8 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
|
|
||||||
palette = NULL;
|
palette = NULL;
|
||||||
#else
|
#else
|
||||||
g_even_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
g_even_bitmaps[mapndx] = wld_read_texturefile(filename);
|
||||||
if (!g_even_bitmaps[bMapIndex])
|
if (!g_even_bitmaps[mapndx])
|
||||||
{
|
{
|
||||||
return BMAP_BML_READ_ERROR;
|
return BMAP_BML_READ_ERROR;
|
||||||
}
|
}
|
||||||
@ -211,7 +210,7 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
/* Load the odd bitmap */
|
/* Load the odd bitmap */
|
||||||
/* Get the name of the file which contains the odd bitmap */
|
/* Get the name of the file which contains the odd bitmap */
|
||||||
|
|
||||||
if (!wld_read_filename(fp, graphicsFileName))
|
if (!wld_read_filename(fp, filename))
|
||||||
{
|
{
|
||||||
return BMAP_BML_READ_ERROR;
|
return BMAP_BML_READ_ERROR;
|
||||||
}
|
}
|
||||||
@ -220,7 +219,7 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
# if MSWINDOWS
|
# if MSWINDOWS
|
||||||
/* Setup to load the PCX bitmap from the file for the odd bitmap */
|
/* Setup to load the PCX bitmap from the file for the odd bitmap */
|
||||||
|
|
||||||
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
|
result = wld_pcx_init(&pcx, BITMAP_HEIGHT, BITMAP_WIDTH,
|
||||||
palette, NULL);
|
palette, NULL);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
@ -229,17 +228,17 @@ static uint8_t wld_load_bitmaps(FILE * fp)
|
|||||||
|
|
||||||
/* Put the bitmap buffer into the oddBitmap list */
|
/* Put the bitmap buffer into the oddBitmap list */
|
||||||
|
|
||||||
g_odd_bitmaps[bMapIndex].w = BITMAP_WIDTH;
|
g_odd_bitmaps[mapndx].w = BITMAP_WIDTH;
|
||||||
g_odd_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
g_odd_bitmaps[mapndx].h = BITMAP_HEIGHT;
|
||||||
g_odd_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
g_odd_bitmaps[mapndx].log2h = BITMAP_LOG2H;
|
||||||
g_odd_bitmaps[bMapIndex].bm = workPCX.buffer;
|
g_odd_bitmaps[mapndx].bm = pcx.buffer;
|
||||||
|
|
||||||
/* Load the PCX bitmap from the file for the odd bitmap */
|
/* Load the PCX bitmap from the file for the odd bitmap */
|
||||||
|
|
||||||
result = wld_loadpcx(graphicsFileName, &workPCX);
|
result = wld_loadpcx(filename, &pcx);
|
||||||
# else
|
# else
|
||||||
g_odd_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
g_odd_bitmaps[mapndx] = wld_read_texturefile(filename);
|
||||||
if (!g_odd_bitmaps[bMapIndex])
|
if (!g_odd_bitmaps[mapndx])
|
||||||
{
|
{
|
||||||
return BMAP_BML_READ_ERROR;
|
return BMAP_BML_READ_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -254,9 +254,9 @@ graphic_file_t *wld_LoadGIF(FILE * fp, char *fname)
|
|||||||
if (fread(ptr, filesize, 1, fp) != 1)
|
if (fread(ptr, filesize, 1, fp) != 1)
|
||||||
wld_fatal_error("GIF data read failed");
|
wld_fatal_error("GIF data read failed");
|
||||||
|
|
||||||
if (strncmp(ptr, id87, 6))
|
if (strncmp((char *)ptr, id87, 6))
|
||||||
{
|
{
|
||||||
if (strncmp(ptr, id89, 6))
|
if (strncmp((char *)ptr, id89, 6))
|
||||||
{
|
{
|
||||||
wld_fatal_error("not a GIF file");
|
wld_fatal_error("not a GIF file");
|
||||||
}
|
}
|
||||||
@ -367,7 +367,7 @@ graphic_file_t *wld_LoadGIF(FILE * fp, char *fname)
|
|||||||
Width, Height, (Interlace) ? "" : "non-");
|
Width, Height, (Interlace) ? "" : "non-");
|
||||||
|
|
||||||
gfile = wld_new_graphicfile();
|
gfile = wld_new_graphicfile();
|
||||||
gfile->palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * ColorMapSize);
|
gfile->palette = (color_rgb_t *) wld_malloc(sizeof(color_rgb_t) * ColorMapSize);
|
||||||
for (i = 0; i < ColorMapSize; i++)
|
for (i = 0; i < ColorMapSize; i++)
|
||||||
{
|
{
|
||||||
gfile->palette[i].red = Red[i];
|
gfile->palette[i].red = Red[i];
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/graphics/traveler/tools/libwld/wld_loadpcx.c
|
* apps/graphics/traveler/tools/libwld/wld_loadpcx.c
|
||||||
|
* This file contains the logic which loads a PCX file.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -33,15 +34,6 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* FILE: wld_loadpcx.c
|
|
||||||
* DESCRIPTION: This file contains the logic which loads a PCX file.
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Compilation Options
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Included files
|
* Included files
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
@ -56,130 +48,25 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "wld_pcx.h"
|
#include "wld_pcx.h"
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Definitions
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Private Type Definitions
|
|
||||||
************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
static void wld_loadpcxHeader(FILE * fp, pcxHeader * header);
|
static void wld_loadpcxHeader(FILE * fp, pcx_header_t * header);
|
||||||
static void wld_loadpcxData(FILE * fp, int32_t imagSize, uint8_t * imageBuffer);
|
static void wld_loadpcxData(FILE * fp, int32_t imagSize, uint8_t * imageBuffer);
|
||||||
static void wld_loadpcxPalette(FILE * fp, RGBColor * palette);
|
static void wld_loadpcxPalette(FILE * fp, color_rgb_t * palette);
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Global Variables
|
* Private Functions
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Private Variables
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* Name: wld_loadpcx
|
|
||||||
* Description:
|
|
||||||
* This function loads a pcx file into a picture structure, the actual image
|
|
||||||
* data for the pcx file is decompressed and expanded into a secondary buffer
|
|
||||||
* within the picture structure, the separate images can be grabbed from this
|
|
||||||
* buffer later. also the header and palette are loaded
|
|
||||||
************************************************************************/
|
|
||||||
|
|
||||||
#if MSWINDOWS
|
|
||||||
uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
|
|
||||||
{
|
|
||||||
FILE *fp, *fopen();
|
|
||||||
uint16_t imageWidth, imageHeight;
|
|
||||||
uint32_t imageSize;
|
|
||||||
|
|
||||||
/* Open the file */
|
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
|
||||||
if (!fp)
|
|
||||||
{
|
|
||||||
return PCX_OPEN_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Load the PCX Header */
|
|
||||||
|
|
||||||
wld_loadpcxHeader(fp, &image->header);
|
|
||||||
|
|
||||||
/* Load the PCX data */
|
|
||||||
|
|
||||||
if (image->buffer)
|
|
||||||
{
|
|
||||||
imageWidth = image->header.width - image->header.x + 1;
|
|
||||||
imageHeight = image->header.height - image->header.y + 1;
|
|
||||||
imageSize = imageHeight * imageWidth;
|
|
||||||
wld_loadpcxData(fp, imageSize, image->buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Load the PCX palette */
|
|
||||||
|
|
||||||
if (image->palette)
|
|
||||||
{
|
|
||||||
wld_loadpcxPalette(fp, &image->palette);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
return PCX_SUCCESS;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
graphic_file_t *wld_loadpcx(FILE * fp, char *filename)
|
|
||||||
{
|
|
||||||
pcxHeader header;
|
|
||||||
trv_pixel_t *buffer;
|
|
||||||
graphic_file_t *gFile;
|
|
||||||
RGBColor *palette;
|
|
||||||
uint16_t imageWidth, imageHeight;
|
|
||||||
uint32_t imageSize;
|
|
||||||
|
|
||||||
/* Load the PCX Header */
|
|
||||||
|
|
||||||
wld_loadpcxHeader(fp, &header);
|
|
||||||
|
|
||||||
/* Allocate Space to hold the image data */
|
|
||||||
|
|
||||||
imageWidth = header.width - header.x + 1;
|
|
||||||
imageHeight = header.height - header.y + 1;
|
|
||||||
imageSize = imageHeight * imageWidth * sizeof(trv_pixel_t);
|
|
||||||
buffer = (trv_pixel_t *) wld_malloc(imageSize + 1);
|
|
||||||
|
|
||||||
/* Load the PCX data into the buffer */
|
|
||||||
|
|
||||||
wld_loadpcxData(fp, imageSize, (uint8_t *) buffer);
|
|
||||||
|
|
||||||
/* Allocate space to hold the PCX palette */
|
|
||||||
|
|
||||||
palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * 256);
|
|
||||||
|
|
||||||
/* Load the PCX palette */
|
|
||||||
|
|
||||||
wld_loadpcxPalette(fp, palette);
|
|
||||||
|
|
||||||
/* Now save the resulting data in a graphic_file_t structure */
|
|
||||||
|
|
||||||
gFile = wld_new_graphicfile();
|
|
||||||
gFile->type = gfPaletted;
|
|
||||||
gFile->palette = palette;
|
|
||||||
gFile->width = imageWidth;
|
|
||||||
gFile->height = imageHeight;
|
|
||||||
gFile->bitmap = buffer;
|
|
||||||
|
|
||||||
return gFile;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Name: wld_loadpcxHeader
|
* Name: wld_loadpcxHeader
|
||||||
* Description:
|
* Description:
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
static void wld_loadpcxHeader(FILE * fp, pcxHeader * header)
|
static void wld_loadpcxHeader(FILE * fp, pcx_header_t * header)
|
||||||
{
|
{
|
||||||
uint8_t *tempBuffer;
|
uint8_t *tempBuffer;
|
||||||
int i;
|
int i;
|
||||||
@ -245,7 +132,7 @@ static void wld_loadpcxData(FILE * fp, int32_t imageSize, uint8_t * imageBuffer)
|
|||||||
* Description:
|
* Description:
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
static void wld_loadpcxPalette(FILE * fp, RGBColor * palette)
|
static void wld_loadpcxPalette(FILE * fp, color_rgb_t * palette)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -270,3 +157,101 @@ static void wld_loadpcxPalette(FILE * fp, RGBColor * palette)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* Name: wld_loadpcx
|
||||||
|
* Description:
|
||||||
|
* This function loads a pcx file into a picture structure, the actual image
|
||||||
|
* data for the pcx file is decompressed and expanded into a secondary buffer
|
||||||
|
* within the picture structure, the separate images can be grabbed from this
|
||||||
|
* buffer later. also the header and palette are loaded
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if MSWINDOWS
|
||||||
|
uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
|
||||||
|
{
|
||||||
|
FILE *fp, *fopen();
|
||||||
|
uint16_t imageWidth, imageHeight;
|
||||||
|
uint32_t imageSize;
|
||||||
|
|
||||||
|
/* Open the file */
|
||||||
|
|
||||||
|
fp = fopen(filename, "rb");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
return PCX_OPEN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load the PCX Header */
|
||||||
|
|
||||||
|
wld_loadpcxHeader(fp, &image->header);
|
||||||
|
|
||||||
|
/* Load the PCX data */
|
||||||
|
|
||||||
|
if (image->buffer)
|
||||||
|
{
|
||||||
|
imageWidth = image->header.width - image->header.x + 1;
|
||||||
|
imageHeight = image->header.height - image->header.y + 1;
|
||||||
|
imageSize = imageHeight * imageWidth;
|
||||||
|
wld_loadpcxData(fp, imageSize, image->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load the PCX palette */
|
||||||
|
|
||||||
|
if (image->palette)
|
||||||
|
{
|
||||||
|
wld_loadpcxPalette(fp, &image->palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return PCX_SUCCESS;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
graphic_file_t *wld_loadpcx(FILE * fp, char *filename)
|
||||||
|
{
|
||||||
|
pcx_header_t header;
|
||||||
|
trv_pixel_t *buffer;
|
||||||
|
graphic_file_t *gFile;
|
||||||
|
color_rgb_t *palette;
|
||||||
|
uint16_t imageWidth, imageHeight;
|
||||||
|
uint32_t imageSize;
|
||||||
|
|
||||||
|
/* Load the PCX Header */
|
||||||
|
|
||||||
|
wld_loadpcxHeader(fp, &header);
|
||||||
|
|
||||||
|
/* Allocate Space to hold the image data */
|
||||||
|
|
||||||
|
imageWidth = header.width - header.x + 1;
|
||||||
|
imageHeight = header.height - header.y + 1;
|
||||||
|
imageSize = imageHeight * imageWidth * sizeof(trv_pixel_t);
|
||||||
|
buffer = (trv_pixel_t *) wld_malloc(imageSize + 1);
|
||||||
|
|
||||||
|
/* Load the PCX data into the buffer */
|
||||||
|
|
||||||
|
wld_loadpcxData(fp, imageSize, (uint8_t *) buffer);
|
||||||
|
|
||||||
|
/* Allocate space to hold the PCX palette */
|
||||||
|
|
||||||
|
palette = (color_rgb_t *) wld_malloc(sizeof(color_rgb_t) * 256);
|
||||||
|
|
||||||
|
/* Load the PCX palette */
|
||||||
|
|
||||||
|
wld_loadpcxPalette(fp, palette);
|
||||||
|
|
||||||
|
/* Now save the resulting data in a graphic_file_t structure */
|
||||||
|
|
||||||
|
gFile = wld_new_graphicfile();
|
||||||
|
gFile->type = gfPaletted;
|
||||||
|
gFile->palette = palette;
|
||||||
|
gFile->width = imageWidth;
|
||||||
|
gFile->height = imageHeight;
|
||||||
|
gFile->bitmap = buffer;
|
||||||
|
|
||||||
|
return gFile;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -225,7 +225,7 @@ trv_pixel_t wld_color_lum2pixel(color_lum_t * lum)
|
|||||||
* to a wider representation.
|
* to a wider representation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return TRV_UVLUM2NDX(uvndx, lumndx);
|
return WLD_UVLUM2NDX(uvndx, lumndx);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
color_rgb_t rgb;
|
color_rgb_t rgb;
|
||||||
|
@ -63,7 +63,7 @@ enum
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct pcx_header_t
|
struct pcx_header_s
|
||||||
{
|
{
|
||||||
char manufacturer;
|
char manufacturer;
|
||||||
char version;
|
char version;
|
||||||
@ -79,17 +79,23 @@ typedef struct pcx_header_t
|
|||||||
int16_t bytes_per_line;
|
int16_t bytes_per_line;
|
||||||
int16_t palette_type;
|
int16_t palette_type;
|
||||||
char padding[58];
|
char padding[58];
|
||||||
} pcxHeader, *pcxHeaderPtr;
|
};
|
||||||
|
|
||||||
|
typedef struct pcx_header_s pcx_header_t;
|
||||||
|
typedef struct pcx_header_s *pcx_pheader_t;
|
||||||
|
|
||||||
#define SIZEOF_PCX_HEADER 128
|
#define SIZEOF_PCX_HEADER 128
|
||||||
|
|
||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
typedef struct pcx_picture_t
|
struct pcx_picture_t
|
||||||
{
|
{
|
||||||
pcxHeader header;
|
pcx_header_t header;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
RGBColor *palette;
|
color_rgb_t *palette;
|
||||||
} pcxPicture, *pcxPicturePtr;
|
};
|
||||||
|
|
||||||
|
typedef struct pcx_picture_t
|
||||||
|
typedef struct pcx_ppicture_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@ -97,9 +103,9 @@ typedef struct pcx_picture_t
|
|||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#if MSWINDOWS
|
#if MSWINDOWS
|
||||||
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
|
uint8_t wld_pcx_init(pcxppicture_t image, uint16_t height, uint16_t width,
|
||||||
RGBColor *palette, uint8_t *buffer);
|
color_rgb_t *palette, uint8_t *buffer);
|
||||||
uint8_t wld_loadpcx(char *filename, pcxPicturePtr image);
|
uint8_t wld_loadpcx(char *filename, pcxppicture_t image);
|
||||||
#else
|
#else
|
||||||
graphic_file_t *wld_loadpcx(FILE *fp, char *filename);
|
graphic_file_t *wld_loadpcx(FILE *fp, char *filename);
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
|
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
|
||||||
RGBColor * palette, uint8_t * buffer)
|
color_rgb_t * palette, uint8_t * buffer)
|
||||||
{
|
{
|
||||||
image->palette = palette;
|
image->palette = palette;
|
||||||
|
|
||||||
|
@ -46,11 +46,9 @@
|
|||||||
#include "wld_color.h"
|
#include "wld_color.h"
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Private Data
|
* Public Functions
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
static float g_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE - 1);
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Function: wld_pixel2lum
|
* Function: wld_pixel2lum
|
||||||
* Description: Convert a pixel value into RGB-Luminance value.
|
* Description: Convert a pixel value into RGB-Luminance value.
|
||||||
@ -69,7 +67,8 @@ void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t * lum)
|
|||||||
/* Get the luminance associated with the RGB value */
|
/* Get the luminance associated with the RGB value */
|
||||||
|
|
||||||
lum->luminance = sqrt(lum->red * lum->red +
|
lum->luminance = sqrt(lum->red * lum->red +
|
||||||
lum->green * lum->green + lum->blue * lum->blue);
|
lum->green * lum->green +
|
||||||
|
lum->blue * lum->blue);
|
||||||
|
|
||||||
/* Convert the RGB Component into unit vector + luminance */
|
/* Convert the RGB Component into unit vector + luminance */
|
||||||
|
|
||||||
|
@ -41,8 +41,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "trv_types.h"
|
#include "trv_types.h"
|
||||||
#include "wld_bitmaps.h"
|
#include "wld_bitmaps.h"
|
||||||
|
#include "wld_color.h"
|
||||||
#include "wld_mem.h"
|
#include "wld_mem.h"
|
||||||
#include "wld_graphicfile.h"
|
#include "wld_graphicfile.h"
|
||||||
#include "wld_utils.h"
|
#include "wld_utils.h"
|
||||||
@ -126,16 +128,17 @@ static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
|
|||||||
|
|
||||||
static void wld_quantize_texture(graphic_file_t * gFile, wld_bitmap_t * t)
|
static void wld_quantize_texture(graphic_file_t * gFile, wld_bitmap_t * t)
|
||||||
{
|
{
|
||||||
RGBColor pixel;
|
color_rgb_t pixel;
|
||||||
trv_pixel_t *destPixel = t->bm;
|
trv_pixel_t *dest = t->bm;
|
||||||
int x, y;
|
int x;
|
||||||
|
int y;
|
||||||
|
|
||||||
for (x = gFile->width - 1; x >= 0; x--)
|
for (x = gFile->width - 1; x >= 0; x--)
|
||||||
{
|
{
|
||||||
for (y = gFile->height - 1; y >= 0; y--)
|
for (y = gFile->height - 1; y >= 0; y--)
|
||||||
{
|
{
|
||||||
pixel = wld_graphicfile_pixel(gFile, x, y);
|
pixel = wld_graphicfile_pixel(gFile, x, y);
|
||||||
*destPixel++ = wld_Rgb2Pixel(&pixel);
|
*dest++ = wld_rgb2pixel(&pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user