Run some .c files throut nuttx/tools/indents.sh
This commit is contained in:
parent
85ba39f596
commit
8db489ed8c
@ -52,32 +52,32 @@
|
||||
* This function adds a plane to a world plane list
|
||||
************************************************************************/
|
||||
|
||||
void wld_add_plane(rect_list_t *newRect, rect_head_t *list)
|
||||
void wld_add_plane(rect_list_t * newRect, rect_head_t * list)
|
||||
{
|
||||
rect_list_t *nextRect, *prevRect;
|
||||
|
||||
/* Search the list to find the location to insert the new rectangle.
|
||||
* Each is list is maintained in ascending plane order.
|
||||
/* Search the list to find the location to insert the new rectangle. Each
|
||||
* list is maintained in ascending plane order.
|
||||
*/
|
||||
|
||||
for (nextRect = list->head;
|
||||
((nextRect) && (nextRect->d.plane < newRect->d.plane));
|
||||
nextRect = nextRect->flink);
|
||||
|
||||
/* Add the newRect to the spot found in the list. Check if the newRect
|
||||
* goes at the end of the list.
|
||||
/* Add the newRect to the spot found in the list. Check if the newRect goes
|
||||
* at the end of the list.
|
||||
*/
|
||||
|
||||
if (!nextRect)
|
||||
{
|
||||
/* No rectangle with plane larger than the one to be added was
|
||||
* found in the list. The newRect goes at the end of the list.
|
||||
/* No rectangle with plane larger than the one to be added was found in
|
||||
* the list. The newRect goes at the end of the list.
|
||||
*/
|
||||
|
||||
prevRect = list->tail;
|
||||
if (!prevRect)
|
||||
{
|
||||
/* Special case: The list is empty */
|
||||
/* Special case: The list is empty */
|
||||
|
||||
newRect->flink = NULL;
|
||||
newRect->blink = NULL;
|
||||
@ -99,7 +99,7 @@ void wld_add_plane(rect_list_t *newRect, rect_head_t *list)
|
||||
prevRect = nextRect->blink;
|
||||
if (!prevRect)
|
||||
{
|
||||
/* Special case: Insert at the head of the list */
|
||||
/* Special case: Insert at the head of the list */
|
||||
|
||||
newRect->flink = nextRect;
|
||||
newRect->blink = NULL;
|
||||
|
@ -50,9 +50,9 @@
|
||||
* bitmaps
|
||||
*/
|
||||
|
||||
wld_bitmap_t *evenBitmaps[MAX_BITMAPS];
|
||||
wld_bitmap_t *g_even_bitmaps[MAX_BITMAPS];
|
||||
#ifndef WEDIT
|
||||
wld_bitmap_t *oddBitmaps[MAX_BITMAPS];
|
||||
wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
|
||||
#endif
|
||||
|
||||
/* This is the palette to use for the selected world */
|
||||
@ -63,7 +63,7 @@ RGBColor worldPalette[256];
|
||||
|
||||
/* This is the maximum value + 1 of a texture code. */
|
||||
|
||||
uint16_t numBitmaps;
|
||||
uint16_t g_nbitmaps;
|
||||
|
||||
/* These are the colors from the worldPalette which should used to rend
|
||||
* the sky and ground
|
||||
|
@ -101,9 +101,9 @@ typedef struct
|
||||
* bitmaps
|
||||
*/
|
||||
|
||||
extern wld_bitmap_t *evenBitmaps[MAX_BITMAPS];
|
||||
extern wld_bitmap_t *g_even_bitmaps[MAX_BITMAPS];
|
||||
#ifndef WEDIT
|
||||
extern wld_bitmap_t *oddBitmaps[MAX_BITMAPS];
|
||||
extern wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
|
||||
#endif
|
||||
|
||||
/* This is the palette to use for the selected world */
|
||||
@ -114,7 +114,7 @@ extern RGBColor worldPalette[256];
|
||||
|
||||
/* This is the maximum value + 1 of a texture code */
|
||||
|
||||
extern uint16_t numBitmaps;
|
||||
extern uint16_t g_nbitmaps;
|
||||
|
||||
/* These are the colors from the worldPalette which should used to rend
|
||||
* the sky and ground
|
||||
|
@ -126,43 +126,50 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
|
||||
/* Read the initial camera/player position */
|
||||
|
||||
result = wld_read_shortint(handle, &g_initial_camera.x,
|
||||
g_camera_section_name,
|
||||
g_camera_initialx_name);
|
||||
g_camera_section_name, g_camera_initialx_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_read_shortint(handle, &g_initial_camera.y,
|
||||
g_camera_section_name,
|
||||
g_camera_initialy_name);
|
||||
g_camera_section_name, g_camera_initialy_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_read_shortint(handle, &g_initial_camera.z,
|
||||
g_camera_section_name,
|
||||
g_camera_initialz_name);
|
||||
g_camera_section_name, g_camera_initialz_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Get the player's yaw/pitch orientation */
|
||||
|
||||
result = wld_read_shortint(handle, &g_initial_camera.yaw,
|
||||
g_camera_section_name,
|
||||
g_camera_initialyaw_name);
|
||||
g_camera_section_name, g_camera_initialyaw_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_read_shortint(handle, &g_initial_camera.pitch,
|
||||
g_camera_section_name, g_camera_initialpitch_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Get the height of the player */
|
||||
|
||||
result = wld_read_shortint(handle, &playerHeight,
|
||||
g_player_section_name,
|
||||
g_player_height_name);
|
||||
g_player_section_name, g_player_height_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Read the player's capability to step on top of things in the world. */
|
||||
|
||||
@ -170,33 +177,45 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
|
||||
g_player_section_name,
|
||||
g_player_walk_stepheight_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_read_shortint(handle, &runStepHeight,
|
||||
g_player_section_name,
|
||||
g_player_run_stepheight_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Get the name of the file containing the world map */
|
||||
|
||||
result = wld_read_filename(handle, &filename,
|
||||
g_world_section_name,
|
||||
g_wold_map_name);
|
||||
g_world_section_name, g_wold_map_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (filename == NULL)
|
||||
return WORLD_PLANE_FILE_NAME_ERROR;
|
||||
{
|
||||
return WORLD_PLANE_FILE_NAME_ERROR;
|
||||
}
|
||||
|
||||
/* Allocate and load the world */
|
||||
|
||||
result = wld_initialize_planes();
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_load_planefile(filename);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
inifile_free_string(filename);
|
||||
|
||||
@ -206,15 +225,22 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
|
||||
result = wld_read_filename(handle, &filename, g_world_section_name,
|
||||
g_world_palette_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (filename == NULL)
|
||||
return WORLD_PALR_FILE_NAME_ERROR;
|
||||
{
|
||||
return WORLD_PALR_FILE_NAME_ERROR;
|
||||
}
|
||||
|
||||
/* Then load it into g_pal_table. */
|
||||
|
||||
result = wld_load_paltable(filename);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
inifile_free_string(filename);
|
||||
|
||||
@ -223,9 +249,14 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
|
||||
result = wld_read_filename(handle, &filename, g_world_section_name,
|
||||
g_world_images_name);
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (filename == NULL)
|
||||
return WORLD_BITMAP_FILE_NAME_ERROR;
|
||||
{
|
||||
return WORLD_BITMAP_FILE_NAME_ERROR;
|
||||
}
|
||||
|
||||
/* Create the RGB lookup table */
|
||||
|
||||
@ -235,7 +266,9 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
|
||||
|
||||
result = wld_initialize_bitmaps();
|
||||
if (result != 0)
|
||||
return result;
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = wld_load_bitmapfile(filename);
|
||||
inifile_free_string(filename);
|
||||
@ -329,8 +362,7 @@ static uint8_t wld_read_filename(INIHANDLE handle,
|
||||
{
|
||||
/* Read the string from the ini file. We supply the default value of NULL.
|
||||
* If this value is returned, we assume that that is evidence that the
|
||||
* requested value was not supplied in the ini file.
|
||||
*/
|
||||
* requested value was not supplied in the ini file. */
|
||||
|
||||
char *value = inifile_read_string(handle, section_name, variable_name,
|
||||
NULL);
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "wld_world.h"
|
||||
#include "wld_bitmaps.h"
|
||||
#if (MSWINDOWS)
|
||||
#include "wld_pcx.h"
|
||||
# include "wld_pcx.h"
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
@ -63,20 +63,20 @@ void wld_discard_bitmaps(void)
|
||||
int i;
|
||||
for (i = 0; i < MAX_BITMAPS; i++)
|
||||
{
|
||||
if (evenBitmaps[i])
|
||||
if (g_even_bitmaps[i])
|
||||
{
|
||||
wld_free_texture((void*)evenBitmaps[i]);
|
||||
evenBitmaps[i] = NULL;
|
||||
wld_free_texture((void *)g_even_bitmaps[i]);
|
||||
g_even_bitmaps[i] = NULL;
|
||||
}
|
||||
|
||||
#ifndef WEDIT
|
||||
if (oddBitmaps[i])
|
||||
if (g_odd_bitmaps[i])
|
||||
{
|
||||
wld_free_texture((void*)oddBitmaps[i]);
|
||||
oddBitmaps[i] = NULL;
|
||||
wld_free_texture((void *)g_odd_bitmaps[i]);
|
||||
g_odd_bitmaps[i] = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
numBitmaps = 0;
|
||||
g_nbitmaps = 0;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@
|
||||
void wld_discard_paltable(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_ZONES; i++)
|
||||
{
|
||||
if (g_pal_table[i])
|
||||
|
@ -53,14 +53,14 @@
|
||||
* This function deallocates one plane of the world
|
||||
************************************************************************/
|
||||
|
||||
static void wld_DiscardWorldPlane(rect_list_t *rect)
|
||||
static void wld_DiscardWorldPlane(rect_list_t * rect)
|
||||
{
|
||||
rect_list_t *next;
|
||||
|
||||
while (rect)
|
||||
{
|
||||
next = rect->flink;
|
||||
wld_free((void *) rect);
|
||||
wld_free((void *)rect);
|
||||
rect = next;
|
||||
}
|
||||
}
|
||||
@ -77,13 +77,12 @@ static void wld_DiscardWorldPlane(rect_list_t *rect)
|
||||
|
||||
void wld_discard_planes(void)
|
||||
{
|
||||
wld_DiscardWorldPlane(xPlane.head);
|
||||
xPlane.head = xPlane.tail = NULL;
|
||||
wld_DiscardWorldPlane(yPlane.head);
|
||||
yPlane.head = yPlane.tail = NULL;
|
||||
wld_DiscardWorldPlane(zPlane.head);
|
||||
zPlane.head = zPlane.tail = NULL;
|
||||
wld_DiscardWorldPlane(g_xplane_list.head);
|
||||
g_xplane_list.head = g_xplane_list.tail = NULL;
|
||||
wld_DiscardWorldPlane(g_yplane_list.head);
|
||||
g_yplane_list.head = g_yplane_list.tail = NULL;
|
||||
wld_DiscardWorldPlane(g_zplane_list.head);
|
||||
g_zplane_list.head = g_zplane_list.tail = NULL;
|
||||
wld_DiscardWorldPlane(freeList);
|
||||
freeList = NULL;
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,12 @@
|
||||
|
||||
void wld_fatal_error(char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
putc('\n', stderr);
|
||||
va_end(args);
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
putc('\n', stderr);
|
||||
va_end(args);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -55,36 +55,31 @@
|
||||
************************************************************************/
|
||||
|
||||
rect_list_t *wld_find_plane(wld_coord_t h, wld_coord_t v, wld_coord_t plane,
|
||||
rect_head_t *list)
|
||||
rect_head_t * list)
|
||||
{
|
||||
rect_list_t *rect;
|
||||
|
||||
/* Search until we find the first occurrence of a rectangle in the
|
||||
* specified plane
|
||||
/* Search until we find the first occurrence of a rectangle in the specified
|
||||
* plane.
|
||||
*/
|
||||
|
||||
for (rect = list->head;
|
||||
((rect) && (rect->d.plane < plane));
|
||||
rect = rect->flink);
|
||||
((rect) && (rect->d.plane < plane)); rect = rect->flink);
|
||||
|
||||
/* Then look at every occurrence of rectangles at this plane or
|
||||
* until a rectangle containing the specified point is found
|
||||
/* Then look at every occurrence of rectangles at this plane or until a
|
||||
* rectangle containing the specified point is found.
|
||||
*/
|
||||
|
||||
for (;
|
||||
((rect) && (rect->d.plane == plane));
|
||||
rect = rect->flink)
|
||||
for (; ((rect) && (rect->d.plane == plane)); rect = rect->flink)
|
||||
{
|
||||
/* There is another rectangle in this plane. Check if the
|
||||
* point lies within the rectangle.
|
||||
/* There is another rectangle in this plane. Check if the point lies
|
||||
* within the rectangle.
|
||||
*/
|
||||
|
||||
if ((h >= rect->d.hStart) && (h <= rect->d.hEnd)
|
||||
&& (v >= rect->d.vStart) && (v <= rect->d.vEnd))
|
||||
&& (v >= rect->d.vStart) && (v <= rect->d.vEnd))
|
||||
return rect;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
void wld_free_graphicfile(graphic_file_t *gfile)
|
||||
void wld_free_graphicfile(graphic_file_t * gfile)
|
||||
{
|
||||
if (gfile != NULL)
|
||||
{
|
||||
|
@ -52,8 +52,12 @@
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
void wld_free_texture(wld_bitmap_t *t)
|
||||
void wld_free_texture(wld_bitmap_t * t)
|
||||
{
|
||||
if (t->bm) wld_free(t->bm);
|
||||
if (t->bm)
|
||||
{
|
||||
wld_free(t->bm);
|
||||
}
|
||||
|
||||
wld_free(t);
|
||||
}
|
||||
|
@ -71,4 +71,3 @@ RGBColor wld_graphicfile_pixel(graphic_file_t *gfile, int x, int y)
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "wld_world.h"
|
||||
#include "wld_bitmaps.h"
|
||||
#if (MSWINDOWS)
|
||||
#include "wld_pcx.h"
|
||||
# include "wld_pcx.h"
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
@ -62,12 +62,12 @@ uint8_t wld_initialize_bitmaps(void)
|
||||
int i;
|
||||
for (i = 0; i < MAX_BITMAPS; i++)
|
||||
{
|
||||
evenBitmaps[i] = NULL;
|
||||
g_even_bitmaps[i] = NULL;
|
||||
#ifndef WEDIT
|
||||
oddBitmaps[i] = NULL;
|
||||
g_odd_bitmaps[i] = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
numBitmaps = 0;
|
||||
g_nbitmaps = 0;
|
||||
return BMAP_SUCCESS;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/****************************************************************************
|
||||
* apps/graphics/traveler/tools/libwld/wld_initializeplanes.c
|
||||
* This file contains the logic initialize world plane data structures
|
||||
@ -54,9 +55,9 @@
|
||||
|
||||
uint8_t wld_initialize_planes(void)
|
||||
{
|
||||
xPlane.head = xPlane.tail = NULL;
|
||||
yPlane.head = yPlane.tail = NULL;
|
||||
zPlane.head = zPlane.tail = NULL;
|
||||
g_xplane_list.head = g_xplane_list.tail = NULL;
|
||||
g_yplane_list.head = g_yplane_list.tail = NULL;
|
||||
g_zplane_list.head = g_zplane_list.tail = NULL;
|
||||
freeList = NULL;
|
||||
|
||||
return PLANE_SUCCESS;
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "wld_world.h"
|
||||
#include "wld_bitmaps.h"
|
||||
#if (MSWINDOWS)
|
||||
#include "wld_pcx.h"
|
||||
# include "wld_pcx.h"
|
||||
#endif
|
||||
#include "wld_utils.h"
|
||||
|
||||
@ -60,9 +60,9 @@
|
||||
* Read a file name from the input stream
|
||||
************************************************************************/
|
||||
|
||||
static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
static bool wld_read_filename(FILE * fp, char *fileName)
|
||||
{
|
||||
int16_t nbytes;
|
||||
int16_t nbytes;
|
||||
int ch;
|
||||
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for
|
||||
@ -72,7 +72,8 @@ static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
do
|
||||
{
|
||||
ch = getc(fp);
|
||||
if (ch == EOF) return false;
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
}
|
||||
while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
|
||||
|
||||
@ -87,7 +88,10 @@ static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
{
|
||||
/* Make sure that the file name is not too large */
|
||||
|
||||
if (nbytes >= FILE_NAME_SIZE) return false;
|
||||
if (nbytes >= FILE_NAME_SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Add the new character to the file name */
|
||||
|
||||
@ -102,10 +106,9 @@ static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get the character for the next time through the loop. Every file
|
||||
* name should be terminated with a space or a new line. EOF is
|
||||
* unexpected in this context.
|
||||
*/
|
||||
/* Get the character for the next time through the loop. Every file name
|
||||
* should be terminated with a space or a new line. EOF is unexpected in
|
||||
* this context. */
|
||||
|
||||
ch = getc(fp);
|
||||
if (ch == EOF)
|
||||
@ -123,15 +126,15 @@ static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
* This function loads the world data from the input file
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_load_bitmaps(FILE *fp)
|
||||
static uint8_t wld_load_bitmaps(FILE * fp)
|
||||
{
|
||||
#if MSWINDOWS
|
||||
volatile pcxPicture workPCX;
|
||||
RGBColor *palette;
|
||||
RGBColor *palette;
|
||||
#endif
|
||||
uint16_t bMapIndex;
|
||||
uint8_t result = BMAP_SUCCESS;
|
||||
uint8_t graphicsFileName[FILE_NAME_SIZE];
|
||||
uint16_t bMapIndex;
|
||||
uint8_t result = BMAP_SUCCESS;
|
||||
uint8_t graphicsFileName[FILE_NAME_SIZE];
|
||||
|
||||
/* Discard any bitmaps that we may currently have buffered */
|
||||
|
||||
@ -139,19 +142,18 @@ static uint8_t wld_load_bitmaps(FILE *fp)
|
||||
|
||||
/* Get the number of bitmaps in the bitmap file */
|
||||
|
||||
numBitmaps = wld_read_decimal(fp);
|
||||
if (numBitmaps >= MAX_BITMAPS)
|
||||
g_nbitmaps = wld_read_decimal(fp);
|
||||
if (g_nbitmaps >= MAX_BITMAPS)
|
||||
return BMAP_TOO_MANY;
|
||||
|
||||
/* Read the colors used to rend the sky and ground */
|
||||
|
||||
skyColor = wld_read_decimal(fp);
|
||||
skyColor = wld_read_decimal(fp);
|
||||
groundColor = wld_read_decimal(fp);
|
||||
|
||||
#if MSWINDOWS
|
||||
/* Load the textures -- Note that the first texture will be used
|
||||
* to define the worldPalette
|
||||
*/
|
||||
/* Load the textures -- Note that the first texture will be used to define
|
||||
* the worldPalette */
|
||||
|
||||
palette = worldPalette;
|
||||
#endif
|
||||
@ -159,74 +161,92 @@ static uint8_t wld_load_bitmaps(FILE *fp)
|
||||
/* Load each bitmap file */
|
||||
|
||||
for (bMapIndex = 0;
|
||||
((bMapIndex < numBitmaps) && (result == BMAP_SUCCESS));
|
||||
bMapIndex++)
|
||||
((bMapIndex < g_nbitmaps) && (result == BMAP_SUCCESS)); bMapIndex++)
|
||||
{
|
||||
/* Load the even bitmap */
|
||||
/* Get the name of the file which contains the even bitmap */
|
||||
|
||||
if (!wld_read_filename(fp, graphicsFileName))
|
||||
return BMAP_BML_READ_ERROR;
|
||||
{
|
||||
return BMAP_BML_READ_ERROR;
|
||||
}
|
||||
|
||||
#if MSWINDOWS
|
||||
/* Setup to load the PCX bitmap from the file for the event bitmap */
|
||||
|
||||
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
|
||||
palette, NULL);
|
||||
if (result) return result;
|
||||
palette, NULL);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Put the bitmap buffer into the evenBitmap list */
|
||||
|
||||
evenBitmaps[bMapIndex].w = BITMAP_WIDTH;
|
||||
evenBitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
||||
evenBitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
||||
evenBitmaps[bMapIndex].bm = workPCX.buffer;
|
||||
g_even_bitmaps[bMapIndex].w = BITMAP_WIDTH;
|
||||
g_even_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
||||
g_even_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
||||
g_even_bitmaps[bMapIndex].bm = workPCX.buffer;
|
||||
|
||||
/* Load the PCX bitmap from the file for the event bitmap */
|
||||
|
||||
result = wld_loadpcx(graphicsFileName, &workPCX);
|
||||
if (result) return result;
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Don't bother to load the palette on the rest of the textures --
|
||||
* we will assume the same palette for all textures.
|
||||
*/
|
||||
/* Don't bother to load the palette on the rest of the textures -- we
|
||||
* will assume the same palette for all textures. */
|
||||
|
||||
palette = NULL;
|
||||
#else
|
||||
evenBitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
||||
if (!evenBitmaps[bMapIndex]) return BMAP_BML_READ_ERROR;
|
||||
g_even_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
||||
if (!g_even_bitmaps[bMapIndex])
|
||||
{
|
||||
return BMAP_BML_READ_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Load the odd bitmap */
|
||||
/* Get the name of the file which contains the odd bitmap */
|
||||
|
||||
if (!wld_read_filename(fp, graphicsFileName))
|
||||
return BMAP_BML_READ_ERROR;
|
||||
{
|
||||
return BMAP_BML_READ_ERROR;
|
||||
}
|
||||
|
||||
#ifndef WEDIT
|
||||
#if MSWINDOWS
|
||||
# if MSWINDOWS
|
||||
/* Setup to load the PCX bitmap from the file for the odd bitmap */
|
||||
|
||||
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
|
||||
palette, NULL);
|
||||
if (result) return result;
|
||||
palette, NULL);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Put the bitmap buffer into the oddBitmap list */
|
||||
|
||||
oddBitmaps[bMapIndex].w = BITMAP_WIDTH;
|
||||
oddBitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
||||
oddBitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
||||
oddBitmaps[bMapIndex].bm = workPCX.buffer;
|
||||
g_odd_bitmaps[bMapIndex].w = BITMAP_WIDTH;
|
||||
g_odd_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
|
||||
g_odd_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
|
||||
g_odd_bitmaps[bMapIndex].bm = workPCX.buffer;
|
||||
|
||||
/* Load the PCX bitmap from the file for the odd bitmap */
|
||||
|
||||
result = wld_loadpcx(graphicsFileName, &workPCX);
|
||||
#else
|
||||
oddBitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
||||
if (!oddBitmaps[bMapIndex]) return BMAP_BML_READ_ERROR;
|
||||
#endif
|
||||
# else
|
||||
g_odd_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
|
||||
if (!g_odd_bitmaps[bMapIndex])
|
||||
{
|
||||
return BMAP_BML_READ_ERROR;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -242,18 +262,20 @@ static uint8_t wld_load_bitmaps(FILE *fp)
|
||||
|
||||
uint8_t wld_load_bitmapfile(char *bmlFile)
|
||||
{
|
||||
FILE *fp;
|
||||
uint8_t result;
|
||||
FILE *fp;
|
||||
uint8_t result;
|
||||
|
||||
/* Open the file which contains the names of all of the bitmap files */
|
||||
|
||||
fp = fopen(bmlFile, "r");
|
||||
if (!fp) return BMAP_BML_OPEN_ERROR;
|
||||
if (!fp)
|
||||
return BMAP_BML_OPEN_ERROR;
|
||||
|
||||
/* Load all of the bitmaps */
|
||||
|
||||
result = wld_load_bitmaps(fp);
|
||||
if (result) wld_discard_bitmaps();
|
||||
if (result)
|
||||
wld_discard_bitmaps();
|
||||
|
||||
/* We are all done with the file, so close it */
|
||||
|
||||
|
@ -66,35 +66,35 @@
|
||||
* Private Data
|
||||
*************************************************************************/
|
||||
|
||||
int BitOffset = 0, /* Bit Offset of next code */
|
||||
XC = 0, YC = 0, /* Output X and Y coords of current pixel */
|
||||
Pass = 0, /* Used by output routine if interlaced pic */
|
||||
OutCount = 0, /* Decompressor output 'stack count' */
|
||||
RWidth, RHeight, /* screen dimensions */
|
||||
Width, Height, /* image dimensions */
|
||||
LeftOfs, TopOfs, /* image offset */
|
||||
BitsPerPixel, /* Bits per pixel, read from GIF header */
|
||||
BytesPerScanline, /* bytes per scanline in output rwld_er */
|
||||
ColorMapSize, /* number of colors */
|
||||
Background, /* background color */
|
||||
CodeSize, /* Code size, read from GIF header */
|
||||
InitCodeSize, /* Starting code size, used during Clear */
|
||||
Code, /* Value returned by ReadCode */
|
||||
MaxCode, /* limiting value for current code size */
|
||||
ClearCode, /* GIF clear code */
|
||||
EOFCode, /* GIF end-of-information code */
|
||||
CurCode, OldCode, InCode, /* Decompressor variables */
|
||||
FirstFree, /* First free code, generated per GIF spec */
|
||||
FreeCode, /* Decompressor, next free slot in hash table*/
|
||||
FinChar, /* Decompressor variable */
|
||||
BitMask, /* AND mask for data size */
|
||||
ReadMask; /* Code AND mask for current code size */
|
||||
int BitOffset = 0, /* Bit Offset of next code */
|
||||
XC = 0, YC = 0, /* Output X and Y coords of current pixel */
|
||||
Pass = 0, /* Used by output routine if interlaced pic */
|
||||
OutCount = 0, /* Decompressor output 'stack count' */
|
||||
RWidth, RHeight, /* screen dimensions */
|
||||
Width, Height, /* image dimensions */
|
||||
LeftOfs, TopOfs, /* image offset */
|
||||
BitsPerPixel, /* Bits per pixel, read from GIF header */
|
||||
BytesPerScanline, /* bytes per scanline in output rwld_er */
|
||||
ColorMapSize, /* number of colors */
|
||||
Background, /* background color */
|
||||
CodeSize, /* Code size, read from GIF header */
|
||||
InitCodeSize, /* Starting code size, used during Clear */
|
||||
Code, /* Value returned by ReadCode */
|
||||
MaxCode, /* limiting value for current code size */
|
||||
ClearCode, /* GIF clear code */
|
||||
EOFCode, /* GIF end-of-information code */
|
||||
CurCode, OldCode, InCode, /* Decompressor variables */
|
||||
FirstFree, /* First free code, generated per GIF spec */
|
||||
FreeCode, /* Decompressor, next free slot in hash table */
|
||||
FinChar, /* Decompressor variable */
|
||||
BitMask, /* AND mask for data size */
|
||||
ReadMask; /* Code AND mask for current code size */
|
||||
|
||||
bool Interlace, HasColormap;
|
||||
bool Verbose = true;
|
||||
|
||||
uint8_t *Image; /* The result array */
|
||||
uint8_t *RawGIF; /* The heap array to hold it, raw */
|
||||
uint8_t *Image; /* The result array */
|
||||
uint8_t *RawGIF; /* The heap array to hold it, raw */
|
||||
uint8_t *Rwld_er; /* The rwld_er data stream, unblocked */
|
||||
|
||||
/* The hash table used by the decompressor */
|
||||
@ -109,7 +109,7 @@ int OutCode[1025];
|
||||
/* The color map, read from the GIF header */
|
||||
|
||||
uint8_t Red[256], Green[256], Blue[256], used[256];
|
||||
int numused;
|
||||
int numused;
|
||||
|
||||
char *id87 = "GIF87a";
|
||||
char *id89 = "GIF89a";
|
||||
@ -134,25 +134,25 @@ static int ReadCode(void)
|
||||
int RawCode, ByteOffset;
|
||||
|
||||
ByteOffset = BitOffset / 8;
|
||||
RawCode = Rwld_er[ByteOffset] + (0x100 * Rwld_er[ByteOffset + 1]);
|
||||
RawCode = Rwld_er[ByteOffset] + (0x100 * Rwld_er[ByteOffset + 1]);
|
||||
|
||||
if (CodeSize >= 8)
|
||||
RawCode += (0x10000 * Rwld_er[ByteOffset + 2]);
|
||||
|
||||
RawCode >>= (BitOffset % 8);
|
||||
RawCode >>= (BitOffset % 8);
|
||||
BitOffset += CodeSize;
|
||||
|
||||
return(RawCode & ReadMask);
|
||||
return (RawCode & ReadMask);
|
||||
}
|
||||
|
||||
static void AddToPixel(uint8_t Index)
|
||||
{
|
||||
if (YC<Height)
|
||||
if (YC < Height)
|
||||
*(Image + YC * BytesPerScanline + XC) = Index;
|
||||
|
||||
if (!used[Index])
|
||||
{
|
||||
used[Index]=1;
|
||||
used[Index] = 1;
|
||||
numused++;
|
||||
}
|
||||
|
||||
@ -161,14 +161,16 @@ static void AddToPixel(uint8_t Index)
|
||||
if (++XC == Width)
|
||||
{
|
||||
|
||||
/* If a non-interlaced picture, just increment YC to the next scan line.
|
||||
/* If a non-interlaced picture, just increment YC to the next scan line.
|
||||
* If it's interlaced, deal with the interlace as described in the GIF
|
||||
* spec. Put the decoded scan line out to the screen if we haven't gone
|
||||
* pwld_ the bottom of it
|
||||
*/
|
||||
* pwld_ the bottom of it */
|
||||
|
||||
XC = 0;
|
||||
if (!Interlace) YC++;
|
||||
if (!Interlace)
|
||||
{
|
||||
YC++;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (Pass)
|
||||
@ -212,11 +214,11 @@ static void AddToPixel(uint8_t Index)
|
||||
************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name:
|
||||
* Name: wld_LoadGIF
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
graphic_file_t *wld_LoadGIF(FILE * fp, char *fname)
|
||||
{
|
||||
graphic_file_t *gfile;
|
||||
int filesize;
|
||||
@ -239,7 +241,9 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
fseek(fp, 0L, 0);
|
||||
|
||||
if (!(ptr = RawGIF = (uint8_t *) malloc(filesize)))
|
||||
wld_fatal_error("not enough memory to read gif file");
|
||||
{
|
||||
wld_fatal_error("not enough memory to read gif file");
|
||||
}
|
||||
|
||||
if (!(Rwld_er = (uint8_t *) malloc(filesize)))
|
||||
{
|
||||
@ -249,49 +253,59 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
|
||||
if (fread(ptr, filesize, 1, fp) != 1)
|
||||
wld_fatal_error("GIF data read failed");
|
||||
|
||||
|
||||
if (strncmp(ptr, id87, 6))
|
||||
if (strncmp(ptr, id89, 6))
|
||||
wld_fatal_error("not a GIF file");
|
||||
{
|
||||
if (strncmp(ptr, id89, 6))
|
||||
{
|
||||
wld_fatal_error("not a GIF file");
|
||||
}
|
||||
}
|
||||
|
||||
ptr += 6;
|
||||
|
||||
/* Get variables from the GIF screen descriptor */
|
||||
|
||||
ch = NEXTBYTE;
|
||||
RWidth = ch + 0x100 * NEXTBYTE; /* screen dimensions... not used. */
|
||||
ch = NEXTBYTE;
|
||||
RHeight = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
RWidth = ch + 0x100 * NEXTBYTE; /* screen dimensions... not used. */
|
||||
ch = NEXTBYTE;
|
||||
RHeight = ch + 0x100 * NEXTBYTE;
|
||||
|
||||
if (Verbose)
|
||||
fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight);
|
||||
{
|
||||
fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight);
|
||||
}
|
||||
|
||||
ch = NEXTBYTE;
|
||||
HasColormap = ((ch & COLORMAPMASK) ? true : false);
|
||||
ch = NEXTBYTE;
|
||||
HasColormap = ((ch & COLORMAPMASK) ? true : false);
|
||||
|
||||
BitsPerPixel = (ch & 7) + 1;
|
||||
ColorMapSize = 1 << BitsPerPixel;
|
||||
BitMask = ColorMapSize - 1;
|
||||
BitMask = ColorMapSize - 1;
|
||||
|
||||
Background = NEXTBYTE; /* background color... not used. */
|
||||
|
||||
if (NEXTBYTE) /* supposed to be NULL */
|
||||
wld_fatal_error("corrupt GIF file (bad screen descriptor)");
|
||||
Background = NEXTBYTE; /* background color... not used. */
|
||||
|
||||
if (NEXTBYTE) /* supposed to be NULL */
|
||||
{
|
||||
wld_fatal_error("corrupt GIF file (bad screen descriptor)");
|
||||
}
|
||||
|
||||
/* Read in global colormap. */
|
||||
|
||||
if (HasColormap)
|
||||
{
|
||||
if (Verbose)
|
||||
fprintf(stderr, "%s is %dx%d, %d bits per pixel, (%d colors).\n",
|
||||
fname, RWidth,RHeight,BitsPerPixel, ColorMapSize);
|
||||
{
|
||||
fprintf(stderr, "%s is %dx%d, %d bits per pixel, (%d colors).\n",
|
||||
fname, RWidth, RHeight, BitsPerPixel, ColorMapSize);
|
||||
}
|
||||
|
||||
for (i = 0; i < ColorMapSize; i++)
|
||||
{
|
||||
Red[i] = NEXTBYTE;
|
||||
Red[i] = NEXTBYTE;
|
||||
Green[i] = NEXTBYTE;
|
||||
Blue[i] = NEXTBYTE;
|
||||
used[i] = 0;
|
||||
Blue[i] = NEXTBYTE;
|
||||
used[i] = 0;
|
||||
}
|
||||
|
||||
numused = 0;
|
||||
@ -299,7 +313,7 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
|
||||
/* look for image separator */
|
||||
|
||||
for (ch = NEXTBYTE ; ch != IMAGESEP ; ch = NEXTBYTE)
|
||||
for (ch = NEXTBYTE; ch != IMAGESEP; ch = NEXTBYTE)
|
||||
{
|
||||
i = ch;
|
||||
fprintf(stderr, "EXTENSION CHARACTER: %x\n", i);
|
||||
@ -314,9 +328,10 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
ch = NEXTBYTE;
|
||||
if (ptr[0] & 0x1)
|
||||
{
|
||||
transparency = ptr[3]; /* transparent color index */
|
||||
transparency = ptr[3]; /* transparent color index */
|
||||
fprintf(stderr, "transparency index: %i\n", transparency);
|
||||
}
|
||||
|
||||
ptr += ch;
|
||||
break;
|
||||
case PLAINTEXT_EXT:
|
||||
@ -330,19 +345,21 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
}
|
||||
|
||||
while ((ch = NEXTBYTE))
|
||||
ptr += ch;
|
||||
{
|
||||
ptr += ch;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now read in values from the image descriptor */
|
||||
|
||||
ch = NEXTBYTE;
|
||||
LeftOfs = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
TopOfs = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
Width = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
Height = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
LeftOfs = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
TopOfs = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
Width = ch + 0x100 * NEXTBYTE;
|
||||
ch = NEXTBYTE;
|
||||
Height = ch + 0x100 * NEXTBYTE;
|
||||
Interlace = ((NEXTBYTE & INTERLACEMASK) ? true : false);
|
||||
|
||||
if (Verbose)
|
||||
@ -350,61 +367,62 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
Width, Height, (Interlace) ? "" : "non-");
|
||||
|
||||
gfile = wld_new_graphicfile();
|
||||
gfile->palette = (RGBColor*)wld_malloc(sizeof(RGBColor) * ColorMapSize);
|
||||
gfile->palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * ColorMapSize);
|
||||
for (i = 0; i < ColorMapSize; i++)
|
||||
{
|
||||
gfile->palette[i].red = Red[i];
|
||||
gfile->palette[i].green = Green[i];
|
||||
gfile->palette[i].blue = Blue[i];
|
||||
}
|
||||
gfile->bitmap = (uint8_t*)wld_malloc(Width * Height);
|
||||
|
||||
gfile->bitmap = (uint8_t *) wld_malloc(Width * Height);
|
||||
gfile->type = gfPaletted;
|
||||
gfile->width = Width;
|
||||
gfile->height = Height;
|
||||
gfile->transparent_entry = transparency;
|
||||
|
||||
/* Note that I ignore the possible existence of a local color map.
|
||||
* I'm told there aren't many files around that use them, and the spec
|
||||
* says it's defined for future use. This could lead to an error
|
||||
* reading some files.
|
||||
/* Note that I ignore the possible existence of a local color map. I'm told
|
||||
* there aren't many files around that use them, and the spec says it's
|
||||
* defined for future use. This could lead to an error reading some files.
|
||||
*/
|
||||
|
||||
/* Start reading the rwld_er data. First we get the intial code size
|
||||
* and compute decompressor constant values, based on this code size.
|
||||
/* Start reading the rwld_er data. First we get the intial code size and
|
||||
* compute decompressor constant values, based on this code size.
|
||||
*/
|
||||
|
||||
CodeSize = NEXTBYTE;
|
||||
CodeSize = NEXTBYTE;
|
||||
ClearCode = (1 << CodeSize);
|
||||
EOFCode = ClearCode + 1;
|
||||
FreeCode = FirstFree = ClearCode + 2;
|
||||
EOFCode = ClearCode + 1;
|
||||
FreeCode = FirstFree = ClearCode + 2;
|
||||
|
||||
/* The GIF spec has it that the code size is the code size used to
|
||||
* compute the above values is the code size given in the file, but the
|
||||
* code size used in compression/decompression is the code size given in
|
||||
* the file plus one. (thus the ++).
|
||||
/* The GIF spec has it that the code size is the code size used to compute
|
||||
* the above values is the code size given in the file, but the code size
|
||||
* used in compression/decompression is the code size given in the file plus
|
||||
* one. (thus the ++).
|
||||
*/
|
||||
|
||||
CodeSize++;
|
||||
InitCodeSize = CodeSize;
|
||||
MaxCode = (1 << CodeSize);
|
||||
ReadMask = MaxCode - 1;
|
||||
MaxCode = (1 << CodeSize);
|
||||
ReadMask = MaxCode - 1;
|
||||
|
||||
/* Read the rwld_er data. Here we just transpose it from the GIF array
|
||||
* to the Rwld_er array, turning it from a series of blocks into one long
|
||||
* data stream, which makes life much easier for ReadCode().
|
||||
/* Read the rwld_er data. Here we just transpose it from the GIF array to
|
||||
* the Rwld_er array, turning it from a series of blocks into one long data
|
||||
* stream, which makes life much easier for ReadCode().
|
||||
*/
|
||||
|
||||
ptr1 = Rwld_er;
|
||||
do
|
||||
{
|
||||
ch = ch1 = NEXTBYTE;
|
||||
while (ch--) *ptr1++ = NEXTBYTE;
|
||||
while (ch--)
|
||||
*ptr1++ = NEXTBYTE;
|
||||
if ((ptr1 - Rwld_er) > filesize)
|
||||
wld_fatal_error("corrupt GIF file (unblock)");
|
||||
}
|
||||
while(ch1);
|
||||
while (ch1);
|
||||
|
||||
free(RawGIF); /* We're done with the raw data now... */
|
||||
free(RawGIF); /* We're done with the raw data now... */
|
||||
|
||||
if (Verbose)
|
||||
{
|
||||
@ -412,12 +430,11 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
fprintf(stderr, "Decompressing...");
|
||||
}
|
||||
|
||||
Image = gfile->bitmap;
|
||||
BytesPerScanline = Width;
|
||||
Image = gfile->bitmap;
|
||||
BytesPerScanline = Width;
|
||||
|
||||
|
||||
/* Decompress the file, continuing until you see the GIF EOF code.
|
||||
* One obvious enhancement is to add checking for corrupt files here.
|
||||
/* Decompress the file, continuing until you see the GIF EOF code. One
|
||||
* obvious enhancement is to add checking for corrupt files here.
|
||||
*/
|
||||
|
||||
Code = ReadCode();
|
||||
@ -431,24 +448,23 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
if (Code == ClearCode)
|
||||
{
|
||||
CodeSize = InitCodeSize;
|
||||
MaxCode = (1 << CodeSize);
|
||||
MaxCode = (1 << CodeSize);
|
||||
ReadMask = MaxCode - 1;
|
||||
FreeCode = FirstFree;
|
||||
CurCode = OldCode = Code = ReadCode();
|
||||
FinChar = CurCode & BitMask;
|
||||
CurCode = OldCode = Code = ReadCode();
|
||||
FinChar = CurCode & BitMask;
|
||||
AddToPixel(FinChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* If not a clear code, then must be data: save same as CurCode
|
||||
* and InCode
|
||||
/* If not a clear code, then must be data: save same as CurCode and
|
||||
* InCode
|
||||
*/
|
||||
|
||||
CurCode = InCode = Code;
|
||||
|
||||
/* If greater or equal to FreeCode, not in the hash table yet;
|
||||
* repeat the lwld_ character decoded
|
||||
/* If greater or equal to FreeCode, not in the hash table yet; repeat
|
||||
* the lwld_ character decoded
|
||||
*/
|
||||
|
||||
if (CurCode >= FreeCode)
|
||||
@ -457,17 +473,16 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
OutCode[OutCount++] = FinChar;
|
||||
}
|
||||
|
||||
/* Unless this code is raw data, pursue the chain pointed to
|
||||
* by CurCode through the hash table to its end; each code
|
||||
* in the chain puts its associated output code on the output
|
||||
* queue.
|
||||
/* Unless this code is raw data, pursue the chain pointed to by
|
||||
* CurCode through the hash table to its end; each code in the chain
|
||||
* puts its associated output code on the output queue.
|
||||
*/
|
||||
|
||||
while (CurCode > BitMask)
|
||||
{
|
||||
if (OutCount > 1024)
|
||||
{
|
||||
fprintf(stderr,"\nCorrupt GIF file (OutCount)!\n");
|
||||
fprintf(stderr, "\nCorrupt GIF file (OutCount)!\n");
|
||||
exit(-1);
|
||||
}
|
||||
OutCode[OutCount++] = Suffix[CurCode];
|
||||
@ -476,11 +491,11 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
|
||||
/* The lwld_ code in the chain is treated as raw data. */
|
||||
|
||||
FinChar = CurCode & BitMask;
|
||||
FinChar = CurCode & BitMask;
|
||||
OutCode[OutCount++] = FinChar;
|
||||
|
||||
/* Now we put the data out to the Output routine.
|
||||
* It's been stacked LIFO, so deal with it that way...
|
||||
/* Now we put the data out to the Output routine. It's been stacked
|
||||
* LIFO, so deal with it that way...
|
||||
*/
|
||||
|
||||
for (i = OutCount - 1; i >= 0; i--)
|
||||
@ -491,12 +506,11 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
|
||||
Prefix[FreeCode] = OldCode;
|
||||
Suffix[FreeCode] = FinChar;
|
||||
OldCode = InCode;
|
||||
OldCode = InCode;
|
||||
|
||||
/* Point to the next slot in the table. If we exceed the current
|
||||
* MaxCode value, increment the code size unless it's already 12.
|
||||
* If it is, do nothing: the next code decompressed better be
|
||||
* CLEAR
|
||||
* MaxCode value, increment the code size unless it's already 12. If
|
||||
* it is, do nothing: the next code decompressed better be CLEAR
|
||||
*/
|
||||
|
||||
FreeCode++;
|
||||
@ -510,16 +524,20 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Code = ReadCode();
|
||||
}
|
||||
|
||||
free(Rwld_er);
|
||||
|
||||
if (Verbose)
|
||||
fprintf(stderr, "done.\n");
|
||||
{
|
||||
fprintf(stderr, "done.\n");
|
||||
}
|
||||
else
|
||||
fprintf(stderr,"(of which %d are used)\n",numused);
|
||||
|
||||
{
|
||||
fprintf(stderr, "(of which %d are used)\n", numused);
|
||||
}
|
||||
|
||||
return gfile;
|
||||
}
|
||||
|
@ -50,8 +50,8 @@
|
||||
#include "wld_world.h"
|
||||
#include "wld_paltable.h"
|
||||
#if (!MSWINDOWS)
|
||||
#include "wld_bitmaps.h"
|
||||
#include "wld_color.h"
|
||||
# include "wld_bitmaps.h"
|
||||
# include "wld_color.h"
|
||||
#endif
|
||||
#include "wld_mem.h"
|
||||
#include "wld_utils.h"
|
||||
@ -65,7 +65,7 @@
|
||||
*/
|
||||
|
||||
#if USE_PAL_RANGES
|
||||
# define MAX_PAL_RANGES 64
|
||||
# define MAX_PAL_RANGES 64
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
@ -74,11 +74,11 @@
|
||||
|
||||
#if USE_PAL_RANGES
|
||||
typedef struct
|
||||
{
|
||||
uint8_t firstColor;
|
||||
int8_t colorRange;
|
||||
uint8_t clipColor;
|
||||
} pal_range_t;
|
||||
{
|
||||
uint8_t firstColor;
|
||||
int8_t colorRange;
|
||||
uint8_t clipColor;
|
||||
} pal_range_t;
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
@ -106,7 +106,8 @@ static void wld_allocate_paltable(uint32_t palTabEntrySize)
|
||||
|
||||
for (i = 0; i < NUM_ZONES; i++)
|
||||
{
|
||||
g_pal_table[i] = (trv_pixel_t*)wld_malloc(palTabEntrySize*sizeof(trv_pixel_t));
|
||||
g_pal_table[i] =
|
||||
(trv_pixel_t *) wld_malloc(palTabEntrySize * sizeof(trv_pixel_t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,13 +126,13 @@ uint8_t wld_load_paltable(char *file)
|
||||
#if (!MSWINDOWS)
|
||||
trv_pixel_t *palptr;
|
||||
color_lum_t lum;
|
||||
int16_t zone;
|
||||
int16_t zone;
|
||||
float scale;
|
||||
int pixel;
|
||||
|
||||
/* Allocate memory to hold the palette range mapping data */
|
||||
|
||||
wld_allocate_paltable(TRV_PIXEL_MAX+1);
|
||||
wld_allocate_paltable(TRV_PIXEL_MAX + 1);
|
||||
|
||||
/* The first zone is just the identity transformation */
|
||||
|
||||
@ -165,9 +166,8 @@ uint8_t wld_load_paltable(char *file)
|
||||
|
||||
lum.luminance *= scale;
|
||||
|
||||
/* Then save the pixel associated with this scaled value in
|
||||
* the range palette table
|
||||
*/
|
||||
/* Then save the pixel associated with this scaled value in the range
|
||||
* palette table */
|
||||
|
||||
*palptr++ = wld_lum2pixel(&lum);
|
||||
}
|
||||
@ -176,12 +176,12 @@ uint8_t wld_load_paltable(char *file)
|
||||
return WORLD_SUCCESS;
|
||||
|
||||
#else
|
||||
#if USE_PAL_RANGES
|
||||
FILE *fp, *fopen();
|
||||
int16_t i;
|
||||
int16_t nranges;
|
||||
int16_t zone;
|
||||
int16_t palndx;
|
||||
# if USE_PAL_RANGES
|
||||
FILE *fp, *fopen();
|
||||
int16_t i;
|
||||
int16_t nranges;
|
||||
int16_t zone;
|
||||
int16_t palndx;
|
||||
trv_pixel_t plotcolor;
|
||||
trv_pixel_t *palptr;
|
||||
pal_range_t ranges[MAX_PAL_RANGES];
|
||||
@ -189,7 +189,10 @@ uint8_t wld_load_paltable(char *file)
|
||||
/* Open the file which contains the palette table */
|
||||
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) return PALR_FILE_OPEN_ERROR;
|
||||
if (!fp)
|
||||
{
|
||||
return PALR_FILE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
/* Read the number of ranges from the file */
|
||||
|
||||
@ -206,7 +209,7 @@ uint8_t wld_load_paltable(char *file)
|
||||
{
|
||||
ranges[i].firstColor = wld_read_decimal(fp);
|
||||
ranges[i].colorRange = wld_read_decimal(fp);
|
||||
ranges[i].clipColor = wld_read_decimal(fp);
|
||||
ranges[i].clipColor = wld_read_decimal(fp);
|
||||
}
|
||||
|
||||
/* We are now done with the input file */
|
||||
@ -229,9 +232,8 @@ uint8_t wld_load_paltable(char *file)
|
||||
|
||||
for (palndx = 0; palndx < PALETTE_SIZE; palndx++)
|
||||
{
|
||||
/* Assume that the range will not be found. In this case, we
|
||||
* will perform the 1-to-1 mapping
|
||||
*/
|
||||
/* Assume that the range will not be found. In this case, we will
|
||||
* perform the 1-to-1 mapping */
|
||||
|
||||
plotcolor = palndx;
|
||||
|
||||
@ -255,12 +257,11 @@ uint8_t wld_load_paltable(char *file)
|
||||
|
||||
plotcolor -= zone;
|
||||
|
||||
/* Check if we have exceeded the range of this
|
||||
* color. If so, then set the color to the
|
||||
* clipColor
|
||||
*/
|
||||
/* Check if we have exceeded the range of this color.
|
||||
* If so, then set the color to the clipColor */
|
||||
|
||||
if (plotcolor <= ranges[i].firstColor + ranges[i].colorRange)
|
||||
if (plotcolor <=
|
||||
ranges[i].firstColor + ranges[i].colorRange)
|
||||
{
|
||||
plotcolor = ranges[i].clipColor;
|
||||
}
|
||||
@ -286,8 +287,7 @@ uint8_t wld_load_paltable(char *file)
|
||||
plotcolor += zone;
|
||||
|
||||
/* Check if we have exceeded the range of this color. If so,
|
||||
* then set the color to black
|
||||
*/
|
||||
* then set the color to black */
|
||||
|
||||
if (plotcolor >= ranges[i].firstColor + ranges[i].colorRange)
|
||||
{
|
||||
@ -308,7 +308,7 @@ uint8_t wld_load_paltable(char *file)
|
||||
}
|
||||
|
||||
return WORLD_SUCCESS;
|
||||
#else
|
||||
# else
|
||||
FILE *fp;
|
||||
int16_t zone;
|
||||
int16_t palndx;
|
||||
@ -322,7 +322,10 @@ uint8_t wld_load_paltable(char *file)
|
||||
/* Open the file which contains the palette table */
|
||||
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) return PALR_FILE_OPEN_ERROR;
|
||||
if (!fp)
|
||||
{
|
||||
return PALR_FILE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
/* Process each distance zone */
|
||||
|
||||
@ -344,6 +347,6 @@ uint8_t wld_load_paltable(char *file)
|
||||
|
||||
fclose(fp);
|
||||
return WORLD_SUCESS;
|
||||
#endif /* USE_PAL_RANGES */
|
||||
#endif /* !MSWINDOWS */
|
||||
# endif /* USE_PAL_RANGES */
|
||||
#endif /* !MSWINDOWS */
|
||||
}
|
||||
|
@ -51,8 +51,8 @@
|
||||
#include "trv_types.h"
|
||||
#include "wld_mem.h"
|
||||
#if (!MSWINDOWS)
|
||||
#include "wld_bitmaps.h"
|
||||
#include "wld_graphicfile.h"
|
||||
# include "wld_bitmaps.h"
|
||||
# include "wld_graphicfile.h"
|
||||
#endif
|
||||
#include "wld_pcx.h"
|
||||
|
||||
@ -68,9 +68,9 @@
|
||||
* Private Function Prototypes
|
||||
*************************************************************************/
|
||||
|
||||
static void wld_loadpcxHeader(FILE *fp, pcxHeader *header);
|
||||
static void wld_loadpcxData(FILE *fp, int32_t imagSize, uint8_t *imageBuffer);
|
||||
static void wld_loadpcxPalette(FILE *fp, RGBColor *palette);
|
||||
static void wld_loadpcxHeader(FILE * fp, pcxHeader * header);
|
||||
static void wld_loadpcxData(FILE * fp, int32_t imagSize, uint8_t * imageBuffer);
|
||||
static void wld_loadpcxPalette(FILE * fp, RGBColor * palette);
|
||||
|
||||
/*************************************************************************
|
||||
* Global Variables
|
||||
@ -93,13 +93,16 @@ static void wld_loadpcxPalette(FILE *fp, RGBColor *palette);
|
||||
uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
|
||||
{
|
||||
FILE *fp, *fopen();
|
||||
uint16_t imageWidth, imageHeight;
|
||||
uint16_t imageWidth, imageHeight;
|
||||
uint32_t imageSize;
|
||||
|
||||
/* Open the file */
|
||||
|
||||
fp = fopen(filename,"rb");
|
||||
if (!fp) return PCX_OPEN_ERROR;
|
||||
fp = fopen(filename, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
return PCX_OPEN_ERROR;
|
||||
}
|
||||
|
||||
/* Load the PCX Header */
|
||||
|
||||
@ -126,13 +129,13 @@ uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
|
||||
return PCX_SUCCESS;
|
||||
}
|
||||
#else
|
||||
graphic_file_t *wld_loadpcx(FILE *fp, char *filename)
|
||||
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;
|
||||
uint16_t imageWidth, imageHeight;
|
||||
uint32_t imageSize;
|
||||
|
||||
/* Load the PCX Header */
|
||||
@ -144,15 +147,15 @@ graphic_file_t *wld_loadpcx(FILE *fp, char *filename)
|
||||
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);
|
||||
buffer = (trv_pixel_t *) wld_malloc(imageSize + 1);
|
||||
|
||||
/* Load the PCX data into the buffer */
|
||||
|
||||
wld_loadpcxData(fp, imageSize, (uint8_t*)buffer);
|
||||
wld_loadpcxData(fp, imageSize, (uint8_t *) buffer);
|
||||
|
||||
/* Allocate space to hold the PCX palette */
|
||||
|
||||
palette = (RGBColor*)wld_malloc(sizeof(RGBColor) * 256);
|
||||
palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * 256);
|
||||
|
||||
/* Load the PCX palette */
|
||||
|
||||
@ -176,14 +179,14 @@ graphic_file_t *wld_loadpcx(FILE *fp, char *filename)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_loadpcxHeader(FILE *fp, pcxHeader *header)
|
||||
static void wld_loadpcxHeader(FILE * fp, pcxHeader * header)
|
||||
{
|
||||
uint8_t *tempBuffer;
|
||||
int i;
|
||||
|
||||
/* Load the header */
|
||||
|
||||
tempBuffer = (uint8_t*)header;
|
||||
tempBuffer = (uint8_t *) header;
|
||||
|
||||
for (i = 0; i < SIZEOF_PCX_HEADER; i++)
|
||||
{
|
||||
@ -196,14 +199,14 @@ static void wld_loadpcxHeader(FILE *fp, pcxHeader *header)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
|
||||
static void wld_loadpcxData(FILE * fp, int32_t imageSize, uint8_t * imageBuffer)
|
||||
{
|
||||
uint32_t count;
|
||||
int16_t numBytes;
|
||||
int16_t numBytes;
|
||||
uint8_t data;
|
||||
|
||||
count = 0;
|
||||
while(count <= imageSize)
|
||||
while (count <= imageSize)
|
||||
{
|
||||
/* Get the first piece of data */
|
||||
|
||||
@ -211,7 +214,7 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
|
||||
|
||||
/* Is this a run length encoding? */
|
||||
|
||||
if ((data >= 192) /* && (data <= 255) */)
|
||||
if ((data >= 192) /* && (data <= 255) */ )
|
||||
{
|
||||
/* How many bytes in run? */
|
||||
|
||||
@ -219,11 +222,11 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
|
||||
|
||||
/* Get the actual data for the run */
|
||||
|
||||
data = getc(fp);
|
||||
data = getc(fp);
|
||||
|
||||
/* Replicate data in buffer numBytes times */
|
||||
|
||||
while(numBytes-- > 0)
|
||||
while (numBytes-- > 0)
|
||||
{
|
||||
imageBuffer[count++] = data;
|
||||
}
|
||||
@ -242,7 +245,7 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_loadpcxPalette(FILE *fp, RGBColor *palette)
|
||||
static void wld_loadpcxPalette(FILE * fp, RGBColor * palette)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -257,13 +260,13 @@ static void wld_loadpcxPalette(FILE *fp, RGBColor *palette)
|
||||
/* Get the RGB components */
|
||||
|
||||
#if MSWINDOWS
|
||||
palette[i].red = (getc(fp) >> 2);
|
||||
palette[i].red = (getc(fp) >> 2);
|
||||
palette[i].green = (getc(fp) >> 2);
|
||||
palette[i].blue = (getc(fp) >> 2);
|
||||
palette[i].blue = (getc(fp) >> 2);
|
||||
#else
|
||||
palette[i].red = getc(fp);
|
||||
palette[i].red = getc(fp);
|
||||
palette[i].green = getc(fp);
|
||||
palette[i].blue = getc(fp);
|
||||
palette[i].blue = getc(fp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
|
||||
uint8_t wld_load_planefile(const char *wldFile)
|
||||
{
|
||||
FILE *fp;
|
||||
FILE *fp;
|
||||
uint8_t result;
|
||||
|
||||
/* Open the map file which contains the description of the world */
|
||||
|
@ -46,14 +46,14 @@
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_LoadWorldPlane
|
||||
* Name: wld_load_worldplane
|
||||
* Description:
|
||||
* This function loads the world data for one plane
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
|
||||
static uint8_t wld_load_worldplane(FILE * fp, rect_head_t * list,
|
||||
uint8_t numRects)
|
||||
{
|
||||
rect_list_t *rect;
|
||||
int i;
|
||||
@ -63,16 +63,18 @@ static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
|
||||
/* Allocate space for the next rectangle */
|
||||
|
||||
rect = wld_new_plane();
|
||||
if (!rect) return PLANE_ALLOCATION_FAILURE;
|
||||
if (!rect)
|
||||
{
|
||||
return PLANE_ALLOCATION_FAILURE;
|
||||
}
|
||||
|
||||
/* Read the next rectangle from the input file */
|
||||
|
||||
if (fread((char*)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
|
||||
if (fread((char *)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
|
||||
{
|
||||
fprintf(stderr, "Error: read of rectangle %d (of %d) failed! ",
|
||||
i, numRects);
|
||||
fprintf(stderr, "feof=%d ferror=%d\n",
|
||||
feof(fp), ferror(fp));
|
||||
fprintf(stderr, "feof=%d ferror=%d\n", feof(fp), ferror(fp));
|
||||
return PLANE_DATA_READ_ERROR;
|
||||
}
|
||||
|
||||
@ -94,23 +96,23 @@ static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
|
||||
* This function loads the world data from the opened file
|
||||
************************************************************************/
|
||||
|
||||
uint8_t wld_load_planes(FILE *fp)
|
||||
uint8_t wld_load_planes(FILE * fp)
|
||||
{
|
||||
plane_file_header_t fileHeader;
|
||||
uint8_t result;
|
||||
|
||||
/* Read the plane file header */
|
||||
|
||||
if (fread((char*)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
|
||||
if (fread((char *)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
|
||||
return PLANE_HEADER_READ_ERROR;
|
||||
|
||||
/* Then load each grid, performing run length (rle) decoding */
|
||||
|
||||
result = wld_LoadWorldPlane(fp, &xPlane, fileHeader.numXRects);
|
||||
result = wld_load_worldplane(fp, &g_xplane_list, fileHeader.numXRects);
|
||||
if (!result)
|
||||
result = wld_LoadWorldPlane(fp, &yPlane, fileHeader.numYRects);
|
||||
result = wld_load_worldplane(fp, &g_yplane_list, fileHeader.numYRects);
|
||||
if (!result)
|
||||
result = wld_LoadWorldPlane(fp, &zPlane, fileHeader.numZRects);
|
||||
result = wld_load_worldplane(fp, &g_zplane_list, fileHeader.numZRects);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "wld_graphicfile.h"
|
||||
#include "wld_utils.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
@ -58,7 +57,7 @@
|
||||
* Skip white space and comments.
|
||||
************************************************************************/
|
||||
|
||||
static void skip_cruft(FILE *fp)
|
||||
static void skip_cruft(FILE * fp)
|
||||
{
|
||||
int c;
|
||||
|
||||
@ -97,7 +96,7 @@ static void skip_cruft(FILE *fp)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
graphic_file_t *wld_LoadPPM(FILE *fp, char *filename)
|
||||
graphic_file_t *wld_LoadPPM(FILE * fp, char *filename)
|
||||
{
|
||||
int width, height;
|
||||
int unknown;
|
||||
@ -132,7 +131,7 @@ graphic_file_t *wld_LoadPPM(FILE *fp, char *filename)
|
||||
gfile->palette = NULL;
|
||||
gfile->width = width;
|
||||
gfile->height = height;
|
||||
gfile->bitmap = (uint8_t*)wld_malloc(height * width * 3);
|
||||
gfile->bitmap = (uint8_t *) wld_malloc(height * width * 3);
|
||||
|
||||
if (fread(gfile->bitmap, height * width * 3, 1, fp) != 1)
|
||||
{
|
||||
|
@ -53,42 +53,42 @@
|
||||
****************************************************************************/
|
||||
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
static uint8_t wld_lum2formtype(color_form_t *lum)
|
||||
static uint8_t wld_lum2formtype(color_form_t * lum)
|
||||
{
|
||||
float factor1;
|
||||
float factor2;
|
||||
float factor3;
|
||||
float error;
|
||||
float lse;
|
||||
uint8_t formno;
|
||||
int i;
|
||||
float factor1;
|
||||
float factor2;
|
||||
float factor3;
|
||||
float error;
|
||||
float lse;
|
||||
uint8_t formno;
|
||||
int i;
|
||||
|
||||
/* Initialize for the search */
|
||||
/* Initialize for the search */
|
||||
|
||||
factor1 = g_wld_colorform[0].max - lum->max;
|
||||
factor2 = g_wld_colorform[0].mid - lum->mid;
|
||||
factor3 = g_wld_colorform[0].min - lum->min;
|
||||
lse = factor1*factor1 + factor2*factor2 + factor3*factor3;
|
||||
formno = 0;
|
||||
factor1 = g_wld_colorform[0].max - lum->max;
|
||||
factor2 = g_wld_colorform[0].mid - lum->mid;
|
||||
factor3 = g_wld_colorform[0].min - lum->min;
|
||||
lse = factor1 * factor1 + factor2 * factor2 + factor3 * factor3;
|
||||
formno = 0;
|
||||
|
||||
/* Now, search the rest of the table, keeping the form with least
|
||||
* squared error value
|
||||
*/
|
||||
/* Now, search the rest of the table, keeping the form with least squared
|
||||
* error value
|
||||
*/
|
||||
|
||||
for (i = 1; i < NCOLOR_FORMS; i++)
|
||||
{
|
||||
factor1 = g_wld_colorform[i].max - lum->max;
|
||||
factor2 = g_wld_colorform[i].mid - lum->mid;
|
||||
factor3 = g_wld_colorform[i].min - lum->min;
|
||||
error = factor1*factor1 + factor2*factor2 + factor3*factor3;
|
||||
if (error < lse)
|
||||
{
|
||||
lse = error;
|
||||
formno = i;
|
||||
}
|
||||
}
|
||||
for (i = 1; i < NCOLOR_FORMS; i++)
|
||||
{
|
||||
factor1 = g_wld_colorform[i].max - lum->max;
|
||||
factor2 = g_wld_colorform[i].mid - lum->mid;
|
||||
factor3 = g_wld_colorform[i].min - lum->min;
|
||||
error = factor1 * factor1 + factor2 * factor2 + factor3 * factor3;
|
||||
if (error < lse)
|
||||
{
|
||||
lse = error;
|
||||
formno = i;
|
||||
}
|
||||
}
|
||||
|
||||
return formno;
|
||||
return formno;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -102,87 +102,87 @@ static uint8_t wld_lum2formtype(color_form_t *lum)
|
||||
****************************************************************************/
|
||||
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
static enum unit_vector_index_e wld_lum2colorform(color_lum_t *lum)
|
||||
static enum unit_vector_index_e wld_lum2colorform(color_lum_t * lum)
|
||||
{
|
||||
color_form_t orderedLum;
|
||||
enum unit_vector_index_e uvndx;
|
||||
color_form_t orderedLum;
|
||||
enum unit_vector_index_e uvndx;
|
||||
|
||||
/* Get an ordered representation of the luminance value */
|
||||
/* Get an ordered representation of the luminance value */
|
||||
|
||||
if (lum->red >= lum->green)
|
||||
{
|
||||
if (lum->red >= lum->blue)
|
||||
{
|
||||
/* RED >= GREEN && RED >= BLUE */
|
||||
if (lum->red >= lum->green)
|
||||
{
|
||||
if (lum->red >= lum->blue)
|
||||
{
|
||||
/* RED >= GREEN && RED >= BLUE */
|
||||
|
||||
if (lum->green >= lum->blue)
|
||||
{
|
||||
/* RED >= GREEN >= BLUE */
|
||||
if (lum->green >= lum->blue)
|
||||
{
|
||||
/* RED >= GREEN >= BLUE */
|
||||
|
||||
orderedLum.max = lum->red;
|
||||
orderedLum.mid = lum->green;
|
||||
orderedLum.min = lum->blue;
|
||||
uvndx = g_wld_rgbform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* RED >= BLUE > GREEN */
|
||||
orderedLum.max = lum->red;
|
||||
orderedLum.mid = lum->green;
|
||||
orderedLum.min = lum->blue;
|
||||
uvndx = g_wld_rgbform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* RED >= BLUE > GREEN */
|
||||
|
||||
orderedLum.max = lum->red;
|
||||
orderedLum.mid = lum->blue;
|
||||
orderedLum.min = lum->green;
|
||||
uvndx = g_wld_rbgform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* BLUE > RED >= GREEN */
|
||||
orderedLum.max = lum->red;
|
||||
orderedLum.mid = lum->blue;
|
||||
orderedLum.min = lum->green;
|
||||
uvndx = g_wld_rbgform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* BLUE > RED >= GREEN */
|
||||
|
||||
orderedLum.max = lum->blue;
|
||||
orderedLum.mid = lum->red;
|
||||
orderedLum.min = lum->green;
|
||||
uvndx = g_wld_brgform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* lum->red < lum->green) */
|
||||
orderedLum.max = lum->blue;
|
||||
orderedLum.mid = lum->red;
|
||||
orderedLum.min = lum->green;
|
||||
uvndx = g_wld_brgform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* lum->red < lum->green) */
|
||||
|
||||
if (lum->green >= lum->blue)
|
||||
{
|
||||
/* GREEN > RED && GREEN >= BLUE */
|
||||
if (lum->green >= lum->blue)
|
||||
{
|
||||
/* GREEN > RED && GREEN >= BLUE */
|
||||
|
||||
if (lum->red >= lum->blue)
|
||||
{
|
||||
/* GREEN > RED >= BLUE */
|
||||
if (lum->red >= lum->blue)
|
||||
{
|
||||
/* GREEN > RED >= BLUE */
|
||||
|
||||
orderedLum.max = lum->green;
|
||||
orderedLum.mid = lum->red;
|
||||
orderedLum.min = lum->blue;
|
||||
uvndx = g_wld_grbform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GREEN >= BLUE > RED*/
|
||||
orderedLum.max = lum->green;
|
||||
orderedLum.mid = lum->red;
|
||||
orderedLum.min = lum->blue;
|
||||
uvndx = g_wld_grbform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GREEN >= BLUE > RED */
|
||||
|
||||
orderedLum.max = lum->green;
|
||||
orderedLum.mid = lum->blue;
|
||||
orderedLum.min = lum->red;
|
||||
uvndx = g_wld_gbrform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* BLUE > GREEN > RED */
|
||||
orderedLum.max = lum->green;
|
||||
orderedLum.mid = lum->blue;
|
||||
orderedLum.min = lum->red;
|
||||
uvndx = g_wld_gbrform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* BLUE > GREEN > RED */
|
||||
|
||||
orderedLum.max = lum->blue;
|
||||
orderedLum.mid = lum->green;
|
||||
orderedLum.min = lum->red;
|
||||
uvndx = g_wld_bgrform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
orderedLum.max = lum->blue;
|
||||
orderedLum.mid = lum->green;
|
||||
orderedLum.min = lum->red;
|
||||
uvndx = g_wld_bgrform_map[wld_lum2formtype(&orderedLum)];
|
||||
}
|
||||
}
|
||||
|
||||
return uvndx;
|
||||
return uvndx;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -191,51 +191,51 @@ static enum unit_vector_index_e wld_lum2colorform(color_lum_t *lum)
|
||||
* Description: Convert an RGB-Luminance value into a pixel
|
||||
****************************************************************************/
|
||||
|
||||
wld_pixel_t wld_color_lum2pixel(color_lum_t *lum)
|
||||
wld_pixel_t wld_color_lum2pixel(color_lum_t * lum)
|
||||
{
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
enum unit_vector_index_e uvndx;
|
||||
uint8_t lumndx;
|
||||
enum unit_vector_index_e uvndx;
|
||||
uint8_t lumndx;
|
||||
|
||||
/* Get the g_unit_vector array index associated with this lum */
|
||||
/* Get the g_unit_vector array index associated with this lum */
|
||||
|
||||
uvndx = wld_lum2colorform(lum);
|
||||
uvndx = wld_lum2colorform(lum);
|
||||
|
||||
/* Get the luminance number associated with this lum at this index
|
||||
* Make sure that the requested luminance does not exceed the maximum
|
||||
* allowed for this unit vector.
|
||||
*/
|
||||
/* Get the luminance number associated with this lum at this index Make sure
|
||||
* that the requested luminance does not exceed the maximum allowed for this
|
||||
* unit vector.
|
||||
*/
|
||||
|
||||
if (lum->luminance >= g_unit_vector[uvndx].luminance)
|
||||
{
|
||||
lumndx = (NLUMINANCES-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lumndx = (uint8_t)((float)NLUMINANCES
|
||||
* lum->luminance / g_unit_vector[uvndx].luminance);
|
||||
if (lumndx > 0)
|
||||
{
|
||||
lumndx--;
|
||||
}
|
||||
}
|
||||
if (lum->luminance >= g_unit_vector[uvndx].luminance)
|
||||
{
|
||||
lumndx = (NLUMINANCES - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lumndx = (uint8_t) ((float)NLUMINANCES
|
||||
* lum->luminance / g_unit_vector[uvndx].luminance);
|
||||
if (lumndx > 0)
|
||||
{
|
||||
lumndx--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now get the pixel value from the unit vector index and the luminance
|
||||
* number. We will probably have to expand this later from the 8-bit
|
||||
* index to a wider representation.
|
||||
*/
|
||||
/* Now get the pixel value from the unit vector index and the luminance
|
||||
* number. We will probably have to expand this later from the 8-bit index
|
||||
* to a wider representation.
|
||||
*/
|
||||
|
||||
return TRV_UVLUM2NDX(uvndx, lumndx);
|
||||
return TRV_UVLUM2NDX(uvndx, lumndx);
|
||||
|
||||
#else
|
||||
color_rgb_t rgb;
|
||||
color_rgb_t rgb;
|
||||
|
||||
/* Convert the luminance value to its RGB components */
|
||||
/* Convert the luminance value to its RGB components */
|
||||
|
||||
rgb.red = lum->red * lum->luminance;
|
||||
rgb.green = lum->green * lum->luminance;
|
||||
rgb.blue = lum->blue * lum->luminance;
|
||||
rgb.red = lum->red * lum->luminance;
|
||||
rgb.green = lum->green * lum->luminance;
|
||||
rgb.blue = lum->blue * lum->luminance;
|
||||
|
||||
return wld_rgb2pixel(&rgb);
|
||||
return wld_rgb2pixel(&rgb);
|
||||
#endif
|
||||
}
|
||||
|
@ -61,5 +61,6 @@ void *wld_malloc(size_t size)
|
||||
{
|
||||
wld_fatal_error("out of memory (wld_malloc %x bytes)", size);
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@
|
||||
* This function concatenates two world plane lists
|
||||
************************************************************************/
|
||||
|
||||
void wld_merge_planelists(rect_head_t *outList, rect_head_t *inList)
|
||||
void wld_merge_planelists(rect_head_t * outList, rect_head_t * inList)
|
||||
{
|
||||
rect_list_t *inRect, *nextInRect;
|
||||
rect_list_t *outRect, *prevRect;
|
||||
@ -67,30 +67,27 @@ void wld_merge_planelists(rect_head_t *outList, rect_head_t *inList)
|
||||
{
|
||||
nextInRect = inRect->flink;
|
||||
|
||||
/* Search the output plane list to find the location to insert the
|
||||
* input rectangle. Each is list is maintained in ascending plane
|
||||
* order.
|
||||
/* Search the output plane list to find the location to insert the input
|
||||
* rectangle. Each is list is maintained in ascending plane order.
|
||||
*/
|
||||
|
||||
for (;
|
||||
((outRect) && (outRect->d.plane < inRect->d.plane));
|
||||
outRect = outRect->flink);
|
||||
|
||||
/* Add the inRect to the spot found in the list. Check if the
|
||||
* inRect goes at the one of the ends of the list.
|
||||
*/
|
||||
/* Add the inRect to the spot found in the list. Check if the inRect
|
||||
* goes at the one of the ends of the list. */
|
||||
|
||||
if (!outRect)
|
||||
{
|
||||
/* No rectangle with plane larger than the one to be added
|
||||
* was found in the list. The inRect goes at the end of
|
||||
* the list.
|
||||
/* No rectangle with plane larger than the one to be added was found
|
||||
* in the list. The inRect goes at the end of the list.
|
||||
*/
|
||||
|
||||
prevRect = outList->tail;
|
||||
if (!prevRect)
|
||||
{
|
||||
/* Special case: The list is empty */
|
||||
/* Special case: The list is empty */
|
||||
|
||||
inRect->flink = NULL;
|
||||
inRect->blink = NULL;
|
||||
@ -112,7 +109,7 @@ void wld_merge_planelists(rect_head_t *outList, rect_head_t *inList)
|
||||
prevRect = outRect->blink;
|
||||
if (!prevRect)
|
||||
{
|
||||
/* Special case: Insert at the head of the list */
|
||||
/* Special case: Insert at the head of the list */
|
||||
|
||||
inRect->flink = outRect;
|
||||
inRect->blink = NULL;
|
||||
|
@ -54,22 +54,30 @@
|
||||
* then adds it to the world plane destList
|
||||
************************************************************************/
|
||||
|
||||
void wld_move_plane(rect_list_t *rect, rect_head_t *destList,
|
||||
rect_head_t *srcList)
|
||||
void wld_move_plane(rect_list_t * rect, rect_head_t * destList,
|
||||
rect_head_t * srcList)
|
||||
{
|
||||
/* Un-hook the backward link to the rect */
|
||||
|
||||
if (rect->flink)
|
||||
rect->flink->blink = rect->blink;
|
||||
{
|
||||
rect->flink->blink = rect->blink;
|
||||
}
|
||||
else
|
||||
srcList->tail = rect->blink;
|
||||
{
|
||||
srcList->tail = rect->blink;
|
||||
}
|
||||
|
||||
/* Un-hook the forward link to the rect */
|
||||
|
||||
if (rect->blink)
|
||||
rect->blink->flink = rect->flink;
|
||||
{
|
||||
rect->blink->flink = rect->flink;
|
||||
}
|
||||
else
|
||||
srcList->head = rect->flink;
|
||||
{
|
||||
srcList->head = rect->flink;
|
||||
}
|
||||
|
||||
/* Then add the rect to the specified list */
|
||||
|
||||
|
@ -47,13 +47,13 @@
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name:
|
||||
* Name: wld_new_graphicfile
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
graphic_file_t *wld_new_graphicfile( void )
|
||||
graphic_file_t *wld_new_graphicfile(void)
|
||||
{
|
||||
graphic_file_t *gf = (graphic_file_t*)wld_malloc(sizeof(graphic_file_t));
|
||||
graphic_file_t *gf = (graphic_file_t *) wld_malloc(sizeof(graphic_file_t));
|
||||
|
||||
gf->transparent_entry = -1;
|
||||
|
||||
|
@ -70,7 +70,7 @@ rect_list_t *wld_new_plane(void)
|
||||
{
|
||||
/* Nothing on the free list. Allocate a new one */
|
||||
|
||||
rect = (rect_list_t*)wld_malloc(sizeof(rect_list_t));
|
||||
rect = (rect_list_t *) wld_malloc(sizeof(rect_list_t));
|
||||
}
|
||||
|
||||
return rect;
|
||||
|
@ -40,11 +40,11 @@
|
||||
* Included files
|
||||
*************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "trv_types.h"
|
||||
#include "wld_mem.h"
|
||||
#include "wld_pcx.h"
|
||||
# include <stdio.h>
|
||||
# include <malloc.h>
|
||||
# include "trv_types.h"
|
||||
# include "wld_mem.h"
|
||||
# include "wld_pcx.h"
|
||||
|
||||
/*************************************************************************
|
||||
* Public Functions
|
||||
@ -56,28 +56,28 @@
|
||||
* This function allocates the buffer region needed to load a pcx file
|
||||
************************************************************************/
|
||||
|
||||
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
|
||||
RGBColor *palette, uint8_t *buffer)
|
||||
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
|
||||
RGBColor * palette, uint8_t * buffer)
|
||||
{
|
||||
image->palette = palette;
|
||||
|
||||
if (buffer)
|
||||
{
|
||||
image->buffer = buffer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
image->buffer = (uint8_t*)wld_malloc(height * width + 1);
|
||||
}
|
||||
image->buffer = (uint8_t *) wld_malloc(height * width + 1);
|
||||
}
|
||||
|
||||
if (!image->buffer)
|
||||
{
|
||||
return PCX_ALLOCATION_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PCX_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MSWINDOWS */
|
||||
|
@ -49,14 +49,14 @@
|
||||
* Private Data
|
||||
*************************************************************************/
|
||||
|
||||
static float g_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE-1);
|
||||
static float g_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE - 1);
|
||||
|
||||
/*************************************************************************
|
||||
* Function: wld_pixel2lum
|
||||
* Description: Convert a pixel value into RGB-Luminance value.
|
||||
************************************************************************/
|
||||
|
||||
void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t *lum)
|
||||
void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t * lum)
|
||||
{
|
||||
dev_pixel_t devpixel = g_devpixel_lut[pixel_value];
|
||||
|
||||
@ -68,16 +68,15 @@ void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t *lum)
|
||||
|
||||
/* Get the luminance associated with the RGB value */
|
||||
|
||||
lum->luminance = sqrt(lum->red * lum->red +
|
||||
lum->green * lum->green +
|
||||
lum->blue * lum->blue);
|
||||
lum->luminance = sqrt(lum->red * lum->red +
|
||||
lum->green * lum->green + lum->blue * lum->blue);
|
||||
|
||||
/* Convert the RGB Component into unit vector + luminance */
|
||||
/* Convert the RGB Component into unit vector + luminance */
|
||||
|
||||
if (lum->luminance > 0.0)
|
||||
{
|
||||
lum->red /= lum->luminance;
|
||||
lum->blue /= lum->luminance;
|
||||
lum->green /= lum->luminance;
|
||||
}
|
||||
if (lum->luminance > 0.0)
|
||||
{
|
||||
lum->red /= lum->luminance;
|
||||
lum->blue /= lum->luminance;
|
||||
lum->green /= lum->luminance;
|
||||
}
|
||||
}
|
||||
|
@ -51,12 +51,11 @@
|
||||
* for each of the X, Y, and Z planes.
|
||||
*/
|
||||
|
||||
rect_head_t xPlane; /* list of X=plane rectangles */
|
||||
rect_head_t yPlane; /* list of Y=plane rectangles */
|
||||
rect_head_t zPlane; /* list of Z=plane rectangles */
|
||||
rect_head_t g_xplane_list; /* list of X=plane rectangles */
|
||||
rect_head_t g_yplane_list; /* list of Y=plane rectangles */
|
||||
rect_head_t g_zplane_list; /* list of Z=plane rectangles */
|
||||
rect_list_t *freeList;
|
||||
|
||||
/*************************************************************************
|
||||
* Private Variables
|
||||
*************************************************************************/
|
||||
|
||||
|
@ -150,9 +150,9 @@ typedef struct
|
||||
* for each of the X, Y, and Z planes.
|
||||
*/
|
||||
|
||||
extern rect_head_t xPlane; /* list of X=plane rectangles */
|
||||
extern rect_head_t yPlane; /* list of Y=plane rectangles */
|
||||
extern rect_head_t zPlane; /* list of Z=plane rectangles */
|
||||
extern rect_head_t g_xplane_list; /* list of X=plane rectangles */
|
||||
extern rect_head_t g_yplane_list; /* list of Y=plane rectangles */
|
||||
extern rect_head_t g_zplane_list; /* list of Z=plane rectangles */
|
||||
|
||||
/* This is the maximum value of a texture code */
|
||||
|
||||
|
@ -53,17 +53,20 @@
|
||||
* Read a decimal number from the steam fp
|
||||
************************************************************************/
|
||||
|
||||
int16_t wld_read_decimal(FILE *fp)
|
||||
int16_t wld_read_decimal(FILE * fp)
|
||||
{
|
||||
int16_t value = 0;
|
||||
int16_t value = 0;
|
||||
bool negative = false;
|
||||
int ch;
|
||||
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for
|
||||
* MSDOS compatibility)
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for MSDOS
|
||||
* compatibility)
|
||||
*/
|
||||
|
||||
do ch = getc(fp);
|
||||
do
|
||||
{
|
||||
ch = getc(fp);
|
||||
}
|
||||
while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
|
||||
|
||||
/* if the first character is '-', then its a negative number */
|
||||
@ -78,13 +81,16 @@ int16_t wld_read_decimal(FILE *fp)
|
||||
|
||||
while ((ch >= '0') && (ch <= '9'))
|
||||
{
|
||||
value = 10*value + (ch - (int)'0');
|
||||
value = 10 * value + (ch - (int)'0');
|
||||
ch = getc(fp);
|
||||
}
|
||||
|
||||
/* Apply the negation, if appropriate */
|
||||
|
||||
if (negative) value = -value;
|
||||
if (negative)
|
||||
{
|
||||
value = -value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -47,8 +47,8 @@
|
||||
#include "wld_pcx.h"
|
||||
#include "wld_utils.h"
|
||||
|
||||
graphic_file_t *wld_LoadPPM(FILE *fp, char *filename);
|
||||
graphic_file_t *wld_LoadGIF(FILE *fp, char *filename);
|
||||
graphic_file_t *wld_LoadPPM(FILE * fp, char *filename);
|
||||
graphic_file_t *wld_LoadGIF(FILE * fp, char *filename);
|
||||
|
||||
/*************************************************************************
|
||||
* Private Data
|
||||
@ -65,7 +65,7 @@ static const char pcxExtension[] = ".PCX";
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
|
||||
static graphic_file_format_t wld_CheckFormat(FILE * fp, char *filename)
|
||||
{
|
||||
char magic[MAGIC_LENGTH];
|
||||
|
||||
@ -74,7 +74,7 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
|
||||
wld_fatal_error("Error reading texture %s.", filename);
|
||||
}
|
||||
|
||||
if (strncmp(magic, PPM_MAGIC, sizeof(PPM_MAGIC) - 1) == 0)
|
||||
if (strncmp(magic, PPM_MAGIC, sizeof(PPM_MAGIC) - 1) == 0)
|
||||
{
|
||||
return formatPPM;
|
||||
}
|
||||
@ -90,7 +90,7 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
|
||||
{
|
||||
char *ptr1;
|
||||
char *ptr2;
|
||||
|
||||
|
||||
/* MS-DOS PCX files will have no magic number, we'll have to make an
|
||||
* educated guess based on the file extension.
|
||||
*/
|
||||
@ -101,7 +101,7 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
|
||||
|
||||
/* Check if the extension matches */
|
||||
|
||||
for (ptr2 = (char*)pcxExtension; ((*ptr1) && (*ptr2)); ptr1++, ptr2++)
|
||||
for (ptr2 = (char *)pcxExtension; ((*ptr1) && (*ptr2)); ptr1++, ptr2++)
|
||||
{
|
||||
if (toupper((int)*ptr1) != *ptr2)
|
||||
{
|
||||
@ -109,17 +109,17 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
/* If it is an exact match, both pointers should refer to the
|
||||
* NULL terminator.
|
||||
/* If it is an exact match, both pointers should refer to the NULL
|
||||
* terminator.
|
||||
*/
|
||||
|
||||
if (!(*ptr1) && !(*ptr2))
|
||||
{
|
||||
return formatPCX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formatUnknown;
|
||||
return formatUnknown;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
@ -177,4 +177,3 @@ graphic_file_t *wld_readgraphic_file(char *filename)
|
||||
fclose(fp);
|
||||
return gfile;
|
||||
}
|
||||
|
||||
|
@ -75,16 +75,24 @@ static int wld_log2(int x)
|
||||
unsigned int n;
|
||||
|
||||
if (x <= 0)
|
||||
return -1;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
n = (unsigned int) x;
|
||||
|
||||
{
|
||||
n = (unsigned int)x;
|
||||
}
|
||||
|
||||
for (i = 0; (n & 0x1) == 0; i++, n >>= 1);
|
||||
|
||||
if (n == 1)
|
||||
return i;
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
@ -92,15 +100,17 @@ static int wld_log2(int x)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
|
||||
static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
|
||||
{
|
||||
wld_bitmap_t *t;
|
||||
|
||||
if (height <= 0 || width <= 0)
|
||||
wld_fatal_error("wld_new_texture: bad texture dimensions");
|
||||
{
|
||||
wld_fatal_error("wld_new_texture: bad texture dimensions");
|
||||
}
|
||||
|
||||
t = (wld_bitmap_t*)wld_malloc(sizeof(wld_bitmap_t));
|
||||
t->bm = (trv_pixel_t*)wld_malloc(height * width * sizeof(trv_pixel_t));
|
||||
t = (wld_bitmap_t *) wld_malloc(sizeof(wld_bitmap_t));
|
||||
t->bm = (trv_pixel_t *) wld_malloc(height * width * sizeof(trv_pixel_t));
|
||||
|
||||
t->w = width;
|
||||
t->h = height;
|
||||
@ -114,7 +124,7 @@ static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
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;
|
||||
trv_pixel_t *destPixel = t->bm;
|
||||
@ -125,7 +135,7 @@ static void wld_quantize_texture(graphic_file_t *gFile, wld_bitmap_t *t)
|
||||
for (y = gFile->height - 1; y >= 0; y--)
|
||||
{
|
||||
pixel = wld_graphicfile_pixel(gFile, x, y);
|
||||
*destPixel++ = wld_Rgb2Pixel(&pixel);
|
||||
*destPixel++ = wld_Rgb2Pixel(&pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,16 +156,18 @@ wld_bitmap_t *wld_read_texturefile(char *filename)
|
||||
|
||||
gFile = wld_readgraphic_file(filename);
|
||||
if (gFile == NULL)
|
||||
wld_fatal_error("Error reading texture %s.", filename);
|
||||
{
|
||||
wld_fatal_error("Error reading texture %s.", filename);
|
||||
}
|
||||
|
||||
/* The height and width should be powers of two for efficient
|
||||
* texture mapping. Here, we enforce this.
|
||||
*/
|
||||
/* The height and width should be powers of two for efficient texture
|
||||
* mapping. Here, we enforce this. */
|
||||
|
||||
if (wld_log2(gFile->width) == -1 || wld_log2(gFile->height) == -1)
|
||||
wld_fatal_error("Dimensions texture %s are not powers of two.",
|
||||
filename);
|
||||
|
||||
{
|
||||
wld_fatal_error("Dimensions texture %s are not powers of two.", filename);
|
||||
}
|
||||
|
||||
t = wld_new_texture(gFile->width, gFile->height);
|
||||
wld_quantize_texture(gFile, t);
|
||||
|
||||
|
@ -61,5 +61,6 @@ void *wld_realloc(void *addr, size_t size)
|
||||
{
|
||||
wld_fatal_error("out of memory (wtrealloc %x bytes)", size);
|
||||
}
|
||||
return new;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
@ -54,21 +54,29 @@
|
||||
* and "deallocates" it by saving it on the free list
|
||||
************************************************************************/
|
||||
|
||||
void wld_remove_plane(rect_list_t *rect, rect_head_t *list)
|
||||
void wld_remove_plane(rect_list_t * rect, rect_head_t * list)
|
||||
{
|
||||
/* Un-hook the backward link to the rect */
|
||||
|
||||
if (rect->flink)
|
||||
rect->flink->blink = rect->blink;
|
||||
{
|
||||
rect->flink->blink = rect->blink;
|
||||
}
|
||||
else
|
||||
list->tail = rect->blink;
|
||||
{
|
||||
list->tail = rect->blink;
|
||||
}
|
||||
|
||||
/* Un-hook the forward link to the rect */
|
||||
|
||||
if (rect->blink)
|
||||
rect->blink->flink = rect->flink;
|
||||
{
|
||||
rect->blink->flink = rect->flink;
|
||||
}
|
||||
else
|
||||
list->head = rect->flink;
|
||||
{
|
||||
list->head = rect->flink;
|
||||
}
|
||||
|
||||
/* Then put the rect on the free list */
|
||||
|
||||
|
@ -49,48 +49,48 @@
|
||||
* TRV_PIXEL_MAX.
|
||||
****************************************************************************/
|
||||
|
||||
trv_pixel_t wld_rgb2pixel(color_rgb_t *pixel)
|
||||
trv_pixel_t wld_rgb2pixel(color_rgb_t * pixel)
|
||||
{
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
color_lum_t lum;
|
||||
color_lum_t lum;
|
||||
|
||||
/* Convert the RGB Value into a luminance value.
|
||||
* Get the luminance associated with the RGB value.
|
||||
*/
|
||||
/* Convert the RGB Value into a luminance value. Get the luminance associated
|
||||
* with the RGB value.
|
||||
*/
|
||||
|
||||
lum.luminance = sqrt(pixel->red * pixel->red
|
||||
+ pixel->green * pixel->green
|
||||
+ pixel->blue * pixel->blue);
|
||||
lum.luminance = sqrt(pixel->red * pixel->red
|
||||
+ pixel->green * pixel->green
|
||||
+ pixel->blue * pixel->blue);
|
||||
|
||||
/* Convert the RGB Component into unit vector + luminance */
|
||||
/* Convert the RGB Component into unit vector + luminance */
|
||||
|
||||
if (lum.luminance > 0.0)
|
||||
{
|
||||
lum.red = (float)pixel->red / lum.luminance;
|
||||
lum.green = (float)pixel->green / lum.luminance;
|
||||
lum.blue = (float)pixel->blue / lum.luminance;
|
||||
}
|
||||
else
|
||||
{
|
||||
lum.red = lum.green = lum.blue = g_unit_vector[GREY_NDX].red;
|
||||
}
|
||||
if (lum.luminance > 0.0)
|
||||
{
|
||||
lum.red = (float)pixel->red / lum.luminance;
|
||||
lum.green = (float)pixel->green / lum.luminance;
|
||||
lum.blue = (float)pixel->blue / lum.luminance;
|
||||
}
|
||||
else
|
||||
{
|
||||
lum.red = lum.green = lum.blue = g_unit_vector[GREY_NDX].red;
|
||||
}
|
||||
|
||||
return wld_lum2pixel(&lum);
|
||||
return wld_lum2pixel(&lum);
|
||||
#else
|
||||
trv_pixel_t ret;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
trv_pixel_t ret;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
|
||||
red = MIN((pixel->red * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
green = MIN((pixel->green * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
blue = MIN((pixel->blue * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
red = MIN((pixel->red * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
green = MIN((pixel->green * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
blue = MIN((pixel->blue * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX + 1),
|
||||
RGB_CUBE_SIZE - 1);
|
||||
|
||||
ret = (red * RGB_CUBE_SIZE + green) * RGB_CUBE_SIZE + blue;
|
||||
ret = (red * RGB_CUBE_SIZE + green) * RGB_CUBE_SIZE + blue;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
@ -59,6 +59,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
|
||||
/* These arrays map color forms into g_unit_vector array indices */
|
||||
|
||||
static const enum unit_vector_index_e g_wld_bgrform_map[NCOLOR_FORMS] =
|
||||
@ -100,42 +101,42 @@ static float g_wld_cube2pixel;
|
||||
****************************************************************************/
|
||||
|
||||
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS
|
||||
FAR color_lum_t *g_pixel2um_lut;
|
||||
color_lum_t *g_pixel2um_lut;
|
||||
|
||||
/* The following defines the "form" of each color in the g_unit_vector array */
|
||||
|
||||
const color_form_t g_wld_colorform[NCOLOR_FORMS] =
|
||||
{
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 0.875, 0.4841229, 0.0 },
|
||||
{ 0.7071068, 0.7071068, 0.0 },
|
||||
{ 0.6666667, 0.5270463, 0.5270463 },
|
||||
{ 0.5773503, 0.5773503, 0.5773503 }
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.875, 0.4841229, 0.0},
|
||||
{0.7071068, 0.7071068, 0.0},
|
||||
{0.6666667, 0.5270463, 0.5270463},
|
||||
{0.5773503, 0.5773503, 0.5773503}
|
||||
};
|
||||
|
||||
/* This array defines each color supported in the luminance model */
|
||||
|
||||
const color_lum_t g_unit_vector[NUNIT_VECTORS] =
|
||||
{
|
||||
{ 0.5773503, 0.5773503, 0.5773503, 441.672932,}, /* GREY_NDX */
|
||||
{0.5773503, 0.5773503, 0.5773503, 441.672932,}, /* GREY_NDX */
|
||||
|
||||
{ 0.0, 0.0, 1.0, 255.0 }, /* BLUE_NDX */
|
||||
{ 0.0, 0.4841229, 0.875, 291.428571 }, /* GREENERBLUE_NDX */
|
||||
{ 0.0, 0.7071068, 0.7071068, 360.624445 }, /* BLUEGREEN_NDX */
|
||||
{ 0.4841229, 0.0, 0.875, 291.428571 }, /* BLUEVIOLET_NDX */
|
||||
{ 0.7071068, 0.0, 0.7071068, 360.624445 }, /* VIOLET_NDX */
|
||||
{ 0.5270463, 0.5270463, 0.6666667, 382.499981 }, /* LIGHTBLUE_NDX */
|
||||
{0.0, 0.0, 1.0, 255.0}, /* BLUE_NDX */
|
||||
{0.0, 0.4841229, 0.875, 291.428571}, /* GREENERBLUE_NDX */
|
||||
{0.0, 0.7071068, 0.7071068, 360.624445}, /* BLUEGREEN_NDX */
|
||||
{0.4841229, 0.0, 0.875, 291.428571}, /* BLUEVIOLET_NDX */
|
||||
{0.7071068, 0.0, 0.7071068, 360.624445}, /* VIOLET_NDX */
|
||||
{0.5270463, 0.5270463, 0.6666667, 382.499981}, /* LIGHTBLUE_NDX */
|
||||
|
||||
{ 0.0, 1.0, 0.0, 255.0 }, /* GREEN_NDX */
|
||||
{ 0.0, 0.875, 0.4841229, 291.428571 }, /* BLUERGREN_NDX */
|
||||
{ 0.4841229, 0.875, 0.0, 291.428571 }, /* YELLOWGREEN_NDX */
|
||||
{ 0.7071068, 0.7071068, 0.0, 360.624445 }, /* YELLOW_NDX */
|
||||
{ 0.5270463, 0.6666667, 0.5270463, 382.499981 }, /* LIGHTGREEN_NDX */
|
||||
{0.0, 1.0, 0.0, 255.0}, /* GREEN_NDX */
|
||||
{0.0, 0.875, 0.4841229, 291.428571}, /* BLUERGREN_NDX */
|
||||
{0.4841229, 0.875, 0.0, 291.428571}, /* YELLOWGREEN_NDX */
|
||||
{0.7071068, 0.7071068, 0.0, 360.624445}, /* YELLOW_NDX */
|
||||
{0.5270463, 0.6666667, 0.5270463, 382.499981}, /* LIGHTGREEN_NDX */
|
||||
|
||||
{ 1.0, 0.0, 0.0, 255.0 }, /* RED_NDX */
|
||||
{ 0.875, 0.0, 0.4841229, 291.428571 }, /* REDVIOLET_NDX */
|
||||
{ 0.875, 0.4841229, 0.0, 291.428571 }, /* ORANGE_NDX */
|
||||
{ 0.6666667, 0.5270463, 0.5270463, 382.499981 }, /* PINK_NDX */
|
||||
{1.0, 0.0, 0.0, 255.0}, /* RED_NDX */
|
||||
{0.875, 0.0, 0.4841229, 291.428571}, /* REDVIOLET_NDX */
|
||||
{0.875, 0.4841229, 0.0, 291.428571}, /* ORANGE_NDX */
|
||||
{0.6666667, 0.5270463, 0.5270463, 382.499981}, /* PINK_NDX */
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -159,8 +160,8 @@ void wld_rgblookup_allocate(void)
|
||||
|
||||
/* Check if a color lookup table has been allocated */
|
||||
|
||||
g_devpixel_lut = (dev_pixel_t*)
|
||||
wld_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS*NLUMINANCES));
|
||||
g_devpixel_lut = (dev_pixel_t *)
|
||||
wld_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS * NLUMINANCES));
|
||||
|
||||
if (!g_devpixel_lut)
|
||||
{
|
||||
@ -169,12 +170,11 @@ void wld_rgblookup_allocate(void)
|
||||
|
||||
lut = g_devpixel_lut;
|
||||
|
||||
/* Save the color information and color lookup table for use in
|
||||
* color mapping below.
|
||||
*/
|
||||
/* Save the color information and color lookup table for use in color mapping
|
||||
* below. */
|
||||
|
||||
g_pixel2um_lut = (color_lum_t*)
|
||||
wld_malloc(sizeof(color_lum_t) * (NUNIT_VECTORS*NLUMINANCES));
|
||||
g_pixel2um_lut = (color_lum_t *)
|
||||
wld_malloc(sizeof(color_lum_t) * (NUNIT_VECTORS * NLUMINANCES));
|
||||
|
||||
if (!g_pixel2um_lut)
|
||||
{
|
||||
@ -189,24 +189,22 @@ void wld_rgblookup_allocate(void)
|
||||
for (lumndx = 0; lumndx < NLUMINANCES; lumndx++)
|
||||
{
|
||||
color_rgb_t color;
|
||||
FAR color_lum_t *lum;
|
||||
color_lum_t *lum;
|
||||
|
||||
/* Get a convenience pointer to the lookup table entry */
|
||||
|
||||
lum = &g_pixel2um_lut[index];
|
||||
lum = &g_pixel2um_lut[index];
|
||||
*lum = g_unit_vector[uvndx];
|
||||
|
||||
/* Get the luminance associated with this lum for this
|
||||
* unit vector.
|
||||
*/
|
||||
/* Get the luminance associated with this lum for this unit vector. */
|
||||
|
||||
lum->luminance = (lum->luminance * (float)(lumndx + 1)) / NLUMINANCES;
|
||||
|
||||
/* Convert to RGB and allocate the color */
|
||||
|
||||
color.red = (short) (lum->red * lum->luminance);
|
||||
color.green = (short) (lum->green * lum->luminance);
|
||||
color.blue = (short) (lum->blue * lum->luminance);
|
||||
color.red = (short)(lum->red * lum->luminance);
|
||||
color.green = (short)(lum->green * lum->luminance);
|
||||
color.blue = (short)(lum->blue * lum->luminance);
|
||||
|
||||
/* Save the RGB to pixel lookup data */
|
||||
|
||||
@ -221,24 +219,23 @@ void wld_rgblookup_allocate(void)
|
||||
|
||||
/* Check if a color lookup table has been allocated */
|
||||
|
||||
g_devpixel_lut = (dev_pixel_t*)
|
||||
wld_malloc(sizeof(dev_pixel_t) * (WLD_PIXEL_MAX+1));
|
||||
g_devpixel_lut = (dev_pixel_t *)
|
||||
wld_malloc(sizeof(dev_pixel_t) * (WLD_PIXEL_MAX + 1));
|
||||
|
||||
if (!g_devpixel_lut)
|
||||
{
|
||||
wld_fatal_error("ERROR: Failed to allocate color lookup table\n");
|
||||
}
|
||||
|
||||
/* Save the color information and color lookup table for use in
|
||||
* subsequent color mapping.
|
||||
*/
|
||||
/* Save the color information and color lookup table for use in subsequent
|
||||
* color mapping. */
|
||||
|
||||
lut = g_devpixel_lut;
|
||||
|
||||
/* Check if a Pixel-to-RGB color mapping table has been allocated */
|
||||
|
||||
g_devpixel_lut = (color_rgb_t*)
|
||||
wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX+1));
|
||||
g_devpixel_lut = (color_rgb_t *)
|
||||
wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX + 1));
|
||||
|
||||
if (!g_devpixel_lut)
|
||||
{
|
||||
@ -248,28 +245,26 @@ void wld_rgblookup_allocate(void)
|
||||
for (index = 0; index <= WLD_PIXEL_MAX; index++)
|
||||
{
|
||||
g_devpixel_lut[index].red
|
||||
= g_devpixel_lut[index].green
|
||||
= g_devpixel_lut[index].blue = 0;
|
||||
= g_devpixel_lut[index].green = g_devpixel_lut[index].blue = 0;
|
||||
}
|
||||
|
||||
/* Calculate the cube to trv_pixel_t scale factor. This factor will
|
||||
* convert an RGB component in the range {0..RGB_CUBE_SIZE-1} to
|
||||
* a value in the range {0..WLD_PIXEL_MAX}.
|
||||
*/
|
||||
/* Calculate the cube to trv_pixel_t scale factor. This factor will convert
|
||||
* an RGB component in the range {0..RGB_CUBE_SIZE-1} to a value in the range
|
||||
* {0..WLD_PIXEL_MAX}. */
|
||||
|
||||
g_wld_cube2pixel = (float)WLD_PIXEL_MAX / (float)(RGB_CUBE_SIZE-1);
|
||||
g_wld_cube2pixel = (float)WLD_PIXEL_MAX / (float)(RGB_CUBE_SIZE - 1);
|
||||
|
||||
/* Allocate each color in the RGB Cube */
|
||||
|
||||
for (rgb.red = 0; rgb.red < RGB_CUBE_SIZE; rgb.red++)
|
||||
for (rgb.red = 0; rgb.red < RGB_CUBE_SIZE; rgb.red++)
|
||||
for (rgb.green = 0; rgb.green < RGB_CUBE_SIZE; rgb.green++)
|
||||
for (rgb.blue = 0; rgb.blue < RGB_CUBE_SIZE; rgb.blue++)
|
||||
for (rgb.blue = 0; rgb.blue < RGB_CUBE_SIZE; rgb.blue++)
|
||||
{
|
||||
color_rgb_t color;
|
||||
|
||||
color.red = (short) (rgb.red * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
color.green = (short) (rgb.green * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
color.blue = (short) (rgb.blue * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
color.red = (short)(rgb.red * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
color.green = (short)(rgb.green * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
color.blue = (short)(rgb.blue * 65535 / (RGB_CUBE_SIZE - 1));
|
||||
|
||||
/* Save the RGB to pixel lookup data */
|
||||
|
||||
@ -278,9 +273,9 @@ void wld_rgblookup_allocate(void)
|
||||
/* Save the pixel to RGB lookup data */
|
||||
|
||||
if (color.pixel <= WLD_PIXEL_MAX)
|
||||
{
|
||||
g_devpixel_lut[color.pixel] = rgb;
|
||||
}
|
||||
{
|
||||
g_devpixel_lut[color.pixel] = rgb;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -47,16 +47,15 @@
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_CountRectangles
|
||||
* Description:
|
||||
* This function counts the number of rectangles in one plane
|
||||
************************************************************************/
|
||||
|
||||
static uint16_t wld_CountRectangles(rect_list_t *rect)
|
||||
static uint16_t wld_CountRectangles(rect_list_t * rect)
|
||||
{
|
||||
uint16_t count;
|
||||
uint16_t count;
|
||||
for (count = 0; (rect); count++, rect = rect->flink);
|
||||
return count;
|
||||
}
|
||||
@ -67,7 +66,7 @@ static uint16_t wld_CountRectangles(rect_list_t *rect)
|
||||
* This function stores the world data for one plane
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_SaveWorldPlane(FILE *fp, rect_list_t *rect)
|
||||
static uint8_t wld_SaveWorldPlane(FILE * fp, rect_list_t * rect)
|
||||
{
|
||||
/* For each rectangle in the list */
|
||||
|
||||
@ -75,7 +74,7 @@ static uint8_t wld_SaveWorldPlane(FILE *fp, rect_list_t *rect)
|
||||
{
|
||||
/* Write the rectangle to the output file */
|
||||
|
||||
if (fwrite((char*)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
|
||||
if (fwrite((char *)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
|
||||
return PLANE_DATA_WRITE_ERROR;
|
||||
}
|
||||
|
||||
@ -94,35 +93,45 @@ static uint8_t wld_SaveWorldPlane(FILE *fp, rect_list_t *rect)
|
||||
|
||||
uint8_t wld_save_planes(const char *wldFile)
|
||||
{
|
||||
FILE *fp;
|
||||
FILE *fp;
|
||||
plane_file_header_t fileHeader;
|
||||
uint8_t result;
|
||||
uint8_t result;
|
||||
|
||||
/* Open the file which contains the description of the world */
|
||||
|
||||
fp = fopen(wldFile, "wb");
|
||||
if (!fp) return PLANE_WRITE_OPEN_ERROR;
|
||||
if (!fp)
|
||||
{
|
||||
return PLANE_WRITE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
/* Create world file header */
|
||||
|
||||
fileHeader.numXRects = wld_CountRectangles(xPlane.head);
|
||||
fileHeader.numYRects = wld_CountRectangles(yPlane.head);
|
||||
fileHeader.numZRects = wld_CountRectangles(zPlane.head);
|
||||
fileHeader.numXRects = wld_CountRectangles(g_xplane_list.head);
|
||||
fileHeader.numYRects = wld_CountRectangles(g_yplane_list.head);
|
||||
fileHeader.numZRects = wld_CountRectangles(g_zplane_list.head);
|
||||
|
||||
/* Write the file header to the output file */
|
||||
|
||||
if (fwrite((char*)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
|
||||
result = PLANE_HEADER_WRITE_ERROR;
|
||||
if (fwrite((char *)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
|
||||
{
|
||||
result = PLANE_HEADER_WRITE_ERROR;
|
||||
}
|
||||
|
||||
/* Save the world, one plane at a time */
|
||||
|
||||
else
|
||||
{
|
||||
result = wld_SaveWorldPlane(fp, xPlane.head);
|
||||
result = wld_SaveWorldPlane(fp, g_xplane_list.head);
|
||||
if (result == PLANE_SUCCESS)
|
||||
result = wld_SaveWorldPlane(fp, yPlane.head);
|
||||
{
|
||||
result = wld_SaveWorldPlane(fp, g_yplane_list.head);
|
||||
}
|
||||
|
||||
if (result == PLANE_SUCCESS)
|
||||
wld_SaveWorldPlane(fp, zPlane.head);
|
||||
{
|
||||
wld_SaveWorldPlane(fp, g_zplane_list.head);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the file */
|
||||
|
@ -112,7 +112,7 @@ extern wld_coord_t runStepHeight;
|
||||
* Global Function Prototypes
|
||||
*************************************************************************/
|
||||
|
||||
uint8_t wld_create_world(FAR char *mapfile);
|
||||
uint8_t wld_create_world(char *mapfile);
|
||||
void wld_deallocate_world(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -64,64 +64,68 @@ static const char astDefaultFileName[] = "planes.pll";
|
||||
* Public Variables
|
||||
***************************************************************************/
|
||||
|
||||
enum editModeEnum editMode = EDITMODE_NONE;
|
||||
enum editModeEnum editMode = EDITMODE_NONE;
|
||||
enum editPlaneEnum editPlane = EDITPLANE_X;
|
||||
int viewSize = WORLD_INFINITY;
|
||||
int gridStep = WORLD_SIZE / 16;
|
||||
int viewSize = WORLD_INFINITY;
|
||||
int gridStep = WORLD_SIZE / 16;
|
||||
|
||||
int coordOffset[NUM_PLANES];
|
||||
int planePosition[NUM_PLANES];
|
||||
tcl_window_t windows[NUM_PLANES] =
|
||||
{
|
||||
{
|
||||
.title = "X-Plane",
|
||||
.plane = EDITPLANE_X,
|
||||
.width = WINDOW_SIZE,
|
||||
.title = "X-Plane",
|
||||
.plane = EDITPLANE_X,
|
||||
.width = WINDOW_SIZE,
|
||||
.height = WINDOW_SIZE,
|
||||
.palette = {
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
.palette =
|
||||
{
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
},
|
||||
},
|
||||
{
|
||||
.title = "Y-Plane",
|
||||
.plane = EDITPLANE_Y,
|
||||
.width = WINDOW_SIZE,
|
||||
.height = WINDOW_SIZE,
|
||||
.palette = {
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
.title = "Y-Plane",
|
||||
.plane = EDITPLANE_Y,
|
||||
.width = WINDOW_SIZE,
|
||||
.height = WINDOW_SIZE,
|
||||
.palette =
|
||||
{
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
},
|
||||
},
|
||||
{
|
||||
.title = "Z-Plane",
|
||||
.plane = EDITPLANE_Z,
|
||||
.width = WINDOW_SIZE,
|
||||
.height = WINDOW_SIZE,
|
||||
.palette = {
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
.title = "Z-Plane",
|
||||
.plane = EDITPLANE_Z,
|
||||
.width = WINDOW_SIZE,
|
||||
.height = WINDOW_SIZE,
|
||||
.palette =
|
||||
{
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
Lavender, Red, Red, LemonChiffon,
|
||||
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
||||
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
LightGray, DarkGray, DarkGray, DarkGray,
|
||||
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
rect_data_t editRect;
|
||||
|
||||
/****************************************************************************
|
||||
@ -166,15 +170,14 @@ static void astUpdateNEWModeDisplay(void)
|
||||
*/
|
||||
|
||||
static int astSetEditMode(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
ginfo("Processing command: %s\n", argv[0]);
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
else if (strcmp(argv[1], "POS") == 0)
|
||||
{
|
||||
@ -190,60 +193,59 @@ static int astSetEditMode(ClientData clientData,
|
||||
if (strcmp(argv[2], "x") == 0)
|
||||
{
|
||||
ginfo("Entering NEWX mode\n");
|
||||
editPlane = EDITPLANE_X;
|
||||
editRect.plane = planePosition[EDITPLANE_X];
|
||||
editPlane = EDITPLANE_X;
|
||||
editRect.plane = planePosition[EDITPLANE_X];
|
||||
editRect.hStart = planePosition[EDITPLANE_Y];
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.vStart = planePosition[EDITPLANE_Z];
|
||||
editRect.vEnd = editRect.vStart;
|
||||
editRect.vEnd = editRect.vStart;
|
||||
}
|
||||
else if (strcmp(argv[2], "y") == 0)
|
||||
{
|
||||
ginfo("Entering NEWY mode\n");
|
||||
editPlane = EDITPLANE_Y;
|
||||
editRect.plane = planePosition[EDITPLANE_Y];
|
||||
editPlane = EDITPLANE_Y;
|
||||
editRect.plane = planePosition[EDITPLANE_Y];
|
||||
editRect.hStart = planePosition[EDITPLANE_X];
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.vStart = planePosition[EDITPLANE_Z];
|
||||
editRect.vEnd = editRect.vStart;
|
||||
editRect.vEnd = editRect.vStart;
|
||||
}
|
||||
else if (strcmp(argv[2], "z") == 0)
|
||||
{
|
||||
ginfo("Entering NEWZ mode\n");
|
||||
editPlane = EDITPLANE_Z;
|
||||
editRect.plane = planePosition[EDITPLANE_Z];
|
||||
editPlane = EDITPLANE_Z;
|
||||
editRect.plane = planePosition[EDITPLANE_Z];
|
||||
editRect.hStart = planePosition[EDITPLANE_X];
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.hEnd = editRect.hStart;
|
||||
editRect.vStart = planePosition[EDITPLANE_Y];
|
||||
editRect.vEnd = editRect.vStart;
|
||||
editRect.vEnd = editRect.vStart;
|
||||
}
|
||||
else
|
||||
{
|
||||
wld_fatal_error("%s: Unrecognized NEW plane: %s\n",
|
||||
__FUNCTION__, argv[2]);
|
||||
__FUNCTION__, argv[2]);
|
||||
}
|
||||
astUpdateNEWModeDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
wld_fatal_error("%s: Unrecognized mode: %s\n",
|
||||
__FUNCTION__, argv[1]);
|
||||
wld_fatal_error("%s: Unrecognized mode: %s\n", __FUNCTION__, argv[1]);
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/* Called in response to the "ast_position" Tcl command */
|
||||
|
||||
static int astNewPosition(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
ginfo("Processing command: %s\n", argv[0]);
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
planePosition[0] = atoi(argv[1]);
|
||||
@ -251,7 +253,7 @@ static int astNewPosition(ClientData clientData,
|
||||
planePosition[2] = atoi(argv[3]);
|
||||
|
||||
ginfo("New plane positions: {%d,%d,%d}\n",
|
||||
planePosition[0], planePosition[1], planePosition[2]);
|
||||
planePosition[0], planePosition[1], planePosition[2]);
|
||||
|
||||
astUpdatePOSModeDisplay();
|
||||
return TCL_OK;
|
||||
@ -260,20 +262,19 @@ static int astNewPosition(ClientData clientData,
|
||||
/* Called in response to the "ast_zoom" Tcl command */
|
||||
|
||||
static int astNewZoom(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
ginfo("Processing command: %s\n", argv[0]);
|
||||
|
||||
if (argc != 5)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
/* Get the zoom settings */
|
||||
|
||||
viewSize = atoi(argv[1]);
|
||||
viewSize = atoi(argv[1]);
|
||||
coordOffset[0] = atoi(argv[2]);
|
||||
coordOffset[1] = atoi(argv[3]);
|
||||
coordOffset[2] = atoi(argv[4]);
|
||||
@ -282,40 +283,40 @@ static int astNewZoom(ClientData clientData,
|
||||
|
||||
if (viewSize <= 256)
|
||||
{
|
||||
gridStep = 16; /* 16 lines at 256 */
|
||||
gridStep = 16; /* 16 lines at 256 */
|
||||
}
|
||||
else if (viewSize <= 512)
|
||||
{
|
||||
gridStep = 32; /* 16 lines at 512 */
|
||||
gridStep = 32; /* 16 lines at 512 */
|
||||
}
|
||||
else if (viewSize <= 1024)
|
||||
{
|
||||
gridStep = 64; /* 16 lines at 1024 */
|
||||
gridStep = 64; /* 16 lines at 1024 */
|
||||
}
|
||||
else if (viewSize <= 2048)
|
||||
{
|
||||
gridStep = 128; /* 16 lines at 2048 */
|
||||
gridStep = 128; /* 16 lines at 2048 */
|
||||
}
|
||||
else if (viewSize <= 4096)
|
||||
{
|
||||
gridStep = 256; /* 16 lines at 4096 */
|
||||
gridStep = 256; /* 16 lines at 4096 */
|
||||
}
|
||||
else if (viewSize <= 8192)
|
||||
{
|
||||
gridStep = 512; /* 16 lines at 8196 */
|
||||
gridStep = 512; /* 16 lines at 8196 */
|
||||
}
|
||||
else if (viewSize <= 16384)
|
||||
{
|
||||
gridStep = 1024; /* 16 lines at 16384 */
|
||||
gridStep = 1024; /* 16 lines at 16384 */
|
||||
}
|
||||
else /* if (viewSize <= 32768) */
|
||||
else /* if (viewSize <= 32768) */
|
||||
{
|
||||
gridStep = 2048; /* 16 lines at 32768 */
|
||||
gridStep = 2048; /* 16 lines at 32768 */
|
||||
}
|
||||
|
||||
ginfo("New viewSize, gridStep: %d, %d\n", viewSize, gridStep);
|
||||
ginfo("New coordinate offsets: {%d,%d,%d}\n",
|
||||
coordOffset[0], coordOffset[1], coordOffset[2]);
|
||||
coordOffset[0], coordOffset[1], coordOffset[2]);
|
||||
|
||||
if (editMode == EDITMODE_POS)
|
||||
{
|
||||
@ -331,8 +332,7 @@ static int astNewZoom(ClientData clientData,
|
||||
/* Called in response to the "ast_edit" Tcl command */
|
||||
|
||||
static int astNewEdit(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
int start;
|
||||
int end;
|
||||
@ -343,7 +343,7 @@ static int astNewEdit(ClientData clientData,
|
||||
if (argc != 4)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
/* Ignore the command if we are not in NEW mode */
|
||||
@ -352,9 +352,9 @@ static int astNewEdit(ClientData clientData,
|
||||
{
|
||||
/* Get the new position information */
|
||||
|
||||
start = atoi(argv[2]);
|
||||
start = atoi(argv[2]);
|
||||
extent = atoi(argv[3]);
|
||||
end = start + extent - 1;
|
||||
end = start + extent - 1;
|
||||
|
||||
/* Which plane are we editting? */
|
||||
|
||||
@ -370,18 +370,18 @@ static int astNewEdit(ClientData clientData,
|
||||
{
|
||||
ginfo("New horizontal Y coordinates: {%d,%d}\n", start, end);
|
||||
editRect.hStart = start;
|
||||
editRect.hEnd = end;
|
||||
editRect.hEnd = end;
|
||||
}
|
||||
else if (strcmp(argv[1], "z") == 0)
|
||||
{
|
||||
ginfo("New vertical Z coordinates: {%d,%d}\n", start, end);
|
||||
editRect.vStart = start;
|
||||
editRect.vEnd = end;
|
||||
editRect.vEnd = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
wld_fatal_error("%s: Unrecognized EDITX plane: %s\n",
|
||||
__FUNCTION__, argv[1]);
|
||||
__FUNCTION__, argv[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -390,7 +390,7 @@ static int astNewEdit(ClientData clientData,
|
||||
{
|
||||
ginfo("New horizontal X coordinates: {%d,%d}\n", start, end);
|
||||
editRect.hStart = start;
|
||||
editRect.hEnd = end;
|
||||
editRect.hEnd = end;
|
||||
}
|
||||
else if (strcmp(argv[1], "y") == 0)
|
||||
{
|
||||
@ -401,12 +401,12 @@ static int astNewEdit(ClientData clientData,
|
||||
{
|
||||
ginfo("New vertical Z coordinates: {%d,%d}\n", start, end);
|
||||
editRect.vStart = start;
|
||||
editRect.vEnd = end;
|
||||
editRect.vEnd = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
wld_fatal_error("%s: Unrecognized EDITY plane: %s\n",
|
||||
__FUNCTION__, argv[1]);
|
||||
__FUNCTION__, argv[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -415,13 +415,13 @@ static int astNewEdit(ClientData clientData,
|
||||
{
|
||||
ginfo("New horizontal X coordinates: {%d,%d}\n", start, end);
|
||||
editRect.hStart = start;
|
||||
editRect.hEnd = end;
|
||||
editRect.hEnd = end;
|
||||
}
|
||||
else if (strcmp(argv[1], "y") == 0)
|
||||
{
|
||||
ginfo("New vertical Y coordinates: {%d,%d}\n", start, end);
|
||||
editRect.vStart = start;
|
||||
editRect.vEnd = end;
|
||||
editRect.vEnd = end;
|
||||
}
|
||||
else if (strcmp(argv[1], "z") == 0)
|
||||
{
|
||||
@ -431,7 +431,7 @@ static int astNewEdit(ClientData clientData,
|
||||
else
|
||||
{
|
||||
wld_fatal_error("%s: Unrecognized EDITZ plane: %s\n",
|
||||
__FUNCTION__, argv[1]);
|
||||
__FUNCTION__, argv[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -446,8 +446,7 @@ static int astNewEdit(ClientData clientData,
|
||||
/* Called in response to the "ast_attribute" Tcl command */
|
||||
|
||||
static int astNewAttributes(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
const char *attributes;
|
||||
int tmp;
|
||||
@ -457,14 +456,14 @@ static int astNewAttributes(ClientData clientData,
|
||||
if (argc != 4)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
attributes = argv[1];
|
||||
if (strlen(attributes) != 3)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected attribute string length: %s\n",
|
||||
__FUNCTION__, argv[1]);
|
||||
__FUNCTION__, argv[1]);
|
||||
}
|
||||
|
||||
/* Ignore the command if we are not in NEW mode */
|
||||
@ -500,7 +499,7 @@ static int astNewAttributes(ClientData clientData,
|
||||
ginfo("attributes: %s->%02x\n", attributes, editRect.attribute);
|
||||
|
||||
tmp = atoi(argv[2]);
|
||||
if ((tmp >=0) && (tmp < 256))
|
||||
if ((tmp >= 0) && (tmp < 256))
|
||||
{
|
||||
editRect.texture = tmp;
|
||||
}
|
||||
@ -511,7 +510,7 @@ static int astNewAttributes(ClientData clientData,
|
||||
ginfo("texture: %s->%d\n", argv[2], editRect.texture);
|
||||
|
||||
tmp = atoi(argv[3]);
|
||||
if ((tmp >=0) && (tmp <= MAXX_SCALING))
|
||||
if ((tmp >= 0) && (tmp <= MAXX_SCALING))
|
||||
{
|
||||
editRect.scale = tmp;
|
||||
}
|
||||
@ -521,22 +520,22 @@ static int astNewAttributes(ClientData clientData,
|
||||
}
|
||||
ginfo("scale: %s->%d\n", argv[3], editRect.scale);
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/* Called in response to the "ast_addrectangle" Tcl command */
|
||||
|
||||
static int astAddRectangle(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
|
||||
|
||||
ginfo("Processing command: %s\n", argv[0]);
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
/* Ignore the command if we are not in NEW mode */
|
||||
@ -556,15 +555,15 @@ static int astAddRectangle(ClientData clientData,
|
||||
switch (editPlane)
|
||||
{
|
||||
case EDITPLANE_X:
|
||||
wld_add_plane(rect, &xPlane);
|
||||
wld_add_plane(rect, &g_xplane_list);
|
||||
break;
|
||||
|
||||
case EDITPLANE_Y:
|
||||
wld_add_plane(rect, &yPlane);
|
||||
wld_add_plane(rect, &g_yplane_list);
|
||||
break;
|
||||
|
||||
case EDITPLANE_Z:
|
||||
wld_add_plane(rect, &zPlane);
|
||||
wld_add_plane(rect, &g_zplane_list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -574,16 +573,15 @@ static int astAddRectangle(ClientData clientData,
|
||||
/* Called in response to the "ast_save" Tcl command */
|
||||
|
||||
static int astSaveRectangles(ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int argc, const char *argv[])
|
||||
Tcl_Interp * interp, int argc, const char *argv[])
|
||||
{
|
||||
|
||||
|
||||
ginfo("Processing command: %s\n", argv[0]);
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
||||
__FUNCTION__, argc);
|
||||
__FUNCTION__, argc);
|
||||
}
|
||||
|
||||
wld_save_planes(astOutFileName);
|
||||
@ -592,8 +590,7 @@ static int astSaveRectangles(ClientData clientData,
|
||||
|
||||
static void show_usage(const char *progname)
|
||||
{
|
||||
fprintf(stderr, "USAGE:\n\t%s [-o <outfilename>] <infilename>\n",
|
||||
progname);
|
||||
fprintf(stderr, "USAGE:\n\t%s [-o <outfilename>] <infilename>\n", progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -613,7 +610,7 @@ int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case 'o' :
|
||||
case 'o':
|
||||
astOutFileName = optarg;
|
||||
break;
|
||||
default:
|
||||
@ -623,29 +620,26 @@ int main(int argc, char **argv, char **envp)
|
||||
}
|
||||
}
|
||||
|
||||
/* We expect at least one argument after the options: The input
|
||||
* file name.
|
||||
*/
|
||||
/* We expect at least one argument after the options: The input file name. */
|
||||
|
||||
if (optind > argc - 1)
|
||||
{
|
||||
fprintf(stderr, "Expected input file name\n");
|
||||
show_usage(argv[0]);
|
||||
}
|
||||
|
||||
astInFileName = argv[optind];
|
||||
|
||||
/* Read the plane file now so that we can be certain that it is
|
||||
* a valid plaine file.
|
||||
*/
|
||||
/* Read the plane file now so that we can be certain that it is a valid
|
||||
* plaine file. */
|
||||
|
||||
if (wld_load_planefile(astInFileName) != PLANE_SUCCESS)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Tk_Main creates a Tcl interpreter and calls Tcl_AppInit() then
|
||||
* begins processing window events and interactive commands.
|
||||
*/
|
||||
/* Tk_Main creates a Tcl interpreter and calls Tcl_AppInit() then begins
|
||||
* processing window events and interactive commands. */
|
||||
|
||||
Tk_Main(1, argv, Tcl_AppInit);
|
||||
exit(0);
|
||||
@ -665,7 +659,7 @@ int do_tcl_action(const char *script)
|
||||
* is entered.
|
||||
*/
|
||||
|
||||
int Tcl_AppInit(Tcl_Interp *interp)
|
||||
int Tcl_AppInit(Tcl_Interp * interp)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -695,19 +689,19 @@ int Tcl_AppInit(Tcl_Interp *interp)
|
||||
/* Define application-specific commands */
|
||||
|
||||
Tcl_CreateCommand(astInterp, "ast_seteditmode", astSetEditMode,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_position", astNewPosition,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_zoom", astNewZoom,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_edit", astNewEdit,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_attributes", astNewAttributes,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_addrectangle", astAddRectangle,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
Tcl_CreateCommand(astInterp, "ast_save", astSaveRectangles,
|
||||
(ClientData)0, (Tcl_CmdDeleteProc *) NULL);
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
/* Initialize the Tcl parser */
|
||||
|
||||
@ -723,12 +717,12 @@ int Tcl_AppInit(Tcl_Interp *interp)
|
||||
|
||||
void wld_fatal_error(char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
putc('\n', stderr);
|
||||
va_end(args);
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
putc('\n', stderr);
|
||||
va_end(args);
|
||||
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -46,8 +46,8 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <sys/ipc.h>
|
||||
#ifndef NO_XSHM
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
# include <sys/shm.h>
|
||||
# include <X11/extensions/XShm.h>
|
||||
#endif
|
||||
|
||||
#include "trv_types.h"
|
||||
@ -75,11 +75,11 @@ static int useShm;
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void x11_create_window(tcl_window_t *w);
|
||||
static void x11_load_palette(tcl_window_t *w);
|
||||
static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap);
|
||||
static void x11_map_sharedmemory(tcl_window_t *w, int depth);
|
||||
static void x11_unmap_sharedmemory(tcl_window_t *w);
|
||||
static void x11_create_window(tcl_window_t * w);
|
||||
static void x11_load_palette(tcl_window_t * w);
|
||||
static bool x11_allocate_colors(tcl_window_t * w, Colormap colormap);
|
||||
static void x11_map_sharedmemory(tcl_window_t * w, int depth);
|
||||
static void x11_unmap_sharedmemory(tcl_window_t * w);
|
||||
static void x11_unmap_all_sharedmemory(void);
|
||||
|
||||
/****************************************************************************
|
||||
@ -91,7 +91,7 @@ static void x11_unmap_all_sharedmemory(void);
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
static void x11_create_window(tcl_window_t *w)
|
||||
static void x11_create_window(tcl_window_t * w)
|
||||
{
|
||||
XGCValues gcValues;
|
||||
char *argv[2] = { "xast", NULL };
|
||||
@ -114,8 +114,8 @@ static void x11_create_window(tcl_window_t *w)
|
||||
XStringListToTextProperty(&iconName, 1, &iNameProp);
|
||||
|
||||
sizeHints.flags = PSize | PMinSize | PMaxSize;
|
||||
sizeHints.width= sizeHints.min_width = sizeHints.max_width = w->width;
|
||||
sizeHints.height= sizeHints.min_height = sizeHints.max_height = w->height;
|
||||
sizeHints.width = sizeHints.min_width = sizeHints.max_width = w->width;
|
||||
sizeHints.height = sizeHints.min_height = sizeHints.max_height = w->height;
|
||||
|
||||
XSetWMProperties(w->display, w->win, &wNameProp, &iNameProp, argv, 1,
|
||||
&sizeHints, NULL, NULL);
|
||||
@ -133,7 +133,7 @@ static void x11_create_window(tcl_window_t *w)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
static void x11_load_palette(tcl_window_t *w)
|
||||
static void x11_load_palette(tcl_window_t * w)
|
||||
{
|
||||
Colormap cMap;
|
||||
|
||||
@ -147,8 +147,7 @@ static void x11_load_palette(tcl_window_t *w)
|
||||
XFreeColors(w->display, cMap, w->colorLookup, w->ncolors, 0);
|
||||
|
||||
cMap = XCreateColormap(w->display, w->win,
|
||||
DefaultVisual(w->display, w->screen),
|
||||
AllocNone);
|
||||
DefaultVisual(w->display, w->screen), AllocNone);
|
||||
|
||||
if (!x11_allocate_colors(w, cMap))
|
||||
{
|
||||
@ -166,7 +165,7 @@ static void x11_load_palette(tcl_window_t *w)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap)
|
||||
static bool x11_allocate_colors(tcl_window_t * w, Colormap colormap)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -184,9 +183,9 @@ static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap)
|
||||
* represented by (65535,65535,65535).
|
||||
*/
|
||||
|
||||
color.red = ((unsigned short)w->palette[i].red << 8);
|
||||
color.red = ((unsigned short)w->palette[i].red << 8);
|
||||
color.green = ((unsigned short)w->palette[i].green << 8);
|
||||
color.blue = ((unsigned short)w->palette[i].blue << 8);
|
||||
color.blue = ((unsigned short)w->palette[i].blue << 8);
|
||||
color.flags = DoRed | DoGreen | DoBlue;
|
||||
|
||||
/* Then allocate a color for this selection */
|
||||
@ -199,9 +198,9 @@ static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap)
|
||||
/* Save the RGB to pixel lookup data */
|
||||
|
||||
ginfo("%d.%d {%02x,%02x,%02x}->0x%06lx\n",
|
||||
w->plane, i,
|
||||
w->palette[i].red, w->palette[i].green, w->palette[i].blue,
|
||||
color.pixel);
|
||||
w->plane, i,
|
||||
w->palette[i].red, w->palette[i].green, w->palette[i].blue,
|
||||
color.pixel);
|
||||
|
||||
w->colorLookup[i] = color.pixel;
|
||||
w->ncolors++;
|
||||
@ -215,7 +214,7 @@ static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap)
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NO_XSHM
|
||||
static int errorHandler(Display *display, XErrorEvent *event)
|
||||
static int errorHandler(Display * display, XErrorEvent * event)
|
||||
{
|
||||
xError = 1;
|
||||
|
||||
@ -242,9 +241,9 @@ static void trapErrors(void)
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NO_XSHM
|
||||
static int untrapErrors(Display *display)
|
||||
static int untrapErrors(Display * display)
|
||||
{
|
||||
XSync(display,0);
|
||||
XSync(display, 0);
|
||||
XSetErrorHandler(NULL);
|
||||
return xError;
|
||||
}
|
||||
@ -255,7 +254,7 @@ static int untrapErrors(Display *display)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
static void x11_map_sharedmemory(tcl_window_t * w, int depth)
|
||||
{
|
||||
#ifndef NO_XSHM
|
||||
Status result;
|
||||
@ -264,7 +263,8 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
shmCheckPoint = 0;
|
||||
x11_unmap_sharedmemory(w);
|
||||
|
||||
if (!shmCheckPoint) atexit(x11_unmap_all_sharedmemory);
|
||||
if (!shmCheckPoint)
|
||||
atexit(x11_unmap_all_sharedmemory);
|
||||
shmCheckPoint = 1;
|
||||
|
||||
useShm = 0;
|
||||
@ -277,7 +277,7 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
|
||||
trapErrors();
|
||||
w->image = XShmCreateImage(w->display,
|
||||
DefaultVisual(w->display, w->screen),
|
||||
DefaultVisual(w->display, w->screen),
|
||||
depth, ZPixmap, NULL, &xshminfo,
|
||||
w->width, w->height);
|
||||
|
||||
@ -302,9 +302,9 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
goto shmerror;
|
||||
}
|
||||
shmCheckPoint++;
|
||||
|
||||
w->image->data = (char *) shmat(xshminfo.shmid, 0, 0);
|
||||
if (image->data == ((char *) -1))
|
||||
|
||||
w->image->data = (char *)shmat(xshminfo.shmid, 0, 0);
|
||||
if (image->data == ((char *)-1))
|
||||
{
|
||||
x11_unmap_sharedmemory(w);
|
||||
goto shmerror;
|
||||
@ -323,35 +323,35 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
}
|
||||
|
||||
shmCheckPoint++;
|
||||
} else
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
if (!useShm)
|
||||
{
|
||||
if (!useShm)
|
||||
{
|
||||
#ifndef NO_XSHM
|
||||
shmerror:
|
||||
shmerror:
|
||||
#endif
|
||||
useShm = 0;
|
||||
useShm = 0;
|
||||
|
||||
w->frameBuffer = (dev_pixel_t*)
|
||||
wld_malloc(w->width * w->height * sizeof(dev_pixel_t));
|
||||
w->frameBuffer = (dev_pixel_t *)
|
||||
wld_malloc(w->width * w->height * sizeof(dev_pixel_t));
|
||||
|
||||
w->image = XCreateImage(w->display,
|
||||
DefaultVisual(w->display, w->screen),
|
||||
depth,
|
||||
ZPixmap,
|
||||
0,
|
||||
(char*)w->frameBuffer,
|
||||
w->width, w->height,
|
||||
8, 0);
|
||||
w->image = XCreateImage(w->display,
|
||||
DefaultVisual(w->display, w->screen),
|
||||
depth,
|
||||
ZPixmap,
|
||||
0,
|
||||
(char *)w->frameBuffer,
|
||||
w->width, w->height, 8, 0);
|
||||
|
||||
if (w->image == NULL)
|
||||
{
|
||||
wld_fatal_error("Unable to create image.");
|
||||
}
|
||||
|
||||
shmCheckPoint++;
|
||||
if (w->image == NULL)
|
||||
{
|
||||
wld_fatal_error("Unable to create image.");
|
||||
}
|
||||
|
||||
shmCheckPoint++;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -359,7 +359,7 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
static void x11_unmap_sharedmemory(tcl_window_t *w)
|
||||
static void x11_unmap_sharedmemory(tcl_window_t * w)
|
||||
{
|
||||
#ifndef NO_XSHM
|
||||
if (shmCheckPoint > 4)
|
||||
@ -413,7 +413,7 @@ static void x11_unmap_all_sharedmemory(void)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
void x11_UpdateScreen(tcl_window_t *w)
|
||||
void x11_UpdateScreen(tcl_window_t * w)
|
||||
{
|
||||
#ifndef NO_XSHM
|
||||
if (useShm)
|
||||
@ -439,7 +439,7 @@ void x11_UpdateScreen(tcl_window_t *w)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
void x11_InitGraphics(tcl_window_t *w)
|
||||
void x11_InitGraphics(tcl_window_t * w)
|
||||
{
|
||||
XWindowAttributes windowAttributes;
|
||||
|
||||
@ -467,7 +467,7 @@ void x11_InitGraphics(tcl_window_t *w)
|
||||
* Description:
|
||||
***************************************************************************/
|
||||
|
||||
void x11_EndGraphics(tcl_window_t *w)
|
||||
void x11_EndGraphics(tcl_window_t * w)
|
||||
{
|
||||
x11_unmap_all_sharedmemory();
|
||||
XCloseDisplay(w->display);
|
||||
|
Loading…
x
Reference in New Issue
Block a user