Merge changes from the-witness.

This commit is contained in:
castano
2010-10-21 18:44:10 +00:00
parent 5d498d6824
commit bd74a9ffc6
27 changed files with 217 additions and 126 deletions

View File

@ -96,35 +96,37 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const
uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const
{
// Does bit expansion before interpolation.
color_array[0].b = col0.b * 22 / 8;
color_array[0].b = (3 * col0.b * 22) / 8;
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
color_array[0].r = col0.r * 22 / 8;
color_array[0].r = (3 * col0.r * 22) / 8;
color_array[0].a = 0xFF;
color_array[1].r = col1.r * 22 / 8;
color_array[1].r = (3 * col1.r * 22) / 8;
color_array[1].g = (col1.g << 2) | (col1.g >> 4);
color_array[1].b = col1.b * 22 / 8;
color_array[1].b = (3 * col1.b * 22) / 8;
color_array[1].a = 0xFF;
int gdiff = color_array[1].g - color_array[0].g;
if( col0.u > col1.u ) {
// Four-color block: derive the other two colors.
color_array[2].r = (2 * col0.r + col1.r) * 22 / 8;
color_array[2].g = (256 * color_array[0].g + (color_array[1].g - color_array[0].g)/4 + 128 + (color_array[1].g - color_array[0].g) * 80) / 256;
color_array[2].b = (2 * col0.b + col1.b) * 22 / 8;
color_array[2].r = ((2 * col0.r + col1.r) * 22) / 8;
color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 80) / 256;
color_array[2].b = ((2 * col0.b + col1.b) * 22) / 8;
color_array[2].a = 0xFF;
color_array[3].r = (2 * col1.r + col0.r) * 22 / 8;
color_array[3].g = (256 * color_array[1].g + (color_array[0].g - color_array[1].g)/4 + 128 + (color_array[0].g - color_array[1].g) * 80) / 256;
color_array[3].b = (2 * col1.b + col0.b) * 22 / 8;
color_array[3].r = ((2 * col1.r + col0.r) * 22) / 8;
color_array[3].g = (256 * color_array[1].g - gdiff / 4 + 128 - gdiff * 80) / 256;
color_array[3].b = ((2 * col1.b + col0.b) * 22) / 8;
color_array[3].a = 0xFF;
return 4;
}
else {
// Three-color block: derive the other color.
color_array[2].r = (col0.r + col1.r) * 33 / 8;
color_array[2].g = (256 * color_array[0].g + (color_array[1].g - color_array[0].g)/4 + 128 + (color_array[1].g - color_array[0].g) * 128) / 256;
color_array[2].b = (col0.b + col1.b) * 33 / 8;
color_array[2].r = ((col0.r + col1.r) * 33) / 8;
color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 128) / 256;
color_array[2].b = ((col0.b + col1.b) * 33) / 8;
color_array[2].a = 0xFF;
// Set all components to 0 to match DXT specs.

View File

@ -977,7 +977,7 @@ bool DirectDrawSurface::hasAlpha() const
{
if (header.hasDX10Header())
{
#pragma message(NV_FILE_LINE "TODO: Update hasAlpha to handle all DX10 formats.")
#pragma NV_MESSAGE("TODO: Update hasAlpha to handle all DX10 formats.")
return
header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM ||
header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM ||
@ -1187,7 +1187,7 @@ void DirectDrawSurface::readLinearImage(Image * img)
uint byteCount = (header.pf.bitcount + 7) / 8;
#pragma message(NV_FILE_LINE "TODO: Support floating point linear images and other FOURCC codes.")
#pragma NV_MESSAGE("TODO: Support floating point linear images and other FOURCC codes.")
// Read linear RGB images.
for (uint y = 0; y < h; y++)

View File

@ -152,7 +152,7 @@ void FloatImage::resizeChannelCount(uint c)
{
if (m_componentNum != c) {
uint count = m_width * m_height * c;
realloc(m_mem, count * sizeof(float));
realloc<float>(m_mem, count);
if (c > m_componentNum) {
memset(m_mem + m_count, 0, (count - m_count) * sizeof(float));

View File

@ -42,7 +42,7 @@ void Image::allocate(uint w, uint h)
free();
m_width = w;
m_height = h;
m_data = (Color32 *)realloc(m_data, w * h * sizeof(Color32));
m_data = realloc<Color32>(m_data, w * h);
}
bool Image::load(const char * name)

View File

@ -224,7 +224,7 @@ FloatImage * nv::ImageIO::loadFloat(const char * fileName, Stream & s)
}
}
#else // defined(HAVE_FREEIMAGE)
#pragma message(NV_FILE_LINE "TODO: Load TIFF and EXR files from stream.")
#pragma NV_MESSAGE("TODO: Load TIFF and EXR files from stream.")
#if defined(HAVE_TIFF)
if (strCaseCmp(extension, ".tif") == 0 || strCaseCmp(extension, ".tiff") == 0) {
return loadFloatTIFF(fileName, s);

View File

@ -82,7 +82,7 @@ static FloatImage * createNormalMap(const FloatImage * img, FloatImage::WrapMode
nvDebugCheck(kdv != NULL);
nvDebugCheck(img != NULL);
#pragma message(NV_FILE_LINE "FIXME: Height scale parameter should go away. It should be a sensible value that produces good results when the heightmap is in the [0, 1] range.")
#pragma NV_MESSAGE("FIXME: Height scale parameter should go away. It should be a sensible value that produces good results when the heightmap is in the [0, 1] range.")
const float heightScale = 1.0f / 16.0f;
const uint w = img->width();
@ -198,7 +198,7 @@ void nv::normalizeNormalMap(FloatImage * img)
{
nvDebugCheck(img != NULL);
#pragma message(NV_FILE_LINE "TODO: Pack and expand normals explicitly?")
#pragma NV_MESSAGE("TODO: Pack and expand normals explicitly?")
img->expandNormals(0);
img->normalize(0);

View File

@ -1,33 +1,33 @@
// This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_H
#define NV_IMAGE_H
#include <nvcore/nvcore.h>
// Function linkage
#if NVIMAGE_SHARED
#ifdef NVIMAGE_EXPORTS
#define NVIMAGE_API DLL_EXPORT
#define NVIMAGE_CLASS DLL_EXPORT_CLASS
#else
#define NVIMAGE_API DLL_IMPORT
#define NVIMAGE_CLASS DLL_IMPORT
#endif
#else
#define NVIMAGE_API
#define NVIMAGE_CLASS
#endif
// Some utility functions:
// This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_H
#define NV_IMAGE_H
#include <nvcore/nvcore.h>
// Function linkage
#if NVIMAGE_SHARED
#ifdef NVIMAGE_EXPORTS
#define NVIMAGE_API DLL_EXPORT
#define NVIMAGE_CLASS DLL_EXPORT_CLASS
#else
#define NVIMAGE_API DLL_IMPORT
#define NVIMAGE_CLASS DLL_IMPORT
#endif
#else
#define NVIMAGE_API
#define NVIMAGE_CLASS
#endif
// Some utility functions:
inline uint computePitch(uint w, uint bitsize, uint alignment)
{
return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment;
}
#endif // NV_IMAGE_H
#endif // NV_IMAGE_H