mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-25 22:10:59 +00:00
Use stb_image for retexturing support, also support png, no more libjpeg
Retexturing support is now always on (you can still switch it off with the gl_retexturing CVAR), as we don't have the additional libjpeg dependency anymore. stb_image is used for tga, jpg and the newly supported png, so the old tga and jpeg loading code has been removed. I furthermore cleaned up the somehow messy and possibly slightly broken retexturing selection code in R_FindImage()
This commit is contained in:
parent
046ae5c7eb
commit
47cde06e27
8 changed files with 6480 additions and 720 deletions
25
Makefile
25
Makefile
|
@ -11,7 +11,6 @@
|
|||
# - libGL #
|
||||
# #
|
||||
# Further dependencies: #
|
||||
# - libjpeg #
|
||||
# - libogg #
|
||||
# - libvorbis #
|
||||
# - OpenAL #
|
||||
|
@ -45,10 +44,6 @@ WITH_OGG:=yes
|
|||
# installed
|
||||
WITH_OPENAL:=yes
|
||||
|
||||
# Enables retexturing support. Adds
|
||||
# a dependency to libjpeg
|
||||
WITH_RETEXTURING:=yes
|
||||
|
||||
# Use SDL2 instead of SDL1.2. Disables CD audio support,
|
||||
# because SDL2 has none. Use OGG/Vorbis music instead :-)
|
||||
# On Windows sdl-config isn't used, so make sure that
|
||||
|
@ -165,7 +160,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
|
|||
CFLAGS += $(OSX_ARCH)
|
||||
else
|
||||
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
|
||||
-Wall -pipe -g -MMD
|
||||
-Wall -pipe -g -ggdb -MMD
|
||||
endif
|
||||
|
||||
# ----------
|
||||
|
@ -312,7 +307,6 @@ config:
|
|||
@echo "============================"
|
||||
@echo "WITH_CDA = $(WITH_CDA)"
|
||||
@echo "WITH_OPENAL = $(WITH_OPENAL)"
|
||||
@echo "WITH_RETEXTURING = $(WITH_RETEXTURING)"
|
||||
@echo "WITH_SDL2 = $(WITH_SDL2)"
|
||||
@echo "WITH_X11GAMMA = $(WITH_X11GAMMA)"
|
||||
@echo "WITH_ZIP = $(WITH_ZIP)"
|
||||
|
@ -376,11 +370,6 @@ ifeq ($(WITH_ZIP),yes)
|
|||
release/quake2.exe : CFLAGS += -DZIP -DNOUNCRYPT
|
||||
release/quake2.exe : LDFLAGS += -lz
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_RETEXTURING),yes)
|
||||
release/quake2.exe : CFLAGS += -DRETEXTURE
|
||||
release/quake2.exe : LDFLAGS += -ljpeg
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_SDL2),yes)
|
||||
release/quake2.exe : CFLAGS += -DSDL2
|
||||
|
@ -438,15 +427,6 @@ ifeq ($(WITH_X11GAMMA),yes)
|
|||
release/quake2 : CFLAGS += -DX11GAMMA
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_RETEXTURING),yes)
|
||||
release/quake2 : CFLAGS += -DRETEXTURE
|
||||
ifeq ($(OSTYPE), Darwin)
|
||||
release/quake2 : LDFLAGS += -framework libjpeg
|
||||
else
|
||||
release/quake2 : LDFLAGS += -ljpeg
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_SDL2),yes)
|
||||
release/quake2 : CFLAGS += -DSDL2
|
||||
endif
|
||||
|
@ -649,8 +629,7 @@ CLIENT_OBJS_ := \
|
|||
src/client/refresh/files/md2.o \
|
||||
src/client/refresh/files/pcx.o \
|
||||
src/client/refresh/files/sp2.o \
|
||||
src/client/refresh/files/tga.o \
|
||||
src/client/refresh/files/jpeg.o \
|
||||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/menu/menu.o \
|
||||
src/client/menu/qmenu.o \
|
||||
|
|
|
@ -1,181 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* The JPEG image format
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#ifdef RETEXTURE
|
||||
|
||||
#include "../header/local.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libjpeg/jpeglib.h>
|
||||
#include <libjpeg/jerror.h>
|
||||
#else
|
||||
#include <jpeglib.h>
|
||||
#include <jerror.h>
|
||||
#endif
|
||||
|
||||
void jpeg_memory_src(j_decompress_ptr cinfo,
|
||||
unsigned char *inbuffer,
|
||||
unsigned long insize);
|
||||
|
||||
void
|
||||
jpg_null(j_decompress_ptr cinfo)
|
||||
{
|
||||
}
|
||||
|
||||
boolean
|
||||
jpg_fill_input_buffer(j_decompress_ptr cinfo)
|
||||
{
|
||||
VID_Printf(PRINT_ALL, "Premature end of JPEG data\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
cinfo->src->next_input_byte += (size_t)num_bytes;
|
||||
cinfo->src->bytes_in_buffer -= (size_t)num_bytes;
|
||||
}
|
||||
|
||||
void
|
||||
jpeg_mem_src(j_decompress_ptr cinfo, unsigned char *mem, unsigned long len)
|
||||
{
|
||||
cinfo->src =
|
||||
(struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr)
|
||||
cinfo,
|
||||
JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr));
|
||||
cinfo->src->init_source = jpg_null;
|
||||
cinfo->src->fill_input_buffer = jpg_fill_input_buffer;
|
||||
cinfo->src->skip_input_data = jpg_skip_input_data;
|
||||
cinfo->src->resync_to_restart = jpeg_resync_to_restart;
|
||||
cinfo->src->term_source = jpg_null;
|
||||
cinfo->src->bytes_in_buffer = len;
|
||||
cinfo->src->next_input_byte = mem;
|
||||
}
|
||||
|
||||
void
|
||||
LoadJPG(char *origname, byte **pic, int *width, int *height)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
char filename[256];
|
||||
struct jpeg_error_mgr jerr;
|
||||
byte *rawdata, *rgbadata, *scanline, *p, *q;
|
||||
unsigned int rawsize, i;
|
||||
|
||||
Q_strlcpy(filename, origname, sizeof(filename));
|
||||
|
||||
/* Add the extension */
|
||||
if (strcmp(COM_FileExtension(filename), "jpg"))
|
||||
{
|
||||
Q_strlcat(filename, ".jpg", sizeof(filename));
|
||||
}
|
||||
|
||||
*pic = NULL;
|
||||
|
||||
/* Load JPEG file into memory */
|
||||
rawsize = FS_LoadFile(filename, (void **)&rawdata);
|
||||
|
||||
if (!rawdata)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((rawsize < 10) || (rawdata[6] != 'J') || (rawdata[7] != 'F') ||
|
||||
(rawdata[8] != 'I') || (rawdata[9] != 'F'))
|
||||
{
|
||||
VID_Printf(PRINT_ALL, "Invalid JPEG header: %s\n", filename);
|
||||
FS_FreeFile(rawdata);
|
||||
return;
|
||||
}
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_mem_src(&cinfo, (unsigned char *)rawdata, (unsigned long)rawsize);
|
||||
jpeg_read_header(&cinfo, true);
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
if ((cinfo.output_components != 3) && (cinfo.output_components != 4))
|
||||
{
|
||||
VID_Printf(PRINT_ALL, "Invalid JPEG colour components\n");
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
FS_FreeFile(rawdata);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate Memory for decompressed image */
|
||||
rgbadata = malloc(cinfo.output_width * cinfo.output_height * 4);
|
||||
|
||||
if (!rgbadata)
|
||||
{
|
||||
VID_Printf(PRINT_ALL, "Insufficient memory for JPEG buffer\n");
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
FS_FreeFile(rawdata);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pass sizes to output */
|
||||
*width = cinfo.output_width;
|
||||
*height = cinfo.output_height;
|
||||
|
||||
/* Allocate Scanline buffer */
|
||||
scanline = malloc(cinfo.output_width * 3);
|
||||
|
||||
if (!scanline)
|
||||
{
|
||||
VID_Printf(PRINT_ALL,
|
||||
"Insufficient memory for JPEG scanline buffer\n");
|
||||
free(rgbadata);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
FS_FreeFile(rawdata);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read Scanlines, and expand from RGB to RGBA */
|
||||
q = rgbadata;
|
||||
|
||||
while (cinfo.output_scanline < cinfo.output_height)
|
||||
{
|
||||
p = scanline;
|
||||
jpeg_read_scanlines(&cinfo, &scanline, 1);
|
||||
|
||||
for (i = 0; i < cinfo.output_width; i++)
|
||||
{
|
||||
q[0] = p[0];
|
||||
q[1] = p[1];
|
||||
q[2] = p[2];
|
||||
q[3] = 255;
|
||||
p += 3;
|
||||
q += 4;
|
||||
}
|
||||
}
|
||||
|
||||
free(scanline);
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
*pic = rgbadata;
|
||||
}
|
||||
|
||||
#endif /* RETEXTURE */
|
93
src/client/refresh/files/stb.c
Normal file
93
src/client/refresh/files/stb.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
* Copyright (C) 2015 Daniel Gibson
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* File formats supported by stb_image, for now only tga, png, jpg
|
||||
* See also https://github.com/nothings/stb
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../header/local.h"
|
||||
|
||||
// don't need HDR stuff
|
||||
#define STBI_NO_LINEAR
|
||||
#define STBI_NO_HDR
|
||||
// make sure STB_image uses standard malloc(), as we'll use standard free() to deallocate
|
||||
#define STBI_MALLOC(sz) malloc(sz)
|
||||
#define STBI_REALLOC(p,sz) realloc(p,sz)
|
||||
#define STBI_FREE(p) free(p)
|
||||
// include implementation part of stb_image into this file
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
/*
|
||||
* origname: the filename to be opened, might be without extension
|
||||
* type: extension of the type we wanna open ("jpg", "png" or "tga")
|
||||
* pic: pointer RGBA pixel data will be assigned to
|
||||
*/
|
||||
qboolean
|
||||
LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height)
|
||||
{
|
||||
char filename[256];
|
||||
|
||||
Q_strlcpy(filename, origname, sizeof(filename));
|
||||
|
||||
/* Add the extension */
|
||||
if (strcmp(COM_FileExtension(filename), type) != 0)
|
||||
{
|
||||
Q_strlcat(filename, ".", sizeof(filename));
|
||||
Q_strlcat(filename, type, sizeof(filename));
|
||||
}
|
||||
|
||||
*pic = NULL;
|
||||
|
||||
byte* rawdata = NULL;
|
||||
int rawsize = FS_LoadFile(filename, (void **)&rawdata);
|
||||
if (rawdata == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int w, h, bytesPerPixel;
|
||||
byte* data = NULL;
|
||||
data = stbi_load_from_memory(rawdata, rawsize, &w, &h, &bytesPerPixel, STBI_rgb_alpha);
|
||||
if (data == NULL)
|
||||
{
|
||||
VID_Printf(PRINT_ALL, "stb_image couldn't load data from %s: %s!\n", filename, stbi_failure_reason());
|
||||
FS_FreeFile(rawdata);
|
||||
return false;
|
||||
}
|
||||
|
||||
FS_FreeFile(rawdata);
|
||||
|
||||
VID_Printf(PRINT_DEVELOPER, "LoadSTB() loaded: %s\n", filename);
|
||||
|
||||
*pic = data;
|
||||
*width = w;
|
||||
*height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
6326
src/client/refresh/files/stb_image.h
Normal file
6326
src/client/refresh/files/stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,429 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* The Targa image format
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "../header/local.h"
|
||||
|
||||
typedef struct _TargaHeader
|
||||
{
|
||||
unsigned char id_length, colormap_type, image_type;
|
||||
unsigned short colormap_index, colormap_length;
|
||||
unsigned char colormap_size;
|
||||
unsigned short x_origin, y_origin, width, height;
|
||||
unsigned char pixel_size, attributes;
|
||||
} TargaHeader;
|
||||
|
||||
void
|
||||
LoadTGA(char *origname, byte **pic, int *width, int *height)
|
||||
{
|
||||
unsigned rows, numPixels;
|
||||
byte *pixbuf;
|
||||
int row, column, columns;
|
||||
byte *buf_p;
|
||||
byte *buffer;
|
||||
TargaHeader targa_header;
|
||||
byte *targa_rgba;
|
||||
int length;
|
||||
int pixel_size;
|
||||
char name[256];
|
||||
|
||||
Q_strlcpy(name, origname, sizeof(name));
|
||||
|
||||
/* Add the extension */
|
||||
if (strcmp(COM_FileExtension(name), "tga"))
|
||||
{
|
||||
Q_strlcat(name, ".tga", sizeof(name));
|
||||
}
|
||||
|
||||
*pic = NULL;
|
||||
|
||||
/* load the file */
|
||||
length = FS_LoadFile(name, (void **)&buffer);
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (length < 18)
|
||||
{
|
||||
VID_Error(ERR_DROP, "LoadTGA: %s has an invalid file size", name);
|
||||
}
|
||||
|
||||
buf_p = buffer;
|
||||
|
||||
targa_header.id_length = buf_p[0];
|
||||
targa_header.colormap_type = buf_p[1];
|
||||
targa_header.image_type = buf_p[2];
|
||||
|
||||
memcpy(&targa_header.colormap_index, &buf_p[3], 2);
|
||||
memcpy(&targa_header.colormap_length, &buf_p[5], 2);
|
||||
targa_header.colormap_size = buf_p[7];
|
||||
memcpy(&targa_header.x_origin, &buf_p[8], 2);
|
||||
memcpy(&targa_header.y_origin, &buf_p[10], 2);
|
||||
memcpy(&targa_header.width, &buf_p[12], 2);
|
||||
memcpy(&targa_header.height, &buf_p[14], 2);
|
||||
targa_header.pixel_size = buf_p[16];
|
||||
targa_header.attributes = buf_p[17];
|
||||
|
||||
targa_header.colormap_index = LittleShort(targa_header.colormap_index);
|
||||
targa_header.colormap_length = LittleShort(targa_header.colormap_length);
|
||||
targa_header.x_origin = LittleShort(targa_header.x_origin);
|
||||
targa_header.y_origin = LittleShort(targa_header.y_origin);
|
||||
targa_header.width = LittleShort(targa_header.width);
|
||||
targa_header.height = LittleShort(targa_header.height);
|
||||
|
||||
buf_p += 18;
|
||||
|
||||
if ((targa_header.image_type != 2) &&
|
||||
(targa_header.image_type != 10) &&
|
||||
(targa_header.image_type != 3))
|
||||
{
|
||||
VID_Error(ERR_DROP, "LoadTGA (%s): Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported", name);
|
||||
}
|
||||
|
||||
if (targa_header.colormap_type != 0)
|
||||
{
|
||||
VID_Error(ERR_DROP, "LoadTGA (%s): colormaps not supported", name);
|
||||
}
|
||||
|
||||
if (((targa_header.pixel_size != 32) && (targa_header.pixel_size != 24)) && (targa_header.image_type != 3))
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA (%s): Only 32 or 24 bit images supported (no colormaps)", name);
|
||||
}
|
||||
|
||||
columns = targa_header.width;
|
||||
rows = targa_header.height;
|
||||
numPixels = columns * rows * 4;
|
||||
|
||||
if (width)
|
||||
{
|
||||
*width = columns;
|
||||
}
|
||||
|
||||
if (height)
|
||||
{
|
||||
*height = rows;
|
||||
}
|
||||
|
||||
if (!columns || !rows || (numPixels > 0x7FFFFFFF) || (numPixels / columns / 4 != rows))
|
||||
{
|
||||
VID_Error(ERR_DROP, "LoadTGA (%s): Invalid image size", name);
|
||||
}
|
||||
|
||||
targa_rgba = malloc(numPixels);
|
||||
*pic = targa_rgba;
|
||||
|
||||
if (targa_header.id_length != 0)
|
||||
{
|
||||
buf_p += targa_header.id_length; /* skip TARGA image comment */
|
||||
}
|
||||
|
||||
pixel_size = targa_header.pixel_size;
|
||||
|
||||
if ((targa_header.image_type == 2) || (targa_header.image_type == 3))
|
||||
{
|
||||
/* Uncompressed RGB or gray scale image */
|
||||
switch (pixel_size)
|
||||
{
|
||||
case 24:
|
||||
|
||||
if (buf_p - buffer + (3 * columns * rows) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
for (row = rows - 1; row >= 0; row--)
|
||||
{
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; column++)
|
||||
{
|
||||
unsigned char red, green, blue;
|
||||
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = 255;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 32:
|
||||
|
||||
if (buf_p - buffer + (4 * columns * rows) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
for (row = rows - 1; row >= 0; row--)
|
||||
{
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; column++)
|
||||
{
|
||||
unsigned char red, green, blue, alphabyte;
|
||||
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
alphabyte = *buf_p++;
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = alphabyte;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
if (buf_p - buffer + (1 * columns * rows) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
for (row = rows - 1; row >= 0; row--)
|
||||
{
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; column++)
|
||||
{
|
||||
unsigned char red, green, blue;
|
||||
|
||||
blue = *buf_p++;
|
||||
green = blue;
|
||||
red = blue;
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = 255;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (targa_header.image_type == 10)
|
||||
{
|
||||
/* Runlength encoded RGB images */
|
||||
byte red, green, blue, alphabyte, packetHeader;
|
||||
unsigned packetSize, j;
|
||||
|
||||
red = 0;
|
||||
green = 0;
|
||||
blue = 0;
|
||||
alphabyte = 0xff;
|
||||
|
||||
for (row = rows - 1; row >= 0; row--)
|
||||
{
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; )
|
||||
{
|
||||
packetHeader = *buf_p++;
|
||||
packetSize = 1 + (packetHeader & 0x7f);
|
||||
|
||||
if (packetHeader & 0x80)
|
||||
{
|
||||
/* run-length packet */
|
||||
switch (pixel_size)
|
||||
{
|
||||
case 24:
|
||||
|
||||
if (buf_p - buffer + (3) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
alphabyte = 255;
|
||||
break;
|
||||
case 32:
|
||||
|
||||
if (buf_p - buffer + (4) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
alphabyte = *buf_p++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (j = 0; j < packetSize; j++)
|
||||
{
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = alphabyte;
|
||||
column++;
|
||||
|
||||
if (column == columns)
|
||||
{
|
||||
/* run spans across rows */
|
||||
column = 0;
|
||||
|
||||
if (row > 0)
|
||||
{
|
||||
row--;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto breakOut;
|
||||
}
|
||||
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* non run-length packet */
|
||||
switch (pixel_size)
|
||||
{
|
||||
case 24:
|
||||
|
||||
if (buf_p - buffer + (3 * packetSize) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
for (j = 0; j < packetSize; j++)
|
||||
{
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = 255;
|
||||
|
||||
column++;
|
||||
|
||||
if (column == columns)
|
||||
{
|
||||
/* pixel packet run spans across rows */
|
||||
column = 0;
|
||||
|
||||
if (row > 0)
|
||||
{
|
||||
row--;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto breakOut;
|
||||
}
|
||||
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 32:
|
||||
|
||||
if (buf_p - buffer + (4 * packetSize) > length)
|
||||
{
|
||||
VID_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name);
|
||||
}
|
||||
|
||||
for (j = 0; j < packetSize; j++)
|
||||
{
|
||||
blue = *buf_p++;
|
||||
green = *buf_p++;
|
||||
red = *buf_p++;
|
||||
alphabyte = *buf_p++;
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
*pixbuf++ = alphabyte;
|
||||
|
||||
column++;
|
||||
|
||||
if (column == columns)
|
||||
{
|
||||
/* pixel packet run spans across rows */
|
||||
column = 0;
|
||||
|
||||
if (row > 0)
|
||||
{
|
||||
row--;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto breakOut;
|
||||
}
|
||||
|
||||
pixbuf = targa_rgba + row * columns * 4;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
breakOut:;
|
||||
}
|
||||
}
|
||||
|
||||
if (targa_header.attributes & 0x20)
|
||||
{
|
||||
byte *temp;
|
||||
temp = malloc(numPixels);
|
||||
|
||||
if (!temp)
|
||||
{
|
||||
VID_Error(ERR_FATAL, "LoadTGA: not enough memory");
|
||||
}
|
||||
|
||||
VID_Printf(PRINT_DEVELOPER, "LoadTGA: Bottom-to-top TGA file (slow): %s\n", name);
|
||||
memcpy(temp, targa_rgba, numPixels);
|
||||
|
||||
for (row = 0; row < rows; row++)
|
||||
{
|
||||
memcpy(targa_rgba + (row * columns * 4), temp + (rows - row - 1) * columns * 4, columns * 4);
|
||||
}
|
||||
|
||||
free(temp);
|
||||
}
|
||||
|
||||
FS_FreeFile(buffer);
|
||||
}
|
|
@ -219,9 +219,7 @@ extern cvar_t *gl_mode;
|
|||
extern cvar_t *gl_customwidth;
|
||||
extern cvar_t *gl_customheight;
|
||||
|
||||
#ifdef RETEXTURE
|
||||
extern cvar_t *gl_retexturing;
|
||||
#endif
|
||||
|
||||
extern cvar_t *gl_lightmap;
|
||||
extern cvar_t *gl_shadows;
|
||||
|
@ -324,8 +322,7 @@ void R_ResampleTexture(unsigned *in, int inwidth, int inheight,
|
|||
void LoadPCX(char *filename, byte **pic, byte **palette,
|
||||
int *width, int *height);
|
||||
image_t *LoadWal(char *name);
|
||||
void LoadJPG(char *origname, byte **pic, int *width, int *height);
|
||||
void LoadTGA(char *origname, byte **pic, int *width, int *height);
|
||||
qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height);
|
||||
void GetWalInfo(char *name, int *width, int *height);
|
||||
void GetPCXInfo(char *filename, int *width, int *height);
|
||||
image_t *R_LoadPic(char *name, byte *pic, int width, int realwidth,
|
||||
|
|
|
@ -1094,12 +1094,20 @@ R_FindImage(char *name, imagetype_t type)
|
|||
char *ptr;
|
||||
char namewe[256];
|
||||
int realwidth = 0, realheight = 0;
|
||||
const char* ext;
|
||||
|
||||
if (!name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ext = COM_FileExtension(name);
|
||||
if(!ext[0])
|
||||
{
|
||||
/* file has no extension */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = strlen(name);
|
||||
|
||||
/* Remove the extension */
|
||||
|
@ -1131,32 +1139,29 @@ R_FindImage(char *name, imagetype_t type)
|
|||
pic = NULL;
|
||||
palette = NULL;
|
||||
|
||||
if (!strcmp(name + len - 4, ".pcx"))
|
||||
if (strcmp(ext, "pcx") == 0)
|
||||
{
|
||||
#ifdef RETEXTURE
|
||||
|
||||
if (gl_retexturing->value)
|
||||
{
|
||||
GetPCXInfo(name, &realwidth, &realheight);
|
||||
|
||||
/* Try to load a TGA */
|
||||
LoadTGA(namewe, &pic, &width, &height);
|
||||
|
||||
if (!pic)
|
||||
if(realwidth == 0)
|
||||
{
|
||||
/* JPEG if no TGA available */
|
||||
LoadJPG(namewe, &pic, &width, &height);
|
||||
/* No texture found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* try to load a tga, png or jpg (in that order/priority) */
|
||||
if ( LoadSTB(namewe, "tga", &pic, &width, &height)
|
||||
|| LoadSTB(namewe, "png", &pic, &width, &height)
|
||||
|| LoadSTB(namewe, "jpg", &pic, &width, &height) )
|
||||
{
|
||||
/* upload tga or png or jpg */
|
||||
image = R_LoadPic(name, pic, width, realwidth, height,
|
||||
realheight, type, 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Upload TGA */
|
||||
R_LoadPic(name, pic, width, realwidth, height,
|
||||
realheight, type, 32);
|
||||
}
|
||||
|
||||
if (!pic)
|
||||
{
|
||||
/* PCX if no JPEG available (exists always) */
|
||||
/* PCX if no TGA/PNG/JPEG available (exists always) */
|
||||
LoadPCX(name, &pic, &palette, &width, &height);
|
||||
|
||||
if (!pic)
|
||||
|
@ -1168,15 +1173,8 @@ R_FindImage(char *name, imagetype_t type)
|
|||
/* Upload the PCX */
|
||||
image = R_LoadPic(name, pic, width, 0, height, 0, type, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Upload JPEG or TGA */
|
||||
image = R_LoadPic(name, pic, width, realwidth,
|
||||
height, realheight, type, 32);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
else /* gl_retexture is not set */
|
||||
{
|
||||
LoadPCX(name, &pic, &palette, &width, &height);
|
||||
|
||||
|
@ -1188,40 +1186,31 @@ R_FindImage(char *name, imagetype_t type)
|
|||
image = R_LoadPic(name, pic, width, 0, height, 0, type, 8);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(name + len - 4, ".wal"))
|
||||
else if (strcmp(ext, "wal") == 0)
|
||||
{
|
||||
#ifdef RETEXTURE
|
||||
|
||||
if (gl_retexturing->value)
|
||||
{
|
||||
/* Get size of the original texture */
|
||||
GetWalInfo(name, &realwidth, &realheight);
|
||||
|
||||
/* Try to load a TGA */
|
||||
LoadTGA(namewe, &pic, &width, &height);
|
||||
|
||||
if (!pic)
|
||||
if(realwidth == 0)
|
||||
{
|
||||
/* JPEG if no TGA available */
|
||||
LoadJPG(namewe, &pic, &width, &height);
|
||||
/* No texture found */
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
|
||||
/* try to load a tga, png or jpg (in that order/priority) */
|
||||
if ( LoadSTB(namewe, "tga", &pic, &width, &height)
|
||||
|| LoadSTB(namewe, "png", &pic, &width, &height)
|
||||
|| LoadSTB(namewe, "jpg", &pic, &width, &height) )
|
||||
{
|
||||
/* Upload TGA */
|
||||
R_LoadPic(name, pic, width, realwidth, height,
|
||||
/* upload tga or png or jpg */
|
||||
image = R_LoadPic(name, pic, width, realwidth, height,
|
||||
realheight, type, 32);
|
||||
}
|
||||
|
||||
if (!pic)
|
||||
{
|
||||
/* WAL of no JPEG available (exists always) */
|
||||
image = LoadWal(namewe);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Upload JPEG or TGA */
|
||||
image = R_LoadPic(name, pic, width, realwidth,
|
||||
height, realheight, type, 32);
|
||||
/* WAL if no TGA/PNG/JPEG available (exists always) */
|
||||
image = LoadWal(namewe);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
|
@ -1230,8 +1219,7 @@ R_FindImage(char *name, imagetype_t type)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
else /* gl_retexture is not set */
|
||||
{
|
||||
image = LoadWal(name);
|
||||
|
||||
|
@ -1242,40 +1230,33 @@ R_FindImage(char *name, imagetype_t type)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(name + len - 4, ".tga"))
|
||||
else if (strcmp(ext, "tga") == 0 || strcmp(ext, "png") == 0 || strcmp(ext, "jpg") == 0)
|
||||
{
|
||||
char tmp_name[256];
|
||||
char tmp_name[256];
|
||||
|
||||
realwidth = 0;
|
||||
realheight = 0;
|
||||
realwidth = 0;
|
||||
realheight = 0;
|
||||
|
||||
strcpy(tmp_name, namewe);
|
||||
strcat(tmp_name, ".wal");
|
||||
GetWalInfo(tmp_name, &realwidth, &realheight);
|
||||
strcpy(tmp_name, namewe);
|
||||
strcat(tmp_name, ".wal");
|
||||
GetWalInfo(tmp_name, &realwidth, &realheight);
|
||||
|
||||
if (realwidth == 0 || realheight == 0) {
|
||||
/* It's a sky. */
|
||||
strcpy(tmp_name, namewe);
|
||||
strcat(tmp_name, ".pcx");
|
||||
GetPCXInfo(tmp_name, &realwidth, &realheight);
|
||||
}
|
||||
if (realwidth == 0 || realheight == 0) {
|
||||
/* It's a sky or model skin. */
|
||||
strcpy(tmp_name, namewe);
|
||||
strcat(tmp_name, ".pcx");
|
||||
GetPCXInfo(tmp_name, &realwidth, &realheight);
|
||||
}
|
||||
|
||||
if (realwidth == 0 || realheight == 0)
|
||||
return NULL;
|
||||
/* TODO: not sure if not having realwidth/heigth is bad - a tga/png/jpg
|
||||
* was requested, after all, so there might be no corresponding wal/pcx?
|
||||
* if (realwidth == 0 || realheight == 0) return NULL;
|
||||
*/
|
||||
|
||||
LoadTGA(name, &pic, &width, &height);
|
||||
LoadSTB(name, ext, &pic, &width, &height);
|
||||
image = R_LoadPic(name, pic, width, realwidth,
|
||||
height, realheight, type, 32);
|
||||
}
|
||||
|
||||
#ifdef RETEXTURE
|
||||
else if (!strcmp(name + len - 4, ".jpg"))
|
||||
{
|
||||
LoadJPG(name, &pic, &width, &height);
|
||||
image = R_LoadPic(name, pic, width, realwidth,
|
||||
height, realheight, type, 32);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
|
|
|
@ -112,9 +112,7 @@ cvar_t *gl_mode;
|
|||
cvar_t *gl_customwidth;
|
||||
cvar_t *gl_customheight;
|
||||
|
||||
#ifdef RETEXTURE
|
||||
cvar_t *gl_retexturing;
|
||||
#endif
|
||||
|
||||
cvar_t *gl_dynamic;
|
||||
cvar_t *gl_modulate;
|
||||
|
@ -1018,9 +1016,7 @@ R_Register(void)
|
|||
gl_customheight = Cvar_Get("gl_customheight", "768", CVAR_ARCHIVE);
|
||||
gl_msaa_samples = Cvar_Get ( "gl_msaa_samples", "0", CVAR_ARCHIVE );
|
||||
|
||||
#ifdef RETEXTURE
|
||||
gl_retexturing = Cvar_Get("gl_retexturing", "1", CVAR_ARCHIVE);
|
||||
#endif
|
||||
|
||||
Cmd_AddCommand("imagelist", R_ImageList_f);
|
||||
Cmd_AddCommand("screenshot", R_ScreenShot);
|
||||
|
@ -1105,11 +1101,9 @@ R_Init(void *hinstance, void *hWnd)
|
|||
|
||||
/* Options */
|
||||
VID_Printf(PRINT_ALL, "Refresher build options:\n");
|
||||
#ifdef RETEXTURE
|
||||
|
||||
VID_Printf(PRINT_ALL, " + Retexturing support\n");
|
||||
#else
|
||||
VID_Printf(PRINT_ALL, " - Retexturing support\n");
|
||||
#endif
|
||||
|
||||
#ifdef X11GAMMA
|
||||
VID_Printf(PRINT_ALL, " + Gamma via X11\n");
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue