More cleanups. Assume static linking.

pull/310/head
Ignacio 4 years ago
parent 7f9c87713a
commit adce1a00da

@ -234,16 +234,16 @@ namespace nv
// Serialization functions. // Serialization functions.
NVIMAGE_API Stream & operator<<(Stream & stream, BlockDXT1 & block); Stream & operator<<(Stream & stream, BlockDXT1 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, AlphaBlockDXT3 & block); Stream & operator<<(Stream & stream, AlphaBlockDXT3 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockDXT3 & block); Stream & operator<<(Stream & stream, BlockDXT3 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, AlphaBlockDXT5 & block); Stream & operator<<(Stream & stream, AlphaBlockDXT5 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockDXT5 & block); Stream & operator<<(Stream & stream, BlockDXT5 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockATI1 & block); Stream & operator<<(Stream & stream, BlockATI1 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockATI2 & block); Stream & operator<<(Stream & stream, BlockATI2 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockCTX1 & block); Stream & operator<<(Stream & stream, BlockCTX1 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockBC6 & block); Stream & operator<<(Stream & stream, BlockBC6 & block);
NVIMAGE_API Stream & operator<<(Stream & stream, BlockBC7 & block); Stream & operator<<(Stream & stream, BlockBC7 & block);
} // nv namespace } // nv namespace

@ -61,7 +61,7 @@ ColorBlock::ColorBlock(const Image * img, uint x, uint y)
void ColorBlock::init(const Image * img, uint x, uint y) void ColorBlock::init(const Image * img, uint x, uint y)
{ {
init(img->width(), img->height(), (const uint *)img->pixels(), x, y); init(img->width, img->height, (const uint *)img->pixels(), x, y);
} }
void ColorBlock::init(uint w, uint h, const uint * data, uint x, uint y) void ColorBlock::init(uint w, uint h, const uint * data, uint x, uint y)

File diff suppressed because it is too large Load Diff

@ -1,29 +1,5 @@
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com> // MIT license see full LICENSE text at end of file
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#pragma once #pragma once
#ifndef NV_IMAGE_DIRECTDRAWSURFACE_H
#define NV_IMAGE_DIRECTDRAWSURFACE_H
#include "nvimage.h" #include "nvimage.h"
@ -34,8 +10,8 @@
namespace nv namespace nv
{ {
class Image; class Image;
class FloatImage;
class Stream; class Stream;
struct ColorBlock;
enum DDPF enum DDPF
{ {
@ -269,7 +245,6 @@ namespace nv
}; };
extern uint findD3D9Format(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); extern uint findD3D9Format(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
extern uint findDXGIFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); extern uint findDXGIFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
struct RGBAPixelFormat struct RGBAPixelFormat
@ -281,9 +256,10 @@ namespace nv
uint amask; uint amask;
}; };
extern const RGBAPixelFormat *findD3D9PixelFormat(uint dxgiFormat);
extern const RGBAPixelFormat *findDXGIPixelFormat(uint dxgiFormat); extern const RGBAPixelFormat *findDXGIPixelFormat(uint dxgiFormat);
struct NVIMAGE_CLASS DDSPixelFormat struct DDSPixelFormat
{ {
uint size; uint size;
uint flags; uint flags;
@ -295,7 +271,7 @@ namespace nv
uint amask; uint amask;
}; };
struct NVIMAGE_CLASS DDSCaps struct DDSCaps
{ {
uint caps1; uint caps1;
uint caps2; uint caps2;
@ -304,7 +280,7 @@ namespace nv
}; };
/// DDS file header for DX10. /// DDS file header for DX10.
struct NVIMAGE_CLASS DDSHeader10 struct DDSHeader10
{ {
uint dxgiFormat; uint dxgiFormat;
uint resourceDimension; uint resourceDimension;
@ -314,7 +290,7 @@ namespace nv
}; };
/// DDS file header. /// DDS file header.
struct NVIMAGE_CLASS DDSHeader struct DDSHeader
{ {
uint fourcc; uint fourcc;
uint size; uint size;
@ -369,16 +345,14 @@ namespace nv
bool isBlockFormat() const; bool isBlockFormat() const;
}; };
NVIMAGE_API Stream & operator<< (Stream & s, DDSHeader & header); Stream & operator<< (Stream & s, DDSHeader & header);
/// DirectDraw Surface. (DDS) /// DirectDraw Surface. (DDS)
class NVIMAGE_CLASS DirectDrawSurface class DirectDrawSurface
{ {
public: public:
DirectDrawSurface(); DirectDrawSurface();
DirectDrawSurface(const char * file);
DirectDrawSurface(Stream * stream);
~DirectDrawSurface(); ~DirectDrawSurface();
bool load(const char * filename); bool load(const char * filename);
@ -388,6 +362,7 @@ namespace nv
bool isSupported() const; bool isSupported() const;
bool hasAlpha() const; bool hasAlpha() const;
bool isColorsRGB() const;
uint mipmapCount() const; uint mipmapCount() const;
uint width() const; uint width() const;
@ -399,13 +374,12 @@ namespace nv
bool isTexture3D() const; bool isTexture3D() const;
bool isTextureCube() const; bool isTextureCube() const;
bool isTextureArray() const; bool isTextureArray() const;
bool isBlockFormat() const;
void setNormalFlag(bool b); void setNormalFlag(bool b);
void setHasAlphaFlag(bool b); void setHasAlphaFlag(bool b);
void setUserVersion(int version); void setUserVersion(int version);
void mipmap(Image * img, uint f, uint m);
uint surfaceWidth(uint mipmap) const; uint surfaceWidth(uint mipmap) const;
uint surfaceHeight(uint mipmap) const; uint surfaceHeight(uint mipmap) const;
uint surfaceDepth(uint mipmap) const; uint surfaceDepth(uint mipmap) const;
@ -422,15 +396,35 @@ namespace nv
uint faceSize() const; uint faceSize() const;
uint offset(uint face, uint mipmap); uint offset(uint face, uint mipmap);
void readLinearImage(Image * img, uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
void readBlockImage(Image * img);
void readBlock(ColorBlock * rgba);
private:
Stream * stream; Stream * stream;
//void * data;
}; };
bool imageFromDDS(Image * img, DirectDrawSurface & dds, uint face, uint mipmap);
bool imageFromDDS(FloatImage * img, DirectDrawSurface & dds, uint face, uint mipmap);
} // nv namespace } // nv namespace
#endif // NV_IMAGE_DIRECTDRAWSURFACE_H // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
// Copyright (c) 2008-2020 -- Ignacio Castano <castano@gmail.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

