Merge private branch.

This commit is contained in:
castano 2008-04-17 06:59:13 +00:00
parent 17a4f765fb
commit 7d3facd81a
10 changed files with 171 additions and 67 deletions

View File

@ -22,6 +22,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#include <nvcore/Stream.h> #include <nvcore/Stream.h>
#include <nvcore/Containers.h> // swap
#include "ColorBlock.h" #include "ColorBlock.h"
#include "BlockDXT.h" #include "BlockDXT.h"

View File

@ -1,5 +1,6 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#include <nvcore/Containers.h> // swap
#include <nvmath/Box.h> #include <nvmath/Box.h>
#include <nvimage/ColorBlock.h> #include <nvimage/ColorBlock.h>
#include <nvimage/Image.h> #include <nvimage/Image.h>

View File

@ -1241,8 +1241,23 @@ void DirectDrawSurface::printInfo() const
if (header.pf.flags & DDPF_ALPHAPREMULT) printf("\t\tDDPF_ALPHAPREMULT\n"); if (header.pf.flags & DDPF_ALPHAPREMULT) printf("\t\tDDPF_ALPHAPREMULT\n");
if (header.pf.flags & DDPF_NORMAL) printf("\t\tDDPF_NORMAL\n"); if (header.pf.flags & DDPF_NORMAL) printf("\t\tDDPF_NORMAL\n");
printf("\tFourCC: '%c%c%c%c'\n", ((header.pf.fourcc >> 0) & 0xFF), ((header.pf.fourcc >> 8) & 0xFF), ((header.pf.fourcc >> 16) & 0xFF), ((header.pf.fourcc >> 24) & 0xFF)); printf("\tFourCC: '%c%c%c%c'\n",
printf("\tBit count: %d (0x%.8X)\n", header.pf.bitcount, header.pf.bitcount); ((header.pf.fourcc >> 0) & 0xFF),
((header.pf.fourcc >> 8) & 0xFF),
((header.pf.fourcc >> 16) & 0xFF),
((header.pf.fourcc >> 24) & 0xFF));
if ((header.pf.fourcc & DDPF_FOURCC) && (header.pf.bitcount != 0))
{
printf("\tSwizzle: '%c%c%c%c'\n",
(header.pf.bitcount >> 0) & 0xFF,
(header.pf.bitcount >> 8) & 0xFF,
(header.pf.bitcount >> 16) & 0xFF,
(header.pf.bitcount >> 24) & 0xFF);
}
else
{
printf("\tBit count: %d\n", header.pf.bitcount);
}
printf("\tRed mask: 0x%.8X\n", header.pf.rmask); printf("\tRed mask: 0x%.8X\n", header.pf.rmask);
printf("\tGreen mask: 0x%.8X\n", header.pf.gmask); printf("\tGreen mask: 0x%.8X\n", header.pf.gmask);
printf("\tBlue mask: 0x%.8X\n", header.pf.bmask); printf("\tBlue mask: 0x%.8X\n", header.pf.bmask);

View File

