From f2c581dec15e9825b42612557ca5ef478edc2ec3 Mon Sep 17 00:00:00 2001 From: castano Date: Mon, 21 Jun 2010 22:23:01 +0000 Subject: [PATCH] Remove unused methods. Add float color block. --- src/nvimage/ColorBlock.cpp | 62 ++++++++++++++++++++++++++++++++------ src/nvimage/ColorBlock.h | 38 +++++++++++++++++------ 2 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/nvimage/ColorBlock.cpp b/src/nvimage/ColorBlock.cpp index ff79817..87bda90 100644 --- a/src/nvimage/ColorBlock.cpp +++ b/src/nvimage/ColorBlock.cpp @@ -209,7 +209,7 @@ uint ColorBlock::countUniqueColors() const return count; } -/// Get average color of the block. +/*/// Get average color of the block. Color32 ColorBlock::averageColor() const { uint r, g, b, a; @@ -223,7 +223,7 @@ Color32 ColorBlock::averageColor() const } return Color32(uint8(r / 16), uint8(g / 16), uint8(b / 16), uint8(a / 16)); -} +}*/ /// Return true if the block is not fully opaque. bool ColorBlock::hasAlpha() const @@ -235,6 +235,7 @@ bool ColorBlock::hasAlpha() const return false; } +#if 0 /// Get diameter color range. void ColorBlock::diameterRange(Color32 * start, Color32 * end) const @@ -367,9 +368,9 @@ void ColorBlock::boundsRangeAlpha(Color32 * start, Color32 * end) const *start = minColor; *end = maxColor; } +#endif - -/// Sort colors by abosolute value in their 16 bit representation. +/*/// Sort colors by abosolute value in their 16 bit representation. void ColorBlock::sortColorsByAbsoluteValue() { // Dummy selection sort. @@ -387,10 +388,10 @@ void ColorBlock::sortColorsByAbsoluteValue() } swap( m_color[a], m_color[max] ); } -} +}*/ -/// Find extreme colors in the given axis. +/*/// Find extreme colors in the given axis. void ColorBlock::computeRange(Vector3::Arg axis, Color32 * start, Color32 * end) const { nvDebugCheck(start != NULL); @@ -419,10 +420,10 @@ void ColorBlock::computeRange(Vector3::Arg axis, Color32 * start, Color32 * end) *start = m_color[mini]; *end = m_color[maxi]; -} +}*/ -/// Sort colors in the given axis. +/*/// Sort colors in the given axis. void ColorBlock::sortColors(const Vector3 & axis) { float luma_array[16]; @@ -443,10 +444,10 @@ void ColorBlock::sortColors(const Vector3 & axis) swap( luma_array[a], luma_array[min] ); swap( m_color[a], m_color[min] ); } -} +}*/ -/// Get the volume of the color block. +/*/// Get the volume of the color block. float ColorBlock::volume() const { Box bounds; @@ -458,6 +459,47 @@ float ColorBlock::volume() const } return bounds.volume(); +}*/ + + +void FloatColorBlock::init(const Image * img, uint x, uint y) +{ + w = min(4U, img->width() - x); + h = min(4U, img->height() - y); + nvDebugCheck(w != 0 && h != 0); + + // Blocks that are smaller than 4x4 are handled by repeating the pixels. + // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :( + // @@ Ideally we should zero the weights of the pixels out of range. + + uint srcPlane = w * h; + + for (uint i = 0; i < 4; i++) + { + const uint by = i % h; + + for (uint e = 0; e < 4; e++) + { + const uint bx = e % w; + Color32 c = img->pixel(x+bx, y+by); + Vector4 & v = color(e, i); + v.x = c.r / 255; + v.y = c.g / 255; + v.z = c.b / 255; + v.w = c.a / 255; + } + } } +void FloatColorBlock::init(const FloatImage * img, uint x, uint y) +{ +} + +void FloatColorBlock::init(const uint * data, uint w, uint h, uint x, uint y) +{ +} + +void FloatColorBlock::init(const float * data, uint w, uint h, uint x, uint y) +{ +} diff --git a/src/nvimage/ColorBlock.h b/src/nvimage/ColorBlock.h index d2cfb35..27eb4c8 100644 --- a/src/nvimage/ColorBlock.h +++ b/src/nvimage/ColorBlock.h @@ -9,6 +9,7 @@ namespace nv { class Image; + class FloatImage; /// Uncompressed 4x4 color block. struct ColorBlock @@ -27,20 +28,20 @@ namespace nv bool isSingleColor() const; //bool isSingleColorNoAlpha() const; uint countUniqueColors() const; - Color32 averageColor() const; + //Color32 averageColor() const; bool hasAlpha() const; - void diameterRange(Color32 * start, Color32 * end) const; - void luminanceRange(Color32 * start, Color32 * end) const; - void boundsRange(Color32 * start, Color32 * end) const; - void boundsRangeAlpha(Color32 * start, Color32 * end) const; + //void diameterRange(Color32 * start, Color32 * end) const; + //void luminanceRange(Color32 * start, Color32 * end) const; + //void boundsRange(Color32 * start, Color32 * end) const; + //void boundsRangeAlpha(Color32 * start, Color32 * end) const; - void sortColorsByAbsoluteValue(); + //void sortColorsByAbsoluteValue(); - void computeRange(const Vector3 & axis, Color32 * start, Color32 * end) const; - void sortColors(const Vector3 & axis); + //void computeRange(const Vector3 & axis, Color32 * start, Color32 * end) const; + //void sortColors(const Vector3 & axis); - float volume() const; + //float volume() const; // Accessors const Color32 * colors() const; @@ -92,6 +93,25 @@ namespace nv return m_color[y * 4 + x]; } + + struct FloatColorBlock + { + FloatColorBlock() : w(4), h(4) {} + FloatColorBlock(uint w, uint h) : w(w), h(h) {} + + void init(const Image * img, uint x, uint y); + void init(const FloatImage * img, uint x, uint y); + void init(const uint * data, uint w, uint h, uint x, uint y); + void init(const float * data, uint w, uint h, uint x, uint y); + + Vector4 color(uint x, uint y) const { nvDebugCheck(x < w && y < h); return colors[y * 4 + x]; } + Vector4 & color(uint x, uint y) { nvDebugCheck(x < w && y < h); return colors[y * 4 + x]; } + + + Vector4 colors[16]; + uint w, h; + }; + } // nv namespace #endif // NV_IMAGE_COLORBLOCK_H