@ -1,8 +1,5 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once #pragma once
#ifndef NV_IMAGE_FILTER_H
#define NV_IMAGE_FILTER_H
#include "nvimage.h" #include "nvimage.h"
#include "nvcore/Debug.h" #include "nvcore/Debug.h"
@ -12,7 +9,7 @@ namespace nv
class Vector4; class Vector4;
/// Base filter class. /// Base filter class.
class NVIMAGE_CLASS Filter class Filter
{ {
public: public:
Filter(float width); Filter(float width);
@ -30,7 +27,7 @@ namespace nv
}; };
// Box filter. // Box filter.
class NVIMAGE_CLASS BoxFilter : public Filter class BoxFilter : public Filter
{ {
public: public:
BoxFilter(); BoxFilter();
@ -39,7 +36,7 @@ namespace nv
}; };
// Triangle (bilinear/tent) filter. // Triangle (bilinear/tent) filter.
class NVIMAGE_CLASS TriangleFilter : public Filter class TriangleFilter : public Filter
{ {
public: public:
TriangleFilter(); TriangleFilter();
@ -48,7 +45,7 @@ namespace nv
}; };
// Quadratic (bell) filter. // Quadratic (bell) filter.
class NVIMAGE_CLASS QuadraticFilter : public Filter class QuadraticFilter : public Filter
{ {
public: public:
QuadraticFilter(); QuadraticFilter();
@ -56,7 +53,7 @@ namespace nv
}; };
// Cubic filter from Thatcher Ulrich. // Cubic filter from Thatcher Ulrich.
class NVIMAGE_CLASS CubicFilter : public Filter class CubicFilter : public Filter
{ {
public: public:
CubicFilter(); CubicFilter();
@ -64,7 +61,7 @@ namespace nv
}; };
// Cubic b-spline filter from Paul Heckbert. // Cubic b-spline filter from Paul Heckbert.
class NVIMAGE_CLASS BSplineFilter : public Filter class BSplineFilter : public Filter
{ {
public: public:
BSplineFilter(); BSplineFilter();
@ -73,7 +70,7 @@ namespace nv
/// 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 NVIMAGE_CLASS MitchellFilter : public Filter class MitchellFilter : public Filter
{ {
public: public:
MitchellFilter(); MitchellFilter();
@ -87,7 +84,7 @@ namespace nv
}; };
// Lanczos3 filter. // Lanczos3 filter.
class NVIMAGE_CLASS LanczosFilter : public Filter class LanczosFilter : public Filter
{ {
public: public:
LanczosFilter(); LanczosFilter();
@ -95,7 +92,7 @@ namespace nv
}; };
// Sinc filter. // Sinc filter.
class NVIMAGE_CLASS SincFilter : public Filter class SincFilter : public Filter
{ {
public: public:
SincFilter(float w); SincFilter(float w);
@ -103,7 +100,7 @@ namespace nv
}; };
// Kaiser filter. // Kaiser filter.
class NVIMAGE_CLASS KaiserFilter : public Filter class KaiserFilter : public Filter
{ {
public: public:
KaiserFilter(float w); KaiserFilter(float w);
@ -132,7 +129,7 @@ namespace nv
/// A 1D kernel. Used to precompute filter weights. /// A 1D kernel. Used to precompute filter weights.
class NVIMAGE_CLASS Kernel1 class Kernel1
{ {
NV_FORBID_COPY(Kernel1); NV_FORBID_COPY(Kernel1);
public: public:
@ -162,7 +159,7 @@ namespace nv
/// A 2D kernel. /// A 2D kernel.
class NVIMAGE_CLASS Kernel2 class Kernel2
{ {
public: public:
Kernel2(uint width); Kernel2(uint width);
@ -195,7 +192,7 @@ namespace nv
/// A 1D polyphase kernel /// A 1D polyphase kernel
class NVIMAGE_CLASS PolyphaseKernel class PolyphaseKernel
{ {
NV_FORBID_COPY(PolyphaseKernel); NV_FORBID_COPY(PolyphaseKernel);
public: public:
@ -230,5 +227,3 @@ namespace nv
}; };
} // nv namespace } // nv namespace
#endif // NV_IMAGE_FILTER_H

@ -56,9 +56,9 @@ void FloatImage::initFrom(const Image * img)
nvCheck(img != NULL); nvCheck(img != NULL);
uint channel_count = 3; uint channel_count = 3;
if (img->format() == Image::Format_ARGB) channel_count = 4; if (img->format == Image::Format_ARGB) channel_count = 4;
allocate(channel_count, img->width(), img->height(), img->depth()); allocate(channel_count, img->width, img->height, img->depth);
float * red_channel = channel(0); float * red_channel = channel(0);
float * green_channel = channel(1); float * green_channel = channel(1);

@ -34,78 +34,78 @@ namespace nv
WrapMode_Mirror WrapMode_Mirror
}; };
NVIMAGE_API FloatImage(); FloatImage();
NVIMAGE_API FloatImage(const FloatImage & img); FloatImage(const FloatImage & img);
NVIMAGE_API FloatImage(const Image * img); FloatImage(const Image * img);
NVIMAGE_API ~FloatImage(); ~FloatImage();
/** @name Conversion. */ /** @name Conversion. */
//@{ //@{
NVIMAGE_API void initFrom(const Image * img); void initFrom(const Image * img);
NVIMAGE_API Image * createImage(uint base_component = 0, uint num = 4) const; Image * createImage(uint base_component = 0, uint num = 4) const;
NVIMAGE_API Image * createImageGammaCorrect(float gamma = 2.2f) const; Image * createImageGammaCorrect(float gamma = 2.2f) const;
//@} //@}
/** @name Allocation. */ /** @name Allocation. */
//@{ //@{
NVIMAGE_API void allocate(uint c, uint w, uint h, uint d = 1); void allocate(uint c, uint w, uint h, uint d = 1);
NVIMAGE_API void free(); // Does not clear members. void free(); // Does not clear members.
NVIMAGE_API void resizeChannelCount(uint c); void resizeChannelCount(uint c);
//@} //@}
/** @name Manipulation. */ /** @name Manipulation. */
//@{ //@{
NVIMAGE_API void clear(float f = 0.0f); void clear(float f = 0.0f);
NVIMAGE_API void clear(uint component, float f = 0.0f); void clear(uint component, float f = 0.0f);
NVIMAGE_API void copyChannel(uint src, uint dst); void copyChannel(uint src, uint dst);
NVIMAGE_API void normalize(uint base_component); void normalize(uint base_component);
NVIMAGE_API void packNormals(uint base_component); void packNormals(uint base_component);
NVIMAGE_API void expandNormals(uint base_component); void expandNormals(uint base_component);
NVIMAGE_API void scaleBias(uint base_component, uint num, float scale, float add); void scaleBias(uint base_component, uint num, float scale, float add);
NVIMAGE_API void clamp(uint base_component, uint num, float low, float high); void clamp(uint base_component, uint num, float low, float high);
NVIMAGE_API void toLinear(uint base_component, uint num, float gamma = 2.2f); void toLinear(uint base_component, uint num, float gamma = 2.2f);
NVIMAGE_API void toGamma(uint base_component, uint num, float gamma = 2.2f); void toGamma(uint base_component, uint num, float gamma = 2.2f);
NVIMAGE_API void exponentiate(uint base_component, uint num, float power); void exponentiate(uint base_component, uint num, float power);
NVIMAGE_API void transform(uint base_component, const Matrix & m, const Vector4 & offset); void transform(uint base_component, const Matrix & m, const Vector4 & offset);
NVIMAGE_API void swizzle(uint base_component, uint r, uint g, uint b, uint a); void swizzle(uint base_component, uint r, uint g, uint b, uint a);
NVIMAGE_API FloatImage * fastDownSample() const; FloatImage * fastDownSample() const;
NVIMAGE_API FloatImage * downSample(const Filter & filter, WrapMode wm) const; FloatImage * downSample(const Filter & filter, WrapMode wm) const;
NVIMAGE_API FloatImage * downSample(const Filter & filter, WrapMode wm, uint alpha) const; FloatImage * downSample(const Filter & filter, WrapMode wm, uint alpha) const;
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm) const; FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm) const;
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, uint d, WrapMode wm) const; FloatImage * resize(const Filter & filter, uint w, uint h, uint d, WrapMode wm) const;
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm, uint alpha) const; FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm, uint alpha) const;
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, uint d, WrapMode wm, uint alpha) const; FloatImage * resize(const Filter & filter, uint w, uint h, uint d, WrapMode wm, uint alpha) const;
NVIMAGE_API void convolve(const Kernel2 & k, uint c, WrapMode wm); void convolve(const Kernel2 & k, uint c, WrapMode wm);
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, WrapMode wm) const; //FloatImage * downSample(const Kernel1 & filter, WrapMode wm) const;
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, uint w, uint h, WrapMode wm) const; //FloatImage * downSample(const Kernel1 & filter, uint w, uint h, WrapMode wm) const;
//@} //@}
NVIMAGE_API float applyKernelXY(const Kernel2 * k, int x, int y, int z, uint c, WrapMode wm) const; float applyKernelXY(const Kernel2 * k, int x, int y, int z, uint c, WrapMode wm) const;
NVIMAGE_API float applyKernelX(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const; float applyKernelX(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const;
NVIMAGE_API float applyKernelY(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const; float applyKernelY(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const;
NVIMAGE_API float applyKernelZ(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const; float applyKernelZ(const Kernel1 * k, int x, int y, int z, uint c, WrapMode wm) const;
NVIMAGE_API void applyKernelX(const PolyphaseKernel & k, int y, int z, uint c, WrapMode wm, float * output) const; void applyKernelX(const PolyphaseKernel & k, int y, int z, uint c, WrapMode wm, float * output) const;
NVIMAGE_API void applyKernelY(const PolyphaseKernel & k, int x, int z, uint c, WrapMode wm, float * output, int output_stride) const; void applyKernelY(const PolyphaseKernel & k, int x, int z, uint c, WrapMode wm, float * output, int output_stride) const;
NVIMAGE_API void applyKernelZ(const PolyphaseKernel & k, int x, int y, uint c, WrapMode wm, float * output) const; void applyKernelZ(const PolyphaseKernel & k, int x, int y, uint c, WrapMode wm, float * output) const;
NVIMAGE_API void applyKernelX(const PolyphaseKernel & k, int y, int z, uint c, uint a, WrapMode wm, float * output) const; void applyKernelX(const PolyphaseKernel & k, int y, int z, uint c, uint a, WrapMode wm, float * output) const;
NVIMAGE_API void applyKernelY(const PolyphaseKernel & k, int x, int z, uint c, uint a, WrapMode wm, float * output, int output_stride) const; void applyKernelY(const PolyphaseKernel & k, int x, int z, uint c, uint a, WrapMode wm, float * output, int output_stride) const;
NVIMAGE_API void applyKernelZ(const PolyphaseKernel & k, int x, int y, uint c, uint a, WrapMode wm, float * output) const; void applyKernelZ(const PolyphaseKernel & k, int x, int y, uint c, uint a, WrapMode wm, float * output) const;
NVIMAGE_API void flipX(); void flipX();
NVIMAGE_API void flipY(); void flipY();
NVIMAGE_API void flipZ(); void flipZ();
NVIMAGE_API float alphaTestCoverage(float alphaRef, int alphaChannel, float alphaScale = 1.0f) const; float alphaTestCoverage(float alphaRef, int alphaChannel, float alphaScale = 1.0f) const;
NVIMAGE_API void scaleAlphaToCoverage(float coverage, float alphaRef, int alphaChannel); void scaleAlphaToCoverage(float coverage, float alphaRef, int alphaChannel);
uint width() const { return m_width; } uint width() const { return m_width; }

@ -15,15 +15,11 @@
using namespace nv; using namespace nv;
Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(NULL) Image::Image(const Image & img)
{ {
} allocate(img.width, img.height, img.depth);
format = img.format;
Image::Image(const Image & img) : m_data(NULL) memcpy(data, img.data, sizeof(Color32) * width * height * depth);
{
allocate(img.m_width, img.m_height, img.m_depth);
m_format = img.m_format;
memcpy(m_data, img.m_data, sizeof(Color32) * m_width * m_height * m_depth);
} }
Image::~Image() Image::~Image()
@ -33,28 +29,35 @@ Image::~Image()
const Image & Image::operator=(const Image & img) const Image & Image::operator=(const Image & img)
{ {
allocate(img.m_width, img.m_height, m_depth); allocate(img.width, img.height, depth);
m_format = img.m_format; format = img.format;
memcpy(m_data, img.m_data, sizeof(Color32) * m_width * m_height * m_depth); memcpy(data, img.data, sizeof(Color32) * width * height * depth);
return *this; return *this;
} }
void Image::allocate(uint w, uint h, uint d/*= 1*/) void Image::allocate(uint w, uint h, uint d/*= 1*/)
{ {
m_width = w; width = w;
m_height = h; height = h;
m_depth = d; depth = d;
m_data = realloc<Color32>(m_data, w * h * d); data = realloc<Color32>(data, w * h * d);
} }
void Image::acquire(Color32 * data, uint w, uint h, uint d/*= 1*/) void Image::acquire(Color32 * data, uint w, uint h, uint d/*= 1*/)
{ {
free(); free();
m_width = w; width = w;
m_height = h; height = h;
m_depth = d; depth = d;
m_data = data; data = data;
}
void Image::free()
{
::free(data);
width = height = depth = 0;
data = NULL;
} }
void Image::resize(uint w, uint h, uint d/*= 1*/) { void Image::resize(uint w, uint h, uint d/*= 1*/) {
@ -66,9 +69,9 @@ void Image::resize(uint w, uint h, uint d/*= 1*/) {
// Copy image. // Copy image.
uint x, y, z; uint x, y, z;
for(z = 0; z < min(d, m_depth); z++) { for(z = 0; z < min(d, depth); z++) {
for(y = 0; y < min(h, m_height); y++) { for(y = 0; y < min(h, height); y++) {
for(x = 0; x < min(w, m_width); x++) { for(x = 0; x < min(w, width); x++) {
img.pixel(x, y, z) = pixel(x, y, z); img.pixel(x, y, z) = pixel(x, y, z);
} }
for(; x < w; x++) { for(; x < w; x++) {
@ -89,11 +92,12 @@ void Image::resize(uint w, uint h, uint d/*= 1*/) {
} }
} }
swap(m_width, img.m_width); swap(width, img.width);
swap(m_height, img.m_height); swap(height, img.height);
swap(m_depth, img.m_depth); swap(depth, img.depth);
swap(m_format, img.m_format); swap(format, img.format);
swap(m_data, img.m_data); swap(sRGB, img.sRGB);
swap(data, img.data);
} }
bool Image::load(const char * name) bool Image::load(const char * name)
@ -105,106 +109,74 @@ bool Image::load(const char * name)
return false; return false;
} }
swap(m_width, img->m_width); swap(width, img->width);
swap(m_height, img->m_height); swap(height, img->height);
swap(m_depth, img->m_depth); swap(depth, img->depth);
swap(m_format, img->m_format); swap(format, img->format);
swap(m_data, img->m_data); swap(sRGB, img->sRGB);
swap(data, img->data);
return true; return true;
} }
void Image::wrap(void * data, uint w, uint h, uint d) void Image::wrap(void * _data, uint w, uint h, uint d)
{ {
free(); free();
m_data = (Color32 *)data; data = (Color32 *)_data;
m_width = w; width = w;
m_height = h; height = h;
m_depth = d; depth = d;
} }
void Image::unwrap() void Image::unwrap()
{ {
m_data = NULL; data = NULL;
m_width = 0; width = 0;
m_height = 0; height = 0;
m_depth = 0; depth = 0;
}
void Image::free()
{
::free(m_data);
m_data = NULL;
}
uint Image::width() const
{
return m_width;
} }
uint Image::height() const
{
return m_height;
}
uint Image::depth() const
{
return m_depth;
}
const Color32 * Image::scanline(uint h) const const Color32 * Image::scanline(uint h) const
{ {
nvDebugCheck(h < m_height); nvDebugCheck(h < height);
return m_data + h * m_width; return data + h * width;
} }
Color32 * Image::scanline(uint h) Color32 * Image::scanline(uint h)
{ {
nvDebugCheck(h < m_height); nvDebugCheck(h < height);
return m_data + h * m_width; return data + h * width;
} }
const Color32 * Image::pixels() const const Color32 * Image::pixels() const
{ {
return m_data; return data;
} }
Color32 * Image::pixels() Color32 * Image::pixels()
{ {
return m_data; return data;
} }
const Color32 & Image::pixel(uint idx) const const Color32 & Image::pixel(uint idx) const
{ {
nvDebugCheck(idx < m_width * m_height * m_depth); nvDebugCheck(idx < width * height * depth);
return m_data[idx]; return data[idx];
} }
Color32 & Image::pixel(uint idx) Color32 & Image::pixel(uint idx)
{ {
nvDebugCheck(idx < m_width * m_height * m_depth); nvDebugCheck(idx < width * height * depth);
return m_data[idx]; return data[idx];
}
Image::Format Image::format() const
{
return m_format;
}
void Image::setFormat(Image::Format f)
{
m_format = f;
} }
void Image::fill(Color32 c) void Image::fill(Color32 c)
{ {
const uint size = m_width * m_height * m_depth; const uint size = width * height * depth;
for (uint i = 0; i < size; ++i) for (uint i = 0; i < size; ++i)
{ {
m_data[i] = c; data[i] = c;
} }
} }

@ -1,8 +1,5 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once #pragma once
#ifndef NV_IMAGE_IMAGE_H
#define NV_IMAGE_IMAGE_H
#include "nvimage.h" #include "nvimage.h"
#include "nvcore/Debug.h" #include "nvcore/Debug.h"
@ -15,18 +12,17 @@ namespace nv
{ {
class Color32; class Color32;
/// 32 bit RGBA image. // 32 bit ARGB image.
class NVIMAGE_CLASS Image class Image
{ {
public: public:
enum Format enum Format : uint8 {
{ Format_XRGB,
Format_RGB,
Format_ARGB, Format_ARGB,
}; };
Image(); Image() {}
Image(const Image & img); Image(const Image & img);
~Image(); ~Image();
@ -36,16 +32,13 @@ namespace nv
void allocate(uint w, uint h, uint d = 1); void allocate(uint w, uint h, uint d = 1);
void acquire(Color32 * data, uint w, uint h, uint d = 1); void acquire(Color32 * data, uint w, uint h, uint d = 1);
bool load(const char * name); bool load(const char * name);
void free();
void resize(uint w, uint h, uint d = 1); void resize(uint w, uint h, uint d = 1);
void wrap(void * data, uint w, uint h, uint d = 1); void wrap(void * data, uint w, uint h, uint d = 1);
void unwrap(); void unwrap();
uint width() const;
uint height() const;
uint depth() const;
const Color32 * scanline(uint h) const; const Color32 * scanline(uint h) const;
Color32 * scanline(uint h); Color32 * scanline(uint h);
@ -58,36 +51,28 @@ namespace nv
const Color32 & pixel(uint x, uint y, uint z = 0) const; const Color32 & pixel(uint x, uint y, uint z = 0) const;
Color32 & pixel(uint x, uint y, uint z = 0); Color32 & pixel(uint x, uint y, uint z = 0);
Format format() const;
void setFormat(Format f);
void fill(Color32 c); void fill(Color32 c);
private:
void free();
private: uint width = 0;
uint m_width; uint height = 0;
uint m_height; uint depth = 0;
uint m_depth; Format format = Format_XRGB;
Format m_format; bool sRGB = false;
Color32 * m_data; Color32 * data = NULL;
}; };
inline const Color32 & Image::pixel(uint x, uint y, uint z) const inline const Color32 & Image::pixel(uint x, uint y, uint z) const
{ {
nvDebugCheck(x < m_width && y < m_height && z < m_depth); nvDebugCheck(x < width && y < height && z < depth);
return pixel((z * m_height + y) * m_width + x); return pixel((z * height + y) * width + x);
} }
inline Color32 & Image::pixel(uint x, uint y, uint z) inline Color32 & Image::pixel(uint x, uint y, uint z)
{ {
nvDebugCheck(x < m_width && y < m_height && z < m_depth); nvDebugCheck(x < width && y < height && z < depth);
return pixel((z * m_height + y) * m_width + x); return pixel((z * height + y) * width + x);
} }
} // nv namespace } // nv namespace
#endif // NV_IMAGE_IMAGE_H

@ -55,12 +55,15 @@ extern "C" {
#endif #endif
#if defined(NV_HAVE_STBIMAGE) #if defined(NV_HAVE_STBIMAGE)
# define STB_IMAGE_STATIC // To avoid conflicts with users importing stb_image on their own.
# define STB_IMAGE_IMPLEMENTATION # define STB_IMAGE_IMPLEMENTATION
# define STBI_NO_STDIO # define STBI_NO_STDIO
# pragma warning(push) # include "stb_image.h"
# pragma warning(disable: 4312)
# include <stb_image.h> //# define STB_IMAGE_WRITE_STATIC
# pragma warning(pop) //# define STB_IMAGE_WRITE_IMPLEMENTATION
//# define STBI_WRITE_NO_STDIO
//# include "stb_image_write.h"
#endif #endif
@ -68,7 +71,7 @@ using namespace nv;
struct Color555 { /*struct Color555 {
uint16 b : 5; uint16 b : 5;
uint16 g : 5; uint16 g : 5;
uint16 r : 5; uint16 r : 5;
@ -198,7 +201,7 @@ static Image * loadTGA(Stream & s)
} }
} }
else if( grey ) { else if( grey ) {
img->setFormat(Image::Format_ARGB); img->format = Image::Format_ARGB;
for( int y = 0; y < tga.height; y++ ) { for( int y = 0; y < tga.height; y++ ) {
for( int x = 0; x < tga.width; x++ ) { for( int x = 0; x < tga.width; x++ ) {
@ -233,7 +236,7 @@ static Image * loadTGA(Stream & s)
} }
} }
else if( tga.pixel_size == 32 ) { else if( tga.pixel_size == 32 ) {
img->setFormat(Image::Format_ARGB); img->format = Image::Format_ARGB;
for( int y = 0; y < tga.height; y++ ) { for( int y = 0; y < tga.height; y++ ) {
for( int x = 0; x < tga.width; x++ ) { for( int x = 0; x < tga.width; x++ ) {
@ -250,6 +253,7 @@ static Image * loadTGA(Stream & s)
return img.release(); return img.release();
} }
*/
// Save TGA image. // Save TGA image.
static bool saveTGA(Stream & s, const Image * img) static bool saveTGA(Stream & s, const Image * img)
@ -269,9 +273,9 @@ static bool saveTGA(Stream & s, const Image * img)
tga.head.x_origin = 0; tga.head.x_origin = 0;
tga.head.y_origin = 0; tga.head.y_origin = 0;
tga.head.width = img->width(); tga.head.width = img->width;
tga.head.height = img->height(); tga.head.height = img->height;
if(img->format() == Image::Format_ARGB) { if(img->format == Image::Format_ARGB) {
tga.head.pixel_size = 32; tga.head.pixel_size = 32;
tga.head.flags = TGA_ORIGIN_UPPER | TGA_HAS_ALPHA; tga.head.flags = TGA_ORIGIN_UPPER | TGA_HAS_ALPHA;
} }
@ -283,8 +287,8 @@ static bool saveTGA(Stream & s, const Image * img)
// @@ Serialize directly. // @@ Serialize directly.
tga.allocate(); tga.allocate();
const uint n = img->width() * img->height(); const uint n = img->width * img->height;
if(img->format() == Image::Format_ARGB) { if(img->format == Image::Format_ARGB) {
for(uint i = 0; i < n; i++) { for(uint i = 0; i < n; i++) {
Color32 color = img->pixel(i); Color32 color = img->pixel(i);
tga.mem[4 * i + 0] = color.b; tga.mem[4 * i + 0] = color.b;
@ -309,13 +313,13 @@ static bool saveTGA(Stream & s, const Image * img)
return true; return true;
} }
#pragma optimize("", off) /*#pragma optimize("", off)
// Save BMP image. // Save BMP image.
static bool saveBMP(Stream & s, const Image * img) static bool saveBMP(Stream & s, const Image * img)
{ {
int w = img->width(); int w = img->width;
int h = img->height(); int h = img->height;
int image_size = w * h * 3; int image_size = w * h * 3;
BmpFileHeader header; BmpFileHeader header;
@ -352,7 +356,7 @@ static bool saveBMP(Stream & s, const Image * img)
} }
return true; return true;
} }*/
/*static Image * loadPPM(Stream & s) /*static Image * loadPPM(Stream & s)
{ {
@ -366,8 +370,8 @@ static bool savePPM(Stream & s, const Image * img)
//if (img->depth() != 1) return false; //if (img->depth() != 1) return false;
//if (img->format() == Image::Format_ARGB) return false; //if (img->format() == Image::Format_ARGB) return false;
uint w = img->width(); uint w = img->width;
uint h = img->height(); uint h = img->height;
TextWriter writer(&s); TextWriter writer(&s);
writer.format("P6\n"); writer.format("P6\n");
@ -396,7 +400,7 @@ static bool savePPM(Stream & s, const Image * img)
}*/ }*/
// Load PSD image. // Load PSD image.
static Image * loadPSD(Stream & s) /*static Image * loadPSD(Stream & s)
{ {
nvCheck(!s.isError()); nvCheck(!s.isError());
nvCheck(s.isLoading()); nvCheck(s.isLoading());
@ -457,7 +461,7 @@ static Image * loadPSD(Stream & s)
else else
{ {
// Enable alpha. // Enable alpha.
img->setFormat(Image::Format_ARGB); img->format = Image::Format_ARGB;
// Ignore remaining channels. // Ignore remaining channels.
channel_num = 4; channel_num = 4;
@ -545,7 +549,7 @@ static Image * loadPSD(Stream & s)
} }
return img.release(); return img.release();
} }*/
static FloatImage * loadFloatDDS(Stream & s) static FloatImage * loadFloatDDS(Stream & s)
{ {
@ -1766,7 +1770,7 @@ static Image * loadSTB(Stream & s)
if (data != NULL) { if (data != NULL) {
Image * img = new Image; Image * img = new Image;
img->acquire((Color32 *)data, w, h); img->acquire((Color32 *)data, w, h);
img->setFormat(n == 4 ? Image::Format_ARGB : Image::Format_RGB); img->format = (n == 4) ? Image::Format_ARGB : Image::Format_XRGB;
int count = w * h; int count = w * h;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
@ -1840,13 +1844,13 @@ Image * nv::ImageIO::load(const char * fileName, Stream & s)
const char * extension = Path::extension(fileName); const char * extension = Path::extension(fileName);
if (strCaseDiff(extension, ".tga") == 0) { /*if (strCaseDiff(extension, ".tga") == 0) {
return loadTGA(s); return loadTGA(s);
} }*/
if (strCaseDiff(extension, ".psd") == 0) { /*if (strCaseDiff(extension, ".psd") == 0) {
return loadPSD(s); return loadPSD(s);
} }*/
/*if (strCaseDiff(extension, ".ppm") == 0) { /*if (strCaseDiff(extension, ".ppm") == 0) {
return loadPPM(s); return loadPPM(s);
@ -1887,9 +1891,9 @@ bool nv::ImageIO::save(const char * fileName, Stream & s, const Image * img, con
const char * extension = Path::extension(fileName); const char * extension = Path::extension(fileName);
if (strCaseDiff(extension, ".bmp") == 0) { /*if (strCaseDiff(extension, ".bmp") == 0) {
return saveBMP(s, img); return saveBMP(s, img);
} }*/
if (strCaseDiff(extension, ".tga") == 0) { if (strCaseDiff(extension, ".tga") == 0) {
return saveTGA(s, img); return saveTGA(s, img);
@ -2030,7 +2034,7 @@ bool nv::ImageIO::saveFloat(const char * fileName, Stream & s, const FloatImage
if (componentCount == 1) if (componentCount == 1)
{ {
Color32 * c = image->pixels(); Color32 * c = image->pixels();
const uint count = image->width() * image->height(); const uint count = image->width * image->height;
for (uint i = 0; i < count; i++) for (uint i = 0; i < count; i++)
{ {
c[i].b = c[i].g = c[i].r; c[i].b = c[i].g = c[i].r;
@ -2039,7 +2043,7 @@ bool nv::ImageIO::saveFloat(const char * fileName, Stream & s, const FloatImage
if (componentCount == 4) if (componentCount == 4)
{ {
image->setFormat(Image::Format_ARGB); image->format = Image::Format_ARGB;
} }
return ImageIO::save(fileName, s, image.ptr()); return ImageIO::save(fileName, s, image.ptr());

@ -1,14 +1,8 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once #pragma once
#ifndef NV_IMAGE_IMAGEIO_H
#define NV_IMAGE_IMAGEIO_H
#include "nvimage.h" #include "nvimage.h"
#include "nvcore/StrLib.h"
namespace nv namespace nv
{ {
class Image; class Image;
@ -17,21 +11,18 @@ namespace nv
namespace ImageIO namespace ImageIO
{ {
NVIMAGE_API Image * load(const char * fileName); Image * load(const char * fileName);
NVIMAGE_API Image * load(const char * fileName, Stream & s); Image * load(const char * fileName, Stream & s);
NVIMAGE_API FloatImage * loadFloat(const char * fileName); FloatImage * loadFloat(const char * fileName);
NVIMAGE_API FloatImage * loadFloat(const char * fileName, Stream & s); FloatImage * loadFloat(const char * fileName, Stream & s);
NVIMAGE_API bool save(const char * fileName, const Image * img, const char ** tags=NULL); // NULL terminated list. bool save(const char * fileName, const Image * img, const char ** tags=NULL); // NULL terminated list.
NVIMAGE_API bool save(const char * fileName, Stream & s, const Image * img, const char ** tags=NULL); bool save(const char * fileName, Stream & s, const Image * img, const char ** tags=NULL);
NVIMAGE_API bool saveFloat(const char * fileName, const FloatImage * fimage, uint baseComponent, uint componentCount); bool saveFloat(const char * fileName, const FloatImage * fimage, uint baseComponent, uint componentCount);
NVIMAGE_API bool saveFloat(const char * fileName, Stream & s, const FloatImage * fimage, uint baseComponent, uint componentCount); bool saveFloat(const char * fileName, Stream & s, const FloatImage * fimage, uint baseComponent, uint componentCount);
} // ImageIO namespace } // ImageIO namespace
} // nv namespace } // nv namespace
#endif // NV_IMAGE_IMAGEIO_H

@ -130,7 +130,7 @@ namespace nv
}; };
NVIMAGE_API Stream & operator<< (Stream & s, KtxHeader & header); Stream & operator<< (Stream & s, KtxHeader & header);
/* struct KtxFile { /* struct KtxFile {

@ -43,8 +43,8 @@ static FloatImage * createNormalMap(const Image * img, FloatImage::WrapMode wm,
nvDebugCheck(kdv != NULL); nvDebugCheck(kdv != NULL);
nvDebugCheck(img != NULL); nvDebugCheck(img != NULL);
const uint w = img->width(); const uint w = img->width;
const uint h = img->height(); const uint h = img->height;
AutoPtr<FloatImage> fimage(new FloatImage()); AutoPtr<FloatImage> fimage(new FloatImage());
fimage->allocate(4, w, h); fimage->allocate(4, w, h);

@ -1,32 +1,13 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once #pragma once
#ifndef NV_IMAGE_H
#define NV_IMAGE_H
#include "nvcore/nvcore.h" #include "nvcore/nvcore.h"
#include "nvcore/Debug.h" // nvDebugCheck #include "nvcore/Debug.h" // nvDebugCheck
#include "nvcore/Utils.h" // isPowerOfTwo #include "nvcore/Utils.h" // isPowerOfTwo
// 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
namespace nv { namespace nv {
// Some utility functions: // Some utility functions:
inline uint computeBitPitch(uint w, uint bitsize, uint alignmentInBits) inline uint computeBitPitch(uint w, uint bitsize, uint alignmentInBits)
{ {
nvDebugCheck(isPowerOfTwo(alignmentInBits)); nvDebugCheck(isPowerOfTwo(alignmentInBits));
@ -42,7 +23,4 @@ namespace nv {
return (pitch + 7) / 8; return (pitch + 7) / 8;
} }
} // nv namespace } // nv namespace
#endif // NV_IMAGE_H

Loading…
Cancel
Save