Merge private branch.
This commit is contained in:
@ -23,10 +23,10 @@
|
||||
|
||||
#include "BlockDXT.h"
|
||||
|
||||
#include <nvimage/ColorBlock.h>
|
||||
#include "ColorBlock.h"
|
||||
|
||||
#include <nvcore/Stream.h>
|
||||
#include <nvcore/Containers.h> // swap
|
||||
#include "nvcore/Stream.h"
|
||||
#include "nvcore/Utils.h" // swap
|
||||
|
||||
|
||||
using namespace nv;
|
||||
|
@ -1,9 +1,11 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#include <nvcore/Containers.h> // swap
|
||||
#include <nvmath/Box.h>
|
||||
#include <nvimage/ColorBlock.h>
|
||||
#include <nvimage/Image.h>
|
||||
#include "ColorBlock.h"
|
||||
#include "Image.h"
|
||||
|
||||
#include "nvmath/Box.h"
|
||||
#include "nvcore/Utils.h" // swap
|
||||
|
||||
|
||||
using namespace nv;
|
||||
|
||||
@ -179,28 +181,28 @@ bool ColorBlock::isSingleColor() const
|
||||
/// Returns true if the block has a single color, ignoring transparent pixels.
|
||||
bool ColorBlock::isSingleColorNoAlpha() const
|
||||
{
|
||||
Color32 c;
|
||||
int i;
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
if (m_color[i].a != 0) {
|
||||
c = m_color[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
Color32 c;
|
||||
int i;
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
if (m_color[i].a != 0) {
|
||||
c = m_color[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
|
||||
uint u = c.u & mask.u;
|
||||
Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
|
||||
uint u = c.u & mask.u;
|
||||
|
||||
for(; i < 16; i++)
|
||||
{
|
||||
if (u != (m_color[i].u & mask.u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(; i < 16; i++)
|
||||
{
|
||||
if (u != (m_color[i].u & mask.u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_IMAGE_COLORBLOCK_H
|
||||
#define NV_IMAGE_COLORBLOCK_H
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
@ -21,15 +21,15 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include <nvimage/DirectDrawSurface.h>
|
||||
#include <nvimage/ColorBlock.h>
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/BlockDXT.h>
|
||||
#include <nvimage/PixelFormat.h>
|
||||
#include "DirectDrawSurface.h"
|
||||
#include "ColorBlock.h"
|
||||
#include "Image.h"
|
||||
#include "BlockDXT.h"
|
||||
#include "PixelFormat.h"
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include <nvcore/Containers.h> // max
|
||||
#include <nvcore/StdStream.h>
|
||||
#include "nvcore/Debug.h"
|
||||
#include "nvcore/Utils.h" // max
|
||||
#include "nvcore/StdStream.h"
|
||||
|
||||
#include <string.h> // memset
|
||||
|
||||
@ -469,57 +469,57 @@ namespace nv
|
||||
/* Not used!
|
||||
namespace
|
||||
{
|
||||
struct FormatDescriptor
|
||||
{
|
||||
uint format;
|
||||
uint bitcount;
|
||||
uint rmask;
|
||||
uint gmask;
|
||||
uint bmask;
|
||||
uint amask;
|
||||
};
|
||||
struct FormatDescriptor
|
||||
{
|
||||
uint format;
|
||||
uint bitcount;
|
||||
uint rmask;
|
||||
uint gmask;
|
||||
uint bmask;
|
||||
uint amask;
|
||||
};
|
||||
|
||||
static const FormatDescriptor s_d3dFormats[] =
|
||||
{
|
||||
{ D3DFMT_R8G8B8, 24, 0xFF0000, 0xFF00, 0xFF, 0 },
|
||||
{ D3DFMT_A8R8G8B8, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000 }, // DXGI_FORMAT_B8G8R8A8_UNORM
|
||||
{ D3DFMT_X8R8G8B8, 32, 0xFF0000, 0xFF00, 0xFF, 0 }, // DXGI_FORMAT_B8G8R8X8_UNORM
|
||||
{ D3DFMT_R5G6B5, 16, 0xF800, 0x7E0, 0x1F, 0 }, // DXGI_FORMAT_B5G6R5_UNORM
|
||||
{ D3DFMT_X1R5G5B5, 16, 0x7C00, 0x3E0, 0x1F, 0 },
|
||||
{ D3DFMT_A1R5G5B5, 16, 0x7C00, 0x3E0, 0x1F, 0x8000 }, // DXGI_FORMAT_B5G5R5A1_UNORM
|
||||
{ D3DFMT_A4R4G4B4, 16, 0xF00, 0xF0, 0xF, 0xF000 },
|
||||
{ D3DFMT_R3G3B2, 8, 0xE0, 0x1C, 0x3, 0 },
|
||||
{ D3DFMT_A8, 8, 0, 0, 0, 8 }, // DXGI_FORMAT_A8_UNORM
|
||||
{ D3DFMT_A8R3G3B2, 16, 0xE0, 0x1C, 0x3, 0xFF00 },
|
||||
{ D3DFMT_X4R4G4B4, 16, 0xF00, 0xF0, 0xF, 0 },
|
||||
{ D3DFMT_A2B10G10R10, 32, 0x3FF, 0xFFC00, 0x3FF00000, 0xC0000000 }, // DXGI_FORMAT_R10G10B10A2
|
||||
{ D3DFMT_A8B8G8R8, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000 }, // DXGI_FORMAT_R8G8B8A8_UNORM
|
||||
{ D3DFMT_X8B8G8R8, 32, 0xFF, 0xFF00, 0xFF0000, 0 },
|
||||
{ D3DFMT_G16R16, 32, 0xFFFF, 0xFFFF0000, 0, 0 }, // DXGI_FORMAT_R16G16_UNORM
|
||||
{ D3DFMT_A2R10G10B10, 32, 0x3FF00000, 0xFFC00, 0x3FF, 0xC0000000 },
|
||||
static const FormatDescriptor s_d3dFormats[] =
|
||||
{
|
||||
{ D3DFMT_R8G8B8, 24, 0xFF0000, 0xFF00, 0xFF, 0 },
|
||||
{ D3DFMT_A8R8G8B8, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000 }, // DXGI_FORMAT_B8G8R8A8_UNORM
|
||||
{ D3DFMT_X8R8G8B8, 32, 0xFF0000, 0xFF00, 0xFF, 0 }, // DXGI_FORMAT_B8G8R8X8_UNORM
|
||||
{ D3DFMT_R5G6B5, 16, 0xF800, 0x7E0, 0x1F, 0 }, // DXGI_FORMAT_B5G6R5_UNORM
|
||||
{ D3DFMT_X1R5G5B5, 16, 0x7C00, 0x3E0, 0x1F, 0 },
|
||||
{ D3DFMT_A1R5G5B5, 16, 0x7C00, 0x3E0, 0x1F, 0x8000 }, // DXGI_FORMAT_B5G5R5A1_UNORM
|
||||
{ D3DFMT_A4R4G4B4, 16, 0xF00, 0xF0, 0xF, 0xF000 },
|
||||
{ D3DFMT_R3G3B2, 8, 0xE0, 0x1C, 0x3, 0 },
|
||||
{ D3DFMT_A8, 8, 0, 0, 0, 8 }, // DXGI_FORMAT_A8_UNORM
|
||||
{ D3DFMT_A8R3G3B2, 16, 0xE0, 0x1C, 0x3, 0xFF00 },
|
||||
{ D3DFMT_X4R4G4B4, 16, 0xF00, 0xF0, 0xF, 0 },
|
||||
{ D3DFMT_A2B10G10R10, 32, 0x3FF, 0xFFC00, 0x3FF00000, 0xC0000000 }, // DXGI_FORMAT_R10G10B10A2
|
||||
{ D3DFMT_A8B8G8R8, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000 }, // DXGI_FORMAT_R8G8B8A8_UNORM
|
||||
{ D3DFMT_X8B8G8R8, 32, 0xFF, 0xFF00, 0xFF0000, 0 },
|
||||
{ D3DFMT_G16R16, 32, 0xFFFF, 0xFFFF0000, 0, 0 }, // DXGI_FORMAT_R16G16_UNORM
|
||||
{ D3DFMT_A2R10G10B10, 32, 0x3FF00000, 0xFFC00, 0x3FF, 0xC0000000 },
|
||||
|
||||
{ D3DFMT_L8, 8, 8, 0, 0, 0 }, // DXGI_FORMAT_R8_UNORM
|
||||
{ D3DFMT_L16, 16, 16, 0, 0, 0 }, // DXGI_FORMAT_R16_UNORM
|
||||
};
|
||||
{ D3DFMT_L8, 8, 8, 0, 0, 0 }, // DXGI_FORMAT_R8_UNORM
|
||||
{ D3DFMT_L16, 16, 16, 0, 0, 0 }, // DXGI_FORMAT_R16_UNORM
|
||||
};
|
||||
|
||||
static const uint s_d3dFormatCount = sizeof(s_d3dFormats) / sizeof(s_d3dFormats[0]);
|
||||
static const uint s_d3dFormatCount = sizeof(s_d3dFormats) / sizeof(s_d3dFormats[0]);
|
||||
|
||||
static uint findD3D9Format(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
|
||||
{
|
||||
for (int i = 0; i < s_d3dFormatCount; i++)
|
||||
{
|
||||
if (s_d3dFormats[i].bitcount == bitcount &&
|
||||
s_d3dFormats[i].rmask == rmask &&
|
||||
s_d3dFormats[i].gmask == gmask &&
|
||||
s_d3dFormats[i].bmask == bmask &&
|
||||
s_d3dFormats[i].amask == amask)
|
||||
{
|
||||
return s_d3dFormats[i].format;
|
||||
}
|
||||
}
|
||||
static uint findD3D9Format(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
|
||||
{
|
||||
for (int i = 0; i < s_d3dFormatCount; i++)
|
||||
{
|
||||
if (s_d3dFormats[i].bitcount == bitcount &&
|
||||
s_d3dFormats[i].rmask == rmask &&
|
||||
s_d3dFormats[i].gmask == gmask &&
|
||||
s_d3dFormats[i].bmask == bmask &&
|
||||
s_d3dFormats[i].amask == amask)
|
||||
{
|
||||
return s_d3dFormats[i].format;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_IMAGE_DIRECTDRAWSURFACE_H
|
||||
#define NV_IMAGE_DIRECTDRAWSURFACE_H
|
||||
|
||||
|
@ -35,8 +35,10 @@
|
||||
|
||||
#include "Filter.h"
|
||||
|
||||
#include <nvmath/Vector.h> // Vector4
|
||||
#include <nvcore/Containers.h> // swap
|
||||
#include "nvmath/Vector.h" // Vector4
|
||||
#include "nvcore/Utils.h" // swap
|
||||
|
||||
#include <string.h> // memset
|
||||
|
||||
using namespace nv;
|
||||
|
||||
@ -360,17 +362,17 @@ void Kernel2::transpose()
|
||||
void Kernel2::initLaplacian()
|
||||
{
|
||||
nvDebugCheck(m_windowSize == 3);
|
||||
// m_data[0] = -1; m_data[1] = -1; m_data[2] = -1;
|
||||
// m_data[3] = -1; m_data[4] = +8; m_data[5] = -1;
|
||||
// m_data[6] = -1; m_data[7] = -1; m_data[8] = -1;
|
||||
// m_data[0] = -1; m_data[1] = -1; m_data[2] = -1;
|
||||
// m_data[3] = -1; m_data[4] = +8; m_data[5] = -1;
|
||||
// m_data[6] = -1; m_data[7] = -1; m_data[8] = -1;
|
||||
|
||||
m_data[0] = +0; m_data[1] = -1; m_data[2] = +0;
|
||||
m_data[3] = -1; m_data[4] = +4; m_data[5] = -1;
|
||||
m_data[6] = +0; m_data[7] = -1; m_data[8] = +0;
|
||||
|
||||
// m_data[0] = +1; m_data[1] = -2; m_data[2] = +1;
|
||||
// m_data[3] = -2; m_data[4] = +4; m_data[5] = -2;
|
||||
// m_data[6] = +1; m_data[7] = -2; m_data[8] = +1;
|
||||
// m_data[0] = +1; m_data[1] = -2; m_data[2] = +1;
|
||||
// m_data[3] = -2; m_data[4] = +4; m_data[5] = -2;
|
||||
// m_data[6] = +1; m_data[7] = -2; m_data[8] = +1;
|
||||
}
|
||||
|
||||
|
||||
@ -487,7 +489,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 9*9; i++) {
|
||||
m_data[i] = elements[i] * scale.w();
|
||||
m_data[i] = elements[i] * scale.w;
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -503,7 +505,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int e = 0; e < 7; e++) {
|
||||
m_data[(i + 1) * 9 + e + 1] += elements[i * 7 + e] * scale.z();
|
||||
m_data[(i + 1) * 9 + e + 1] += elements[i * 7 + e] * scale.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -518,7 +520,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int e = 0; e < 5; e++) {
|
||||
m_data[(i + 2) * 9 + e + 2] += elements[i * 5 + e] * scale.y();
|
||||
m_data[(i + 2) * 9 + e + 2] += elements[i * 5 + e] * scale.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -531,7 +533,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int e = 0; e < 3; e++) {
|
||||
m_data[(i + 3) * 9 + e + 3] += elements[i * 3 + e] * scale.x();
|
||||
m_data[(i + 3) * 9 + e + 3] += elements[i * 3 + e] * scale.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_IMAGE_FILTER_H
|
||||
#define NV_IMAGE_FILTER_H
|
||||
|
||||
#include <nvimage/nvimage.h>
|
||||
#include <nvcore/Debug.h>
|
||||
#include "nvimage.h"
|
||||
#include "nvcore/Debug.h"
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
@ -4,11 +4,13 @@
|
||||
#include "Filter.h"
|
||||
#include "Image.h"
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include <nvmath/Matrix.h>
|
||||
#include "nvmath/Color.h"
|
||||
#include "nvmath/Matrix.h"
|
||||
|
||||
#include <nvcore/Containers.h>
|
||||
#include <nvcore/Ptr.h>
|
||||
#include "nvcore/Utils.h" // max
|
||||
#include "nvcore/Ptr.h"
|
||||
#include "nvcore/Memory.h"
|
||||
#include "nvcore/Array.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@ -150,6 +152,16 @@ void FloatImage::clear(float f/*=0.0f*/)
|
||||
}
|
||||
}
|
||||
|
||||
void FloatImage::clear(uint component, float f/*= 0.0f*/)
|
||||
{
|
||||
float * channel = this->channel(component);
|
||||
|
||||
const uint size = m_width * m_height;
|
||||
for(uint i = 0; i < size; i++) {
|
||||
channel[i] = f;
|
||||
}
|
||||
}
|
||||
|
||||
void FloatImage::normalize(uint base_component)
|
||||
{
|
||||
nvCheck(base_component + 3 <= m_componentNum);
|
||||
@ -164,20 +176,20 @@ void FloatImage::normalize(uint base_component)
|
||||
Vector3 normal(xChannel[i], yChannel[i], zChannel[i]);
|
||||
normal = normalizeSafe(normal, Vector3(zero), 0.0f);
|
||||
|
||||
xChannel[i] = normal.x();
|
||||
yChannel[i] = normal.y();
|
||||
zChannel[i] = normal.z();
|
||||
xChannel[i] = normal.x;
|
||||
yChannel[i] = normal.y;
|
||||
zChannel[i] = normal.z;
|
||||
}
|
||||
}
|
||||
|
||||
void FloatImage::packNormals(uint base_component)
|
||||
{
|
||||
scaleBias(base_component, 3, 0.5f, 0.5f);
|
||||
scaleBias(base_component, 3, 0.5f, 1.0f);
|
||||
}
|
||||
|
||||
void FloatImage::expandNormals(uint base_component)
|
||||
{
|
||||
scaleBias(base_component, 3, 2.0f, -1.0f);
|
||||
scaleBias(base_component, 3, 2, -0.5);
|
||||
}
|
||||
|
||||
void FloatImage::scaleBias(uint base_component, uint num, float scale, float bias)
|
||||
@ -188,22 +200,16 @@ void FloatImage::scaleBias(uint base_component, uint num, float scale, float bia
|
||||
float * ptr = this->channel(base_component + c);
|
||||
|
||||
for(uint i = 0; i < size; i++) {
|
||||
ptr[i] = scale * ptr[i] + bias;
|
||||
ptr[i] = scale * (ptr[i] + bias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clamp the elements of the image.
|
||||
void FloatImage::clamp(uint base_component, uint num, float low, float high)
|
||||
void FloatImage::clamp(float low, float high)
|
||||
{
|
||||
const uint size = m_width * m_height;
|
||||
|
||||
for(uint c = 0; c < num; c++) {
|
||||
float * ptr = this->channel(base_component + c);
|
||||
|
||||
for(uint i = 0; i < size; i++) {
|
||||
ptr[i] = nv::clamp(ptr[i], low, high);
|
||||
}
|
||||
for(uint i = 0; i < m_count; i++) {
|
||||
m_mem[i] = nv::clamp(m_mem[i], low, high);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,10 +255,10 @@ void FloatImage::transform(uint base_component, const Matrix & m, Vector4::Arg o
|
||||
{
|
||||
Vector4 color = nv::transform(m, Vector4(*r, *g, *b, *a)) + offset;
|
||||
|
||||
*r++ = color.x();
|
||||
*g++ = color.y();
|
||||
*b++ = color.z();
|
||||
*a++ = color.w();
|
||||
*r++ = color.x;
|
||||
*g++ = color.y;
|
||||
*b++ = color.z;
|
||||
*a++ = color.w;
|
||||
}
|
||||
}
|
||||
|
||||
@ -932,7 +938,6 @@ void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Vertical flip in place.
|
||||
void FloatImage::flip()
|
||||
{
|
||||
@ -998,7 +1003,6 @@ void FloatImage::scaleAlphaToCoverage(float desiredCoverage, float alphaRef, int
|
||||
scaleBias(alphaChannel, 1, alphaScale, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
FloatImage* FloatImage::clone() const
|
||||
{
|
||||
FloatImage* copy = new FloatImage();
|
||||
|
@ -3,30 +3,28 @@
|
||||
#ifndef NV_IMAGE_FLOATIMAGE_H
|
||||
#define NV_IMAGE_FLOATIMAGE_H
|
||||
|
||||
#include <nvimage/nvimage.h>
|
||||
#include "nvimage.h"
|
||||
|
||||
#include <nvmath/Vector.h>
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include <nvcore/Algorithms.h> // clamp
|
||||
#include "nvcore/Debug.h"
|
||||
#include "nvcore/Utils.h" // clamp
|
||||
|
||||
#include <stdlib.h> // abs
|
||||
|
||||
|
||||
namespace nv
|
||||
{
|
||||
class Vector4;
|
||||
class Matrix;
|
||||
class Image;
|
||||
class Filter;
|
||||
class Kernel1;
|
||||
class Kernel2;
|
||||
class PolyphaseKernel;
|
||||
class Vector4;
|
||||
class Matrix;
|
||||
class Image;
|
||||
class Filter;
|
||||
class Kernel1;
|
||||
class Kernel2;
|
||||
class PolyphaseKernel;
|
||||
|
||||
/// Multicomponent floating point image class.
|
||||
class FloatImage
|
||||
{
|
||||
public:
|
||||
/// Multicomponent floating point image class.
|
||||
class FloatImage
|
||||
{
|
||||
public:
|
||||
|
||||
enum WrapMode {
|
||||
WrapMode_Clamp,
|
||||
@ -53,15 +51,17 @@ public:
|
||||
|
||||
/** @name Manipulation. */
|
||||
//@{
|
||||
NVIMAGE_API void clear(float f=0.0f);
|
||||
NVIMAGE_API void clear(float f = 0.0f);
|
||||
NVIMAGE_API void clear(uint component, float f = 0.0f);
|
||||
|
||||
NVIMAGE_API 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 bias);
|
||||
NVIMAGE_API void scaleBias(uint base_component, uint num, float scale, float add);
|
||||
|
||||
NVIMAGE_API void clamp(uint base_component, uint num, float low, float high);
|
||||
//NVIMAGE_API void clamp(uint base_component, uint num);
|
||||
NVIMAGE_API void clamp(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);
|
||||
@ -74,9 +74,12 @@ public:
|
||||
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, WrapMode wm, uint alpha) const;
|
||||
|
||||
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, WrapMode wm) const;
|
||||
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, uint w, uint h, WrapMode wm) const;
|
||||
//@}
|
||||
|
||||
NVIMAGE_API float applyKernel(const Kernel2 * k, int x, int y, uint c, WrapMode wm) const;
|
||||
NVIMAGE_API float applyKernelVertical(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const;
|
||||
NVIMAGE_API float applyKernelHorizontal(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const;
|
||||
@ -89,7 +92,7 @@ public:
|
||||
|
||||
NVIMAGE_API float alphaTestCoverage(float alphaRef, int alphaChannel) const;
|
||||
NVIMAGE_API void scaleAlphaToCoverage(float coverage, float alphaRef, int alphaChannel);
|
||||
//@}
|
||||
|
||||
|
||||
uint width() const { return m_width; }
|
||||
uint height() const { return m_height; }
|
||||
@ -105,12 +108,11 @@ public:
|
||||
const float * scanline(uint y, uint c) const;
|
||||
float * scanline(uint y, uint c);
|
||||
|
||||
void setPixel(float f, uint x, uint y, uint c);
|
||||
void addPixel(float f, uint x, uint y, uint c);
|
||||
float pixel(uint x, uint y, uint c) const;
|
||||
float & pixel(uint x, uint y, uint c);
|
||||
|
||||
void setPixel(float f, uint idx);
|
||||
float pixel(uint idx) const;
|
||||
float & pixel(uint idx);
|
||||
|
||||
float sampleNearest(float x, float y, int c, WrapMode wm) const;
|
||||
float sampleLinear(float x, float y, int c, WrapMode wm) const;
|
||||
@ -127,7 +129,7 @@ public:
|
||||
|
||||
FloatImage* clone() const;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
uint index(uint x, uint y) const;
|
||||
uint indexClamp(int x, int y) const;
|
||||
@ -135,7 +137,7 @@ public:
|
||||
uint indexMirror(int x, int y) const;
|
||||
uint index(int x, int y, WrapMode wm) const;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
uint16 m_width; ///< Width of the texture.
|
||||
uint16 m_height; ///< Height of the texture.
|
||||
@ -143,107 +145,97 @@ public:
|
||||
uint32 m_count; ///< Image pixel count.
|
||||
float * m_mem;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/// Get const channel pointer.
|
||||
inline const float * FloatImage::channel(uint c) const
|
||||
{
|
||||
/// Get const channel pointer.
|
||||
inline const float * FloatImage::channel(uint c) const
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem + c * m_width * m_height;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get channel pointer.
|
||||
inline float * FloatImage::channel(uint c) {
|
||||
/// Get channel pointer.
|
||||
inline float * FloatImage::channel(uint c) {
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem + c * m_width * m_height;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get const scanline pointer.
|
||||
inline const float * FloatImage::scanline(uint y, uint c) const
|
||||
{
|
||||
/// Get const scanline pointer.
|
||||
inline const float * FloatImage::scanline(uint y, uint c) const
|
||||
{
|
||||
nvDebugCheck(y < m_height);
|
||||
return channel(c) + y * m_width;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get scanline pointer.
|
||||
inline float * FloatImage::scanline(uint y, uint c)
|
||||
{
|
||||
/// Get scanline pointer.
|
||||
inline float * FloatImage::scanline(uint y, uint c)
|
||||
{
|
||||
nvDebugCheck(y < m_height);
|
||||
return channel(c) + y * m_width;
|
||||
}
|
||||
}
|
||||
|
||||
/// Set pixel component.
|
||||
inline void FloatImage::setPixel(float f, uint x, uint y, uint c)
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(x < m_width);
|
||||
nvDebugCheck(y < m_height);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
m_mem[(c * m_height + y) * m_width + x] = f;
|
||||
}
|
||||
|
||||
/// Add to pixel component.
|
||||
inline void FloatImage::addPixel(float f, uint x, uint y, uint c)
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(x < m_width);
|
||||
nvDebugCheck(y < m_height);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
m_mem[(c * m_height + y) * m_width + x] += f;
|
||||
}
|
||||
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint x, uint y, uint c) const
|
||||
{
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint x, uint y, uint c) const
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(x < m_width);
|
||||
nvDebugCheck(y < m_height);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem[(c * m_height + y) * m_width + x];
|
||||
}
|
||||
}
|
||||
|
||||
/// Set pixel component.
|
||||
inline void FloatImage::setPixel(float f, uint idx)
|
||||
{
|
||||
nvDebugCheck(idx < m_count);
|
||||
m_mem[idx] = f;
|
||||
}
|
||||
/// Get pixel component.
|
||||
inline float & FloatImage::pixel(uint x, uint y, uint c)
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(x < m_width);
|
||||
nvDebugCheck(y < m_height);
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem[(c * m_height + y) * m_width + x];
|
||||
}
|
||||
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint idx) const
|
||||
{
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint idx) const
|
||||
{
|
||||
nvDebugCheck(idx < m_count);
|
||||
return m_mem[idx];
|
||||
}
|
||||
}
|
||||
|
||||
inline uint FloatImage::index(uint x, uint y) const
|
||||
{
|
||||
/// Get pixel component.
|
||||
inline float & FloatImage::pixel(uint idx)
|
||||
{
|
||||
nvDebugCheck(idx < m_count);
|
||||
return m_mem[idx];
|
||||
}
|
||||
|
||||
inline uint FloatImage::index(uint x, uint y) const
|
||||
{
|
||||
nvDebugCheck(x < m_width);
|
||||
nvDebugCheck(y < m_height);
|
||||
return y * m_width + x;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint FloatImage::indexClamp(int x, int y) const
|
||||
{
|
||||
inline uint FloatImage::indexClamp(int x, int y) const
|
||||
{
|
||||
return nv::clamp(y, int(0), int(m_height-1)) * m_width + nv::clamp(x, int(0), int(m_width-1));
|
||||
}
|
||||
}
|
||||
|
||||
inline int repeat_remainder(int a, int b)
|
||||
{
|
||||
inline int repeat_remainder(int a, int b)
|
||||
{
|
||||
if (a >= 0) return a % b;
|
||||
else return (a + 1) % b + b - 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint FloatImage::indexRepeat(int x, int y) const
|
||||
{
|
||||
inline uint FloatImage::indexRepeat(int x, int y) const
|
||||
{
|
||||
return repeat_remainder(y, m_height) * m_width + repeat_remainder(x, m_width);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint FloatImage::indexMirror(int x, int y) const
|
||||
{
|
||||
inline uint FloatImage::indexMirror(int x, int y) const
|
||||
{
|
||||
if (m_width == 1) x = 0;
|
||||
|
||||
x = abs(x);
|
||||
@ -259,14 +251,14 @@ inline uint FloatImage::indexMirror(int x, int y) const
|
||||
}
|
||||
|
||||
return index(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint FloatImage::index(int x, int y, WrapMode wm) const
|
||||
{
|
||||
inline uint FloatImage::index(int x, int y, WrapMode wm) const
|
||||
{
|
||||
if (wm == WrapMode_Clamp) return indexClamp(x, y);
|
||||
if (wm == WrapMode_Repeat) return indexRepeat(x, y);
|
||||
/*if (wm == WrapMode_Mirror)*/ return indexMirror(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/ImageIO.h>
|
||||
#include "Image.h"
|
||||
#include "ImageIO.h"
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include <nvcore/Ptr.h>
|
||||
#include <nvcore/Containers.h> // swap
|
||||
#include "nvcore/Debug.h"
|
||||
#include "nvcore/Ptr.h"
|
||||
#include "nvcore/Utils.h" // swap
|
||||
|
||||
|
||||
using namespace nv;
|
||||
|
@ -1,10 +1,11 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_IMAGE_IMAGE_H
|
||||
#define NV_IMAGE_IMAGE_H
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include <nvimage/nvimage.h>
|
||||
#include "nvimage.h"
|
||||
#include "nvcore/Debug.h"
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
@ -6,12 +6,13 @@
|
||||
#include "TgaFile.h"
|
||||
#include "PsdFile.h"
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
#include <nvcore/Ptr.h>
|
||||
#include <nvcore/Containers.h>
|
||||
#include <nvcore/StrLib.h>
|
||||
#include <nvcore/StdStream.h>
|
||||
#include "nvcore/Ptr.h"
|
||||
#include "nvcore/Utils.h"
|
||||
#include "nvcore/Array.h"
|
||||
#include "nvcore/StrLib.h"
|
||||
#include "nvcore/StdStream.h"
|
||||
|
||||
// Extern
|
||||
#if defined(HAVE_FREEIMAGE)
|
||||
|
@ -1,11 +1,13 @@
|
||||
// This code is in the public domain -- castanyo@yahoo.es
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_IMAGE_IMAGEIO_H
|
||||
#define NV_IMAGE_IMAGEIO_H
|
||||
|
||||
#include <nvimage/nvimage.h>
|
||||
#include "nvimage.h"
|
||||
|
||||
#include <nvcore/StrLib.h>
|
||||
#include "nvcore/StrLib.h"
|
||||
#include "nvcore/HashMap.h"
|
||||
|
||||
|
||||
namespace nv
|
||||
|
@ -65,9 +65,9 @@ static FloatImage * createNormalMap(const Image * img, FloatImage::WrapMode wm,
|
||||
|
||||
Vector3 n = normalize(Vector3(du, dv, heightScale));
|
||||
|
||||
fimage->setPixel(0.5f * n.x() + 0.5f, x, y, 0);
|
||||
fimage->setPixel(0.5f * n.y() + 0.5f, x, y, 1);
|
||||
fimage->setPixel(0.5f * n.z() + 0.5f, x, y, 2);
|
||||
fimage->pixel(x, y, 0) = 0.5f * n.x + 0.5f;
|
||||
fimage->pixel(x, y, 1) = 0.5f * n.y + 0.5f;
|
||||
fimage->pixel(x, y, 2) = 0.5f * n.z + 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,9 +100,9 @@ static FloatImage * createNormalMap(const FloatImage * img, FloatImage::WrapMode
|
||||
|
||||
Vector3 n = normalize(Vector3(du, dv, heightScale));
|
||||
|
||||
img_out->setPixel(n.x(), x, y, 0);
|
||||
img_out->setPixel(n.y(), x, y, 1);
|
||||
img_out->setPixel(n.z(), x, y, 2);
|
||||
img_out->pixel(x, y, 0) = n.x;
|
||||
img_out->pixel(x, y, 1) = n.y;
|
||||
img_out->pixel(x, y, 2) = n.z;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ static FloatImage * createNormalMap(const FloatImage * img, FloatImage::WrapMode
|
||||
{
|
||||
for (uint x = 0; x < w; x++)
|
||||
{
|
||||
img_out->setPixel(img->pixel(x, y, 3), x, y, 3);
|
||||
img_out->pixel(x, y, 3) = img->pixel(x, y, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,15 @@ http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT
|
||||
@@ This code needs to be reviewed, I'm not sure it's correct.
|
||||
*/
|
||||
|
||||
#include <nvimage/Quantize.h>
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/PixelFormat.h>
|
||||
#include "Quantize.h"
|
||||
#include "Image.h"
|
||||
#include "PixelFormat.h"
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
#include <nvcore/Containers.h> // swap
|
||||
#include "nvcore/Utils.h" // swap
|
||||
|
||||
#include <string.h> // memset
|
||||
|
||||
|
||||
using namespace nv;
|
||||
@ -174,10 +176,10 @@ void nv::Quantize::FloydSteinberg(Image * image, uint rsize, uint gsize, uint bs
|
||||
Color32 pixel = image->pixel(x, y);
|
||||
|
||||
// Add error.
|
||||
pixel.r = clamp(int(pixel.r) + int(row0[1+x].x()), 0, 255);
|
||||
pixel.g = clamp(int(pixel.g) + int(row0[1+x].y()), 0, 255);
|
||||
pixel.b = clamp(int(pixel.b) + int(row0[1+x].z()), 0, 255);
|
||||
pixel.a = clamp(int(pixel.a) + int(row0[1+x].w()), 0, 255);
|
||||
pixel.r = clamp(int(pixel.r) + int(row0[1+x].x), 0, 255);
|
||||
pixel.g = clamp(int(pixel.g) + int(row0[1+x].y), 0, 255);
|
||||
pixel.b = clamp(int(pixel.b) + int(row0[1+x].z), 0, 255);
|
||||
pixel.a = clamp(int(pixel.a) + int(row0[1+x].w), 0, 255);
|
||||
|
||||
int r = pixel.r;
|
||||
int g = pixel.g;
|
||||
|
Reference in New Issue
Block a user