summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fuller <relnev@icculus.org>2008-05-04 02:51:54 -0700
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-20 02:22:37 +0200
commit76403986b15eb10e3045397ccb4262b87419c86c (patch)
treef4effc045a39bf1bef37e5dddad0c20111ab1b3c
parenta64e1008385dd2eef5f44f9adb135f7644da92fd (diff)
Removed unused image and font code.
-rw-r--r--src/afont.c914
-rw-r--r--src/avp/win95/font.h19
-rw-r--r--src/avp/win95/gadgets/trepgadg.cpp115
-rw-r--r--src/avp/win95/pcmenus.cpp222
-rw-r--r--src/win95/chnkimag.cpp699
-rw-r--r--src/win95/chnkimag.hpp33
-rw-r--r--src/win95/cl_init.cpp34
-rw-r--r--src/win95/cl_init.h23
-rw-r--r--src/win95/d3_image.cpp2491
-rw-r--r--src/win95/d3_image.hpp1223
10 files changed, 0 insertions, 5773 deletions
diff --git a/src/afont.c b/src/afont.c
deleted file mode 100644
index 891a909..0000000
--- a/src/afont.c
+++ /dev/null
@@ -1,914 +0,0 @@
-#include "3dc.h"
-#include "inline.h"
-#include "module.h"
-
-#include "gamedef.h"
-#include "font.h"
-
-#include "indexfnt.hpp"
-
-#define UseLocalAssert 1
-#include "ourasert.h"
-
-
-/* Roxbys font stuff. any comments will be useful!!!
-
- font control - Fonts description and sturctures game/plat/font.h
- Platform dependent processing game/plat/platsup.c or ddplat.cpp
-*/
-
-
-
-/* general ideas. Crap I know!!!
-
- written to maintain compatiblity with the current texture (bitmap) processing tools.
- all the information about spacing of the font is maintained witin the bitmap itself,
- using hotspots for the texture processing, that way we dont need extra tools to convert
- fonts. It also allows complete font positioning (except different letter combos changing)
- I have shifted most of the emphasis onto the artists to set up the font and to mark it how they
- see fit. All the fonts must contain hotspots for all the letters. In that way we can easily
- expand fonts. The character offests at the mo are simply -32. We may have to set up jump tables
- at some later date to get chars for different languages.
-
- Nothing supports anti-aliasing at the moment. Be careful with colours!!!
-
- Most of the info is being passed as locals. Clumsy I know. I didnt want to take up more
- space than was nessecery
-
-
- HARD coded. Names of the fonts
- Number of fonts to load
- Number of characters in the font. you can leave letters blank. The number of
- characters in the fonts can be changed for different languages
-
- AVP-Win95
-
- This loads all the fonts in the structure PFFONT AvpFonts[] that is passed
- to while NUM_FONTS. The Imageheader->ImagePtr for the data is maintained
- untill we have processd the characters. I dont fancy manipulating the data
- in a LPDIRECTDRAWSURFACE. The character descriptors in the font contain
- nothing but a src RECT. the void* pointer in the PFFONT structure in this
- case is cast to LPDIRECTDRAWSURFACE.
-
-
-
- Not that the entire font is placed into a
- file That is then processed. CLUT where to
- put the CLU???? Put it into the vid memory.
- use a void*
-*/
-
-/*
- Only have 8 bit support a tne moment. More to come!!!
- Screen modes. I recommend loading up different fonts for different screen modes.
- Simply reference a different structure.
-*/
-
-
-#define CHAR_WIDTH(font_num, offset) ((AvpFonts[font_num].srcRect[offset].right - AvpFonts[font_num].srcRect[offset].left))
-#define CHAR_HEIGHT(font_num, offset) ((AvpFonts[font_num].srcRect[offset].bottom - AvpFonts[font_num].srcRect[offset].top))
-#define IS_CHAR_WHITE_SPACE(ch) ((ch == '\t' || ch == '\n' || ch == ' ' || (int)ch == 0x0))
-
-
-
-static int ProcessFontEntry
-(
- PFFONT* font,
- unsigned char* fontstartaddress,
- unsigned pitch,
- int* countfromrow,
- int* countfromcol,
- int charnum
-);
-
-static int ProcessLineLength
-(
- char* start_ch, // start char of string
- AVP_FONTS fontnum, // the font we are using
- int offset, // the offset from the font
- int max_width, // the width of the line
- char** end_ch, // filled with end address
- int* line_length
-);
-
-void LoadAllFonts()
-{
- // these fonts end up being in memory all the time,
- // I will also supply a function which is delete
- // specific font.
-
- int fontnum = 0;
-
- while(fontnum < NUM_FONTS)
- {
- /* load the font in turn */
- LoadPFFont(fontnum);
- fontnum ++;
- }
-}
-
-
-void LoadPFFont(int fontnum)
-{
- // these fonts end up being in memory all the time,
- // I will also supply a function which is delete
- // specific font.
-
- PFFONT *font = &AvpFonts[fontnum];
- unsigned nPitch;
- unsigned char * pSurface;
-
- LoadFont(font);
-
- /* get the hotspot color first entry in */
-
- if(font->fttexBitDepth == 15)font->fttexBitDepth = 16;
-
- pSurface = FontLock(font,&nPitch);
- GLOBALASSERT(pSurface);
-
- font->hotSpotValue = *(unsigned *)pSurface & (font->fttexBitDepth<32 ? (1<<font->fttexBitDepth)-1 : 0xffffffffU);
-
- /* the hotspot value is the top-left pixel */
- {
- int charnum = 0;
- int countfromrow = 1;
- int countfromcol = 0;
-
- /*
- find the hotspots and send everything to the
- processing function. This part of routine find the
- hotspots in numbers of pixels
- */
-
- /*Top line of the texture is redundent we get the hotspot from this*/
- /*edge of the texture has only lines*/
-
-
- while(charnum < font->num_chars_in_font)
- {
- ProcessFontEntry(font,pSurface,nPitch,&countfromrow,&countfromcol,charnum);
- charnum++;
- }
-
- #if 0
- // Taken out by DHM 26/11/97:
- fontnum++;
- #endif
- charnum = 0;
- }
-
- FontUnlock(font);
-
- #if SupportWindows95
- INDEXFNT_PFLoadHook
- (
- (FontIndex) fontnum,
- // FontIndex I_Font_New,
- font // PFFONT *pffont_New
- );
- #endif
-}
-
-
-
-static int ProcessFontEntry
-(
- PFFONT* font,
- unsigned char* fontstartaddress,
- unsigned pitch,
- int* countfromrow,
- int* countfromcol,
- int charnum
-)
-{
- /*
- okay set the starting point
-
- countfromrow marks the current depth of the processing row in the texture.
- countfromcol marks how far along the current coloum we have processed
-
- * = HOTSPOT .. the first pixel is used as the hotspot
-
- **********************
- * ** ** **** * <---- startfromrow
- ###
- #
- ## # # ###
- # # # # # ##
- ### ### #### ##
- * * # * **** * Blank chars marked by two hotspots adjacent
- ### ^^ |at the top and the bottom
- * * || |
- ^ ||______|
- |
- |
- startfromcol
-
- ********************* Note that the spot in col 0 marks a new linw of chars
-
- */
-
-
- int curr_row = *countfromrow;
- int curr_col = *countfromcol;
- int y_offset = 0, x_offset = curr_col;
-
-
- GLOBALASSERT(font);
- GLOBALASSERT(fontstartaddress);
- GLOBALASSERT(charnum < font->num_chars_in_font);
- GLOBALASSERT(curr_row < font->fttexHeight);
- GLOBALASSERT(curr_col <= font->fttexWidth);
-
- /*remember that all the corrdinates are done by pixels
- find the x and y corrdinates of the left lower hotspot
- we process each line (row) from startfromrow to the end
- first find the next marker in startfromrow
- */
-
- // only supported if bit depth is a whole number of bytes
- GLOBALASSERT(8==font->fttexBitDepth || 16==font->fttexBitDepth || 24==font->fttexBitDepth || 32==font->fttexBitDepth);
-
- while(1)
- {
- // this bit processes the chars, finds uvs, extents and fills in the sturcture*/
- // count along the row to find the next x position
-
- unsigned int colour_here;
-
- if(x_offset > font->fttexWidth - 1)
- {
- // reached the end of the line! reset x and then y
-
- x_offset = 0;
- curr_col = 0;
-
- curr_row += font->fontHeight; // max line height
- *countfromrow = curr_row;
-
- GLOBALASSERT(curr_row < font->fttexHeight);
- }
-
- switch (font->fttexBitDepth)
- {
- default:
- GLOBALASSERT(0);
- case 8:
- colour_here = *(fontstartaddress + (curr_row*pitch + x_offset));
- break;
- case 16:
- colour_here = *(unsigned short *)(fontstartaddress + (curr_row*pitch + 2*x_offset));
- break;
- case 24:
- {
- unsigned char * pPixel = fontstartaddress + (curr_row*pitch + 3*x_offset);
- // assuming the right endianness
- colour_here = pPixel[0] | (unsigned)pPixel[1] << 8 | (unsigned)pPixel[2] << 16;
- break;
- }
- case 32:
- colour_here = *(unsigned *)(fontstartaddress + (curr_row*pitch + 4*x_offset));
- break;
-
- }
-
- if(colour_here == font->hotSpotValue)
- {
- int width = -1, height = -1;
- /* set up the uv corrds of the top left corner*/
- int u = x_offset + 1;
- int v = curr_row + 1;
-
-
- /* scan down to give height*/
- for(y_offset = (curr_row + 1); y_offset < font->fttexHeight; y_offset++)
- {
- switch (font->fttexBitDepth)
- {
- default:
- GLOBALASSERT(0);
- case 8:
- colour_here = *(fontstartaddress + (y_offset*pitch + x_offset));
- break;
- case 16:
- colour_here = *(unsigned short *)(fontstartaddress + (y_offset*pitch + 2*x_offset));
- break;
- case 24:
- {
- unsigned char * pPixel = fontstartaddress + (y_offset*pitch + 3*x_offset);
- // assuming the right endianness
- colour_here = pPixel[0] | (unsigned)pPixel[1] << 8 | (unsigned)pPixel[2] << 16;
- break;
- }
- case 32:
- colour_here = *(unsigned *)(fontstartaddress + (y_offset*pitch + 4*x_offset));
- break;
-
- }
-
- if(colour_here == font->hotSpotValue)
- {
- height = y_offset - curr_row - 1; // -1 because we exclude the top and bottom hotspots
- break;
- }
- }
-
- /* scan along to get the width*/
- for(++x_offset; x_offset < font->fttexWidth; x_offset ++)
- {
- switch (font->fttexBitDepth)
- {
- default:
- GLOBALASSERT(0);
- case 8:
- colour_here = *(fontstartaddress + (curr_row*pitch + x_offset));
- break;
- case 16:
- colour_here = *(unsigned short *)(fontstartaddress + (curr_row*pitch + 2*x_offset));
- break;
- case 24:
- {
- unsigned char * pPixel = fontstartaddress + (curr_row*pitch + 3*x_offset);
- // assuming the right endianness
- colour_here = pPixel[0] | (unsigned)pPixel[1] << 8 | (unsigned)pPixel[2] << 16;
- break;
- }
- case 32:
- colour_here = *(unsigned *)(fontstartaddress + (curr_row*pitch + 4*x_offset));
- break;
-
- }
-
- if(colour_here == font->hotSpotValue)
- {
- width = x_offset - curr_col - 1; // exclude end hotspot
- break;
- }
- }
-
- *countfromcol = x_offset + 1; /* ready for the next char*/
-
- /*fill in the data structure - platform dependent*/
- FillCharacterSlot(u, v, width, height, charnum, font);
- return 0;
- }
-
- x_offset++;
-
- }
- return 0;
-}
-
-
-#if 0 // obsolete
-static int Process8BitEntry(PFFONT* font,
- char* fontstartaddress,
- int* countfromrow,
- int* countfromcol,
- int charnum)
-{
- /*
- okay set the starting point
-
- countfromrow marks the current depth of the processing row in the texture.
- countfromcol marks how far along the current coloum we have processed
-
- * = HOTSPOT .. the first pixel is used as the hotspot
-
- **********************
- * ** ** **** * <---- startfromrow
- ###
- #
- ## # # ###
- # # # # # ##
- ### ### #### ##
- * * # * **** * Blank chars marked by two hotspots adjacent
- ### ^^ |at the top and the bottom
- * * || |
- ^ ||______|
- |
- |
- startfromcol
-
- ********************* Note that the spot in col 0 marks a new linw of chars
-
- */
-
-
- int curr_row = *countfromrow;
- int curr_col = *countfromcol;
- int y_offset = 0, x_offset = curr_col;
-
-
- GLOBALASSERT(font);
- GLOBALASSERT(fontstartaddress);
- GLOBALASSERT(charnum < font->num_chars_in_font);
- GLOBALASSERT(curr_row < font->fttexHeight);
- GLOBALASSERT(curr_col <= font->fttexWidth);
-
- /*remember that all the corrdinates are done by pixels
- find the x and y corrdinates of the left lower hotspot
- we process each line (row) from startfromrow to the end
- first find the next marker in startfromrow
- */
-
- while(1)
- {
- // this bit processes the chars, finds uvs, extents and fills in the sturcture*/
- // count along the row to find the next x position
-
- unsigned int colour_here;
-
- if(x_offset > font->fttexWidth - 1)
- {
- // reached the end of the line! reset x and then y
-
- x_offset = 0;
- curr_col = 0;
-
- curr_row += font->fontHeight; // max line height
- *countfromrow = curr_row;
-
- GLOBALASSERT(curr_row < font->fttexHeight);
- }
-
- colour_here = (int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset));
-
-
- if(colour_here == font->hotSpotValue)
- {
- int width = -1, height = -1;
- /* set up the uv corrds of the top left corner*/
- int u = x_offset + 1;
- int v = curr_row + 1;
-
-
- /* scan down to give height*/
- for(y_offset = (curr_row + 1); y_offset < font->fttexHeight; y_offset++)
- {
- colour_here = (int)*(fontstartaddress + (y_offset*font->fttexWidth + x_offset));
-
- if(colour_here == font->hotSpotValue)
- {
- height = y_offset - curr_row - 1; // -1 because we exclude the top and bottom hotspots
- break;
- }
- }
-
- /* scan along to get the width*/
- for(++x_offset; x_offset < font->fttexWidth; x_offset ++)
- {
- colour_here = (int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset));
-
-
- if(colour_here == font->hotSpotValue)
- {
- width = x_offset - curr_col - 1; // exclude end hotspot
- break;
- }
- }
-
- *countfromcol = x_offset + 1; /* ready for the next char*/
-
- /*fill in the data structure - platform dependent*/
- FillCharacterSlot(u, v, width, height, charnum, font);
- return 0;
- }
-
- x_offset++;
-
- } a
-}
-
-
-
-
-static int Process16BitEntry(PFFONT *font,
- char* fontstartaddress,
- int* countfromrow,
- int* countfromcol,
- int charnum)
-{
-int curr_row = *countfromrow;
-int curr_col = *countfromcol;
-int y_offset = 0, x_offset = curr_col;
-
-
-GLOBALASSERT(font);
-GLOBALASSERT(fontstartaddress);
-GLOBALASSERT(charnum < font->num_chars_in_font);
-GLOBALASSERT(curr_row < font->fttexHeight);
-GLOBALASSERT(curr_col <= font->fttexWidth);
-
-/*remember that all the corrdinates are done by pixels
- find the x and y corrdinates of the left lower hotspot
- we process each line (row) from startfromrow to the end
- first find the next marker in startfromrow
-*/
-
- while(1)
- {
- // this bit processes the chars, finds uvs, extents and fills in the sturcture*/
- // count along the row to find the next x position
-
- unsigned int colour_here;
-
- if(x_offset > font->fttexWidth - 1)
- {
- // reached the end of the line! reset x and then y
-
- x_offset = 0;
- curr_col = 0;
-
- curr_row += font->fontHeight; // max line height
- *countfromrow = curr_row;
-
- GLOBALASSERT(curr_row < font->fttexHeight);
- }
-
- {
- unsigned int colour_high = 0x000000ff & (unsigned int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset)*2);
- unsigned int colour_low = 0x000000ff & (int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset)*2 + 1);
- colour_here = (colour_high << 8) | colour_low;
- }
-
- if(colour_here == font->hotSpotValue)
- {
- int width = -1, height = -1;
- /* set up the uv corrds of the top left corner*/
- int u = x_offset + 1;
- int v = curr_row + 1;
-
-
- /* scan down to give height*/
- for(y_offset = (curr_row + 1); y_offset < font->fttexHeight; y_offset++)
- {
- {
- int colour_high = 0x000000ff & (int)*(fontstartaddress + (y_offset*font->fttexWidth + x_offset)*2);
- int colour_low = 0x000000ff & (int)*(fontstartaddress + (y_offset*font->fttexWidth + x_offset)*2 + 1);
- colour_here = (colour_high << 8) | colour_low;
- }
-
- if(colour_here == font->hotSpotValue)
- {
- height = y_offset - curr_row - 1; // -1 because we exclude the top and bottom hotspots
- break;
- }
- }
-
- /* scan along to get the width*/
- for(++x_offset; x_offset < font->fttexWidth; x_offset ++)
- {
- {
- int colour_high = 0x000000ff & (int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset)*2);
- int colour_low = 0x000000ff & (int)*(fontstartaddress + (curr_row*font->fttexWidth + x_offset)*2 + 1);
- colour_here = (colour_high << 8) | colour_low;
- }
-
- if(colour_here == font->hotSpotValue)
- {
- width = x_offset - curr_col - 1; // exclude end hotspot
- break;
- }
- }
-
- *countfromcol = x_offset + 1; /* ready for the next char*/
-
- /*fill in the data structure - platform dependent*/
- FillCharacterSlot(u, v, width, height, charnum, font);
- return 0;
- }
-
- x_offset++;
-
- }
- return 0;
-}
-
-static int Process24BitEntry(PFFONT* font,
- char* fontstartaddress,
- int* countfromrow,
- int* countfromcol,
- int charnum)
-{
- return 0;
-}
-
-#endif
-
-
-
-
-
-void BLTWholeFont(int fontnum, int x , int y, int win_width)
-{
- int i = 0;
- int plotto_x = x, plotto_y = y;
-
- while(i < AvpFonts[fontnum].num_chars_in_font)
- {
- int charwidth = AvpFonts[fontnum].srcRect[i].right - AvpFonts[fontnum].srcRect[i].left;
-
- if((charwidth + plotto_x - x) > win_width)
- {
- plotto_y += AvpFonts[fontnum].fontHeight;
- plotto_x= x;
- }
-
- BLTFontOffsetToHUD(&AvpFonts[fontnum], plotto_x, plotto_y, i);
-
- plotto_x += charwidth + 1;
-
- i++;
- }
- return;
-}
-
-
-void BLTString(FONT_DESC str_packet)
-{
- PFFONT font = AvpFonts[str_packet.fontnum];
-
- unsigned char *strptr = str_packet.string;
- int offset = 0;
- int not_finished = Yes;
- int pos_x = str_packet.destx;
- int pos_y = str_packet.desty;
- int white_space_width = CHAR_WIDTH(str_packet.fontnum, 0);
-
-
- // set up the font processing varibles depending on the type of font
-
- switch(font.font_type)
- {
- case(I_FONT_NUMERIC):
- {
- offset = 0x30;
- break;
- }
- case(I_FONT_UC_NUMERIC):
- {
- offset = 0x20;
- break;
- }
- case(I_FONT_UCLC_NUMERIC):
- {
- offset = 0x20;
- break;
- }
- default:
- GLOBALASSERT(2<1);
- }
-
- while(not_finished)
- {
- int line_length;
- char *end_char;
-
-
- // find the line length and the end char in the line
-
- not_finished = ProcessLineLength
- (
- strptr, // start char of string
- str_packet.fontnum, // the font we are using
- offset, // the offset from the font
- str_packet.width, // the width of the line
- &end_char, // filled with end address
- &line_length // filled with line length
- );
-
-
- // work out where to print the line
-
- if(line_length)
- {
- switch(str_packet.just)
- {
-
- case FJ_LEFT_JUST:
- {
- pos_x = str_packet.destx;
- break;
- }
- case FJ_CENTRED:
- {
- pos_x = str_packet.destx + ((str_packet.width - line_length) >> 1);
- break;
- }
- case FJ_RIGHT_JUST:
- {
- pos_x = str_packet.destx + (str_packet.width - line_length);
- break;
- }
- default:
- {
- ;
- }
- }
-
- // now print the line untill we reach the address of
- // the end char
-
- do
- {
- if(*strptr == ' ')
- {
- pos_x += white_space_width;
- }
- else if(*strptr == '\t')
- {
- pos_x += 4*white_space_width;
- }
- else if(*strptr == '\n' || strptr == 0x0)
- {
- GLOBALASSERT(strptr == end_char);
- }
- else if((int)*strptr == 0xD)
- {
- // carrige return
- // do nothing - our next char should be '\n'
-
- GLOBALASSERT(*(strptr + 1) == '\n');
- }
- else
- {
- extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
- int end_pos = pos_x + CHAR_WIDTH(str_packet.fontnum, ((int)*strptr - offset));
- int bottom_pos = pos_y + CHAR_HEIGHT(str_packet.fontnum, ((int)*strptr - offset));
-
- if(end_pos > ScreenDescriptorBlock.SDB_Width || pos_x < 0)
- {
- //dont draw
- //not_finished = No;
- }
- else if( bottom_pos > ScreenDescriptorBlock.SDB_Height || pos_y < 0)
- {
- not_finished = No;
- }
- else
- {
- pos_x += BLTFontOffsetToHUD
- (
- &font,
- pos_x,
- pos_y,
- (int)*strptr - offset
- );
-
- pos_x ++; // to make space between letters
- }
- }
- }
- while(++strptr != (unsigned char *)end_char);
-
- pos_y += font.fontHeight - 2;
- }
-
- strptr++;
- }
-}
-
-
-
-/*
-RWH - changes to font line processing
-This function takes a pointer to a string a font and a width and
-puts the length of the line into line_length AND puts the end char address into end_ch
-
-It returns 0 when we have reached the end of a string
-
-*/
-
-
-
-int ProcessLineLength
-(
- char* start_ch, // start char of string
- AVP_FONTS fontnum, // the font we are using
- int offset, // the offset from the font
- int max_width, // the width of the line
- char** end_ch, // filled with end address
- int* line_length
-)
-{
- int continue_to_process_word = Yes;
- int white_space_width = CHAR_WIDTH(fontnum, 0);
- char *word_ptr = start_ch;
-
- *line_length = 0;
-
- if(start_ch == NULL)
- {
- *end_ch = NULL;
- *line_length = 0;
- return 0;
- }
-
- // first process any white space at the end of the
- // line out
-
- while(*start_ch == ' ')
- {
- // make sure we havent run out
- // of chars to process
- if(*start_ch == 0x0)
- {
- *end_ch = NULL;
- *line_length = 0;
- return 0;
- }
-
- start_ch++;
- }
-
- // Now we can start on the characters in the line
- // note that we have to have two loops. The first
- // continues untill we break out of it. The second
- // adds up the length of each word and sees if the line
- // with the new word will overrun the max_width
-
-
- // the word_ptr points to the current char - it is only incremented
- // when we can be sure that we can add the current letter to the word
-
-
- while(1)
- {
- int word_length = 0;
-
- continue_to_process_word = Yes;
-
- while(continue_to_process_word)
- {
- // is the next char white space ?
- // if so close the word
-
- if(IS_CHAR_WHITE_SPACE(*(word_ptr + 1)))
- {
- // hit white space - finish this current word but only
- // AFTER we have processed the current char
- continue_to_process_word = No;
- }
-
- // need to process every white space seperately
- if(*word_ptr == '\t')
- {
- // a one char word!
- word_length = 4 * white_space_width;
- continue_to_process_word = No;
- word_ptr++;
- }
- else if(*word_ptr == 0x0)
- {
- // reached end of file - need to return 0
-
- *end_ch = word_ptr;
- return 0;
- }
- else if(*word_ptr == '\n')
- {
- *end_ch = word_ptr;
- return 1;
- }
- else if(*word_ptr == ' ')
- {
- if(word_length)
- {
- // tag on the white space onto the word length
- word_length += white_space_width;
- }
- // other wise keep on tiking on
-
- word_ptr++;
- }
- else
- {
- // yeah add a letter to the word length
- int char_off = (char)(*word_ptr - offset);
- word_length += CHAR_WIDTH(fontnum, char_off);
- word_length ++; //for space between lettes
-
- word_ptr++; //process next char
- }
- }
-
- // okay we have the length of this word - check to see if
- // it overruns the end of the line - if it is too long,
- // break out of the line loop
-
-
- if((word_length + *line_length) >= max_width)
- {
- *end_ch = start_ch;
- return 1;
- }
- else
- {
- *line_length += word_length;
- // set up the next word save the beginning of teh word in start_ch
- start_ch = word_ptr;
- }
- }
-} \ No newline at end of file
diff --git a/src/avp/win95/font.h b/src/avp/win95/font.h
index 00ec068..bf66adf 100644
--- a/src/avp/win95/font.h
+++ b/src/avp/win95/font.h
@@ -60,19 +60,6 @@ typedef enum font_justification
}FONT_JUST;
-// this prints a string packet
-
-typedef struct font_desc {
- int fontnum; // see list of PFFONTS;
- char *string; // this will eventually point into a resource fileMENU_GRAPHIC_ITEM Gamestart_MenuItems[] = {
- short destx;
- short desty;
- FONT_JUST just;
- short width; // width - the width we have to print
- // the font in - overrides onto next line
-} FONT_DESC;
-
-
// bitfield of flags
typedef struct
@@ -201,12 +188,6 @@ extern void * FontLock(PFFONT const * pFont, unsigned * pPitch);
extern void FontUnlock(PFFONT const * pFont);
-// drawing functions
-
-extern void BLTWholeFont(int fontnum, int x , int y, int win_width);
-extern void BLTString(FONT_DESC str_packet);
-
-
// the array of all the Fonts int the game
extern PFFONT AvpFonts[];
diff --git a/src/avp/win95/gadgets/trepgadg.cpp b/src/avp/win95/gadgets/trepgadg.cpp
index 43539b7..46f81d9 100644
--- a/src/avp/win95/gadgets/trepgadg.cpp
+++ b/src/avp/win95/gadgets/trepgadg.cpp
@@ -30,9 +30,6 @@
#include "hudgadg.hpp"
// for ClearTheQueue()
- #include "font.h"
- // for the font tests
-
#define UseLocalAssert Yes
#include "ourasert.h"
@@ -154,40 +151,6 @@ void TextReportGadget :: Render
/* CODE */
{
- #if 0
- BLTFontOffsetToHUD
- (
- // PFFONT* font ,
- 400, // int xdest,
- 100, // int ydest,
- 0 // int offset
- );
- #endif
-
- #if 0
- BLTWholeFont
- (
- 3, // int fontnum,
- 30, // int x ,
- 130, // int y,
- 100 // int win_width
- );
- #endif
-
- #if 0
- textprint
- (
- "TextReportGadget :: Render at (%i,%i) clipped (%i,%i,%i,%i) alpha=%i\n",
- R2Pos . x,
- R2Pos . y,
- R2Rect_Clip . x0,
- R2Rect_Clip . y0,
- R2Rect_Clip . x1,
- R2Rect_Clip . y1,
- FixP_Alpha
- );
- #endif
-
IndexedFont* pLetterFont = IndexedFont :: GetFont( I_Font_TeletypeLettering );
GLOBALASSERT( pLetterFont );
@@ -916,81 +879,3 @@ void CheesyDaemon_Lifetime :: Reset(void)
#endif // UseGadgets
-
-
-
-
-
-
-
-
-#if UseGadgets && 0
- // test code
- #define FONT_INDEX (3)
-
-void TestStringRender_Unclipped
-(
- r2pos& R2Pos_Cursor,
- // start position for string;
- // gets written back to with final position
-
- // Renders as a single line; it is asserted that the result is fully within
- // the physical screen (i.e. already clipped)
- const SCString& SCStr
-)
-{
- /* PRECONDITION */
- {
- }
-
- /* CODE */
- {
- // GetOffset:
- const pffont& PFFont = AvpFonts[FONT_INDEX];
-
- ProjChar* pProjChar_I = SCStr . pProjCh();
-
- while ( *pProjChar_I )
- {
- const ProjChar ProjCh = *pProjChar_I;
-
- if
- (
- PFFont . bPrintable( ProjCh )
- )
- {
- #if 0
- textprint("printable \'%c\'\n",ProjCh);
- #endif
-
- R2Pos_Cursor . x += 1+BLTFontOffsetToHUD
- (
- (PFFONT*)&PFFont, // PFFONT* font,
- // "cast away the const-ness" for the moment
- R2Pos_Cursor . x, // int xdest,
- R2Pos_Cursor . y, // int ydest,
- PFFont . ProjCharToOffset( ProjCh ) // int offset
- );
- // appears to return the width of the character...
- }
- else
- {
- #if 0
- textprint("unprintable \'%c\'\n",ProjCh);
- #endif
- }
-
- pProjChar_I++;
- }
- }
-}
-
-void TestStringRender_Clipped
-(
- r2pos& R2Pos_Cursor,
- const r2rect& R2Rect_Clip,
- const SCString& SCStr
-)
-{
-}
-#endif // test code
diff --git a/src/avp/win95/pcmenus.cpp b/src/avp/win95/pcmenus.cpp
index 357a6d8..9034ae5 100644
--- a/src/avp/win95/pcmenus.cpp
+++ b/src/avp/win95/pcmenus.cpp
@@ -480,232 +480,12 @@ static void LoadVideoModeSettings(void)
static size_t IsNotEnoughVidMemForBytes(size_t required)
{
return 0;
-
- // Won't be using this. I don't think
- #if 0
-
- char buff[128];
- sprintf(buff,"Want: %d Have: %d",(int)required,GetAvailableVideoMemory());
- LOGDXSTR(buff);
-
- if (required > GetAvailableVideoMemory()) return GetAvailableVideoMemory();
-
- LOGDXSTR("Maybe enough");
-
- #if DISABLE_VIDEOCARD_ANALYSIS
- return 0;
- #endif
-
- static size_t what_we_know_we_can_have = 0;
-
- if (required <= what_we_know_we_can_have) return 0;
-
- // deal with cards whose video memory is fragmented
- // such that textures may not be able to use all the
- // available video memory
-
- // we don't know we can use all the available video memory
- // for textures - so try and find out what we can use
- // with the current options - and in future, as long as
- // available video memory exceeds this amount, we'll know
- // at least a minimum amount that we can have without having
- // to run this test again
-
- List<IMAGEHEADER *> imgs;
- size_t vidmem_before = GetAvailableVideoMemory();
- CL_Image random_tx;
-
- CL_Select_Mode(CLL_D3DTEXTURE);
- random_tx.MakeRandom(512,512,RND_SEED1);
-
- // throw d3d textures at the system until we can no more
- do
- {
- CL_Error copyerr;
- do
- {
- IMAGEHEADER * new_ih = new IMAGEHEADER;
- memset(new_ih,0,sizeof(IMAGEHEADER));
- size_t vidmem_before_create = GetAvailableVideoMemory();
- copyerr = random_tx.CopyToD3DTexture((LPDIRECTDRAWSURFACE *)&new_ih->DDPtr,(LPVOID *)&new_ih->DDSurface,DDSCAPS_SYSTEMMEMORY);
- if (CLE_OK == copyerr)
- {
- copyerr = CLE_DXERROR;
- if (CopyD3DTexture(new_ih))
- {
- if (LoadD3DTextureIntoD3DMaterial(new_ih))
- copyerr = CLE_OK;
- }
- }
- size_t vidmem_after_create = GetAvailableVideoMemory();
- imgs.add_entry(new_ih);
- if (vidmem_after_create >= vidmem_before_create) copyerr = CLE_DXERROR;
- LOGDXFMT(("VidMem: %d",vidmem_after_create));
- }
- while (CLE_OK==copyerr);
- random_tx.MakeRandom(random_tx.width>>1,random_tx.height>>1);
- }
- while (random_tx.width>=32 && random_tx.height>=32);
-
- size_t vidmem_after = GetAvailableVideoMemory();
-
- what_we_know_we_can_have = vidmem_before - vidmem_after;
-
- char buf[128];
- sprintf(buf,"Can have %d\n",what_we_know_we_can_have);
- LOGDXSTR(buf);
-
- // release all dummy textures we threw at the system
- while (imgs.size())
- {
- if (imgs.first_entry()->DDSurface)
- ReleaseDDSurface(imgs.first_entry()->DDSurface);
- if (imgs.first_entry()->D3DTexture)
- ReleaseD3DTexture(imgs.first_entry()->D3DTexture);
- delete imgs.first_entry();
- imgs.delete_first_entry();
- }
-
-
- if (required <= what_we_know_we_can_have)
- return 0;
- else
- return what_we_know_we_can_have;
- #endif
}
static BOOL IsNotEnoughVidMemForScreenDepth(int s_depth)
{
// bollocks - this is all obsolete - FIXME
return FALSE;
-
- #if 0
-
- LOGDXSTR("Testing Vid Mem");
-
- CL_Init_All(); - not required any more
-
- // determine if d3d textures need to be a power of two in width and height
- // try 48x48
- IMAGEHEADER tmp_iheader;
- memset(&tmp_iheader,0,sizeof(IMAGEHEADER));
- CL_Image random_tx;
- CL_Error copyerr;
-
- // do we need texture powers of two or square
- need_textures_powers_of_two = d3d.ThisDriver.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 ? 1 : 0;
- need_textures_square = d3d.ThisDriver.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ? 1 : 0;
-
- LOGDXFMT(("Need POW_2 : %d",need_textures_powers_of_two));
- LOGDXFMT(("Need SQUARE : %d",need_textures_square));
-
- // determine how much texture memory is used by a typical 64x64 hud graphic
-
- #if DISABLE_VIDEOCARD_ANALYSIS
- size_t vidmem_before, vidmem_after;
- copyerr = CLE_DXERROR;
- #else
-
- CL_Select_Mode(CLL_DDSURFACE);
- random_tx.MakeRandom(64,64,RND_SEED4);
- size_t vidmem_before = GetAvailableVideoMemory();
- copyerr = random_tx.CopyToDirectDrawSurface((LPDIRECTDRAWSURFACE *)&tmp_iheader.DDSurface,(LPVOID *)&tmp_iheader.DDPtr,DDSCAPS_SYSTEMMEMORY);
- size_t vidmem_after = GetAvailableVideoMemory();
- if (tmp_iheader.DDSurface)
- {
- ReleaseDDSurface(tmp_iheader.DDSurface);
- tmp_iheader.DDSurface = (void*) 0;
- tmp_iheader.DDPtr = (void*) 0;
- }
- if (tmp_iheader.D3DTexture)
- {
- ReleaseD3DTexture(tmp_iheader.D3DTexture);
- tmp_iheader.D3DTexture = (void*) 0;
- tmp_iheader.D3DMaterial = (void*) 0;
- tmp_iheader.D3DHandle = (void*) 0;
- }
-
- #endif
-
- float hud_bytespertexel =
- CLE_OK == copyerr
- ? (float)(vidmem_before-vidmem_after)/(random_tx.width*random_tx.height)
- : (float)s_depth/8
- ;
-
- char buf[128];
- sprintf(buf,"HUD BPP: %f",hud_bytespertexel);
- LOGDXSTR(buf);
-
- // determine how much texture memory is used by a typical 128x128 texture
-
- #if DISABLE_VIDEOCARD_ANALYSIS
- #else
-
- CL_Select_Mode(CLL_D3DTEXTURE);
- random_tx.MakeRandom(128,128,RND_SEED2);
- LOGDXSTR("Trying D3D");
-
- //size_t
- vidmem_before = GetAvailableVideoMemory();
- copyerr = random_tx.CopyToD3DTexture((LPDIRECTDRAWSURFACE *)&tmp_iheader.DDPtr,(LPVOID *)&tmp_iheader.DDSurface,DDSCAPS_SYSTEMMEMORY);
- if (CLE_OK == copyerr)
- {
- copyerr = CLE_DXERROR;
- if (CopyD3DTexture(&tmp_iheader))
- if (LoadD3DTextureIntoD3DMaterial(&tmp_iheader))
- copyerr = CLE_OK;
- }
- //size_t
- vidmem_after = GetAvailableVideoMemory();
- if (tmp_iheader.DDSurface)
- {
- ReleaseDDSurface(tmp_iheader.DDSurface);
- tmp_iheader.DDSurface = (void*) 0;
- tmp_iheader.DDPtr = (void*) 0;
- }
- if (tmp_iheader.D3DTexture)
- {
- ReleaseD3DTexture(tmp_iheader.D3DTexture);
- tmp_iheader.D3DTexture = (void*) 0;
- tmp_iheader.D3DMaterial = (void*) 0;
- tmp_iheader.D3DHandle = (void*) 0;
- }
- #endif
-
- float textures_bytespertexel =
- CLE_OK == copyerr
- ? (float)(vidmem_before-vidmem_after)/(random_tx.width*random_tx.height)
- : (float)BitsPerPixel(&d3d.TextureFormat[d3d.CurrentTextureFormat])/8
- ;
-
- //char buf[128];
- sprintf(buf,"Textures BPP: %f",textures_bytespertexel);
- LOGDXSTR(buf);
-
- ImageSizeRestrictionIdx isri = need_textures_square ? need_textures_powers_of_two ? ISRI_SQUAREANDPOWER2 : ISRI_SQUARE : need_textures_powers_of_two ? ISRI_POWER2 : ISRI_UNIT4;
-
- size_t vram_rq;
- size_t vram_avail;
- for (int i=0; hw_try_desc[i]; ++i)
- {
- desc_textures_to_load = hw_try_desc[i];
- vram_rq = (size_t)(
- hw_max_num_texels[isri][ITI_HUD][desc_textures_to_load[ITI_HUD]] * hud_bytespertexel +
- hw_max_num_texels[isri][ITI_TEXTURE][desc_textures_to_load[ITI_TEXTURE]] * textures_bytespertexel +
- hw_max_num_texels[isri][ITI_SPRITE][desc_textures_to_load[ITI_SPRITE]] * textures_bytespertexel
- );
- vram_avail = IsNotEnoughVidMemForBytes(vram_rq);
- if (!vram_avail) return FALSE;
- }
- // bollocks - return FALSE anayway, since the following doesn't actually work anymore anyway
- return FALSE;
-
- char errstring[512];
- sprintf(errstring,"THIS SET OF OPTIONS REQUIRES AT LEAST %d BYTES OF VIDEO MEMORY FREE. THERE ARE ONLY %d BYTES FREE. THE TEXTURE FORMAT WAS %d-BIT",(int)vram_rq,(int)vram_avail,BitsPerPixel(&d3d.TextureFormat[d3d.CurrentTextureFormat]));
- EmergencyPcOptionsMenu(errstring);
- return TRUE;
- #endif
}
@@ -1011,8 +791,6 @@ extern int SetGameVideoMode(void)
return 0;
}
- // CL_Init_All(); // set up shifts for display pixel format - not required
-
if (ScanDrawMode == ScanDrawDirectDraw)
{
ScreenDescriptorBlock.SDB_Depth = ScreenDescriptorBlock.SDB_ScreenDepth;
diff --git a/src/win95/chnkimag.cpp b/src/win95/chnkimag.cpp
deleted file mode 100644
index a2f703a..0000000
--- a/src/win95/chnkimag.cpp
+++ /dev/null
@@ -1,699 +0,0 @@
-#include <string.h>
-
-#define TRY_OLD_DIRS 0 // obsolete
-#define ALLOW_LOAD_ORIGINAL 0
-
-#if TRY_OLD_DIRS // temporary until all textures go into subshps directory
-#include "ffstdio.h"
-#endif
-
-#include "chnkimag.hpp"
-
-#include "list_tem.hpp"
-#include "envchunk.hpp"
-#include "chunkpal.hpp"
-#include "bmpnames.hpp"
-
-#include "chnkload.hpp"
-
-char const * CL_RIFFImage::game_mode = 0;
-
-// useful filename handling functions
-
-// returns pointer into string pointing to filename without dirname
-template <class C> // C can be char or char const
-static C * strip_path(C * n)
-{
- C * rm = strrchr(n,':');
- if (rm) n = rm+1;
- rm = strrchr(n,'/');
- if (rm) n = rm+1;
- rm = strrchr(n,'\\');
- if (rm) n = rm+1;
-
- return n;
-}
-
-// removes any .extension from filename by inserting null character
-static void strip_file_extension(char * n)
-{
- char * dotpos = strrchr(n,'.');
- if (dotpos) *dotpos = 0;
-}
-
-static char * strip_file_extension(char const * n)
-{
- char * nn = new char[strlen(n)+1];
- strcpy(nn,n);
- strip_file_extension(nn);
- return nn;
-}
-
-////////////////////////
-//
-// riff file interface
-//
-////////////////////////
-
-
-// get the directory associated with the riff - free with delete[]
-static char * riff_basename(Chunk_With_Children * envd)
-{
- RIF_Name_Chunk * rnc = 0;
-
- List<Chunk *> chlst = envd->lookup_child("RIFFNAME");
-
- if (chlst.size())
- {
- rnc = (RIF_Name_Chunk *)chlst.first_entry();
- const char * rif_name = strip_path(rnc->rif_name);
-
- char * basename = new char[strlen(rif_name)+1];
- strcpy(basename,rif_name);
- strip_file_extension(basename);
-
- return basename;
- }
- const char * deflt = "empty";
- char * basename = new char [strlen(deflt)+1];
- strcpy(basename,deflt);
-
- return basename;
-}
-
-#if OUTPUT_LOG
-#define _LOGID CL_LogFile.lprintf("%s:%d :: ",__FILE__,__LINE__)
-#define _LOGPUT(s) _LOGID,CL_LogFile.lputs(s)
-#define _LOGPRINT(args) _LOGID,CL_LogFile.lprintf args
-#else
-#define _LOGPUT(s) (void)0
-#define _LOGPRINT(args) (void)0
-#endif
-
-void CL_RIFFImage::GetPath(ImageDescriptor const & idsc, Environment_Data_Chunk * envd, BMPN_Flags bflags)
-{
- if (fname) delete[] fname;
- fname = 0;
-
- // set the name
- if (name) delete[] name;
- char * nptr = strip_path(idsc.filename);
- name = new char[strlen(nptr)+1];
- strcpy(name,nptr);
- #if 0
- char orig_ext[32];
- char const * oeP = strrchr(name,'.');
- if (!oeP) eoP = "";
- strcpy(orig_ext,oeP);
- #endif
- strip_file_extension(name);
-
- // load this image
- char const * pg0ext = ".PG0";
- switch (imode)
- {
- case CLM_16BIT:
- case CLM_24BIT:
- case CLM_32BIT:
- #if ALLOW_LOAD_ORIGINAL
- {
- char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
- char * riffname = riff_basename(envd);
- char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
- fname = new char[strlen(ToolsTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
- strcpy(fname,ToolsTex_Directory);
- strcat(fname,dir2);
- strcat(fname,dir3);
- strcat(fname,"\\");
- strcat(fname,name);
- strcat(fname,".PP0");
- delete[] riffname;
- break;
- }
- #endif
- case CLM_ATTACHEDPALETTE:
- {
- char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : idsc.flags & IDSCF_SUBSHAPE ? "SubShps\\All\\" : "";
- char * riffname = riff_basename(envd);
- char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
- fname = new char[strlen(GenTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
- strcpy(fname,GenTex_Directory);
- strcat(fname,dir2);
- strcat(fname,dir3);
- strcat(fname,"\\");
- strcat(fname,name);
- strcat(fname,".BM0");
- delete[] riffname;
- #if TRY_OLD_DIRS // temporary until all textures go into subshps directory
- FFILE * ftest = ffopen(fname,"rb");
- if (ftest) ffclose(ftest);
- else
- {
- _LOGPUT("WARNING! Not found in SubShps directory\n");
- char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
- char * riffname = riff_basename(envd);
- char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
- delete[] fname;
- fname = new char[strlen(GenTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
- strcpy(fname,GenTex_Directory);
- strcat(fname,dir2);
- strcat(fname,dir3);
- strcat(fname,"\\");
- strcat(fname,name);
- strcat(fname,".BM0");
- delete[] riffname;
- }
- #endif
- break;
- }
- case CLM_TLTPALETTE:
- if (!(bflags & ChunkBMPFlag_NotLit))
- {
- pg0ext = ".PW0";
- flags.tltpalette = 1;
- }
- case CLM_GLOBALPALETTE:
- {
- if (idsc.flags & IDSCF_FIXEDPALETTE)
- {
- char const * dir2 = idsc.fixrifname ? *idsc.fixrifname ? idsc.fixrifname : 0 : 0;
- char const * dir3 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
- char * riffname = riff_basename(envd);
- char const * dir4 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
- fname = new char[strlen(FixTex_Directory)+(dir2 ? strlen(dir2)+1 : 0)+strlen(dir3)+strlen(dir4)+1+strlen(name)+5];
- strcpy(fname,FixTex_Directory);
- if (dir2)
- {
- strcat(fname,dir2);
- strcat(fname,"\\");
- }
- strcat(fname,dir3);
- strcat(fname,dir4);
- strcat(fname,"\\");
- strcat(fname,name);
- strcat(fname,pg0ext);
- delete[] riffname;
- }
- else
- {
- char const * dir1 = game_mode ? GameTex_Directory : ToolsTex_Directory;
- char * dir2 = riff_basename(envd);
- char const * dir4 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
- char const * dir5 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : 0;
- fname = new char[strlen(dir1)+strlen(dir2)+1+(game_mode ? strlen(game_mode)+1 : 0)+strlen(dir4)+(dir5 ? strlen(dir5)+1 : 0)+strlen(name)+5];
- strcpy(fname,dir1);
- strcat(fname,dir2);
- strcat(fname,"\\");
- if (game_mode)
- {
- strcat(fname,game_mode);
- strcat(fname,"\\");
- }
- strcat(fname,dir4);
- if (dir5)
- {
- strcat(fname,dir5);
- strcat(fname,"\\");
- }
- strcat(fname,name);
- strcat(fname,pg0ext);
- delete[] dir2;
- }
- break;
- }
- }
-
- if (!fname)
- {
- _LOGPUT("WARNING! GetPath returning NULL pointer\n");
- }
- else
- _LOGPRINT(("file expected to be %s\n",fname));
-}
-
-
-CL_Error CL_RIFFImage::Locate(char const * iname, int const enum_id)
-{
- _LOGPRINT(("RIF File image finder called for %s, id %d\n",iname,enum_id));
-
- if (!Env_Chunk)
- _LOGPUT("WARNING! no .RIF file loaded\n");
-
- if (!Env_Chunk) return CLE_RIFFERROR;
-
- switch (imode)
- {
- case CLM_ATTACHEDPALETTE:
- case CLM_16BIT:
- case CLM_24BIT:
- case CLM_32BIT:
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- break;
- default:
- _LOGPUT("WARNING! undefined video mode\n");
- return CLE_INVALIDDXMODE;
- }
-
- // remove projectsubdirectory from start of image name if it is there
- unsigned int const psdirlen = strlen(projectsubdirectory);
- if (!strncmp(projectsubdirectory,iname,psdirlen))
- iname += psdirlen;
-
- List<Chunk *> envdl (Env_Chunk->lookup_child("REBENVDT"));
-
- if (!envdl.size())
- {
- _LOGPUT("WARNING! no environment data chunk\n");
- return CLE_RIFFERROR;
- }
-
- Environment_Data_Chunk * envd = (Environment_Data_Chunk *) envdl.first_entry();
-
- CL_Error retval = CLE_OK;
- Environment_Game_Mode_Chunk * egmc = 0;
- if (game_mode)
- {
- if (*game_mode)
- {
- List<Chunk *> egmcl (envd->lookup_child("GAMEMODE"));
-
- for (LIF<Chunk *> egmci(&egmcl); !egmci.done(); egmci.next())
- {
- Environment_Game_Mode_Chunk * egmcm = (Environment_Game_Mode_Chunk *) egmci();
- if (egmcm->id_equals(game_mode))
- {
- egmc = egmcm;
- break;
- }
- }
-
- if (!egmc) retval = CLE_INVALIDGAMEMODE;
- // only returns this error if the game mode cannot be found *and* the image is not listed
- }
- }
-
- if (name)
- {
- delete[] name;
- name = 0;
- }
- if (iname) name = strip_file_extension(strip_path(iname));
-
- char * rcname = 0;
- if (iname)
- {
- if (strchr(iname,'\\'))
- {
- rcname = new char[strlen(iname)+1];
- strcpy(rcname,iname);
- *strchr(rcname,'\\')=0;
- }
- else if (strchr(iname,'/'))
- {
- rcname = new char[strlen(iname)+1];
- strcpy(rcname,iname);
- *strchr(rcname,'/')=0;
- }
- }
-
- if (egmc)
- {
- int shapefoundingm = rcname ? 0 : 1;
- // Get the matching image 'Processor' chunk
- List<Chunk *> micl = egmc->lookup_child("MATCHIMG");
-
- Matching_Images_Chunk * mic = 0;
- if (micl.size()) mic = (Matching_Images_Chunk *)micl.first_entry();
-
- List<Chunk *> rcl = egmc->lookup_child("RIFCHILD");
-
- for (LIF<Chunk *> rci(&rcl); !rci.done(); rci.next())
- {
- RIF_Child_Chunk * rcm = (RIF_Child_Chunk *) rci();
-
- if (rcname)
- {
- if (_stricmp(rcname,rcm->rifname) && (*rcname || *rcm->filename))
- continue;
- shapefoundingm = 1;
- }
-
- for (LIF<BMP_Flags> bmpfi(&rcm->bmps); !bmpfi.done(); bmpfi.next())
- {
- BMP_Flags bmpft(bmpfi());
- strip_file_extension(bmpft.filename);
-
- if (iname ? !_stricmp(name,strip_path(bmpft.filename)) : enum_id == bmpft.enum_id)
- {
- // select image descriptor
- ImageDescriptor const idsc
- (
- *rcm->filename ?
- (IDscFlags)((bmpft.flags & ChunkBMPFlag_FixedPalette ?
- IDSCF_FIXEDPALETTE
- :
- IDSCF_0)
- |IDSCF_INCLUDED)
- :
- IDSCF_0,
- bmpfi().filename,
- *rcm->filename ? rcm->rifname : 0
- );
- ImageDescriptor const * p_idsc = &idsc;
-
- if (mic) p_idsc = &mic->GetLoadImage(idsc);
- else _LOGPRINT(("WARNING! no rule to find matching images in game mode %s\n",egmc->header->mode_identifier));
-
- // load this image
- GetPath(*p_idsc,envd,bmpft.flags);
-
- if (fname)
- {
- if (rcname)
- {
- delete[] rcname;
- rcname = 0;
- }
- flags.located = 1;
- return CLE_OK;
- }
- }
- }
- }
-
- List<Chunk *> ssc = egmc->lookup_child("SHBMPNAM");
-
- for (LIF<Chunk *> ssi(&ssc); !ssi.done(); ssi.next())
- {
- External_Shape_BMPs_Store_Chunk * ss = (External_Shape_BMPs_Store_Chunk *) ssi();
-
- if (rcname)
- if (_stricmp(rcname,ss->shapename) && *rcname)
- continue;
-
- for (LIF<BMP_Name> bmpfi(&ss->bmps); !bmpfi.done(); bmpfi.next())
- {
- BMP_Name bmpft(bmpfi());
- strip_file_extension(bmpft.filename);
-
- if (iname ? !_stricmp(name,strip_path(bmpft.filename)) : enum_id == bmpft.enum_id)
- {
-
- // select image descriptor
- ImageDescriptor const idsc
- (
- (IDscFlags)((bmpft.flags & ChunkBMPFlag_FixedPalette ?
- IDSCF_FIXEDPALETTE
- :
- IDSCF_0)
- |(ss->GetExtendedData()->flags & GBF_SPRITE ?
- IDSCF_SPRITE
- :
- IDSCF_SUBSHAPE)
- |IDSCF_INCLUDED),
- bmpfi().filename,
- ss->shapename,
- bmpft.flags & ChunkBMPFlag_FixedPalette ? ss->rifname : 0
- );
- ImageDescriptor const * p_idsc = &idsc;
-
- if (mic) p_idsc = &mic->GetLoadImage(idsc);
- else _LOGPRINT(("WARNING! no rule to find matching images in game mode %s\n",egmc->header->mode_identifier));
-
- #if TRY_OLD_DIRS // temporary until all textures move to SubShps/All directory
- if (*p_idsc == idsc)
- {
- // select image descriptor
- ImageDescriptor const idsc2
- (
- (IDscFlags)((bmpft.flags & ChunkBMPFlag_FixedPalette ?
- IDSCF_FIXEDPALETTE
- :
- IDSCF_0)
- |(ss->GetExtendedData()->flags & GBF_SPRITE ?
- IDSCF_SPRITE
- :
- IDSCF_0)
- |IDSCF_INCLUDED),
- bmpfi().filename,
- ss->shapename,
- bmpft.flags & ChunkBMPFlag_FixedPalette ? ss->rifname : 0
- );
- ImageDescriptor const * p_idsc2 = &idsc2;
-
- if (mic) p_idsc2 = &mic->GetLoadImage(idsc2);
- else _LOGPRINT(("WARNING! no rule to find matching images in game mode %s\n",egmc->header->mode_identifier));
-
- if (*p_idsc2 != idsc2)
- {
- _LOGPUT("WARNING! Not listed as in SubShps directory\n");
- p_idsc = p_idsc2;
- }
- }
- #endif
-
- // load this image
- GetPath(*p_idsc,envd,bmpft.flags);
-
- if (fname)
- {
- if (rcname)
- {
- delete[] rcname;
- rcname = 0;
- }
- flags.located = 1;
- return CLE_OK;
- }
- }
- }
- }
-
- if (rcname)
- {
- if (!shapefoundingm)
- _LOGPRINT(("WARNING! shape/sprite %s not found in this RIF file\n",rcname));
- else
- _LOGPRINT(("WARNING! shape/sprite %s does not appear to list %s\n",rcname,name));
- }
-
- }
-
- List<Chunk *> micl = envd->lookup_child("MATCHIMG");
-
- Matching_Images_Chunk * mic_fix = 0;
- Matching_Images_Chunk * mic_nrm = 0;
-
- for (LIF<Chunk *> mici(&micl); !mici.done(); mici.next())
- {
- Matching_Images_Chunk * mic = (Matching_Images_Chunk *)mici();
- if (mic->flags & MICF_FIXEDPALETTE)
- mic_fix = mic;
- else
- mic_nrm = mic;
- }
-
- List<Chunk_With_Children *> shapesandsprites;
-
- List<Chunk *> shlst = Env_Chunk->lookup_child("REBSHAPE");
- for (LIF<Chunk *> shLIF(&shlst); !shLIF.done(); shLIF.next())
- {
- List<Chunk *> shxflst = ((Shape_Chunk *)shLIF())->lookup_child("SHPEXTFL");
- if (shxflst.size())
- {
- shapesandsprites.add_entry( (Shape_External_File_Chunk *)shxflst.first_entry() );
- }
- }
- shlst = Env_Chunk->lookup_child("RSPRITES");
- if (shlst.size())
- {
- List<Chunk *> splst = ((Chunk_With_Children *)shlst.first_entry())->lookup_child("SPRIHEAD");
-
- for (LIF<Chunk *> spLIF(&splst); !spLIF.done(); spLIF.next())
- {
- shapesandsprites.add_entry( (Chunk_With_Children *)spLIF() );
- }
- }
-
- int shapefound = rcname ? 0 : 1;
-
- for (LIF<Chunk_With_Children *> sasLIF(&shapesandsprites); !sasLIF.done(); sasLIF.next())
- {
- char * subrifname = riff_basename(sasLIF());
-
- if (rcname)
- {
- if (_stricmp(subrifname,rcname)) // must match shapes name exactly
- {
- delete[] subrifname;
- continue;
- }
- shapefound = 1;
- }
-
- List<Chunk *> blsclst = sasLIF()->lookup_child("BMPLSTST");
- if (blsclst.size())
- {
- Bitmap_List_Store_Chunk * gbnc = (Bitmap_List_Store_Chunk *) blsclst.first_entry();
-
- for (LIF<BMP_Name> bmpni(&gbnc->bmps); !bmpni.done(); bmpni.next())
- {
- BMP_Name bmpnt(bmpni());
- strip_file_extension(bmpnt.filename);
-
- if (iname ? !_stricmp(name,strip_path(bmpnt.filename)) : enum_id == bmpnt.enum_id)
- {
-
- // select image descriptor
- char * riffname = riff_basename(envd);
- ImageDescriptor const idsc
- (
- (IDscFlags)((bmpnt.flags & ChunkBMPFlag_FixedPalette ?
- IDSCF_FIXEDPALETTE
- :
- IDSCF_0)
- |(gbnc->GetExtendedData()->flags & GBF_SPRITE ?
- IDSCF_SPRITE
- :
- IDSCF_SUBSHAPE)
- |IDSCF_INCLUDED),
- bmpni().filename,
- subrifname,
- bmpnt.flags & ChunkBMPFlag_FixedPalette ? riffname : 0
- );
- ImageDescriptor const * p_idsc = &idsc;
- delete[] riffname;
-
- if (bmpnt.flags & ChunkBMPFlag_FixedPalette)
- {
- if (mic_fix) p_idsc = &mic_fix->GetLoadImage(idsc);
- else _LOGPUT("WARNING! no rule to find fixed palette matching images in environment data\n");
- }
- else
- {
- if (mic_nrm) p_idsc = &mic_nrm->GetLoadImage(idsc);
- else _LOGPUT("WARNING! no rule to find matching images in environment data (interface engine?)\n");
- }
-
- #if TRY_OLD_DIRS // temporary until all textures move to SubShps/All directory
- if (*p_idsc == idsc)
- {
- // select image descriptor
- char * riffname = riff_basename(envd);
- ImageDescriptor const idsc2
- (
- (IDscFlags)((bmpnt.flags & ChunkBMPFlag_FixedPalette ?
- IDSCF_FIXEDPALETTE
- :
- IDSCF_0)
- |(gbnc->GetExtendedData()->flags & GBF_SPRITE ?
- IDSCF_SPRITE
- :
- IDSCF_0)
- |IDSCF_INCLUDED),
- bmpni().filename,
- subrifname,
- bmpnt.flags & ChunkBMPFlag_FixedPalette ? riffname : 0
- );
- ImageDescriptor const * p_idsc2 = &idsc2;
- delete[] riffname;
-
- if (bmpnt.flags & ChunkBMPFlag_FixedPalette)
- {
- if (mic_fix) p_idsc2 = &mic_fix->GetLoadImage(idsc2);
- else _LOGPUT("WARNING! no rule to find fixed palette matching images in environment data\n");
- }
- else
- {
- if (mic_nrm) p_idsc2 = &mic_nrm->GetLoadImage(idsc2);
- else _LOGPUT("WARNING! no rule to find matching images in environment data (interface engine?)\n");
- }
- if (*p_idsc2 != idsc2)
- {
- _LOGPUT("WARNING! Not listed as in SubShps directory\n");
- p_idsc = p_idsc2;
- }
- }
- #endif
-
- // load this image
- GetPath(*p_idsc,envd,bmpnt.flags);
-
- if (fname)
- {
- delete[] subrifname;
- if (rcname)
- {
- delete[] rcname;
- rcname = 0;
- }
- flags.located = 1;
- return CLE_OK;
- }
- }
- }
- }
- delete[] subrifname;
- }
-
- if (rcname)
- {
- if (!shapefound)
- _LOGPRINT(("WARNING! shape/sprite %s not found in this RIF file\n",rcname));
- else
- _LOGPRINT(("WARNING! shape/sprite %s does not appear to list %s\n",rcname,name));
- delete[] rcname;
- rcname = 0;
- }
-
- // not found in game textures, so look in default
-
- else // but only if there is no virtual shape directory
- {
- List<Chunk *> gbncl = envd->lookup_child("BMPNAMES");
- if (gbncl.size())
- {
- Global_BMP_Name_Chunk * gbnc = (Global_BMP_Name_Chunk *) gbncl.first_entry();
-
- for (LIF<BMP_Name> bmpni(&gbnc->bmps); !bmpni.done(); bmpni.next())
- {
- BMP_Name bmpnt(bmpni());
- strip_file_extension(bmpnt.filename);
-
- if (iname ? !_stricmp(name,strip_path(bmpnt.filename)) : enum_id == bmpnt.enum_id)
- {
- // select image descriptor
- ImageDescriptor const idsc (bmpnt.flags & ChunkBMPFlag_FixedPalette ? IDSCF_FIXEDPALETTE : IDSCF_0, bmpni().filename);
- ImageDescriptor const * p_idsc = &idsc;
-
- if (bmpnt.flags & ChunkBMPFlag_FixedPalette)
- {
- if (mic_fix) p_idsc = &mic_fix->GetLoadImage(idsc);
- else _LOGPUT("WARNING! no rule to find fixed palette matching images in environment data\n");
- }
- else
- {
- if (mic_nrm) p_idsc = &mic_nrm->GetLoadImage(idsc);
- else _LOGPUT("WARNING! no rule to find matching images in environment data (interface engine?)\n");
- }
-
- // load this image
- GetPath(*p_idsc,envd,bmpnt.flags);
-
- if (fname)
- {
- flags.located = 1;
- return CLE_OK;
- }
- }
- }
- }
- }
-
- if (retval != CLE_OK) return retval;
- return CLE_FINDERROR;
-}
-
-
-
diff --git a/src/win95/chnkimag.hpp b/src/win95/chnkimag.hpp
deleted file mode 100644
index df0dc62..0000000
--- a/src/win95/chnkimag.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef _included__chnkimag_hpp_
-#define _included__chnkimag_hpp_
-
-#error "This file is obsolete"
-
-#include <stdio.h>
-
-#include "d3_image.hpp"
-#include "mishchnk.hpp"
-#include "bmpnames.hpp"
-
-extern "C" extern char projectsubdirectory[];
-
-extern char const * GameTex_Directory;
-extern char const * GenTex_Directory;
-extern char const * FixTex_Directory;
-extern char const * ToolsTex_Directory;
-
-struct CL_RIFFImage : public CL_Image
-{
-public:
- static char const * game_mode; // game mode defines palette and set of graphics - can be null or "" for default
-
- CL_RIFFImage() : CL_Image() {}
- CL_RIFFImage(CL_Image const & base) : CL_Image(base) {}
-
-private:
- virtual CL_Error Locate(char const * iname, int const enum_id);
-
- void GetPath(ImageDescriptor const & idsc, Environment_Data_Chunk * envd, BMPN_Flags bflags);
-};
-
-#endif // !_included__chnkimag_hpp_
diff --git a/src/win95/cl_init.cpp b/src/win95/cl_init.cpp
deleted file mode 100644
index beab242..0000000
--- a/src/win95/cl_init.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "cl_init.h"
-#include "system.h" // because the 3dc header files don't automatically include the ones they need
-#include "equates.h" // because the 3dc header files don't automatically include the ones they need
-#include "platform.h" // for VideoModeTypes
-#include "shape.h" // because the 3dc header files don't automatically include the ones they need
-#include "prototyp.h" // for SDB
-#include "d3_image.hpp" // for init functions
-
-extern "C" extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
-
-void CL_Init_All(void)
-{
- switch (VideoModeTypeScreen)
- {
- case VideoModeType_8:
- if (ScreenDescriptorBlock.SDB_Flags & SDB_Flag_TLTPalette)
- CL_Init_DirectDrawMode(CLV_8TLT);
- else
- CL_Init_DirectDrawMode(CLV_8);
- break;
- case VideoModeType_15:
- CL_Init_DirectDrawMode(CLV_15);
- break;
- case VideoModeType_24:
- CL_Init_DirectDrawMode(CLV_24);
- break;
- case VideoModeType_8T:
- CL_Init_DirectDrawMode(CLV_8T);
- break;
- }
-
- if (ScanDrawDirectDraw != ScanDrawMode)
- CL_Init_D3DMode(&(d3d.TextureFormat[d3d.CurrentTextureFormat].ddsd));
-}
diff --git a/src/win95/cl_init.h b/src/win95/cl_init.h
deleted file mode 100644
index a0b35c7..0000000
--- a/src/win95/cl_init.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _included_cl_init_h_
-#define _included_cl_init_h_
-
-#error "This file is obsolete"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "d3d.h" // required by d3_func.hpp
-#include "d3_func.h" // for D3DINFO definition
-
-extern int VideoModeTypeScreen;
-extern int ScanDrawMode;
-extern D3DINFO d3d;
-
-void CL_Init_All(void);
-
-#ifdef __cplusplus
-};
-#endif
-
-#endif // !_included_cl_init_h_
diff --git a/src/win95/d3_image.cpp b/src/win95/d3_image.cpp
deleted file mode 100644
index c068b82..0000000
--- a/src/win95/d3_image.cpp
+++ /dev/null
@@ -1,2491 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include "d3_image.hpp"
-#include "platform.h"
-
-// define = 1 if you dont have pre-quantized images to load into palettized D3D texture surfaces
-#define QUANTISE_ON_LOAD 0
-
-#if debug
-#define DEBUG_TRANSPARENCY 1
-#else
-#define DEBUG_TRANSPARENCY 0
-#endif
-
-// image loader stuff
-
-#if OUTPUT_LOG
-#include "debuglog.hpp"
-LogFile CL_LogFile("DB_IMLD.LOG");
-#endif
-
-#if TIME_LOADS
-unsigned int OpenTime;
-unsigned int CloseTime;
-unsigned int ReadTime;
-#endif
-
-static inline unsigned long read_le_dword(D3I_FILE * f)
-{
- unsigned char d1,d2,d3,d4;
- d3i_fread(&d1,1,1,f);
- d3i_fread(&d2,1,1,f);
- d3i_fread(&d3,1,1,f);
- d3i_fread(&d4,1,1,f);
-
- return (unsigned long)d1 | (unsigned long)d2<<8 | (unsigned long)d3<<16 | (unsigned long)d4<<24;
-}
-
-static inline unsigned short read_le_word(D3I_FILE * f)
-{
- unsigned char d1,d2;
- d3i_fread(&d1,1,1,f);
- d3i_fread(&d2,1,1,f);
-
- return (unsigned short)d1 | (unsigned short)((unsigned short)d2<<8);
-}
-
-// some default globals
-CL_ImageMode CL_Image::imode = CLM_GLOBALPALETTE;
-CL_ImageMode CL_Image::imode_d3d = CLM_ATTACHEDPALETTE;
-CL_ImageMode CL_Image::imode_ddraw = CLM_GLOBALPALETTE;
-LPDDSURFACEDESC CL_Image::format = 0;
-unsigned int CL_Image::bitsperpixel;
-unsigned int CL_Image::bitsperpixel_d3d;
-unsigned int CL_Image::bitsperpixel_ddraw;
-CL_LoadMode CL_Image::lmode = CLL_DDSURFACE;
-
-CL_DX_Format CL_Pixel_32::f;
-CL_DX_Format CL_Pixel_32::f_d3d;
-CL_DX_Format CL_Pixel_32::f_ddraw;
-CL_DX_Format CL_Pixel_16::f;
-CL_DX_Format CL_Pixel_16::f_d3d;
-CL_DX_Format CL_Pixel_16::f_ddraw;
-
-
-void CL_Image::DeleteNotMips(void)
-{
- if (im24)
- {
- delete[] *im24;
- delete[] im24;
- im24 = 0;
- }
- if (im16)
- {
- delete[] *im16;
- delete[] im16;
- im16 = 0;
- }
- if (im8)
- {
- delete[] *im8;
- delete[] im8;
- im8 = 0;
- }
- if (palette)
- {
- delete[] palette;
- palette = 0;
- palette_size = 0;
- }
- flags.loaded = 0;
- flags.raw16bit = 0;
-}
-
-void CL_Image::Delete(void)
-{
- DeleteNotMips();
- while (mipmaps.size())
- {
- delete mipmaps.last_entry();
- mipmaps.delete_last_entry();
- }
-}
-
-
-void CL_Image::Copy(CL_Image const & i2)
-{
- if (i2.im24)
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- CL_Pixel_24 const * sptr = *i2.im24;
- CL_Pixel_24 * dptr = *im24;
-
- for (int i=size; i; --i)
- {
- *dptr++ = *sptr++;
- }
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 const * aptr = *im24;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
-
- if (i2.im16)
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 const * sptr = *i2.im16;
- CL_Pixel_16 * dptr = *im16;
-
- for (int i=size; i; --i)
- {
- *dptr++ = *sptr++;
- }
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
-
- if (i2.im8)
- {
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- unsigned char const * sptr = *i2.im8;
- unsigned char * dptr = *im8;
-
- for (int i=size; i; --i)
- {
- *dptr++ = *sptr++;
- }
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char const * aptr = *im8;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
-
- if (i2.palette)
- {
- palette = new CL_Pixel_24 [palette_size];
-
- CL_Pixel_24 const * sptr = i2.palette;
- CL_Pixel_24 * dptr = palette;
-
- for (int i=palette_size; i; --i)
- {
- *dptr++ = *sptr;
- }
- }
-
- if (i2.name)
- {
- name = new char [strlen(i2.name)+1];
- strcpy(name,i2.name);
- }
-
- if (i2.fname)
- {
- fname = new char [strlen(i2.fname)+1];
- strcpy(fname,i2.fname);
- }
-
- for (CLIF<CL_Image *> i_mip(&i2.mipmaps); !i_mip.done(); i_mip.next())
- {
- mipmaps.add_entry_end(new CL_Image(*i_mip()));
- }
-}
-
-
-CL_Image::~CL_Image()
-{
- Delete();
- if (fname) delete[] fname;
- if (name) delete[] name;
-}
-
-
-CL_Image::CL_Image(CL_Image const & i2)
-: width(i2.width)
-, height(i2.height)
-, size(i2.size)
-, im24(0)
-, im16(0)
-, im8(0)
-, palette(0)
-, palette_size(i2.palette_size)
-, fname(0)
-, name(0)
-, flags(i2.flags)
-{
- Copy(i2);
-}
-
-
-CL_Image & CL_Image::operator = (CL_Image const & i2)
-{
- if (&i2 != this)
- {
- Delete();
- if (fname) delete[] fname;
- if (name) delete[] name;
-
- width = i2.width;
- height = i2.height;
- size = i2.size;
- palette_size = i2.palette_size;
-
- fname = 0;
- name = 0;
-
- flags = i2.flags;
-
- Copy(i2);
- }
- return *this;
-}
-
-
-CL_Error CL_Image::Make(int const _width, int const _height)
-{
- Delete();
-
- width = _width;
- height = _height;
- palette_size = 0;
- size = width*height;
-
- switch (imode)
- {
- case CLM_ATTACHEDPALETTE:
- {
- palette_size = 256;
- palette = new CL_Pixel_24 [palette_size];
- }
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- {
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char * dptr = *im8;
- for (int i=height; i; --i, dptr+=width)
- {
- *dptrptr++ = dptr;
- }
-
- break;
- }
- case CLM_24BIT:
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 const * aptr = *im24;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- break;
- }
- case CLM_16BIT:
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- break;
- }
- case CLM_32BIT:
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 const * aptr = *im32;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- break;
- }
- default:
- return CLE_INVALIDDXMODE;
- }
-
- flags.loaded = 1;
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::MakeRandom(int const _width, int const _height, int const seed)
-{
- Delete();
-
- if (-1!=seed) srand((unsigned int)seed);
-
- width = _width;
- height = _height;
- size = width*height;
- palette_size = 0;
-
- switch (imode)
- {
- case CLM_ATTACHEDPALETTE:
- {
- palette_size = 256;
- palette = new CL_Pixel_24 [palette_size];
- CL_Pixel_24 * palP = palette;
- for (int i=palette_size; i; --i, ++palP)
- {
- *palP = CL_Pixel_24(rand()&255,rand()&255,rand()&255);
- }
- }
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- {
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char * dptr = *im8;
- for (int i=height; i; --i)
- {
- *dptrptr++ = dptr;
- for (int j=width; j; --j, ++dptr)
- *dptr = (unsigned char)(rand()&(palette_size-1));
- }
-
- break;
- }
- case CLM_24BIT:
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 * aptr = *im24;
- for (int i=height; i; --i)
- {
- *dptrptr++ = aptr;
- for (int j=width; j; --j, ++aptr)
- *aptr = CL_Pixel_24(rand()&255,rand()&255,rand()&255);
- }
-
- break;
- }
- case CLM_16BIT:
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 * aptr = *im16;
- for (int i=height; i; --i)
- {
- *dptrptr++ = aptr;
- for (int j=width; j; --j, ++aptr)
- *aptr = CL_Pixel_24(rand()&255,rand()&255,rand()&255);
- }
-
- break;
- }
- case CLM_32BIT:
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 * aptr = *im32;
- for (int i=height; i; --i)
- {
- *dptrptr++ = aptr;
- for (int j=width; j; --j, ++aptr)
- *aptr = CL_Pixel_24(rand()&255,rand()&255,rand()&255);
- }
-
- break;
- }
- default:
- return CLE_INVALIDDXMODE;
- }
-
- flags.loaded = 1;
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::Load_BMP(D3I_FILE * f)
-{
- if (!f) return CLE_OPENERROR;
-
- DeleteNotMips();
-
- switch (imode)
- {
- case CLM_ATTACHEDPALETTE:
- case CLM_24BIT:
- case CLM_16BIT:
- case CLM_32BIT:
- break;
- default:
- return CLE_INVALIDDXMODE;
- }
-
- d3i_fseek(f,0,SEEK_SET);
- unsigned short magic;
- d3i_fread(&magic,2,1,f);
- if (magic != *(unsigned short const *)"BM") return CLE_LOADERROR;
-
- size_t filesize = read_le_dword(f);
- d3i_fseek(f,4,SEEK_CUR);
- size_t offset = read_le_dword(f);
- size_t headsize = read_le_dword(f);
-
- unsigned short bitdepth;
-
- if (12 == headsize) // OS/2 1.x
- {
- width = read_le_word(f);
- height = read_le_word(f);
- size = width * height;
- if (!width || !height) return CLE_LOADERROR;
- unsigned short planes = read_le_word(f);
- if (1 != planes) return CLE_LOADERROR;
- bitdepth = read_le_word(f);
-
- if (bitdepth != 24)
- {
- palette_size = 1<<bitdepth;
- palette = new CL_Pixel_24 [palette_size];
- CL_Pixel_24 * rptr = palette;
- for (int i=palette_size; i; --i)
- {
- rptr++->Read(f,CLF_BGR);
- }
- }
- }
- else if (40 == headsize || 64 == headsize) // Windows 3.x || OS/2 2.x
- {
- width = read_le_dword(f);
- height = read_le_dword(f);
- unsigned short planes = read_le_word(f);
- if (1 != planes) return CLE_LOADERROR;
- bitdepth = read_le_word(f);
-
- if (read_le_dword(f)) return CLE_LOADERROR; // compressed bmps not supported
-
- size = read_le_dword(f);
-
- d3i_fseek(f,8,SEEK_CUR);
- palette_size = read_le_dword(f);
- if (!palette_size && bitdepth != 24) palette_size = 1<<bitdepth;
-
- if (palette_size)
- {
- d3i_fseek(f,headsize+14,SEEK_SET);
- palette = new CL_Pixel_24 [palette_size];
- CL_Pixel_24 * rptr = palette;
- for (int i=palette_size; i; --i)
- {
- rptr++->Read(f,CLF_BGRX);
- }
- }
- }
- else return CLE_LOADERROR;
-
- d3i_fseek(f,offset,SEEK_SET);
-
- if (palette_size)
- {
- if (bitdepth < 4)
- {
- delete[] palette;
- palette_size = 0;
- return CLE_LOADERROR;
- }
-
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char * dptr = *im8;
- for (int i=height; i; --i, dptr+=width)
- {
- *dptrptr++ = dptr;
- }
-
- #if DEBUG_TRANSPARENCY
- int num_tps=0;
- #endif
- for (i=height-1; i>=0; --i)
- {
- dptr = im8[i];
-
- if (4==bitdepth)
- {
- for (int i=width>>1; i; --i)
- {
- unsigned char byte;
- d3i_fread(&byte,1,1,f);
- #if DEBUG_TRANSPARENCY
- *dptr = (unsigned char)(byte >> 4 & 0xf);
- if (!*dptr) num_tps++;
- *++dptr = (unsigned char)(byte & 0xf);
- if (!*dptr) num_tps++;
- ++dptr;
- #else
- *dptr++ = (unsigned char)(byte >> 4 & 0xf);
- *dptr++ = (unsigned char)(byte & 0xf);
- #endif
- }
- if (width & 1)
- {
- d3i_fread(dptr,1,1,f);
- *dptr &= 0xf;
- #if DEBUG_TRANSPARENCY
- if (!*dptr) num_tps++;
- #endif
- }
-
- d3i_fseek(f,(~(width-1) & 7)>>1,SEEK_CUR);
- }
- else
- {
- for (int i=width; i; --i)
- {
- #if DEBUG_TRANSPARENCY
- d3i_fread(dptr,1,1,f);
- if (!*dptr) num_tps++;
- dptr++;
- #else
- d3i_fread(dptr++,1,1,f);
- #endif
- }
- d3i_fseek(f,~(width-1) & 3,SEEK_CUR);
- }
- }
- #if DEBUG_TRANSPARENCY
- if (num_tps) CL_LogFile.lprintf("-- %d TRANSPARENT PIXELS FOUND\n",num_tps);
- #endif
- }
- else if (CLM_16BIT == imode)
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (i=height-1; i>=0; --i)
- {
- CL_Pixel_16 * dptr = im16[i];
-
- for (int i=width; i; --i)
- {
- dptr++->Read(f,CLF_BGR);
- }
- d3i_fseek(f,~(width*3-1) & 3,SEEK_CUR);
- }
-
- }
- else if (CLM_32BIT == imode)
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 const * aptr = *im32;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (i=height-1; i>=0; --i)
- {
- CL_Pixel_32 * dptr = im32[i];
-
- for (int i=width; i; --i)
- {
- dptr++->Read(f,CLF_BGR);
- }
- d3i_fseek(f,~(width*3-1) & 3,SEEK_CUR);
- }
-
- }
- else if (CLM_24BIT == imode)
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 const * aptr = *im24;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (i=height-1; i>=0; --i)
- {
- CL_Pixel_24 * dptr = im24[i];
-
- for (int i=width; i; --i)
- {
- dptr++->Read(f,CLF_BGR);
- }
- d3i_fseek(f,~(width*3-1) & 3,SEEK_CUR);
- }
-
- }
- else return CLE_INVALIDDXMODE;
-
- if (palette_size && CLM_ATTACHEDPALETTE != imode)
- {
- if (CLM_16BIT == imode)
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- unsigned char const * sptr = *im8;
- CL_Pixel_16 * dptr = *im16;
-
- for (int i=size; i; --i, ++dptr,++sptr)
- {
- if (*sptr && !palette[*sptr])
- *dptr = dptr->f.dx_black;
- else
- *dptr = palette[*sptr];
- }
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
- else if (CLM_32BIT == imode)
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- unsigned char const * sptr = *im8;
- CL_Pixel_32 * dptr = *im32;
-
- for (int i=size; i; --i, ++dptr,++sptr)
- {
- if (*sptr && !palette[*sptr])
- *dptr = dptr->f.dx_black;
- else
- *dptr = palette[*sptr];
- }
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 const * aptr = *im32;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
- else
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- unsigned char const * sptr = *im8;
- CL_Pixel_24 * dptr = *im24;
-
- for (int i=size; i; --i, ++dptr,++sptr)
- {
- if (*sptr && !palette[*sptr])
- *dptr = CL_Pixel_24(0,1,0);
- else
- *dptr = palette[*sptr];
- }
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 const * aptr = *im24;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
-
- delete[] palette;
- palette = 0;
- palette_size = 0;
- delete[] *im8;
- delete[] im8;
- im8 = 0;
- }
-
- if (d3i_ferror(f) || d3i_feof(f))
- {
- DeleteNotMips();
- return CLE_LOADERROR;
- }
-
- flags.loaded = 1;
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::Load_PPM(D3I_FILE * f)
-{
- if (!f) return CLE_OPENERROR;
-
- DeleteNotMips();
-
- switch (imode)
- {
- case CLM_24BIT:
- case CLM_16BIT:
- case CLM_32BIT:
- break;
- default:
- return CLE_INVALIDDXMODE;
- }
-
- d3i_fseek(f,0,SEEK_SET);
- unsigned short magic;
- d3i_fread(&magic,2,1,f);
- if (magic != *(unsigned short const *)"P6") return CLE_LOADERROR;
-
- d3i_fseek(f,1,SEEK_CUR);
- char buf[256];
- char * bufptr = buf;
- unsigned int fields[5];
- unsigned int fields_read = 0;
- while (fields_read < 3 && bufptr)
- {
- do bufptr = d3i_fgets(buf, sizeof buf, f);
- while ('#'==buf[0] && bufptr);
-
- int num_fields_read = sscanf(buf,"%u %u %u",&fields[fields_read],&fields[fields_read+1],&fields[fields_read+2]);
- if (EOF != num_fields_read) fields_read += num_fields_read;
- }
- if (fields_read < 3) return CLE_LOADERROR;
- width = fields[0];
- height = fields[1];
- unsigned int maxval = fields[2];
- if (maxval > 255) return CLE_LOADERROR;
-
- size = width * height;
-
- if (CLM_16BIT == imode)
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 * rptr = *im16;
- for (int i=size; i; --i)
- {
- rptr++->Read(f,CLF_RGB,maxval);
- }
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
- else if (CLM_32BIT == imode)
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- CL_Pixel_32 * rptr = *im32;
- for (int i=size; i; --i)
- {
- rptr++->Read(f,CLF_RGB,maxval);
- }
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 const * aptr = *im32;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
- else
- {
- im24 = new CL_Pixel_24 * [height];
- *im24 = new CL_Pixel_24 [size];
-
- CL_Pixel_24 * rptr = *im24;
- for (int i=size; i; --i)
- {
- rptr++->Read(f,CLF_RGB,maxval);
- }
-
- CL_Pixel_24 const * * dptrptr = (CL_Pixel_24 const * *) im24;
- CL_Pixel_24 const * aptr = *im24;
- for (i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
- }
-
- if (d3i_ferror(f) || d3i_feof(f))
- {
- DeleteNotMips();
- return CLE_LOADERROR;
- }
-
- flags.loaded = 1;
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::Load_PGM(D3I_FILE * f)
-{
- if (!f) return CLE_OPENERROR;
-
- DeleteNotMips();
-
- switch (imode)
- {
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- break;
- default:
- return CLE_INVALIDDXMODE;
- }
-
- d3i_fseek(f,0,SEEK_SET);
- unsigned short magic;
- d3i_fread(&magic,2,1,f);
- if (magic != *(unsigned short const *)"P5") return CLE_LOADERROR;
-
- d3i_fseek(f,1,SEEK_CUR);
- char buf[256];
- char * bufptr = buf;
- unsigned int fields[5];
- unsigned int fields_read = 0;
- while (fields_read < 3 && bufptr)
- {
- do bufptr = d3i_fgets(buf, sizeof buf, f);
- while ('#'==buf[0] && bufptr);
-
- int num_fields_read = sscanf(buf,"%u %u %u",&fields[fields_read],&fields[fields_read+1],&fields[fields_read+2]);
- if (EOF != num_fields_read) fields_read += num_fields_read;
- }
- if (fields_read < 3) return CLE_LOADERROR;
- width = fields[0];
- height = fields[1];
- unsigned int maxval = fields[2];
- if (maxval > 255) return CLE_LOADERROR;
-
- size = width * height;
-
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- d3i_fread(*im8,1,size,f);
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char const * aptr = *im8;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- if (d3i_ferror(f) || d3i_feof(f))
- {
- DeleteNotMips();
- return CLE_LOADERROR;
- }
-
- flags.loaded = 1;
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::Load_PWM(D3I_FILE * f)
-{
- if (!f) return CLE_OPENERROR;
-
- DeleteNotMips();
-
- switch (imode)
- {
- case CLM_TLTPALETTE:
- break;
- default:
- return CLE_INVALIDDXMODE;
- }
-
- d3i_fseek(f,0,SEEK_SET);
- unsigned short magic;
- d3i_fread(&magic,2,1,f);
- if (magic != *(unsigned short const *)"P8") return CLE_LOADERROR;
-
- d3i_fseek(f,1,SEEK_CUR);
- char buf[256];
- char * bufptr = buf;
- unsigned int fields[5];
- unsigned int fields_read = 0;
- while (fields_read < 3 && bufptr)
- {
- do bufptr = d3i_fgets(buf, sizeof buf, f);
- while ('#'==buf[0] && bufptr);
-
- int num_fields_read = sscanf(buf,"%u %u %u",&fields[fields_read],&fields[fields_read+1],&fields[fields_read+2]);
- if (EOF != num_fields_read) fields_read += num_fields_read;
- }
- if (fields_read < 3) return CLE_LOADERROR;
- width = fields[0];
- height = fields[1];
- unsigned int maxval = fields[2];
- if (maxval > 65535) return CLE_LOADERROR;
-
- size = width * height;
-
- im16raw = new unsigned short * [height];
- *im16raw = new unsigned short [size];
-
- d3i_fread(*im16raw,2,size,f);
-
- unsigned short const * * dptrptr = (unsigned short const * *) im16raw;
- unsigned short const * aptr = *im16raw;
- for (int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- if (d3i_ferror(f) || d3i_feof(f))
- {
- DeleteNotMips();
- return CLE_LOADERROR;
- }
-
- flags.loaded = 1;
- flags.raw16bit = 1;
- return CLE_OK;
-}
-
-
-
-CL_Error CL_Image::GetBitsPerPixel(unsigned int* bpp)
-{
- *bpp = bitsperpixel;
- return CLE_OK;
-}
-
-CL_Error CL_Image::Load_Image(D3I_FILE * f)
-{
- if (!f) return CLE_OPENERROR;
-
- CL_Error retval = CLE_LOADERROR;
-
- START_TIMER
-
- d3i_fseek(f,0,SEEK_SET);
- unsigned short magic;
- d3i_fread(&magic,2,1,f);
-
- if ( *(unsigned short const *)"BM" == magic)
- retval = Load_BMP(f);
- else if ( *(unsigned short const *)"P6" == magic)
- retval = Load_PPM(f);
- else if ( *(unsigned short const *)"P5" == magic)
- retval = Load_PGM(f);
- else if ( *(unsigned short const *)"P8" == magic)
- retval = Load_PWM(f);
- #if OUTPUT_LOG
- else CL_LogFile.lputs("** ERROR: Not a recognized file format\n");
- #endif
-
- END_TIMER(ReadTime)
-
- #if OUTPUT_LOG
- #if TIME_LOADS
- CL_LogFile.lprintf("-- Timer Stats (ms): Open %d Read %d Close %d\n",OpenTime,ReadTime,CloseTime);
- #endif
- #endif
-
- return retval;
-}
-
-
-void CL_Image::PadTo(int const width_unit,int const height_unit)
-{
- if (!flags.loaded) return;
-
- unsigned int const owidth = width;
- unsigned int const oheight = height;
-
- width += width_unit-1;
- width &= ~(width_unit-1);
- height += height_unit-1;
- height &= ~(height_unit-1);
-
- if (width == owidth && height == oheight) return; // already in spec
-
- size = width * height;
-
- CL_Pixel_32 * * const oim32 = im32;
- CL_Pixel_16 * * const oim16 = im16;
- unsigned char * * const oim8 = im8;
-
- if (oim32)
- {
- im32 = new CL_Pixel_32 * [height];
- *im32 = new CL_Pixel_32 [size];
-
- CL_Pixel_32 const * * dptrptr = (CL_Pixel_32 const * *) im32;
- CL_Pixel_32 const * aptr = *im32;
- for (unsigned int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (unsigned int y = 0; y < oheight; ++y)
- {
- CL_Pixel_32 const * sptr = oim32[y];
- CL_Pixel_32 * dptr = im32[y];
-
- for (unsigned int x = 0; x < owidth; ++x, ++dptr, ++sptr)
- *dptr = *sptr;
-
- for (; x < width; ++x, ++dptr)
- *dptr = CL_Pixel_24(0,0,0);
- }
-
- for (; y < height; ++y)
- {
- CL_Pixel_32 * dptr = im32[y];
- for (unsigned int x = 0; x < width; ++x, ++dptr)
- *dptr = CL_Pixel_24(0,0,0);
- }
-
- delete[] *oim32;
- delete[] oim32;
- }
-
- if (oim16)
- {
- im16 = new CL_Pixel_16 * [height];
- *im16 = new CL_Pixel_16 [size];
-
- CL_Pixel_16 const * * dptrptr = (CL_Pixel_16 const * *) im16;
- CL_Pixel_16 const * aptr = *im16;
- for (unsigned int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (unsigned int y = 0; y < oheight; ++y)
- {
- CL_Pixel_16 const * sptr = oim16[y];
- CL_Pixel_16 * dptr = im16[y];
-
- for (unsigned int x = 0; x < owidth; ++x, ++dptr, ++sptr)
- *dptr = *sptr;
-
- for (; x < width; ++x, ++dptr)
- *dptr = CL_Pixel_24(0,0,0);
- }
-
- for (; y < height; ++y)
- {
- CL_Pixel_16 * dptr = im16[y];
- for (unsigned int x = 0; x < width; ++x, ++dptr)
- *dptr = CL_Pixel_24(0,0,0);
- }
-
- delete[] *oim16;
- delete[] oim16;
- }
-
- if (oim8)
- {
- im8 = new unsigned char * [height];
- *im8 = new unsigned char [size];
-
- unsigned char const * * dptrptr = (unsigned char const * *) im8;
- unsigned char const * aptr = *im8;
- for (unsigned int i=height; i; --i, aptr+=width)
- {
- *dptrptr++ = aptr;
- }
-
- for (unsigned int y = 0; y < oheight; ++y)
- {
- unsigned char const * sptr = oim8[y];
- unsigned char * dptr = im8[y];
-
- for (unsigned int x = 0; x < owidth; ++x, ++dptr, ++sptr)
- *dptr = *sptr;
-
- for (; x < width; ++x, ++dptr)
- *dptr = 0;
- }
-
- for (; y < height; ++y)
- {
- unsigned char * dptr = im8[y];
- for (unsigned int x = 0; x < width; ++x, ++dptr)
- *dptr = 0;
- }
-
- delete[] *oim8;
- delete[] oim8;
- }
-}
-
-// implementation of the 'popularity algorithm' for reducing palette
-
-unsigned int CL_Pixel_24::FVD_Distance(CL_Pixel_24 const & p2) const
-{
- unsigned int dg = g > p2.g ? g - p2.g : p2.g - g;
- unsigned int db = b > p2.b ? b - p2.b : p2.b - b;
-
- unsigned int dgb = dg + db + ((dg > db ? dg : db)<<1);
-
- unsigned int dr = r > p2.r ? r - p2.r : p2.r - r;
- dr += dr<<1; // *= 3
-
- return dr + dgb + ((dr > dgb ? dr : dgb)<<1);
-}
-
-struct _CL_palpixcnt
-{
- unsigned int cnt;
- unsigned int palpos;
-};
-
-int _CL_cmp_palpixcnt(void const * e1, void const * e2)
-{
- return ((_CL_palpixcnt *)e2)->cnt - ((_CL_palpixcnt *)e1)->cnt;
-}
-
-CL_Error CL_Image::ReducePalette(unsigned int const num_colours)
-{
- if (!flags.loaded) return CLE_LOADERROR;
-
- if (!palette) return CLE_INVALIDDXMODE;
- if (!im8) return CLE_INVALIDDXMODE;
-
- if (palette_size <= num_colours) return CLE_OK;
-
- _CL_palpixcnt * const sortarray = new _CL_palpixcnt[palette_size];
-
- for (unsigned int i=0; i<palette_size; ++i)
- {
- sortarray[i].cnt = 0;
- sortarray[i].palpos = i;
- }
-
- for (unsigned int y=0; y<height; ++y)
- {
- unsigned char const * sptr = im8[y];
-
- for (unsigned int x=width; x; --x, ++sptr)
- ++ sortarray[*sptr].cnt;
- }
-
- unsigned int const palstart = CL_Pixel_24(0,0,0) == palette[0] ? 1 : 0;
- qsort(sortarray + palstart, palette_size - palstart, sizeof(_CL_palpixcnt), _CL_cmp_palpixcnt);
-
- CL_Pixel_24 * const opalette = palette;
- unsigned int const opalette_size = palette_size;
- palette = new CL_Pixel_24[num_colours];
- palette_size = num_colours;
-
- for (i=0; i<palette_size; ++i)
- palette[i] = opalette[sortarray[i].palpos];
-
- delete[] sortarray;
-
- // umm - if theres black thats not transparent, make sure it doesnt become colour 0 in palette
- for (unsigned int pswap=1; pswap<palette_size && 0==palstart && CL_Pixel_24(0,0,0)==palette[0]; ++pswap)
- {
- palette[0]=palette[pswap];
- palette[pswap]=CL_Pixel_24(0,0,0);
- }
-
- // emergency?
- if (0==palstart && CL_Pixel_24(0,0,0)==palette[0])
- palette[0] = CL_Pixel_24(1,1,1);
-
- unsigned int * const palmaps = new unsigned int [opalette_size];
- palmaps[0] = 0;
- for (i=palstart; i<opalette_size; ++i)
- {
- unsigned int closest = palstart;
- unsigned int distance = opalette[i].FVD_Distance(palette[palstart]);
-
- for (unsigned int j = palstart+1; j<palette_size; ++j)
- {
- unsigned int thisdist = opalette[i].FVD_Distance(palette[j]);
- if (thisdist < distance)
- {
- distance = thisdist;
- closest = j;
- }
- }
-
- palmaps[i] = closest;
- }
-
- delete[] opalette;
-
- for (y=0; y<height; ++y)
- {
- unsigned char * sptr = im8[y];
-
- for (unsigned int x=width; x; --x, ++sptr)
- *sptr = (unsigned char)palmaps[*sptr];
- }
-
- delete[] palmaps;
-
- return CLE_OK;
-}
-
-// useful filename handling functions
-
-// returns pointer into string pointing to filename without dirname
-static char const * strip_path(char const * n)
-{
- char const * rm = strrchr(n,':');
- if (rm) n = rm+1;
- rm = strrchr(n,'/');
- if (rm) n = rm+1;
- rm = strrchr(n,'\\');
- if (rm) n = rm+1;
-
- return n;
-}
-
-#if 0
-static char * strip_path(char * n)
-{
- char * rm = strrchr(n,':');
- if (rm) n = rm+1;
- rm = strrchr(n,'/');
- if (rm) n = rm+1;
- rm = strrchr(n,'\\');
- if (rm) n = rm+1;
-
- return n;
-}
-#endif
-
-// removes any .extension from filename by inserting null character
-static void strip_file_extension(char * n)
-{
- char * dotpos = strrchr(n,'.');
- if (dotpos) *dotpos = 0;
-}
-
-static char * strip_file_extension(char const * n)
-{
- char * nn = new char[strlen(n)+1];
- strcpy(nn,n);
- strip_file_extension(nn);
- return nn;
-}
-
-// CL_Image functions
-
-CL_Error CL_Image::Locate(char const * iname, int const /* enum_id */)
-{
- if (!iname) return CLE_RIFFERROR;
-
- if (name)
- delete[] name;
- name = strip_file_extension(strip_path(iname));
-
- if (fname)
- delete[] fname;
- fname = new char[strlen(iname)+1];
- strcpy(fname,iname);
-
- flags.located = 1;
- return CLE_OK;
-}
-
-CL_Error CL_Image::Load(char const * const iname, int const enum_id)
-{
- if (iname || CL_EID_INVALID != enum_id || !flags.located)
- {
- CL_Error locate_err = Locate(iname,enum_id);
-
- if (locate_err != CLE_OK)
- {
- EXITONLOCATEFAIL(locate_err,iname,enum_id)
- return locate_err;
- }
- }
-
- #if OUTPUT_LOG
- char const * texformat;
- unsigned int redbits = 8;
- unsigned int greenbits = 8;
- unsigned int bluebits = 8;
- switch (imode)
- {
- case CLM_GLOBALPALETTE:
- texformat = "Palettized Display";
- break;
- case CLM_TLTPALETTE:
- texformat = "Palettized Display with Abstract TLT Palette";
- break;
- case CLM_ATTACHEDPALETTE:
- texformat = "Palettized Textures";
- break;
- case CLM_32BIT:
- texformat = "32BIT DX";
- redbits += CL_Pixel_32::f.red_bits_gt8;
- redbits -= CL_Pixel_32::f.red_bits_lt8;
- greenbits += CL_Pixel_32::f.green_bits_gt8;
- greenbits -= CL_Pixel_32::f.green_bits_lt8;
- bluebits += CL_Pixel_32::f.blue_bits_gt8;
- bluebits -= CL_Pixel_32::f.blue_bits_lt8;
- break;
- case CLM_24BIT:
- texformat = "24-bit for runtime conversion";
- break;
- case CLM_16BIT:
- texformat = "16BIT DX";
- redbits += CL_Pixel_16::f.red_bits_gt8;
- redbits -= CL_Pixel_16::f.red_bits_lt8;
- greenbits += CL_Pixel_16::f.green_bits_gt8;
- greenbits -= CL_Pixel_16::f.green_bits_lt8;
- bluebits += CL_Pixel_16::f.blue_bits_gt8;
- bluebits -= CL_Pixel_16::f.blue_bits_lt8;
- break;
- }
- CL_LogFile.lprintf("--%s %s (%u-bit, %u-%u-%u)\n",fname,texformat,bitsperpixel,redbits,greenbits,bluebits);
- #endif
-
- START_TIMER
- D3I_FILE * fp = d3i_fopen(fname,"rb");
- END_TIMER(OpenTime)
-
- if (fp)
- {
- CL_Error retval = Load_Image(fp);
- START_TIMER
- d3i_fclose(fp);
- END_TIMER(CloseTime)
- if (CLE_OK != retval)
- {
- #if OUTPUT_LOG
- CL_LogFile.lputs("** ERROR: unable to read\n");
- #endif
- EXITONREADFAIL(fname)
- }
- return retval;
- }
-
- #if OUTPUT_LOG
- CL_LogFile.lputs("** ERROR: unable to open\n");
- #endif
- EXITONLOADFAIL(fname)
- return CLE_OPENERROR;
-}
-
-CL_Error CL_Image::PreLoad(char const * const iname, int const enum_id)
-{
- CL_Error locate_err = Locate(iname,enum_id);
-
- if (locate_err != CLE_OK)
- {
- return locate_err;
- }
-
- return CLE_OK;
-}
-
-CL_Error CL_Image::LoadMipMaps(int const n_mips) // assumes locating has been done (ie. PreLoad or Load has been called)
-{
- if (!flags.located) return CLE_FINDERROR;
-
- while (mipmaps.size())
- {
- delete mipmaps.last_entry();
- mipmaps.delete_last_entry();
- }
-
- for (int mip_idx = 1; mip_idx < n_mips; ++mip_idx)
- {
- CL_Image * mip_n = new CL_Image;
-
- mip_n->name = new char[strlen(name)+1];
- mip_n->fname = new char[strlen(fname)+1];
- strcpy(mip_n->name,name);
- strcpy(mip_n->fname,fname);
-
- char * dotpos = strrchr(mip_n->fname,'.');
- if (!dotpos)
- {
- delete mip_n;
- break;
- }
- sprintf(dotpos+3,"%1d",mip_idx);
-
- mip_n->flags.located = 1;
-
- if (CLE_OK!=mip_n->Load())
- {
- delete mip_n;
- break;
- }
-
- if (mip_n->width << mip_idx < width || mip_n->height << mip_idx < height)
- {
- delete mip_n;
- #if OUTPUT_LOG
- CL_LogFile.lputs("** Warning: less than half size\n");
- #endif
- break;
- }
-
- mipmaps.add_entry_end(mip_n);
- }
- return CLE_OK;
-}
-
-void CL_Select_Mode(CL_LoadMode const lmode)
-{
- switch (lmode)
- {
- case CLL_D3DTEXTURE:
- CL_Image::imode = CL_Image::imode_d3d;
- CL_Image::bitsperpixel = CL_Image::bitsperpixel_d3d;
- CL_Pixel_16::f = CL_Pixel_16::f_d3d;
- CL_Pixel_32::f = CL_Pixel_32::f_d3d;
- break;
- case CLL_DDSURFACE:
- CL_Image::imode = CL_Image::imode_ddraw;
- CL_Image::bitsperpixel = CL_Image::bitsperpixel_ddraw;
- CL_Pixel_16::f = CL_Pixel_16::f_ddraw;
- CL_Pixel_32::f = CL_Pixel_32::f_ddraw;
- break;
- }
- CL_Image::lmode = lmode;
-}
-
-// 3DC interface
-
-void CL_Init_DirectDrawMode(CL_VideoMode const vmode)
-{
- switch (vmode)
- {
- case CLV_8:
- CL_Image::bitsperpixel_ddraw = 8;
- CL_Image::imode_ddraw = CLM_GLOBALPALETTE;
- break;
- case CLV_8TLT:
- CL_Image::bitsperpixel_ddraw = 8;
- CL_Image::imode_ddraw = CLM_TLTPALETTE;
- break;
- case CLV_15:
- CL_Image::bitsperpixel_ddraw = 16;
- CL_Image::imode_ddraw = CLM_16BIT;
- CL_Pixel_16::f_ddraw.Init
- (
- DisplayPixelFormat.dwRBitMask,
- DisplayPixelFormat.dwGBitMask,
- DisplayPixelFormat.dwBBitMask
- );
- break;
- case CLV_24:
- CL_Image::bitsperpixel_ddraw = DisplayPixelFormat.dwRGBBitCount;
- if (24 == CL_Image::bitsperpixel_ddraw)
- CL_Image::imode_ddraw = CLM_24BIT;
- else
- {
- CL_Image::imode_ddraw = CLM_32BIT;
- CL_Pixel_32::f_ddraw.Init
- (
- DisplayPixelFormat.dwRBitMask,
- DisplayPixelFormat.dwGBitMask,
- DisplayPixelFormat.dwBBitMask
- );
- }
- break;
- case CLV_8T:
- CL_Image::bitsperpixel_ddraw = 8;
- CL_Image::imode_ddraw = CLM_16BIT;
- CL_Pixel_16::f_ddraw.Init(7<<5,7<<2,3);
- break;
- }
- CL_Select_Mode(CLL_DDSURFACE);
-}
-
-
-CL_Error CL_Image::CopyToScanDrawTexture(unsigned char * * const ImagePtrA [], unsigned int n_mips_max)
-{
- if (!flags.loaded) return CLE_LOADERROR;
-
- if (CLL_DDSURFACE != lmode) CL_Select_Mode(CLL_DDSURFACE);
-
- if (n_mips_max > mipmaps.size()+1) n_mips_max = mipmaps.size()+1;
-
- if (!*ImagePtrA[0])
- {
- if (flags.raw16bit)
- {
- if (n_mips_max>1)
- *ImagePtrA[0] = (unsigned char *) AllocateMem((2*width+1)*(2*height+1)*2/3+(n_mips_max-3)*2); // slightly more than 4/3 w*h*bytedepth
- else
- *ImagePtrA[0] = (unsigned char *) AllocateMem(width*height*2);
- }
- else
- {
- if (n_mips_max>1)
- *ImagePtrA[0] = (unsigned char *) AllocateMem((2*width+1)*(2*height+1)*bitsperpixel/24+(n_mips_max-3)*(bitsperpixel/8)); // slightly more than 4/3 w*h*bytedepth
- else
- *ImagePtrA[0] = (unsigned char *) AllocateMem(width*height*(bitsperpixel>>3));
- }
- }
- if (!*ImagePtrA[0])
- return CLE_ALLOCFAIL;
-
- unsigned int my_bitsperpixel = bitsperpixel;
-
- switch (imode)
- {
- unsigned char * tptr;
- unsigned short * tSptr;
- unsigned long * tLptr;
-
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- if (flags.raw16bit)
- {
- my_bitsperpixel = 16;
- tSptr = (unsigned short *)*ImagePtrA[0];
- if (tSptr)
- {
- for (int i=0; i<height; ++i)
- {
- memcpy(tSptr,im16raw[i],width*sizeof(unsigned short));
- tSptr += width;
- }
- }
- }
- else
- {
- tptr = *ImagePtrA[0];
- if (tptr)
- {
- for (int i=0; i<height; ++i)
- {
- memcpy(tptr,im8[i],width);
- tptr += width;
- }
- }
- }
- break;
- case CLM_16BIT:
- switch (bitsperpixel)
- {
- case 8:
- tptr = *ImagePtrA[0];
- if (tptr)
- {
- for (int i=0; i<height; ++i)
- {
- unsigned char const * i8ptr = im8[i];
- for (int j=width; j; --j)
- {
- *tptr++ = *i8ptr++;
- }
- }
- }
- break;
- case 16:
- tSptr = (unsigned short *)*ImagePtrA[0];
- if (tSptr)
- {
- for (int i=0; i<height; ++i)
- {
- CL_Pixel_16 const * i16ptr = im16[i];
- for (int j=width; j; --j)
- {
- *tSptr++ = *i16ptr++;
- }
- }
- }
- break;
- }
- break;
- case CLM_24BIT:
- switch (bitsperpixel)
- {
- case 24:
- tptr = *ImagePtrA[0];
- if (tptr)
- {
- for (int i=0; i<height; ++i)
- {
- CL_Pixel_24 const * i24ptr = im24[i];
- for (int j=width; j; --j)
- {
- *tptr++ = i24ptr->b;
- *tptr++ = i24ptr->g;
- *tptr++ = i24ptr->r;
- i24ptr++;
- }
- }
- }
- break;
- case 32:
- tLptr = (unsigned long *)*ImagePtrA[0];
- if (tLptr)
- {
- for (int i=0; i<height; ++i)
- {
- CL_Pixel_32 const * i32ptr = im32[i];
- for (int j=width; j; --j)
- {
- *tLptr++ = *i32ptr++;
- }
- }
- }
- break;
- }
- break;
- default:
- return CLE_INVALIDDXMODE;
- }
-
- // now do mipmaps if avail
-
- CL_Image * last_mipP = this;
-
- LIF<CL_Image *> i_mip(&mipmaps);
- for (int i=1; i<n_mips_max && !i_mip.done(); ++i, i_mip.next())
- {
- *ImagePtrA[i] = *ImagePtrA[i-1] + last_mipP->width*last_mipP->height*(my_bitsperpixel>>3);
- CL_Error thismipmaperror = i_mip()->CopyToScanDrawTexture(&ImagePtrA[i],1);
- if (CLE_OK != thismipmaperror) return thismipmaperror;
- last_mipP = i_mip();
- }
- return CLE_OK;
-}
-
-
-
-// Direct X interface
-
-void CL_Init_D3DMode(LPDDSURFACEDESC const format)
-{
- CL_Image::format = format;
-
- if (format->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
- {
- #if QUANTISE_ON_LOAD
- CL_Image::imode_d3d = CLM_24BIT;
- #else
- CL_Image::imode_d3d = CLM_ATTACHEDPALETTE;
- #endif
- CL_Image::bitsperpixel_d3d = 8;
- }
- else if (format->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4)
- {
- #if QUANTISE_ON_LOAD
- CL_Image::imode_d3d = CLM_24BIT;
- #else
- CL_Image::imode_d3d = CLM_ATTACHEDPALETTE;
- #endif
- CL_Image::bitsperpixel_d3d = 4;
- }
- else if (format->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED2)
- {
- #if QUANTISE_ON_LOAD
- CL_Image::imode_d3d = CLM_24BIT;
- #else
- CL_Image::imode_d3d = CLM_ATTACHEDPALETTE;
- #endif
- CL_Image::bitsperpixel_d3d = 2;
- }
- else if (format->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED1)
- {
- #if QUANTISE_ON_LOAD
- CL_Image::imode_d3d = CLM_24BIT;
- #else
- CL_Image::imode_d3d = CLM_ATTACHEDPALETTE;
- #endif
- CL_Image::bitsperpixel_d3d = 1;
- }
- else
- {
- CL_Image::bitsperpixel_d3d = format->ddpfPixelFormat.dwRGBBitCount;
- if (format->ddpfPixelFormat.dwRGBBitCount > 16)
- {
- CL_Image::imode_d3d = CLM_32BIT;
- CL_Pixel_32::f_d3d.Init
- (
- format->ddpfPixelFormat.dwRBitMask,
- format->ddpfPixelFormat.dwGBitMask,
- format->ddpfPixelFormat.dwBBitMask
- );
- }
- else
- {
- CL_Image::imode_d3d = CLM_16BIT;
- CL_Pixel_16::f_d3d.Init
- (
- format->ddpfPixelFormat.dwRBitMask,
- format->ddpfPixelFormat.dwGBitMask,
- format->ddpfPixelFormat.dwBBitMask
- );
- }
- }
- CL_Select_Mode(CLL_D3DTEXTURE);
-}
-
-
-CL_Error CL_Image::CopyToD3DTexture(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], int const MemoryType, unsigned int n_mips_max)
-{
- if (!flags.loaded) return CLE_LOADERROR;
-
- WaitForVRamReady(VWS_D3DTEXCREATE);
-
- if (CLL_D3DTEXTURE != lmode) CL_Select_Mode(CLL_D3DTEXTURE);
-
- LPDIRECTDRAWSURFACE lpDDS;
- DDSURFACEDESC ddsd;
- HRESULT ddrval;
-
- // Check for image being 4 byte aligned
- // and fail if it is not
- if (width & 3 || height & 3)
- {
- // return error code
- return CLE_DXERROR;
- }
-
-
- // Set up the surface description. starting
- // with the passed texture format and then
- // incorporating the information read from the
- // ppm.
- memcpy(&ddsd, format, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT);
- ddsd.ddsCaps.dwCaps = (DDSCAPS_TEXTURE | MemoryType);
- ddsd.dwHeight = height;
- ddsd.dwWidth = width;
-
- if (n_mips_max > mipmaps.size()+1) n_mips_max = mipmaps.size()+1;
-
- if (n_mips_max>1)
- {
- ddsd.dwFlags |= DDSD_MIPMAPCOUNT;
- ddsd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX;
- ddsd.dwMipMapCount = n_mips_max;
- }
-
- // Create the surface
- ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
-
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
-
- // now do mipmaps if avail
-
- if (n_mips_max>1)
- {
- // We must now traverse the mip-map chain from highest to lowest
- // resolutions, For each surface AFTER the first one, we must
- // load a new file, using a name obtained from the mip map number
-
- int MipMapNum = 0;
- LPDIRECTDRAWSURFACE lpThisMipMap, lpNextMipMap;
- DDSCAPS ddsCaps;
-
-
- lpThisMipMap = lpDDS;
- // Component Object Model, increase reference count on
- // mip-map surface by one.
- lpThisMipMap->AddRef();
- ddsCaps.dwCaps = (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
- ddrval = DD_OK;
-
- LIF<CL_Image *> i_mip(&mipmaps);
-
- CL_Image * last_mipP = this;
-
- while ((ddrval == DD_OK) && (MipMapNum < n_mips_max)) // both tests in case...
- {
- // Call LoadPPMIntoDDSurface with lpThisMipMap, new file name, and
- // other values.
-
- *DDSurfaceA[MipMapNum] = last_mipP->CopyToDDSurface(lpThisMipMap);
-
- // Death trap
- if (!*DDSurfaceA[MipMapNum])
- {
- return CLE_DXERROR;
- }
- *DDPtrA[MipMapNum] = lpThisMipMap;
-
- // Proceed to the next level.
- // Collect bonus rings.
- ddrval = lpThisMipMap->GetAttachedSurface(&ddsCaps, &lpNextMipMap);
- // Necessary to match the manual increment of the reference count on the
- // COM texture. I think.
- lpThisMipMap->Release();
- // ?? lpNextMipMap = lpThisMipMap;
- lpThisMipMap = lpNextMipMap;
-
- MipMapNum++;
- if (!i_mip.done())
- {
- last_mipP = i_mip();
- i_mip.next();
- }
- }
- }
- else
- {
- *DDSurfaceA[0] = CopyToDDSurface(lpDDS);
-
- if (!*DDSurfaceA[0]) return CLE_DXERROR;
-
- *DDPtrA[0] = lpDDS;
- }
-
- return CLE_OK;
-}
-
-
-CL_Error CL_Image::CopyToDirectDrawSurface(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], int const MemoryType, unsigned int n_mips_max)
-{
- if (!flags.loaded) return CLE_LOADERROR;
-
- WaitForVRamReady(VWS_DDCREATE);
-
- if (CLL_DDSURFACE != lmode) CL_Select_Mode(CLL_DDSURFACE);
-
- LPDIRECTDRAWSURFACE lpDDS;
- DDSURFACEDESC ddsd;
- HRESULT ddrval;
-
- // Check for image being 4 byte aligned
- // and fail if it is not
- if (width & 3 || height & 3)
- {
- // return error code
- return CLE_DXERROR;
- }
-
- if (n_mips_max > mipmaps.size()+1) n_mips_max = mipmaps.size()+1;
-
- // Set up the surface description. starting
- // with the passed texture format and then
- // incorporating the information read from the
- // ppm.
- memset(&ddsd, 0, sizeof ddsd);
- ddsd.dwSize = sizeof ddsd;
- ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT);
- // Ensure that created surface has same pixel desription
- // as primary
- memcpy(&ddsd.ddpfPixelFormat, &DisplayPixelFormat, sizeof(DDPIXELFORMAT));
- ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | MemoryType);
- ddsd.dwHeight = height;
- ddsd.dwWidth = width;
-
- if (n_mips_max>1)
- {
- ddsd.dwFlags |= DDSD_MIPMAPCOUNT;
- ddsd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX;
- ddsd.dwMipMapCount = n_mips_max;
- }
-
- // Create the surface
- ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
-
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
- DDCOLORKEY set_zero = {0,0};
- ddrval = lpDDS->SetColorKey(DDCKEY_SRCBLT, &set_zero);
-
- LOGDXERR(ddrval);
- if(ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
-
- // now do mipmaps if avail
-
- if (n_mips_max>1)
- {
- // We must now traverse the mip-map chain from highest to lowest
- // resolutions, For each surface AFTER the first one, we must
- // load a new file, using a name obtained from the mip map number
-
- int MipMapNum = 0;
- LPDIRECTDRAWSURFACE lpThisMipMap, lpNextMipMap;
- DDSCAPS ddsCaps;
-
-
- lpThisMipMap = lpDDS;
- // Component Object Model, increase reference count on
- // mip-map surface by one.
- lpThisMipMap->AddRef();
- ddsCaps.dwCaps = (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
- ddrval = DD_OK;
-
- LIF<CL_Image *> i_mip(&mipmaps);
-
- CL_Image * last_mipP = this;
-
- while ((ddrval == DD_OK) && (MipMapNum < n_mips_max)) // both tests in case...
- {
- // Call LoadPPMIntoDDSurface with lpThisMipMap, new file name, and
- // other values.
-
- *DDSurfaceA[MipMapNum] = last_mipP->CopyToDDSurface(lpThisMipMap);
-
- // Death trap
- if (!*DDSurfaceA[MipMapNum])
- {
- return CLE_DXERROR;
- }
- *DDPtrA[MipMapNum] = lpThisMipMap;
-
- // Proceed to the next level.
- // Collect bonus rings.
- ddrval = lpThisMipMap->GetAttachedSurface(&ddsCaps, &lpNextMipMap);
- // Necessary to match the manual increment of the reference count on the
- // COM texture. I think.
- lpThisMipMap->Release();
- // ?? lpNextMipMap = lpThisMipMap;
- lpThisMipMap = lpNextMipMap;
-
- MipMapNum++;
- if (!i_mip.done())
- {
- last_mipP = i_mip();
- i_mip.next();
- }
- }
- }
- else
- {
- *DDSurfaceA[0] = CopyToDDSurface(lpDDS);
-
- if (!*DDSurfaceA[0]) return CLE_DXERROR;
-
- *DDPtrA[0] = lpDDS;
- }
-
- return CLE_OK;
-}
-
-
-LPVOID CL_Image::CopyToDDSurface(LPDIRECTDRAWSURFACE lpDDS)
-{
- if (!flags.loaded) return 0;
-
- LPDIRECTDRAWPALETTE lpDDPPMPal;
- PALETTEENTRY ppe[256];
- DDSURFACEDESC ddsd;
- #if QUANTISE_ON_LOAD
- D3DCOLOR colors[256];
- D3DCOLOR c;
- int color_count;
- #endif
- int psize;
- char *lpC;
- HRESULT ddrval;
- unsigned int i, j;
- unsigned int pcaps;
-
- // Lock the surface so it can be filled with the PPM file
-
- memset(&ddsd, 0, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- ddrval = lpDDS->Lock(NULL, &ddsd, 0, NULL);
-
- if (!ddsd.lpSurface)
- {
- lpDDS->Unlock(NULL);
- lpDDS->Release();
- LOGDXSTR("No surface");
- return 0;
- }
-
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return 0;
- #endif
- }
-
- // The method of loading depends on the pixel format of the dest surface
-
- switch (imode)
- {
- case CLM_32BIT:
- switch (bitsperpixel)
- {
- case 32:
- for (j = 0; j < height; j++)
- {
- // Point to next row in texture surface
- unsigned long * lpLP = (unsigned long*)((char*)ddsd.lpSurface
- + ddsd.lPitch * j);
- CL_Pixel_32 * lpP32 = im32[j];
- for (i = width; i; --i)
- {
- *lpLP++ = *lpP32++;
- }
- }
- break;
- case 24:
- for (j = 0; j < height; j++)
- {
- // Point to next row in texture surface
- unsigned char * lpCP = (unsigned char*)ddsd.lpSurface
- + ddsd.lPitch * j;
- CL_Pixel_32 * lpP32 = im32[j];
- for (i = width; i; --i)
- {
- unsigned long lv = *lpP32++;
- unsigned char const * lpSrcCP = (unsigned char const *)&lv;
- // dodgy - makes assumtions about 24-bit values...
- *lpCP++ = *lpSrcCP++;
- *lpCP++ = *lpSrcCP++;
- *lpCP++ = *lpSrcCP++;
- }
- }
- break;
- default:
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Unlock(NULL);
- lpDDS->Release();
- return 0;
- #endif
- }
- lpDDS->Unlock(NULL);
- break;
- case CLM_16BIT:
- switch (bitsperpixel)
- {
- case 16:
- for (j = 0; j < height; j++)
- {
- // Point to next row in texture surface
- unsigned short * lpSP = (unsigned short*)((char*)ddsd.lpSurface
- + ddsd.lPitch * j);
- CL_Pixel_16 * lpP16 = im16[j];
- for (i = width; i; --i)
- {
- *lpSP++ = *lpP16++;
- }
- }
- break;
- case 8:
- for (j = 0; j < height; j++)
- {
- // Point to next row in texture surface
- unsigned char * lpCP = (unsigned char*)ddsd.lpSurface
- + ddsd.lPitch * j;
- CL_Pixel_16 * lpP16 = im16[j];
- for (i = width; i; --i)
- {
- *lpCP++ = *lpP16++;
- }
- }
- break;
- default:
- // Everything's gone pear-shaped...
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Unlock(NULL);
- lpDDS->Release();
- return 0;
- #endif
- }
- lpDDS->Unlock(NULL);
- break;
- case CLM_24BIT:
- if (24==bitsperpixel)
- {
- for (j = 0; j < height; j++)
- {
- // Point to next row in surface
- unsigned char * lpCP = ((unsigned char*)ddsd.lpSurface) + ddsd.lPitch * j;
- CL_Pixel_24 * lpP24 = im24[j];
- for (i = 0; i < width; i++)
- {
- // making an assumption about the ordering of r,g,b on the video card
- *lpCP++ = lpP24->b;
- *lpCP++ = lpP24->g;
- *lpCP++ = lpP24->r;
- lpP24++;
- }
- }
- lpDDS->Unlock(NULL);
- }
- else
- {
- #if QUANTISE_ON_LOAD // Neal's quantize on load stuff
-
- // Paletted target texture surface
- psize = 1<<bitsperpixel;
- color_count = 0; // number of colors in the texture
- for (j = 0; j < height; j++)
- {
- // Point to next row in surface
- lpC = ((char*)ddsd.lpSurface) + ddsd.lPitch * j;
- CL_Pixel_24 * lpP24 = im24[j];
- for (i = 0; i < width; i++, lpP24++)
- {
- int k;
- // Get the next red, green and blue values and turn them into a
- // D3DCOLOR.
- c = RGB_MAKE(lpP24->r, lpP24->g, lpP24->b);
- // Search for this color in a table of colors in this texture
- for (k = 0; k < color_count; k++)
- if (c == colors[k]) break;
- if (k == color_count)
- {
- // This is a new color, so add it to the list
- color_count++;
- // More than 256 and we fail (8-bit)
- if (color_count > psize)
- {
- color_count--;
- k = color_count - 1;
- }
- colors[k] = c;
- }
- // Set the "pixel" value on the surface to be the index into the
- // color table
- if (psize<256)
- {
- unsigned int bitmask;
- switch (psize)
- {
- default:
- bitmask = 1;
- break;
- case 4:
- bitmask = 3;
- break;
- case 2:
- bitmask = 7;
- break;
- }
- if ((i & bitmask) == 0)
- *lpC = (char)(k & (psize-1));
- else
- *lpC |= (char)((k & (psize-1)) << (i & (psize-1)));
- if ((~i & bitmask) == 0)
- lpC++;
- }
- else
- {
- *lpC = (char)k;
- lpC++;
- }
- }
- }
-
- // Close the file and unlock the surface
-
- lpDDS->Unlock(NULL);
-
- if (color_count > psize)
- {
- // If there are more than 256 colors, we overran our palette
- #if debug
- ReleaseDirect3D();
- exit(0x321123);
- #else
- lpDDS->Release();
- return 0;
- #endif
- }
-
- // Create a palette with the colors in our color table
-
- memset(ppe, 0, sizeof(PALETTEENTRY) * 256);
- for (i = 0; i < color_count; i++)
- {
- ppe[i].peRed = (unsigned char)RGB_GETRED(colors[i]);
- ppe[i].peGreen = (unsigned char)RGB_GETGREEN(colors[i]);
- ppe[i].peBlue = (unsigned char)RGB_GETBLUE(colors[i]);
- }
-
- // Set all remaining entry flags to D3DPAL_RESERVED, which are ignored by
- // the renderer.
-
- for (; i < 256; i++)
- ppe[i].peFlags = D3DPAL_RESERVED;
-
- // Create the palette with the DDPCAPS_ALLOW256 flag because we want to
- // have access to all entries.
-
- switch (bitsperpixel)
- {
- default:
- pcaps = DDPCAPS_8BIT | DDPCAPS_ALLOW256;
- break;
- case 4:
- pcaps = DDPCAPS_4BIT;
- break;
- case 2:
- pcaps = DDPCAPS_2BIT;
- break;
- case 1:
- pcaps = DDPCAPS_1BIT;
- break;
- }
-
- ddrval = lpDD->CreatePalette
- (DDPCAPS_INITIALIZE | pcaps,
- ppe, &lpDDPPMPal, NULL);
- LOGDXERR(ddrval);
-
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return 0;
- #endif
- }
-
- // Finally, bind the palette to the surface
-
- ddrval = lpDDS->SetPalette(lpDDPPMPal);
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- lpDDPPMPal->Release();
- return 0;
- #endif
- }
-
- lpDDPPMPal->Release();
- }
- break;
- #else
- // Everything's gone pear-shaped...
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Unlock(NULL);
- lpDDS->Release();
- return 0;
- #endif
- }
- break;
- case CLM_ATTACHEDPALETTE:
- #endif
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- // Paletted target texture surface
-
- psize = 1<<bitsperpixel;
- ReducePalette(psize); // will do nothing if palette is already small enough
- // ignore returned error code, because I don't care if it failed
- for (j = 0; j < height; j++)
- {
- // Point to next row in surface
- lpC = ((char*)ddsd.lpSurface) + ddsd.lPitch * j;
- unsigned char * lpP8 = im8[j];
-
- if (psize<256)
- {
- unsigned int bitmask;
- unsigned int nextpixelshift;
- switch (psize)
- {
- default:
- nextpixelshift = 2;
- break;
- case 4:
- nextpixelshift = 1;
- break;
- case 2:
- nextpixelshift = 0;
- break;
- }
- bitmask = 7 >> nextpixelshift;
- for (i = 0; i < width; i++)
- {
- unsigned char k = *lpP8++;
- // Set the "pixel" value on the surface to be the index into the
- // color table
- if ((i & bitmask) == 0)
- *lpC = (char) (k & (psize-1));
- else
- *lpC |= (char) ((k & (psize-1)) << ((i & bitmask)<<nextpixelshift));
- if ((~i & bitmask) == 0)
- lpC++;
- }
- }
- else
- {
- memcpy(lpC,lpP8,width);
- }
- }
-
- // Close the file and unlock the surface
-
- lpDDS->Unlock(NULL);
-
- // Create a palette with the colors in our color table
-
- memset(ppe, 0, sizeof(PALETTEENTRY) * 256);
- for (i = 0; i < palette_size; i++)
- {
- ppe[i].peRed = palette[i].r;
- ppe[i].peGreen = palette[i].g;
- ppe[i].peBlue = palette[i].b;
- }
-
- // Set all remaining entry flags to D3DPAL_RESERVED, which are ignored by
- // the renderer.
-
- for (; i < 256; i++)
- ppe[i].peFlags = D3DPAL_RESERVED;
-
- // Create the palette with the DDPCAPS_ALLOW256 flag because we want to
- // have access to all entries.
-
- switch (bitsperpixel)
- {
- default:
- pcaps = DDPCAPS_8BIT | DDPCAPS_ALLOW256;
- break;
- case 4:
- pcaps = DDPCAPS_4BIT;
- break;
- case 2:
- pcaps = DDPCAPS_2BIT;
- break;
- case 1:
- pcaps = DDPCAPS_1BIT;
- break;
- }
-
- ddrval = lpDD->CreatePalette
- (DDPCAPS_INITIALIZE | pcaps,
- ppe, &lpDDPPMPal, NULL);
- LOGDXERR(ddrval);
-
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return 0;
- #endif
- }
-
- // Finally, bind the palette to the surface
-
- ddrval = lpDDS->SetPalette(lpDDPPMPal);
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- lpDDPPMPal->Release();
- return 0;
- #endif
- }
-
- lpDDPPMPal->Release();
- break;
- default:
- // Everything's gone pear-shaped...
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Unlock(NULL);
- lpDDS->Release();
- return 0;
- #endif
-
-
- }
-
- return ddsd.lpSurface;
-}
-
-
diff --git a/src/win95/d3_image.hpp b/src/win95/d3_image.hpp
deleted file mode 100644
index a2bc639..0000000
--- a/src/win95/d3_image.hpp
+++ /dev/null
@@ -1,1223 +0,0 @@
-#ifndef _included__d3_image_hpp_
-#define _included__d3_image_hpp_
-
-#error "This file is obsolete"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "list_tem.hpp"
-
-#include "ddraw.h"
-#include "d3d.h"
-#include "vramtime.h"
-
-#include "system.h"
-#include "mem3dc.h"
-
-#include "dxlog.h"
-// define = 1 if you want an output log file of all texture files loaded and for which DD surface format
-#if debug
-#define OUTPUT_LOG 1
-#else
-#define OUTPUT_LOG 0
-#endif
-
-// define = 1 to use fast files for loading (will still try normal files if fastfile doesn't contain correct data)
-#define USE_FASTFILE 1
-
-#if USE_FASTFILE
-
-#include "ffstdio.h"
-#define D3I_FILE FFILE
-#define d3i_fpos_t ffpos_t
-#define d3i_fclearerr ffclearerr
-#define d3i_fclose ffclose
-#define d3i_fcloseall ffcloseall
-#define d3i_feof ffeof
-#define d3i_ferror fferror
-#define d3i_fgetc ffgetc
-#define d3i_fgetpos ffgetpos
-#define d3i_fgets ffgets
-#define d3i_flook fflook
-#define d3i_flookb fflookb
-#define d3i_fopen ffopen
-#define d3i_fread ffread
-#define d3i_freadb ffreadb
-#define d3i_fseek ffseek
-#define d3i_fsetpos ffsetpos
-#define d3i_ftell fftell
-
-#else
-
-#define D3I_FILE FILE
-#define d3i_fpos_t fpos_t
-#define d3i_fclearerr fclearerr
-#define d3i_fclose fclose
-#define d3i_fcloseall fcloseall
-#define d3i_feof feof
-#define d3i_ferror ferror
-#define d3i_fgetc fgetc
-#define d3i_fgetpos fgetpos
-#define d3i_fgets fgets
-#define d3i_fopen fopen
-#define d3i_fread fread
-#define d3i_fseek fseek
-#define d3i_fsetpos fsetpos
-#define d3i_ftell ftell
-
-#endif
-
-
-// define = 1 if you do not want to handle the error return codes, and require a load failure to cause an exit
-#define EXIT_ON_LOAD_FAIL 0
-
-// define = 1 if you are locating images through rif files and expect this to always succeed
-// works like EXIT_ON_LOAD_FAIL, and only if EXIT_ON_LOAD_FAIL is set, but most failures are handled
-// by assuming the given name to be a complete path and filename
-#define EXIT_ON_LOCATE_FAIL 0
-
-// define = 1 to time file opens, file closes and file reads
-#define TIME_LOADS 0
-
-// I tested the times with a typically complex set of images from AVP,
-// loaded over a nework.
-// Opening took 16secs, Reading 38secs and Closing 2secs for approx
-// for about 500 images (including mip maps)
-
-#if TIME_LOADS
-#include <time.h>
-#define START_TIMER {clock_t __stime = clock();
-#define END_TIMER(__var) __var += (unsigned int) ((clock() - __stime) * 1000 / CLOCKS_PER_SEC);}
-#else
-#define START_TIMER
-#define END_TIMER(__var)
-#endif
-
-#if TIME_LOADS
-extern unsigned int OpenTime;
-extern unsigned int CloseTime;
-extern unsigned int ReadTime;
-#endif
-
-#if OUTPUT_LOG
-#include "debuglog.hpp"
-extern LogFile CL_LogFile;
-#endif
-
-// externs for 3dc things
-extern "C" {
- extern LPDIRECTDRAW lpDD;
- extern DDPIXELFORMAT DisplayPixelFormat;
-};
-
-enum CL_RGBFormat // for loading from files
-{
- CLF_RGB, CLF_BGR, CLF_BGRX
-};
-
-struct CL_Pixel_24
-{
- union
- {
- struct
- {
- unsigned char r,g,b;
- unsigned char xx;
- };
- unsigned long l;
- };
-
- CL_Pixel_24() : l(0) {}
- CL_Pixel_24(unsigned char const r,unsigned char const g,unsigned char const b) : r(r),g(g),b(b),xx(0) {}
- CL_Pixel_24(CL_Pixel_24 const & p24) : l(p24.l) {}
- CL_Pixel_24(unsigned long const i) : l(i) {}
-
- operator unsigned long (void) const { return l; }
-
- inline void Read (D3I_FILE * const f, CL_RGBFormat const t)
- {
- switch(t)
- {
- case CLF_RGB:
- d3i_fread(&r,1,1,f);
- d3i_fread(&g,1,1,f);
- d3i_fread(&b,1,1,f);
- break;
- case CLF_BGR:
- d3i_fread(&b,1,1,f);
- d3i_fread(&g,1,1,f);
- d3i_fread(&r,1,1,f);
- break;
- case CLF_BGRX:
- d3i_fread(&b,1,1,f);
- d3i_fread(&g,1,1,f);
- d3i_fread(&r,1,1,f);
- d3i_fseek(f,1,SEEK_CUR);
- default:
- break;
- }
- }
-
- inline void Read (D3I_FILE * const f, CL_RGBFormat const t, unsigned int const maxval)
- {
- Read(f,t);
- if (maxval != 255)
- {
- r = (unsigned char) ( ((unsigned int)r << 8) / (maxval+1) );
- g = (unsigned char) ( ((unsigned int)g << 8) / (maxval+1) );
- b = (unsigned char) ( ((unsigned int)b << 8) / (maxval+1) );
- }
- }
-
- unsigned int FVD_Distance(CL_Pixel_24 const & p2) const;
-};
-
-
-struct CL_DX_Format
-{
- unsigned int
- red_mask,
- red_shift,
- red_bits,
- red_bits_gt8,
- red_bits_lt8,
- blue_mask,
- blue_shift,
- blue_bits,
- blue_bits_gt8,
- blue_bits_lt8,
- green_mask,
- green_shift,
- green_bits,
- green_bits_gt8,
- green_bits_lt8;
-
- CL_Pixel_24 dx_black;
-
- inline void Init(unsigned int rmask,unsigned int gmask,unsigned int bmask)
- {
- red_mask = rmask;
- blue_mask = bmask;
- green_mask = gmask;
- for (red_shift = 0; !(rmask & 1); red_shift++, rmask>>=1);
- for (green_shift = 0; !(gmask & 1); green_shift++, gmask>>=1);
- for (blue_shift = 0; !(bmask & 1); blue_shift++, bmask>>=1);
- for (red_bits = 0; rmask; red_bits++, rmask>>=1);
- for (green_bits = 0; gmask; green_bits++, gmask>>=1);
- for (blue_bits = 0; bmask; blue_bits++, bmask>>=1);
- if (blue_bits >= green_bits && blue_bits >= red_bits)
- {
- dx_black = CL_Pixel_24(0,0,1);
- }
- else if (red_bits >= green_bits)
- {
- dx_black = CL_Pixel_24(1,0,0);
- }
- else
- {
- dx_black = CL_Pixel_24(0,1,0);
- }
- if (red_bits >= 8)
- {
- red_bits_gt8 = red_bits-8;
- red_bits_lt8 = 0;
- }
- else
- {
- red_bits_lt8 = 8-red_bits;
- red_bits_gt8 = 0;
- }
- if (green_bits >= 8)
- {
- green_bits_gt8 = green_bits-8;
- green_bits_lt8 = 0;
- }
- else
- {
- green_bits_lt8 = 8-green_bits;
- green_bits_gt8 = 0;
- }
- if (blue_bits >= 8)
- {
- blue_bits_gt8 = blue_bits-8;
- blue_bits_lt8 = 0;
- }
- else
- {
- blue_bits_lt8 = 8-blue_bits;
- blue_bits_gt8 = 0;
- }
- }
-};
-
-
-// for 32 bit and 24 bit DirectX formats
-template <class S>
-struct CL_Pixel_T
-{
- static CL_DX_Format f;
- static CL_DX_Format f_d3d;
- static CL_DX_Format f_ddraw;
-
- S p;
-
- inline S r(void) const { return (S)((p & f.red_mask)>>f.red_shift); }
- inline S g(void) const { return (S)((p & f.green_mask)>>f.green_shift); }
- inline S b(void) const { return (S)((p & f.blue_mask)>>f.blue_shift); }
-
- CL_Pixel_T() {}
- CL_Pixel_T(CL_Pixel_T<S> const & p32) : p(p32.p) {}
- CL_Pixel_T(CL_Pixel_24 const & p24)
- : p((S)(
- (S)p24.r>>f.red_bits_lt8<<f.red_shift+f.red_bits_gt8 |
- (S)p24.g>>f.green_bits_lt8<<f.green_shift+f.green_bits_gt8 |
- (S)p24.b>>f.blue_bits_lt8<<f.blue_shift+f.blue_bits_gt8 ))
- {
- // make the 32bit pixel non-black to avoid transparency problems
- if (!p && p24.l) // if the 24bit pixel is not black and the 32 bit pixel is black
- {
- // choose which of r,g or b to make non-zero - try and get as close to black as poss
- if ((1<<f.blue_bits_lt8)-p24.b <= (1<<f.red_bits_lt8)-p24.r && (1<<f.blue_bits_lt8)-p24.b <= (1<<f.green_bits_lt8)-p24.g)
- p = (S)(1<<f.blue_shift);
- else if ((1<<f.red_bits_lt8)-p24.r <= (1<<f.green_bits_lt8)-p24.g)
- p = (S)(1<<f.red_shift);
- else
- p = (S)(1<<f.green_shift);
- }
- }
-
- inline operator CL_Pixel_24 (void) const
- {
- S rr = (S)(r()>>f.red_bits_gt8<<f.red_bits_lt8);
- S gg = (S)(g()>>f.green_bits_gt8<<f.green_bits_lt8);
- S bb = (S)(b()>>f.blue_bits_gt8<<f.blue_bits_lt8);
-
- if (!(rr|gg|bb) && p)
- {
- if (b()<<f.red_bits>=r()<<f.blue_bits && b()<<f.green_bits>=g()<<f.blue_bits) // make the 16bit pixel non-black to avoid transparency problems
- bb = 1;
- else if (r()<<f.green_bits>=g()<<f.red_bits)
- rr = 1;
- else
- gg = 1;
- }
-
- return CL_Pixel_24((unsigned char)rr,(unsigned char)gg,(unsigned char)bb);
- };
- operator S (void) const { return p; }
-
- inline void Read (D3I_FILE * const f, CL_RGBFormat const t)
- {
- CL_Pixel_24 p24;
- p24.Read(f,t);
- *this = (CL_Pixel_T<S>)p24;
- }
-
- inline void Read (D3I_FILE * const f, CL_RGBFormat const t, unsigned int const maxval)
- {
- CL_Pixel_24 p24;
- p24.Read(f,t,maxval);
- *this = (CL_Pixel_T<S>)p24;
- }
-};
-
-
-typedef CL_Pixel_T<unsigned long> CL_Pixel_32;
-typedef CL_Pixel_T<unsigned short> CL_Pixel_16;
-
-
-enum CL_Error
-{
- CLE_OK,
- CLE_LOADERROR, // file cannot be loaded - format is wrong
- CLE_OPENERROR, // file cannot be opened - does not exist?
- CLE_FINDERROR, // file cannot be found - not listed in .RIF file
- CLE_RIFFERROR, // rif file not loaded, or invalid
- CLE_INVALIDGAMEMODE, // specified game mode does not exist
- CLE_INVALIDDXMODE, // video mode is invalid
- CLE_DXERROR, // other direct X related error
- CLE_ALLOCFAIL // failed memory allocation
-};
-
-
-enum CL_ImageMode {
-
- CLM_GLOBALPALETTE, // image shares a global palette in a palettized mode
- CLM_TLTPALETTE, // images may also share an abstract palette which remaps via a tlt to a global display palette
- CLM_ATTACHEDPALETTE, // 256 colour image with attached palette
- CLM_16BIT, // 16 bit in specified RGB format
- CLM_32BIT, // 32 bit in specified RGB format
- CLM_24BIT // 24 bit truecolour image in 888 format
-};
-// Note:
-// currently 24-bit and 16-bit image formats are not output.
-// If the desired format is 24-bit or 16-bit then 256 colour BMPs are loaded
-// and 'unquantized' to generate the required format.
-
-
-enum CL_LoadMode {
-
- CLL_D3DTEXTURE,
- CLL_DDSURFACE
-};
-
-void CL_Select_Mode(CL_LoadMode const lmode);
-
-
-void CL_Init_D3DMode(LPDDSURFACEDESC const format);
-
-enum CL_VideoMode {
-
- CLV_8,
- CLV_15,
- CLV_24,
- CLV_8T,
- CLV_8TLT
-};
-
-void CL_Init_DirectDrawMode(CL_VideoMode const vmode);
-
-
-
-// test!!!
-#if HwTextureHack
-static int craptest = 0;
-#endif
-
-#if EXIT_ON_LOAD_FAIL
- extern "C"
- {
- #include "3dc.h"
- }
- #if EXIT_ON_LOCATE_FAIL
- #define EXITONLOCATEFAIL(__errcode,__iname,__enum_id) \
- if (CLE_RIFFERROR != __errcode) { \
- if (__iname) textprint("Cannot figure path for:\n%s\n",__iname); \
- else textprint("Cannot figure path for:\nImage ID %d\n",__enum_id); \
- WaitForReturn(); \
- ExitSystem(); \
- exit(0x10cafa11); \
- }
- #else
- #define EXITONLOCATEFAIL(__errcode,__iname,__enum_id)
- #endif
- #define EXITONLOADFAIL(__iname) \
- { \
- textprint("Cannot open:\n%s\n",__iname); \
- WaitForReturn(); \
- ExitSystem(); \
- exit(0x10adfa11); \
- }
- #define EXITONREADFAIL(__iname) \
- { \
- textprint("Cannot read:\n%s\n",__iname); \
- WaitForReturn(); \
- ExitSystem(); \
- exit(0x10adfa11); \
- }
-#else
- #define EXITONLOCATEFAIL(__errcode,__iname,__enum_id)
- #define EXITONLOADFAIL(__iname)
- #define EXITONREADFAIL(__iname)
-#endif
-
-struct CL_Flags
-{
- unsigned int loaded : 1;
- unsigned int located : 1;
- unsigned int raw16bit : 1;
- unsigned int tltpalette : 1;
-
- CL_Flags()
- : loaded(0)
- , located(0)
- , tltpalette(0)
- , raw16bit(0)
- {}
-};
-
-#define CL_EID_INVALID (-1)
-
-
-#if 0
-template <class I>
-class CL_MIP_Image
-{
-public:
- unsigned int num_mipmaps;
- I * * mipmaps; // array of CL_Image pointers of decreasing image size
-
- unsigned int width; // == mipmaps[0]->width
- unsigned int height; // == mipmaps[0]->height
- unsigned int size; // == mipmaps[0]->size
-
- char * fname; // full filename (including directory/path) of mipmap with index 0
- char * name; // name of image without directory/path or extension
-
- CL_MIP_Image() : mipmaps(0), num_mipmaps(0), fname(0), name(0) {}
- ~CL_MIP_Image() { Delete(); }
-
- CL_MIP_Image(CL_MIP_Image<I> const & i2)
- : width (i2.width)
- , height (i2.height)
- , size (i2.size)
- , num_mipmaps (i2.num_mipmaps)
- { Copy(i2); }
-
- CL_MIP_Image<I> & operator = (CL_MIP_Image<I> const & i2)
- {
- if (&i2 != this)
- {
- Delete();
-
- width = i2.width;
- height = i2.height;
- size = i2.size;
- num_mipmaps = i2.num_mipmaps;
-
- Copy(i2);
- }
- return *this;
- }
-
-private:
- void Copy(CL_MIP_Image<I> const & i2)
- {
- if (i2.mipmaps)
- {
- mipmaps = new I * [num_mipmaps];
- for (int i=0; i<num_mipmaps; ++i)
- {
- mipmaps[i] = new I(*i2.mipmaps[i]);
- }
- }
-
- if (i2.fname)
- {
- fname = new char[strlen(i2.fname)+1];
- strcpy(fname,i2.fname);
- }
-
- if (i2.name)
- {
- name = new char[strlen(i2.name)+1];
- strcpy(name,i2.name);
- }
- }
- void Delete(void)
- {
- if (mipmaps)
- {
- for (int i=0; i<num_mipmaps; ++i) delete mipmaps[i];
- delete[] mipmaps;
- mipmaps = 0;
- }
-
- if (name)
- {
- delete[] name;
- name = 0;
- }
-
- if (fname)
- {
- delete[] fname;
- fname = 0;
- }
- }
-
- CL_Flags flags;
-
-public:
- inline CL_Error Load(int const enum_id)
- {
- return Load(0,enum_id);
- }
- inline CL_Error Load(char const * const iname)
- {
- return Load(iname,CL_EID_INVALID);
- }
- inline CL_Error Load()
- {
- return Load(0,CL_EID_INVALID);
- }
-
- inline CL_Error PreLoad(int const enum_id)
- {
- return PreLoad(0,enum_id);
- }
- inline CL_Error PreLoad(char const * const iname)
- {
- return PreLoad(iname,CL_EID_INVALID);
- }
-
- CL_Error CopyToScanDrawTexture(unsigned char * * const ImagePtrA [], unsigned int maxnummips)
- {
- if (!flags.loaded) return CLE_LOADERROR;
-
- if (CLL_DDSURFACE != I::lmode) CL_Select_Mode(CLL_DDSURFACE);
-
- if (num_mipmaps < maxnummips) maxnummips = num_mipmaps;
- if (!maxnummips) return CLE_ALLOCFAIL;
-
- if (!*ImagePtrA[0]) *ImagePtrA[0] = (unsigned char *) AllocateMem((2*width+1)*(2*height+1)*I::bitsperpixel/24+(maxnummips-3)*I::bitsperpixel/8); // slightly more than 4/3 w*h*bytedepth
-
- for (int i=0; i<maxnummips; ++i)
- {
- if (i) *ImagePtrA[i] = *ImagePtrA[i-1] + mipmaps[i-1]->width*mipmaps[i-1]->height*(I::bitsperpixel>>3);
- CL_Error thismipmaperror = mipmaps[i]->CopyToScanDrawTexture(ImagePtrA[i]);
- if (CLE_OK != thismipmaperror) return thismipmaperror;
- }
- return CLE_OK;
- }
-
- CL_Error CopyToD3DTexture(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], unsigned int maxnummips, int const MemoryType)
- {
- if (!flags.loaded) return CLE_LOADERROR;
-
- WaitForVRamReady(VWS_D3DTEXCREATE);
-
- if (CLL_D3DTEXTURE != I::lmode) CL_Select_Mode(CLL_D3DTEXTURE);
-
- LPDIRECTDRAWSURFACE lpDDS;
- DDSURFACEDESC ddsd;
- HRESULT ddrval;
-
- if (width & 3 || height & 3)
- {
- // return error code
- return CLE_DXERROR;
- }
-
- /* test !!! */
- {
- #if HwTextureHack
- craptest++;
- if (craptest > 10)
- return CLE_DXERROR;
- #endif
- }
-
-
- if (num_mipmaps < maxnummips) maxnummips = num_mipmaps;
- // Set up the mip-mapped surface description. starting
- // with the passed texture format and then
- // incorporating the information read from the
- // ppm.
- memcpy(&ddsd, I::format, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
- | DDSD_MIPMAPCOUNT);
- ddsd.dwMipMapCount = maxnummips; // engine standard, primary plus six mip-maps
- ddsd.ddsCaps.dwCaps = (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP
- | DDSCAPS_COMPLEX | MemoryType);
- ddsd.dwHeight = height;
- ddsd.dwWidth = width;
-
-
- // Create the surface
- ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
- LOGDXERR(ddrval);
-
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
- // We must now traverse the mip-map chain from highest to lowest
- // resolutions, For each surface AFTER the first one, we must
- // load a new file, using a name obtained from the mip map number
-
- int MipMapNum = 0;
- LPDIRECTDRAWSURFACE lpThisMipMap, lpNextMipMap;
- DDSCAPS ddsCaps;
-
-
- lpThisMipMap = lpDDS;
- // Component Object Model, increase reference count on
- // mip-map surface by one.
- lpThisMipMap->AddRef();
- ddsCaps.dwCaps = (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
- ddrval = DD_OK;
-
- while ((ddrval == DD_OK) && (MipMapNum < maxnummips)) // both tests in case...
- {
- // Call LoadPPMIntoDDSurface with lpThisMipMap, new file name, and
- // other values.
-
- *DDSurfaceA[MipMapNum] = mipmaps[MipMapNum]->CopyToDDSurface(lpThisMipMap);
-
- // Death trap
- if (!*DDSurfaceA[MipMapNum])
- {
- return CLE_DXERROR;
- }
- *DDPtrA[MipMapNum] = lpThisMipMap;
-
- // Proceed to the next level.
- // Collect bonus rings.
- ddrval = lpThisMipMap->GetAttachedSurface(&ddsCaps, &lpNextMipMap);
- // Necessary to match the manual increment of the reference count on the
- // COM texture. I think.
- lpThisMipMap->Release();
- // ?? lpNextMipMap = lpThisMipMap;
- lpThisMipMap = lpNextMipMap;
-
- MipMapNum++;
- }
-
- return CLE_OK;
-
- }
-
- CL_Error CopyToDirectDrawSurface(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], unsigned int maxnummips, int const MemoryType)
- {
- if (!flags.loaded) return CLE_LOADERROR;
-
- WaitForVRamReady(VWS_DDCREATE);
-
- if (CLL_DDSURFACE != I::lmode) CL_Select_Mode(CLL_DDSURFACE);
-
- LPDIRECTDRAWSURFACE lpDDS;
- DDSURFACEDESC ddsd;
- HRESULT ddrval;
-
- if (width & 3 || height & 3)
- {
- // return error code
- return CLE_DXERROR;
- }
-
- if (num_mipmaps < maxnummips) maxnummips = num_mipmaps;
- // Set up the mip-mapped surface description. starting
- // with the passed texture format and then
- // incorporating the information read from the
- // ppm.
- memset(&ddsd, 0, sizeof ddsd);
- ddsd.dwSize = sizeof ddsd;
- ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
- | DDSD_MIPMAPCOUNT);
- ddsd.dwMipMapCount = maxnummips; // engine standard, primary plus six mip-maps
- ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_MIPMAP
- | DDSCAPS_COMPLEX | MemoryType);
- ddsd.dwHeight = height;
- ddsd.dwWidth = width;
-
-
- // Create the surface
- ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
-
- LOGDXERR(ddrval);
- if (ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
- DDCOLORKEY set_zero = {0,0};
- ddrval = lpDDS->SetColorKey(DDCKEY_SRCBLT, &set_zero);
-
- LOGDXERR(ddrval);
- if(ddrval != DD_OK)
- {
- #if debug
- ReleaseDirect3D();
- exit(ddrval);
- #else
- lpDDS->Release();
- return CLE_DXERROR;
- #endif
- }
-
- // We must now traverse the mip-map chain from highest to lowest
- // resolutions, For each surface AFTER the first one, we must
- // load a new file, using a name obtained from the mip map number
-
- int MipMapNum = 0;
- LPDIRECTDRAWSURFACE lpThisMipMap, lpNextMipMap;
- DDSCAPS ddsCaps;
-
-
- lpThisMipMap = lpDDS;
- // Component Object Model, increase reference count on
- // mip-map surface by one.
- lpThisMipMap->AddRef();
- ddsCaps.dwCaps = (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
- ddrval = DD_OK;
-
- while ((ddrval == DD_OK) && (MipMapNum < maxnummips)) // both tests in case...
- {
- // Call LoadPPMIntoDDSurface with lpThisMipMap, new file name, and
- // other values.
-
- *DDSurfaceA[MipMapNum] = mipmaps[MipMapNum]->CopyToDDSurface(lpThisMipMap);
-
- // Death trap
- if (!*DDSurfaceA[MipMapNum])
- {
- return CLE_DXERROR;
- }
- *DDPtrA[MipMapNum] = lpThisMipMap;
-
- // Proceed to the next level.
- // Collect bonus rings.
- ddrval = lpThisMipMap->GetAttachedSurface(&ddsCaps, &lpNextMipMap);
- // Necessary to match the manual increment of the reference count on the
- // COM texture. I think.
- lpThisMipMap->Release();
- // ?? lpNextMipMap = lpThisMipMap;
- lpThisMipMap = lpNextMipMap;
-
- MipMapNum++;
- }
-
- return CLE_OK;
-
- }
-
-private:
- // I was using Dan's list template for this,
- // but since it is not a standard part of 3DC,
- // I have had to write a specific simple list handler
- struct TempListMember
- {
- I * mip;
- TempListMember * next;
- TempListMember(I * data) : mip(data), next(0) {}
- //TempListMember() : next(0) {}
- ~TempListMember() { if (next) delete next; }
- };
- struct TempList
- {
- unsigned int n_entries;
- TempListMember * first;
- TempListMember * last;
- TempList(I * data) : first(new TempListMember(data)), n_entries(1) { last = first; }
- TempList & operator += (I * data)
- {
- if (!first)
- {
- first = new TempListMember(data);
- last = first;
- }
- else
- {
- last->next = new TempListMember(data);
- last = last->next;
- }
- ++ n_entries;
- return *this;
- }
- ~TempList()
- {
- if (first) delete first;
- }
- };
-
- CL_Error Load(char const * const iname, int const enum_id)
- {
- if (iname || CL_EID_INVALID != enum_id) flags.located = 0;
-
- I * mip0;
-
- if (flags.located && mipmaps)
- {
- mip0 = mipmaps[0];
- // we have grabbed the previously allocated pointer
- // it will now be treated as if it were allocated here,
- // so we must remove it from the class, in case the
- // deconstructor tries to deallocate it
- delete[] mipmaps;
- mipmaps = 0;
- }
- else
- {
- mip0 = new I;
-
- CL_Error locate_err = mip0->Locate(iname,enum_id);
-
- if (locate_err != CLE_OK)
- {
- delete mip0;
- EXITONLOCATEFAIL(locate_err,iname,enum_id)
- return locate_err;
- }
- }
-
- #if OUTPUT_LOG
- char const * texformat;
- unsigned int redbits = 8;
- unsigned int greenbits = 8;
- unsigned int bluebits = 8;
- switch (I::imode)
- {
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- texformat = "Palettized Display";
- break;
- case CLM_ATTACHEDPALETTE:
- texformat = "Palettized Textures";
- break;
- case CLM_32BIT:
- texformat = "32BIT DX";
- redbits += CL_Pixel_32::f.red_bits_gt8;
- redbits -= CL_Pixel_32::f.red_bits_lt8;
- greenbits += CL_Pixel_32::f.green_bits_gt8;
- greenbits -= CL_Pixel_32::f.green_bits_lt8;
- bluebits += CL_Pixel_32::f.blue_bits_gt8;
- bluebits -= CL_Pixel_32::f.blue_bits_lt8;
- break;
- case CLM_24BIT:
- texformat = "24-bit for runtime conversion";
- break;
- case CLM_16BIT:
- texformat = "16BIT DX";
- redbits += CL_Pixel_16::f.red_bits_gt8;
- redbits -= CL_Pixel_16::f.red_bits_lt8;
- greenbits += CL_Pixel_16::f.green_bits_gt8;
- greenbits -= CL_Pixel_16::f.green_bits_lt8;
- bluebits += CL_Pixel_16::f.blue_bits_gt8;
- bluebits -= CL_Pixel_16::f.blue_bits_lt8;
- break;
- }
- CL_LogFile.lprintf("--%s %s (%u-bit, %u-%u-%u)\n",mip0->fname,texformat,I::bitsperpixel,redbits,greenbits,bluebits);
- #endif
-
- START_TIMER
- D3I_FILE * fp = d3i_fopen(mip0->fname,"rb");
- END_TIMER(OpenTime)
-
- if (!fp)
- {
- #if OUTPUT_LOG
- CL_LogFile.lputs("** ERROR: unable to open\n");
- #endif
- EXITONLOADFAIL(mip0->fname)
- delete mip0;
- return CLE_OPENERROR;
- }
-
- CL_Error load_err = mip0->Load_Image(fp);
- START_TIMER
- d3i_fclose(fp);
- END_TIMER(CloseTime)
-
- if (load_err != CLE_OK)
- {
- if (!flags.located) delete mip0;
- #if OUTPUT_LOG
- CL_LogFile.lputs("** ERROR: unable to read\n");
- #endif
- EXITONREADFAIL(mip0->fname)
- return load_err;
- }
-
- TempList miplist(mip0);
-
- width = mip0->width;
- height = mip0->height;
- size = mip0->size;
-
- if (!flags.located)
- {
- if (fname) delete[] fname;
- if (name) delete[] name;
- fname = new char[strlen(mip0->fname)+1];
- name = new char[strlen(mip0->name)+1];
- strcpy(fname,mip0->fname);
- strcpy(name,mip0->name);
- }
-
- for (int mip_idx = 1; mip_idx < 7; ++mip_idx)
- {
- I * mip_n;
-
- mip_n = new I;
- mip_n->name = new char[strlen(name)+1];
- mip_n->fname = new char[strlen(fname)+1];
- strcpy(mip_n->name,name);
- strcpy(mip_n->fname,fname);
-
- char * dotpos = strrchr(mip_n->fname,'.');
- if (!dotpos)
- {
- delete mip_n;
- break;
- }
- sprintf(dotpos+3,"%1d",mip_idx);
-
- #if OUTPUT_LOG
- char const * texformat;
- unsigned int redbits = 8;
- unsigned int greenbits = 8;
- unsigned int bluebits = 8;
- switch (I::imode)
- {
- case CLM_GLOBALPALETTE:
- case CLM_TLTPALETTE:
- texformat = "Palettized Display";
- break;
- case CLM_ATTACHEDPALETTE:
- texformat = "Palettized Textures";
- break;
- case CLM_32BIT:
- texformat = "32BIT DX";
- redbits += CL_Pixel_32::f.red_bits_gt8;
- redbits -= CL_Pixel_32::f.red_bits_lt8;
- greenbits += CL_Pixel_32::f.green_bits_gt8;
- greenbits -= CL_Pixel_32::f.green_bits_lt8;
- bluebits += CL_Pixel_32::f.blue_bits_gt8;
- bluebits -= CL_Pixel_32::f.blue_bits_lt8;
- break;
- case CLM_24BIT:
- texformat = "24-bit for runtime conversion";
- break;
- case CLM_16BIT:
- texformat = "16BIT DX";
- redbits += CL_Pixel_16::f.red_bits_gt8;
- redbits -= CL_Pixel_16::f.red_bits_lt8;
- greenbits += CL_Pixel_16::f.green_bits_gt8;
- greenbits -= CL_Pixel_16::f.green_bits_lt8;
- bluebits += CL_Pixel_16::f.blue_bits_gt8;
- bluebits -= CL_Pixel_16::f.blue_bits_lt8;
- break;
- }
- CL_LogFile.lprintf("--%s %s (%u-bit, %u-%u-%u)\n",mip_n->fname,texformat,I::bitsperpixel,redbits,greenbits,bluebits);
- #endif
-
- START_TIMER
- fp = d3i_fopen(mip_n->fname,"rb");
- END_TIMER(OpenTime)
-
- if (!fp)
- {
- delete mip_n;
- #if OUTPUT_LOG
- CL_LogFile.lputs("** Warning: unable to open\n");
- #endif
- break;
- }
-
- load_err = mip_n->Load_Image(fp);
- START_TIMER
- d3i_fclose(fp);
- END_TIMER(CloseTime)
-
- if (load_err != CLE_OK)
- {
- delete mip_n;
- #if OUTPUT_LOG
- CL_LogFile.lputs("** Warning: unable to read\n");
- #endif
- break;
- }
-
- if (mip_n->width << mip_idx < width || mip_n->height << mip_idx < height)
- {
- delete mip_n;
- #if OUTPUT_LOG
- CL_LogFile.lputs("** Warning: less than half size\n");
- #endif
- break;
- }
-
- miplist += mip_n;
- }
-
- if (mipmaps)
- {
- for (int i = 0; i<num_mipmaps; ++i) delete mipmaps[i];
- delete[] mipmaps;
- }
-
- num_mipmaps = miplist.n_entries;
- mipmaps = new I * [num_mipmaps];
-
- TempListMember * listP = miplist.first;
- for (int i=0; i<num_mipmaps; ++i)
- {
- mipmaps[i] = listP->mip;
- listP = listP->next;
- }
-
- flags.loaded = 1;
- flags.located = 1;
- return CLE_OK;
- }
-
- CL_Error PreLoad(char const * const iname, int const enum_id)
- {
- I * mip0 = new I;
-
- CL_Error locate_err = mip0->Locate(iname,enum_id);
-
- if (locate_err != CLE_OK)
- {
- delete mip0;
- return locate_err;
- }
-
- if (fname) delete[] fname;
- if (name) delete[] name;
- fname = new char[strlen(mip0->fname)+1];
- name = new char[strlen(mip0->name)+1];
- strcpy(fname,mip0->fname);
- strcpy(name,mip0->name);
-
- if (mipmaps)
- {
- for (int i=0; i<num_mipmaps; ++i) delete mipmaps[i];
- delete[] mipmaps;
- }
-
- num_mipmaps = 1;
- mipmaps = new I * [1];
- *mipmaps = mip0;
-
- flags.loaded = 0;
- flags.located = 1;
-
- return CLE_OK;
- }
-};
-#endif
-
-struct CL_Image
-{
-public:
- static CL_ImageMode imode; // video mode defines which format images should be loaded
- static CL_ImageMode imode_d3d; // video mode defines which format images should be loaded
- static CL_ImageMode imode_ddraw; // video mode defines which format images should be loaded
- static LPDDSURFACEDESC format;
- static unsigned int bitsperpixel;
- static unsigned int bitsperpixel_d3d;
- static unsigned int bitsperpixel_ddraw;
- static CL_LoadMode lmode;
-
- // any one of these 3 may be valid
- union
- { // array of 24 bit or 32 bit pixels
- CL_Pixel_24 * * im24; // array of 24 bit pixels
- CL_Pixel_32 * * im32; // array of 32 bit pixels
- // the data storage sizes of CL_Pixel_24 and CL_Pixel_32 must match
- };
- union
- {
- CL_Pixel_16 * * im16; // array of 16 bit pixels
- unsigned short * * im16raw; // raw double-byte pixel data
- };
- unsigned char * * im8; // array of entrys into CLUT
-
- unsigned int palette_size;
- CL_Pixel_24 * palette; // CLUT (applicable only if 'im8' is valid)
-
- unsigned int width;
- unsigned int height;
- unsigned int size; // width * height
-
- char * fname; // full name of image including directory/path and extension
- char * name; // name of image without directory/path or extension
-
- List<CL_Image *> mipmaps;
-
- CL_Image() : im8(0),im16(0),im24(0),palette(0),palette_size(0),fname(0),name(0) {}
- virtual ~CL_Image();
-
- CL_Image(CL_Image const &);
- CL_Image & operator = (CL_Image const &);
-
- inline CL_Error Load(char const * const iname) // looks at rif file and video mode to determine which file to load
- {
- return Load(iname,CL_EID_INVALID);
- }
- inline CL_Error Load(int const enum_id) // looks at rif file and video mode to determine which file to load
- {
- return Load(0,enum_id);
- }
- inline CL_Error Load() // assumes preload has been called
- {
- return Load(0,CL_EID_INVALID);
- }
-
- inline CL_Error PreLoad(char const * const iname) // looks at rif file and video mode to determine which file to load
- {
- return PreLoad(iname,CL_EID_INVALID);
- }
- inline CL_Error PreLoad(int const enum_id) // looks at rif file and video mode to determine which file to load
- {
- return PreLoad(0,enum_id);
- }
-
- CL_Error LoadMipMaps(int const n_mips = 7); // assumes locating has been done (ie. PreLoad or Load has been called)
-
- CL_Error Load_BMP(D3I_FILE * f); // videomode != CLM_GLOBALPALETTE
- CL_Error Load_PPM(D3I_FILE * f); // videomode == CLM_16BIT || CLM_24BIT
- CL_Error Load_PGM(D3I_FILE * f); // videomode == CLM_GLOBALPALETTE
- CL_Error Load_PWM(D3I_FILE * f); // videomode == CLM_GLOBALPALETTE
-
- CL_Error Load_Image(D3I_FILE * f); // calls one of the above if correct format
-
- CL_Error GetBitsPerPixel(unsigned int* bpp); //returns bitsperpixel;
-
- // needs CL_Init_D3DMode((LPDDSURFACEDESC)format) to have been called
- inline CL_Error CopyToD3DTexture(LPDIRECTDRAWSURFACE * const DDPtrA, LPVOID * const DDSurfaceA, int const MemoryType)
- {
- return CopyToD3DTexture(&DDPtrA,&DDSurfaceA,MemoryType);
- }
- CL_Error CopyToD3DTexture(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], int const MemoryType, unsigned int n_mips_max = 1);
- // needs CL_Init_ScanDrawMode((CL_VideoMode) videomode) to have been called
- inline CL_Error CopyToDirectDrawSurface(LPDIRECTDRAWSURFACE * const DDPtrA, LPVOID * const DDSurfaceA, int const MemoryType)
- {
- return CopyToDirectDrawSurface(&DDPtrA,&DDSurfaceA,MemoryType);
- }
- CL_Error CopyToDirectDrawSurface(LPDIRECTDRAWSURFACE * const DDPtrA [], LPVOID * const DDSurfaceA [], int const MemoryType, unsigned int n_mips_max = 1);
- // needs CL_Init_ScanDrawMode((CL_VideoMode) videomode) to have been called
- inline CL_Error CopyToScanDrawTexture(unsigned char * * const ImagePtrA)
- {
- return CopyToScanDrawTexture(&ImagePtrA);
- }
- CL_Error CopyToScanDrawTexture(unsigned char * * const ImagePtrA [], unsigned int n_mips_max = 1);
- // create an empty image for user manipulation
- CL_Error Make(int const _width,int const _height);
- // create an empty random image for user manipulation
- CL_Error MakeRandom(int const _width,int const _height,int const seed = -1);
- // ensure with and height are multiples of given units
- void PadTo(int const width_unit,int const height_unit);
-
- inline CL_Flags const & GetFlags() const
- {
- return flags;
- }
-protected:
- CL_Flags flags;
-
- virtual CL_Error Locate(char const * iname, int const enum_id);
- CL_Error Load(char const * const iname, int const enum_id);
- CL_Error PreLoad(char const * const iname, int const enum_id);
-
- CL_Error ReducePalette(unsigned int const num_colours);
-
- // returns DDSURFACEDESC.lpSurface
- // does what LoadPPMIntoDDSurface did
- LPVOID CopyToDDSurface(LPDIRECTDRAWSURFACE lpDDS);
-
-private:
- void Copy(CL_Image const &);
- void Delete(void);
- void DeleteNotMips(void);
-};
-
-#endif // !_included__d3_image_hpp_