More cleanups. Assume static linking.

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

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

File diff suppressed because it is too large Load Diff

@ -1,29 +1,5 @@
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.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.
// MIT license see full LICENSE text at end of file
#pragma once
#ifndef NV_IMAGE_DIRECTDRAWSURFACE_H
#define NV_IMAGE_DIRECTDRAWSURFACE_H
#include "nvimage.h"
@ -34,8 +10,8 @@
namespace nv
{
class Image;
class FloatImage;
class Stream;
struct ColorBlock;
enum DDPF
{
@ -269,7 +245,6 @@ namespace nv
};
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);
struct RGBAPixelFormat
@ -281,9 +256,10 @@ namespace nv
uint amask;
};
extern const RGBAPixelFormat *findD3D9PixelFormat(uint dxgiFormat);
extern const RGBAPixelFormat *findDXGIPixelFormat(uint dxgiFormat);
struct NVIMAGE_CLASS DDSPixelFormat
struct DDSPixelFormat
{
uint size;
uint flags;
@ -295,7 +271,7 @@ namespace nv
uint amask;
};
struct NVIMAGE_CLASS DDSCaps
struct DDSCaps
{
uint caps1;
uint caps2;
@ -304,7 +280,7 @@ namespace nv
};
/// DDS file header for DX10.
struct NVIMAGE_CLASS DDSHeader10
struct DDSHeader10
{
uint dxgiFormat;
uint resourceDimension;
@ -314,7 +290,7 @@ namespace nv
};
/// DDS file header.
struct NVIMAGE_CLASS DDSHeader
struct DDSHeader
{
uint fourcc;
uint size;
@ -369,16 +345,14 @@ namespace nv
bool isBlockFormat() const;
};
NVIMAGE_API Stream & operator<< (Stream & s, DDSHeader & header);
Stream & operator<< (Stream & s, DDSHeader & header);
/// DirectDraw Surface. (DDS)
class NVIMAGE_CLASS DirectDrawSurface
class DirectDrawSurface
{
public:
DirectDrawSurface();
DirectDrawSurface(const char * file);
DirectDrawSurface(Stream * stream);
~DirectDrawSurface();
bool load(const char * filename);
@ -388,6 +362,7 @@ namespace nv
bool isSupported() const;
bool hasAlpha() const;
bool isColorsRGB() const;
uint mipmapCount() const;
uint width() const;
@ -399,13 +374,12 @@ namespace nv
bool isTexture3D() const;
bool isTextureCube() const;
bool isTextureArray() const;
bool isBlockFormat() const;
void setNormalFlag(bool b);
void setHasAlphaFlag(bool b);
void setUserVersion(int version);
void mipmap(Image * img, uint f, uint m);
uint surfaceWidth(uint mipmap) const;
uint surfaceHeight(uint mipmap) const;
uint surfaceDepth(uint mipmap) const;
@ -422,15 +396,35 @@ namespace nv
uint faceSize() const;
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;
//void * data;
};
bool imageFromDDS(Image * img, DirectDrawSurface & dds, uint face, uint mipmap);
bool imageFromDDS(FloatImage * img, DirectDrawSurface & dds, uint face, uint mipmap);
} // 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
#pragma once
#ifndef NV_IMAGE_FILTER_H
#define NV_IMAGE_FILTER_H
#include "nvimage.h"
#include "nvcore/Debug.h"
@ -12,7 +9,7 @@ namespace nv
class Vector4;
/// Base filter class.
class NVIMAGE_CLASS Filter
class Filter
{
public:
Filter(float width);
@ -30,7 +27,7 @@ namespace nv
};
// Box filter.
class NVIMAGE_CLASS BoxFilter : public Filter
class BoxFilter : public Filter
{
public:
BoxFilter();
@ -39,7 +36,7 @@ namespace nv
};
// Triangle (bilinear/tent) filter.
class NVIMAGE_CLASS TriangleFilter : public Filter
class TriangleFilter : public Filter
{
public:
TriangleFilter();
@ -48,7 +45,7 @@ namespace nv
};
// Quadratic (bell) filter.
class NVIMAGE_CLASS QuadraticFilter : public Filter
class QuadraticFilter : public Filter
{
public:
QuadraticFilter();
@ -56,7 +53,7 @@ namespace nv
};
// Cubic filter from Thatcher Ulrich.
class NVIMAGE_CLASS CubicFilter : public Filter
class CubicFilter : public Filter
{
public:
CubicFilter();
@ -64,7 +61,7 @@ namespace nv
};
// Cubic b-spline filter from Paul Heckbert.
class NVIMAGE_CLASS BSplineFilter : public Filter
class BSplineFilter : public Filter
{
public:
BSplineFilter();
@ -73,7 +70,7 @@ namespace nv
/// Mitchell & Netravali's two-param cubic
/// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
class NVIMAGE_CLASS MitchellFilter : public Filter
class MitchellFilter : public Filter
{
public:
MitchellFilter();
@ -87,7 +84,7 @@ namespace nv
};
// Lanczos3 filter.
class NVIMAGE_CLASS LanczosFilter : public Filter
class LanczosFilter : public Filter
{
public:
LanczosFilter();
@ -95,7 +92,7 @@ namespace nv
};
// Sinc filter.
class NVIMAGE_CLASS SincFilter : public Filter
class SincFilter : public Filter
{
public:
SincFilter(float w);
@ -103,7 +100,7 @@ namespace nv
};
// Kaiser filter.
class NVIMAGE_CLASS KaiserFilter : public Filter
class KaiserFilter : public Filter
{
public:
KaiserFilter(float w);
@ -132,7 +129,7 @@ namespace nv
/// A 1D kernel. Used to precompute filter weights.
class NVIMAGE_CLASS Kernel1
class Kernel1
{
NV_FORBID_COPY(Kernel1);
public:
@ -162,7 +159,7 @@ namespace nv
/// A 2D kernel.
class NVIMAGE_CLASS Kernel2
class Kernel2
{
public:
Kernel2(uint width);
@ -195,7 +192,7 @@ namespace nv
/// A 1D polyphase kernel
class NVIMAGE_CLASS PolyphaseKernel
class PolyphaseKernel
{
NV_FORBID_COPY(PolyphaseKernel);
public:
@ -230,5 +227,3 @@ namespace nv
};
} // nv namespace
#endif // NV_IMAGE_FILTER_H

@ -56,9 +56,9 @@ void FloatImage::initFrom(const Image * img)
nvCheck(img != NULL);
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 * green_channel = channel(1);

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

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

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

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

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

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

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

Loading…
Cancel
Save