Recovered from microbel
This commit is contained in:
8
common/lib/texture/Makefile.am
Normal file
8
common/lib/texture/Makefile.am
Normal file
@@ -0,0 +1,8 @@
|
||||
INCLUDES = -I../../include
|
||||
|
||||
noinst_LIBRARIES = libtexture.a
|
||||
|
||||
libtexture_a_SOURCES = texture.C texturemap.C \
|
||||
load_rgb.C \
|
||||
load_tiff.C save_tiff.C \
|
||||
load_tex.C save_tex.C
|
||||
331
common/lib/texture/Makefile.in
Normal file
331
common/lib/texture/Makefile.in
Normal file
@@ -0,0 +1,331 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ../../..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
GL_CFLAGS = @GL_CFLAGS@
|
||||
GL_LIBS = @GL_LIBS@
|
||||
LEX = @LEX@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
NETLIBS = @NETLIBS@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
TIFF_CFLAGS = @TIFF_CFLAGS@
|
||||
TIFF_LIBS = @TIFF_LIBS@
|
||||
VERSION = @VERSION@
|
||||
YACC = @YACC@
|
||||
|
||||
INCLUDES = -I../../include
|
||||
|
||||
noinst_LIBRARIES = libtexture.a
|
||||
|
||||
libtexture_a_SOURCES = texture.C texturemap.C load_rgb.C load_tiff.C save_tiff.C load_tex.C save_tex.C
|
||||
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
X_CFLAGS = @X_CFLAGS@
|
||||
X_LIBS = @X_LIBS@
|
||||
X_EXTRA_LIBS = @X_EXTRA_LIBS@
|
||||
X_PRE_LIBS = @X_PRE_LIBS@
|
||||
libtexture_a_LIBADD =
|
||||
libtexture_a_OBJECTS = texture.o texturemap.o load_rgb.o load_tiff.o \
|
||||
save_tiff.o load_tex.o save_tex.o
|
||||
AR = ar
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
GZIP_ENV = --best
|
||||
DEP_FILES = .deps/load_rgb.P .deps/load_tex.P .deps/load_tiff.P \
|
||||
.deps/save_tex.P .deps/save_tiff.P .deps/texture.P .deps/texturemap.P
|
||||
SOURCES = $(libtexture_a_SOURCES)
|
||||
OBJECTS = $(libtexture_a_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .C .S .c .o .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/texture/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-noinstLIBRARIES:
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
|
||||
distclean-noinstLIBRARIES:
|
||||
|
||||
maintainer-clean-noinstLIBRARIES:
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
libtexture.a: $(libtexture_a_OBJECTS) $(libtexture_a_DEPENDENCIES)
|
||||
-rm -f libtexture.a
|
||||
$(AR) cru libtexture.a $(libtexture_a_OBJECTS) $(libtexture_a_LIBADD)
|
||||
$(RANLIB) libtexture.a
|
||||
.C.o:
|
||||
$(CXXCOMPILE) -c $<
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = common/lib/texture
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
here=`cd $(top_builddir) && pwd`; \
|
||||
top_distdir=`cd $(top_distdir) && pwd`; \
|
||||
distdir=`cd $(distdir) && pwd`; \
|
||||
cd $(top_srcdir) \
|
||||
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/texture/Makefile
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||
|
||||
-include $(DEP_FILES)
|
||||
|
||||
mostlyclean-depend:
|
||||
|
||||
clean-depend:
|
||||
|
||||
distclean-depend:
|
||||
-rm -rf .deps
|
||||
|
||||
maintainer-clean-depend:
|
||||
|
||||
%.o: %.c
|
||||
@echo '$(COMPILE) -c $<'; \
|
||||
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-cp .deps/$(*F).pp .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm .deps/$(*F).pp
|
||||
|
||||
%.lo: %.c
|
||||
@echo '$(LTCOMPILE) -c $<'; \
|
||||
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
|
||||
< .deps/$(*F).pp > .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm -f .deps/$(*F).pp
|
||||
|
||||
%.o: %.C
|
||||
@echo '$(CXXCOMPILE) -c $<'; \
|
||||
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-cp .deps/$(*F).pp .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm .deps/$(*F).pp
|
||||
|
||||
%.lo: %.C
|
||||
@echo '$(LTCXXCOMPILE) -c $<'; \
|
||||
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
|
||||
< .deps/$(*F).pp > .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm -f .deps/$(*F).pp
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am:
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am:
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am:
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(LIBRARIES)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-depend mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
|
||||
clean-generic mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-noinstLIBRARIES distclean-compile \
|
||||
distclean-tags distclean-depend distclean-generic \
|
||||
clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-depend maintainer-clean-generic \
|
||||
distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
|
||||
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
|
||||
mostlyclean-compile distclean-compile clean-compile \
|
||||
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
|
||||
distclean-depend clean-depend maintainer-clean-depend info-am info \
|
||||
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
|
||||
install-exec install-data-am install-data install-am install \
|
||||
uninstall-am uninstall all-redirect all-am all installdirs \
|
||||
mostlyclean-generic distclean-generic clean-generic \
|
||||
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
280
common/lib/texture/load_rgb.C
Normal file
280
common/lib/texture/load_rgb.C
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "texture.H"
|
||||
#include "load_rgb.H"
|
||||
#include "exception.H"
|
||||
#include <iostream.h>
|
||||
|
||||
#define IMAGIC 0x01da
|
||||
#define IMAGIC_SWAP 0xda01
|
||||
|
||||
#define SWAP_SHORT_BYTES(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
|
||||
#define SWAP_LONG_BYTES(x) (((((x) & 0xff) << 24) | (((x) & 0xff00) << 8)) | \
|
||||
((((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24)))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short imagic;
|
||||
unsigned short type;
|
||||
unsigned short dim;
|
||||
unsigned short sizeX, sizeY, sizeZ;
|
||||
unsigned long min, max;
|
||||
unsigned long wasteBytes;
|
||||
char name[80];
|
||||
unsigned long colorMap;
|
||||
FILE *file;
|
||||
unsigned char *tmp[5];
|
||||
unsigned long rleEnd;
|
||||
unsigned long *rowStart;
|
||||
unsigned long *rowSize;
|
||||
} Image_RGB;
|
||||
|
||||
|
||||
static Image_RGB *ImageRGB_Open(char *fileName)
|
||||
{
|
||||
Image_RGB *image;
|
||||
unsigned long *rowStart, *rowSize, ulTmp;
|
||||
int x, i;
|
||||
|
||||
image = (Image_RGB *)malloc(sizeof(Image_RGB));
|
||||
if (image == NULL)
|
||||
{
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
if ((image->file = fopen(fileName, "rb")) == NULL)
|
||||
{
|
||||
perror(fileName);
|
||||
exit(-1);
|
||||
}
|
||||
/*
|
||||
* Read the image header
|
||||
*/
|
||||
fread(image, 1, 12, image->file);
|
||||
/*
|
||||
* Check byte order
|
||||
*/
|
||||
if (image->imagic == IMAGIC_SWAP)
|
||||
{
|
||||
image->type = SWAP_SHORT_BYTES(image->type);
|
||||
image->dim = SWAP_SHORT_BYTES(image->dim);
|
||||
image->sizeX = SWAP_SHORT_BYTES(image->sizeX);
|
||||
image->sizeY = SWAP_SHORT_BYTES(image->sizeY);
|
||||
image->sizeZ = SWAP_SHORT_BYTES(image->sizeZ);
|
||||
}
|
||||
|
||||
for ( i = 0 ; i <= image->sizeZ ; i++ )
|
||||
{
|
||||
image->tmp[i] = (unsigned char *)malloc(image->sizeX*256);
|
||||
if (image->tmp[i] == NULL )
|
||||
{
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if ((image->type & 0xFF00) == 0x0100) /* RLE image */
|
||||
{
|
||||
x = image->sizeY * image->sizeZ * sizeof(long);
|
||||
image->rowStart = (unsigned long *)malloc(x);
|
||||
image->rowSize = (unsigned long *)malloc(x);
|
||||
if (image->rowStart == NULL || image->rowSize == NULL)
|
||||
{
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
image->rleEnd = 512 + (2 * x);
|
||||
fseek(image->file, 512, SEEK_SET);
|
||||
fread(image->rowStart, 1, x, image->file);
|
||||
fread(image->rowSize, 1, x, image->file);
|
||||
if (image->imagic == IMAGIC_SWAP)
|
||||
{
|
||||
x /= sizeof(long);
|
||||
rowStart = image->rowStart;
|
||||
rowSize = image->rowSize;
|
||||
while (x--)
|
||||
{
|
||||
ulTmp = *rowStart;
|
||||
*rowStart++ = SWAP_LONG_BYTES(ulTmp);
|
||||
ulTmp = *rowSize;
|
||||
*rowSize++ = SWAP_LONG_BYTES(ulTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
static void ImageRGB_Close( Image_RGB *image)
|
||||
{
|
||||
int i;
|
||||
|
||||
fclose(image->file);
|
||||
for ( i = 0 ; i <= image->sizeZ ; i++ )
|
||||
free(image->tmp[i]);
|
||||
free(image);
|
||||
}
|
||||
|
||||
static void ImageRGB_GetRow( Image_RGB *image, unsigned char *buf, int y, int z)
|
||||
{
|
||||
unsigned char *iPtr, *oPtr, pixel;
|
||||
int count;
|
||||
|
||||
if ((image->type & 0xFF00) == 0x0100) /* RLE image */
|
||||
{
|
||||
fseek(image->file, image->rowStart[y+z*image->sizeY], SEEK_SET);
|
||||
fread(image->tmp[0], 1, (unsigned int)image->rowSize[y+z*image->sizeY],
|
||||
image->file);
|
||||
|
||||
iPtr = image->tmp[0];
|
||||
oPtr = buf;
|
||||
while (1)
|
||||
{
|
||||
pixel = *iPtr++;
|
||||
count = (int)(pixel & 0x7F);
|
||||
if (!count)
|
||||
return;
|
||||
if (pixel & 0x80)
|
||||
{
|
||||
while (count--)
|
||||
{
|
||||
*oPtr++ = *iPtr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel = *iPtr++;
|
||||
while (count--)
|
||||
{
|
||||
*oPtr++ = pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* verbatim image */
|
||||
{
|
||||
fseek(image->file, 512+(y*image->sizeX)+(z*image->sizeX*image->sizeY),
|
||||
SEEK_SET);
|
||||
fread(buf, 1, image->sizeX, image->file);
|
||||
}
|
||||
}
|
||||
|
||||
static void ImageRGB_GetRawData( Image_RGB *image, char *data)
|
||||
{
|
||||
int i, j, k;
|
||||
int remain;
|
||||
|
||||
switch ( image->sizeZ )
|
||||
{
|
||||
case 1:
|
||||
remain = image->sizeX % 4;
|
||||
break;
|
||||
case 2:
|
||||
remain = image->sizeX % 2;
|
||||
break;
|
||||
case 3:
|
||||
remain = (image->sizeX * 3) & 0x3;
|
||||
if (remain)
|
||||
remain = 4 - remain;
|
||||
break;
|
||||
case 4:
|
||||
remain = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < image->sizeY; i++)
|
||||
{
|
||||
for ( k = 0; k < image->sizeZ ; k++ )
|
||||
ImageRGB_GetRow(image, image->tmp[k+1], i, k);
|
||||
for (j = 0; j < image->sizeX; j++)
|
||||
for ( k = 1; k <= image->sizeZ ; k++ )
|
||||
*data++ = *(image->tmp[k] + j);
|
||||
data += remain;
|
||||
}
|
||||
}
|
||||
|
||||
void CTextureMap::loadRGB(char *fileName)
|
||||
{
|
||||
Image_RGB *image;
|
||||
IMAGE_RGB_t *final;
|
||||
int sx,ii,rgbIndex;
|
||||
unsigned char * rgbData;
|
||||
|
||||
image = ImageRGB_Open(fileName);
|
||||
|
||||
if (image == NULL){
|
||||
throw new CException();
|
||||
}
|
||||
|
||||
final = (IMAGE_RGB_t *)malloc(sizeof(IMAGE_RGB_t));
|
||||
if (final == NULL)
|
||||
{
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
final->imagic = image->imagic;
|
||||
final->type = image->type;
|
||||
final->dim = image->dim;
|
||||
final->sizeX = image->sizeX;
|
||||
final->sizeY = image->sizeY;
|
||||
final->sizeZ = image->sizeZ;
|
||||
|
||||
/*
|
||||
* Round up so rows are long-word aligned
|
||||
*/
|
||||
sx = ( (image->sizeX) * (image->sizeZ) + 3) >> 2;
|
||||
|
||||
rgbData = (unsigned char *)malloc( sx * image->sizeY * sizeof(unsigned int));
|
||||
|
||||
if (rgbData == NULL) {
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
final->data
|
||||
= (unsigned long *)malloc( image->sizeX * image->sizeY * sizeof(unsigned long));
|
||||
|
||||
if (final->data == NULL) {
|
||||
cdebug << "Out of memory!\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ImageRGB_GetRawData(image, (char*)rgbData);
|
||||
ImageRGB_Close(image);
|
||||
|
||||
m_width = final->sizeX;
|
||||
m_height = final->sizeY;
|
||||
|
||||
rgbIndex = 0;
|
||||
for (ii = 0; ii < m_width*m_height; ii++){
|
||||
final->data[ii] = ((DWORD)(rgbData[rgbIndex+2]) << 16) +
|
||||
((DWORD)(rgbData[rgbIndex+1]) << 8) +
|
||||
(DWORD)(rgbData[rgbIndex]) + 0xFF000000;
|
||||
rgbIndex += 3;
|
||||
}
|
||||
|
||||
m_data = (unsigned char*)final->data;
|
||||
|
||||
free(final);
|
||||
free(rgbData);
|
||||
}
|
||||
33
common/lib/texture/load_rgb.H
Normal file
33
common/lib/texture/load_rgb.H
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#ifndef _IMAGE_RGB_H
|
||||
#define _IMAGE_RGB_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short imagic;
|
||||
unsigned short type;
|
||||
unsigned short dim;
|
||||
unsigned short sizeX, sizeY, sizeZ;
|
||||
char name[128];
|
||||
unsigned long *data;
|
||||
} IMAGE_RGB_t;
|
||||
|
||||
#endif /* _IMAGE_RGB_H */
|
||||
35
common/lib/texture/load_rgb.h
Normal file
35
common/lib/texture/load_rgb.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#ifndef _IMAGE_RGB_H
|
||||
#define _IMAGE_RGB_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short imagic;
|
||||
unsigned short type;
|
||||
unsigned short dim;
|
||||
unsigned short sizeX, sizeY, sizeZ;
|
||||
char name[128];
|
||||
unsigned char *data;
|
||||
} IMAGE_RGB_t;
|
||||
|
||||
TextureMap_t *ImageRGB_Load(char *);
|
||||
|
||||
#endif /* _IMAGE_RGB_H */
|
||||
52
common/lib/texture/load_tex.C
Normal file
52
common/lib/texture/load_tex.C
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <iostream.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
void CTextureMap::loadTEX(char * fileName){
|
||||
char idString[16];
|
||||
DWORD *data,value;
|
||||
int version,ii,jj,counter;
|
||||
FILE * file = fopen(fileName,"r");
|
||||
if (file == NULL){
|
||||
throw new CException();
|
||||
}
|
||||
fscanf(file,"%s %i\n",idString,&version);
|
||||
if (strcmp(idString,"TEX") != 0 || version != 1){
|
||||
fclose(file);
|
||||
throw new CException("Unknown file format!");
|
||||
}
|
||||
fscanf(file,"%hu %hu\n",&m_width,&m_height);
|
||||
data = (DWORD*)malloc(m_width*m_height*sizeof(DWORD));
|
||||
counter = 0;
|
||||
for (ii = 0; ii < m_height; ii ++){
|
||||
for (jj = 0; jj < m_width; jj++){
|
||||
fscanf(file,"%lX",&value);
|
||||
data[counter++] = value;
|
||||
}
|
||||
}
|
||||
m_data = (BYTE*)data;
|
||||
fclose(file);
|
||||
}
|
||||
65
common/lib/texture/load_tiff.C
Normal file
65
common/lib/texture/load_tiff.C
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdlib.h>
|
||||
#include <tiffio.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
/******************************************************************************
|
||||
* load_tiff *
|
||||
* input tiff_file_name File name of tiff file to open *
|
||||
* retun NULL if failed to open tiff. *
|
||||
* Created 17/11-1997 by Anders Reggestad *
|
||||
******************************************************************************/
|
||||
void CTextureMap::loadTIFF(char * tiff_file_name){
|
||||
|
||||
uint32 w, h, ii;
|
||||
uint32 * tif_raster;
|
||||
TIFF* tif;
|
||||
|
||||
tif = TIFFOpen( tiff_file_name, "r" );
|
||||
|
||||
if (tif == NULL){
|
||||
throw new CException("Failed to open tiff file");
|
||||
}
|
||||
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
|
||||
|
||||
m_width = w;
|
||||
m_height = h;
|
||||
m_data = (unsigned char*)malloc(w*h*sizeof(DWORD));
|
||||
|
||||
|
||||
tif_raster = (uint32*)_TIFFmalloc( w*h*sizeof(uint32) );
|
||||
if (tif_raster == NULL){
|
||||
throw new CException("Failed to malloc tif_raster");
|
||||
}
|
||||
|
||||
if (TIFFReadRGBAImage(tif, w, h, tif_raster, 0)){
|
||||
for (ii=0; ii < w*h; ii++)
|
||||
((DWORD*)m_data)[ii] = tif_raster[ii];
|
||||
}
|
||||
_TIFFfree( tif_raster );
|
||||
|
||||
TIFFClose( tif );
|
||||
|
||||
}
|
||||
50
common/lib/texture/save_tex.C
Normal file
50
common/lib/texture/save_tex.C
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <iostream.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
void CTextureMap::saveTEX(char * fileName){
|
||||
int ii,jj,count;
|
||||
DWORD * data;
|
||||
FILE * file = fopen(fileName,"w+");
|
||||
if (file == NULL) throw new CException();
|
||||
fprintf(file,"TEX 1\n%i %i\n",
|
||||
getWidth(),
|
||||
getHeight());
|
||||
count = 0;
|
||||
data = (DWORD*)getData();
|
||||
if (data == NULL) {
|
||||
fclose(file);
|
||||
throw new CException();
|
||||
}
|
||||
for (ii = 0; ii < getHeight(); ii ++){
|
||||
for (jj = 1; jj <= getWidth(); jj ++){
|
||||
fprintf(file,"%08lX",data[count++]);
|
||||
if (jj != getWidth()) fprintf(file," ");
|
||||
}
|
||||
fprintf(file,"\n");
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
70
common/lib/texture/save_tiff.C
Normal file
70
common/lib/texture/save_tiff.C
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdlib.h>
|
||||
#include <tiffio.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
/******************************************************************************
|
||||
* save_tiff *
|
||||
* input tiff_file_name File name of tiff file to create *
|
||||
* retun NULL if failed to open tiff. *
|
||||
* Created 23/11-1999 by Anders Reggestad *
|
||||
******************************************************************************/
|
||||
void CTextureMap::saveTIFF(char * tiff_file_name){
|
||||
|
||||
int width,height,ii;
|
||||
uint32 *data,*tif_raster;
|
||||
TIFF* tif;
|
||||
|
||||
tif = TIFFOpen( tiff_file_name, "w" );
|
||||
|
||||
if (tif == NULL){
|
||||
cdebug << "ERROR: Faild to create tiff file: " << tiff_file_name << endl;
|
||||
throw new CException();
|
||||
}
|
||||
|
||||
width = getWidth();
|
||||
height = getHeight();
|
||||
data = (uint32*)getData();
|
||||
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
|
||||
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 0);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8, 8, 8, 8);
|
||||
TIFFSetField(tif, TIFFTAG_COMPRESSION, 1);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
|
||||
// TIFFSetField(tif, TIFFTAG_STRIPOFFSETS, 0);
|
||||
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, height);
|
||||
// TIFFSetField(tif, TIFFTAG_STRIPBYTECOUNTS, height*width*4);
|
||||
TIFFSetField(tif, TIFFTAG_XRESOLUTION, 1);
|
||||
TIFFSetField(tif, TIFFTAG_YRESOLUTION, 1);
|
||||
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, 1);
|
||||
|
||||
for (ii = 0; ii < height; ii++){
|
||||
TIFFWriteScanline(tif,&data[(height-ii-1)*width], ii, 0);
|
||||
}
|
||||
|
||||
TIFFClose( tif );
|
||||
|
||||
}
|
||||
153
common/lib/texture/texture.C
Normal file
153
common/lib/texture/texture.C
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Create texture
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
CTexture::CTexture(){
|
||||
|
||||
m_id = -1;
|
||||
m_state = 0;
|
||||
m_textureMap = NULL;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Create texture with given id
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
CTexture::CTexture(int id){
|
||||
|
||||
m_id = id;
|
||||
m_state = 0;
|
||||
m_textureMap = NULL;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Create texture with given id
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
CTexture::~CTexture(){
|
||||
|
||||
if (m_textureMap != NULL) delete m_textureMap;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Test if texturemap is loaded
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
int CTexture::loaded(){
|
||||
return ((m_state & TEX_STATE_LOADED)==TEX_STATE_LOADED);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Set texturemap to use with texture
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
void CTexture::setTextureMap(CTextureMap * textureMap){
|
||||
|
||||
if (m_textureMap != NULL) delete m_textureMap;
|
||||
|
||||
m_textureMap = textureMap;
|
||||
|
||||
m_state = m_state | TEX_STATE_LOADED;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Get texturemap from texture.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
CTextureMap * CTexture::getTextureMap(){
|
||||
return m_textureMap;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Exec texture
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
int CTexture::exec(){
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Load texture
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
void CTexture::load(char * fileName){
|
||||
CTextureMap * map = new CTextureMap();
|
||||
map->load(fileName);
|
||||
setTextureMap(map);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Save texture
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
void CTexture::save(char * fileName){
|
||||
m_textureMap->save(fileName);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Add texture to TextureCache
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
CTextureCache::CTextureCache():CCache(){
|
||||
}
|
||||
|
||||
CTexture * CTextureCache::add(CTexture * texture){
|
||||
return (CTexture*)CCache::add(texture->getId(), (CObject*)texture );
|
||||
}
|
||||
|
||||
CTexture * CTextureCache::get(int id){
|
||||
return (CTexture*)CCache::get(id);
|
||||
}
|
||||
|
||||
99
common/lib/texture/texturemap.C
Normal file
99
common/lib/texture/texturemap.C
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <iostream.h>
|
||||
#include "texture.H"
|
||||
#include "exception.H"
|
||||
|
||||
CTextureMap::CTextureMap(){
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
m_data = NULL;
|
||||
}
|
||||
|
||||
CTextureMap::CTextureMap(WORD width, WORD height, BYTE * data){
|
||||
setMap(width,height,data);
|
||||
}
|
||||
|
||||
CTextureMap::~CTextureMap(){
|
||||
if (m_data != NULL) free(m_data);
|
||||
}
|
||||
|
||||
|
||||
WORD CTextureMap::getWidth(){
|
||||
return m_width;
|
||||
}
|
||||
|
||||
WORD CTextureMap::getHeight(){
|
||||
return m_height;
|
||||
}
|
||||
|
||||
BYTE * CTextureMap::getData(){
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void CTextureMap::setMap(WORD width, WORD height, BYTE * data){
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_data = (BYTE*)malloc(m_width*m_height*sizeof(DWORD));
|
||||
memcpy(m_data,data,m_width*m_height*sizeof(DWORD));
|
||||
}
|
||||
|
||||
void CTextureMap::load(char * fileName){
|
||||
char * sufix;
|
||||
|
||||
if (m_data != NULL) free(m_data);
|
||||
m_width = m_height = 0;
|
||||
m_data = NULL;
|
||||
|
||||
sufix = strrchr(fileName,'.');
|
||||
|
||||
if ( (strncmp(sufix,".tif",4)==0) || (strncmp(sufix,".TIF",4)==0) ){
|
||||
loadTIFF(fileName);
|
||||
} else if ( (strcmp(sufix,".rgb")==0) || (strcmp(sufix,".RGB")==0) ){
|
||||
loadRGB(fileName);
|
||||
} else if ( (strcmp(sufix,".tex")==0) || (strcmp(sufix,".TEX")==0) ){
|
||||
loadTEX(fileName);
|
||||
} else {
|
||||
cdebug << "Failed!";
|
||||
throw new CException();
|
||||
}
|
||||
}
|
||||
|
||||
void CTextureMap::save(char * fileName){
|
||||
char * sufix;
|
||||
|
||||
sufix = strrchr(fileName,'.');
|
||||
|
||||
if ( (strncmp(sufix,".tif",4)==0) || (strncmp(sufix,".TIF",4)==0) ){
|
||||
saveTIFF(fileName);
|
||||
} else /* if ( (strcmp(sufix,".rgb")==0) || (strcmp(sufix,".RGB")==0) ){
|
||||
saveRGB(fileName);
|
||||
} else */ if ( (strcmp(sufix,".tex")==0) || (strcmp(sufix,".TEX")==0) ){
|
||||
saveTEX(fileName);
|
||||
} else {
|
||||
cdebug << "Failed!";
|
||||
throw new CException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user