@ -11,16 +11,16 @@ namespace nv
class Vector4; class Vector4;
/// Base filter class. /// Base filter class.
class Filter class NVIMAGE_CLASS Filter
{ {
public: public:
NVIMAGE_API Filter(float width); Filter(float width);
NVIMAGE_API virtual ~Filter(); virtual ~Filter();
NVIMAGE_API float width() const { return m_width; } float width() const { return m_width; }
NVIMAGE_API float sampleDelta(float x, float scale) const; float sampleDelta(float x, float scale) const;
NVIMAGE_API float sampleBox(float x, float scale, int samples) const; float sampleBox(float x, float scale, int samples) const;
NVIMAGE_API float sampleTriangle(float x, float scale, int samples) const; float sampleTriangle(float x, float scale, int samples) const;
virtual float evaluate(float x) const = 0; virtual float evaluate(float x) const = 0;
@ -29,56 +29,56 @@ namespace nv
}; };
// Box filter. // Box filter.
class BoxFilter : public Filter class NVIMAGE_CLASS BoxFilter : public Filter
{ {
public: public:
NVIMAGE_API BoxFilter(); BoxFilter();
NVIMAGE_API BoxFilter(float width); BoxFilter(float width);
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Triangle (bilinear/tent) filter. // Triangle (bilinear/tent) filter.
class TriangleFilter : public Filter class NVIMAGE_CLASS TriangleFilter : public Filter
{ {
public: public:
NVIMAGE_API TriangleFilter(); TriangleFilter();
NVIMAGE_API TriangleFilter(float width); TriangleFilter(float width);
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Quadratic (bell) filter. // Quadratic (bell) filter.
class QuadraticFilter : public Filter class NVIMAGE_CLASS QuadraticFilter : public Filter
{ {
public: public:
NVIMAGE_API QuadraticFilter(); QuadraticFilter();
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Cubic filter from Thatcher Ulrich. // Cubic filter from Thatcher Ulrich.
class CubicFilter : public Filter class NVIMAGE_CLASS CubicFilter : public Filter
{ {
public: public:
NVIMAGE_API CubicFilter(); CubicFilter();
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Cubic b-spline filter from Paul Heckbert. // Cubic b-spline filter from Paul Heckbert.
class BSplineFilter : public Filter class NVIMAGE_CLASS BSplineFilter : public Filter
{ {
public: public:
NVIMAGE_API BSplineFilter(); BSplineFilter();
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
/// Mitchell & Netravali's two-param cubic /// Mitchell & Netravali's two-param cubic
/// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88 /// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
class MitchellFilter : public Filter class NVIMAGE_CLASS MitchellFilter : public Filter
{ {
public: public:
NVIMAGE_API MitchellFilter(); MitchellFilter();
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
NVIMAGE_API void setParameters(float a, float b); void setParameters(float a, float b);
private: private:
float p0, p2, p3; float p0, p2, p3;
@ -86,29 +86,29 @@ namespace nv
}; };
// Lanczos3 filter. // Lanczos3 filter.
class LanczosFilter : public Filter class NVIMAGE_CLASS LanczosFilter : public Filter
{ {
public: public:
NVIMAGE_API LanczosFilter(); LanczosFilter();
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Sinc filter. // Sinc filter.
class SincFilter : public Filter class NVIMAGE_CLASS SincFilter : public Filter
{ {
public: public:
NVIMAGE_API SincFilter(float w); SincFilter(float w);
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
}; };
// Kaiser filter. // Kaiser filter.
class KaiserFilter : public Filter class NVIMAGE_CLASS KaiserFilter : public Filter
{ {
public: public:
NVIMAGE_API KaiserFilter(float w); KaiserFilter(float w);
NVIMAGE_API virtual float evaluate(float x) const; virtual float evaluate(float x) const;
NVIMAGE_API void setParameters(float a, float stretch); void setParameters(float a, float stretch);
private: private:
float alpha; float alpha;
@ -118,12 +118,12 @@ namespace nv
/// A 1D kernel. Used to precompute filter weights. /// A 1D kernel. Used to precompute filter weights.
class Kernel1 class NVIMAGE_CLASS Kernel1
{ {
NV_FORBID_COPY(Kernel1); NV_FORBID_COPY(Kernel1);
public: public:
NVIMAGE_API Kernel1(const Filter & f, int iscale, int samples = 32); Kernel1(const Filter & f, int iscale, int samples = 32);
NVIMAGE_API ~Kernel1(); ~Kernel1();
float valueAt(uint x) const { float valueAt(uint x) const {
nvDebugCheck(x < (uint)m_windowSize); nvDebugCheck(x < (uint)m_windowSize);
@ -138,7 +138,7 @@ namespace nv
return m_width; return m_width;
} }
NVIMAGE_API void debugPrint(); void debugPrint();
private: private:
int m_windowSize; int m_windowSize;
@ -148,15 +148,15 @@ namespace nv
/// A 2D kernel. /// A 2D kernel.
class Kernel2 class NVIMAGE_CLASS Kernel2
{ {
public: public:
NVIMAGE_API Kernel2(uint width); Kernel2(uint width);
NVIMAGE_API Kernel2(const Kernel2 & k); Kernel2(const Kernel2 & k);
NVIMAGE_API ~Kernel2(); ~Kernel2();
NVIMAGE_API void normalize(); void normalize();
NVIMAGE_API void transpose(); void transpose();
float valueAt(uint x, uint y) const { float valueAt(uint x, uint y) const {
return m_data[y * m_windowSize + x]; return m_data[y * m_windowSize + x];
@ -166,12 +166,12 @@ namespace nv
return m_windowSize; return m_windowSize;
} }
NVIMAGE_API void initLaplacian(); void initLaplacian();
NVIMAGE_API void initEdgeDetection(); void initEdgeDetection();
NVIMAGE_API void initSobel(); void initSobel();
NVIMAGE_API void initPrewitt(); void initPrewitt();
NVIMAGE_API void initBlendedSobel(const Vector4 & scale); void initBlendedSobel(const Vector4 & scale);
private: private:
const uint m_windowSize; const uint m_windowSize;
@ -180,12 +180,12 @@ namespace nv
/// A 1D polyphase kernel /// A 1D polyphase kernel
class PolyphaseKernel class NVIMAGE_CLASS PolyphaseKernel
{ {
NV_FORBID_COPY(PolyphaseKernel); NV_FORBID_COPY(PolyphaseKernel);
public: public:
NVIMAGE_API PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32); PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
NVIMAGE_API ~PolyphaseKernel(); ~PolyphaseKernel();
int windowSize() const { int windowSize() const {
return m_windowSize; return m_windowSize;
@ -205,7 +205,7 @@ namespace nv
return m_data[column * m_windowSize + x]; return m_data[column * m_windowSize + x];
} }
NVIMAGE_API void debugPrint() const; void debugPrint() const;
private: private:
int m_windowSize; int m_windowSize;

View File

@ -636,7 +636,7 @@ FloatImage * FloatImage::downSample(const Filter & filter, uint w, uint h, WrapM
float * dst_channel = dst_image->channel(c); float * dst_channel = dst_image->channel(c);
for (uint x = 0; x < w; x++) { for (uint x = 0; x < w; x++) {
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.unsecureBuffer()); tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.mutableBuffer());
for (uint y = 0; y < h; y++) { for (uint y = 0; y < h; y++) {
dst_channel[y * w + x] = tmp_column[y]; dst_channel[y * w + x] = tmp_column[y];
@ -657,7 +657,7 @@ FloatImage * FloatImage::downSample(const Filter & filter, uint w, uint h, WrapM
float * tmp_channel = tmp_image->channel(c); float * tmp_channel = tmp_image->channel(c);
for (uint x = 0; x < w; x++) { for (uint x = 0; x < w; x++) {
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.unsecureBuffer()); tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.mutableBuffer());
for (uint y = 0; y < h; y++) { for (uint y = 0; y < h; y++) {
tmp_channel[y * w + x] = tmp_column[y]; tmp_channel[y * w + x] = tmp_column[y];

View File

@ -3,8 +3,10 @@
#ifndef NV_IMAGE_FLOATIMAGE_H #ifndef NV_IMAGE_FLOATIMAGE_H
#define NV_IMAGE_FLOATIMAGE_H #define NV_IMAGE_FLOATIMAGE_H
#include <stdlib.h> // abs
#include <nvcore/Debug.h> #include <nvcore/Debug.h>
#include <nvcore/Containers.h> // clamp #include <nvcore/Algorithms.h> // clamp
#include <nvimage/nvimage.h> #include <nvimage/nvimage.h>
namespace nv namespace nv

View File

@ -2,6 +2,7 @@
#include <nvcore/Debug.h> #include <nvcore/Debug.h>
#include <nvcore/Ptr.h> #include <nvcore/Ptr.h>
#include <nvcore/Containers.h> // swap
#include <nvmath/Color.h> #include <nvmath/Color.h>

View File

@ -162,6 +162,9 @@ FloatImage * nv::ImageIO::loadFloat(const char * fileName, Stream & s)
if (strCaseCmp(extension, ".pfm") == 0) { if (strCaseCmp(extension, ".pfm") == 0) {
return loadFloatPFM(fileName, s); return loadFloatPFM(fileName, s);
} }
if (strCaseCmp(extension, ".hdr") == 0) {
return loadGridFloat(fileName, s);
}
*/ */
return NULL; return NULL;
@ -794,7 +797,7 @@ Image * nv::ImageIO::loadJPG(Stream & s)
// Read the entire file. // Read the entire file.
Array<uint8> byte_array; Array<uint8> byte_array;
byte_array.resize(s.size()); byte_array.resize(s.size());
s.serialize(byte_array.unsecureBuffer(), s.size()); s.serialize(byte_array.mutableBuffer(), s.size());
jpeg_decompress_struct cinfo; jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr; jpeg_error_mgr jerr;
@ -1089,7 +1092,8 @@ namespace
virtual void seekg(Imf::Int64 pos) virtual void seekg(Imf::Int64 pos)
{ {
m_stream.seek(pos); nvDebugCheck(pos >= 0 && pos < UINT_MAX);
m_stream.seek((uint)pos);
} }
virtual void clear() virtual void clear()
@ -1298,6 +1302,77 @@ bool nv::ImageIO::saveFloatPFM(const char * fileName, const FloatImage * fimage,
return true; return true;
} }
#pragma warning(disable : 4996)
NVIMAGE_API FloatImage * nv::ImageIO::loadGridFloat(const char * fileName, Stream & s)
{
nvCheck(s.isLoading());
nvCheck(!s.isError());
Tokenizer parser(&s);
parser.nextLine();
if (parser.token() != "ncols")
{
nvDebug("Failed to find 'ncols' token in file '%s'.\n", fileName);
return NULL;
}
parser.nextToken(true);
const int nCols = parser.token().toInt();
parser.nextToken(true);
if (parser.token() != "nrows")
{
nvDebug("Failed to find 'nrows' token in file '%s'.\n", fileName);
return NULL;
}
parser.nextToken(true);
const int nRows = parser.token().toInt();
/* There's a byte order defined in the header. We could read it. However, here we
just assume that it matches the platform's byte order.
// There is then a bunch of data that we don't care about (lat, long definitions, etc).
for (int i=0; i!=9; ++i)
parser.nextToken(true);
if (parser.token() != "byteorder")
return NULL;
parser.nextToken(true);
const Stream::ByteOrder byteOrder = (parser.token() == "LSBFIRST")? Stream::LittleEndian: Stream::BigEndian;
*/
// GridFloat comes in two files: an ASCII header which was parsed above (.hdr) and a big blob
// of binary data in a .flt file.
Path dataPath(fileName);
dataPath.stripExtension();
dataPath.append(".flt");
// Open the binary data.
FILE* file = fopen(dataPath.fileName(), "rb");
if (!file)
{
nvDebug("Failed to find GridFloat blob file '%s' corresponding to '%s'.\n", dataPath.fileName(), fileName);
return NULL;
}
// Allocate image.
AutoPtr<FloatImage> fimage(new FloatImage());
fimage->allocate(1, nCols, nRows);
float * channel = fimage->channel(0);
// The binary blob is defined to be in row-major order, containing IEEE floats.
// So we can just slurp it in. Theoretically, we ought to use the byte order.
const size_t nRead = fread((void*) channel, sizeof(float), nRows * nCols, file);
fclose(file);
return fimage.release();
}
#endif #endif
#if 0 #if 0

View File

@ -47,10 +47,15 @@ namespace nv
NVIMAGE_API bool saveFloatEXR(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components); NVIMAGE_API bool saveFloatEXR(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
#endif #endif
/*
NVIMAGE_API FloatImage * loadFloatPFM(const char * fileName, Stream & s);
NVIMAGE_API bool saveFloatPFM(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
// NVIMAGE_API FloatImage * loadFloatPFM(const char * fileName, Stream & s); // GridFloat is a simple, open format for terrain elevation data. See http://ned.usgs.gov/Ned/faq.asp.
// NVIMAGE_API bool saveFloatPFM(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components); // Expects: 1) fileName will be an ".hdr" header file, 2) there will also exist a corresponding float data
// blob in a ".flt" file. (This is what USGS gives you.)
NVIMAGE_API FloatImage * loadGridFloat(const char * fileName, Stream & s);
*/
} // ImageIO namespace } // ImageIO namespace
} // nv namespace } // nv namespace

View File

@ -12,6 +12,10 @@ http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT
@@ This code needs to be reviewed, I'm not sure it's correct. @@ This code needs to be reviewed, I'm not sure it's correct.
*/ */
#include <string.h> // memset
#include <nvcore/Containers.h> // swap
#include <nvmath/Color.h> #include <nvmath/Color.h>
#include <nvimage/Image.h> #include <nvimage/Image.h>