66 lines
2.1 KiB
C
66 lines
2.1 KiB
C
/*
|
|
* 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 );
|
|
|
|
}
|