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;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
||||
@ -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,12 +3,10 @@
|
||||
#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
|
||||
|
||||
@ -54,14 +52,16 @@ public:
|
||||
/** @name Manipulation. */
|
||||
//@{
|
||||
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;
|
||||
@ -175,26 +177,6 @@ inline float * FloatImage::scanline(uint y, uint c)
|
||||
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
|
||||
{
|
||||
@ -205,11 +187,14 @@ inline float FloatImage::pixel(uint x, uint y, uint c) const
|
||||
return m_mem[(c * m_height + y) * m_width + x];
|
||||
}
|
||||
|
||||
/// Set pixel component.
|
||||
inline void FloatImage::setPixel(float f, uint idx)
|
||||
/// Get pixel component.
|
||||
inline float & FloatImage::pixel(uint x, uint y, uint c)
|
||||
{
|
||||
nvDebugCheck(idx < m_count);
|
||||
m_mem[idx] = f;
|
||||
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.
|
||||
@ -219,6 +204,13 @@ inline float FloatImage::pixel(uint idx) const
|
||||
return m_mem[idx];
|
||||
}
|
||||
|
||||
/// 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);
|
||||
|
@ -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