Remove unused methods. Add float color block.

pull/216/head
castano 14 years ago
parent f9753b649a
commit f2c581dec1

@ -209,7 +209,7 @@ uint ColorBlock::countUniqueColors() const
return count; return count;
} }
/// Get average color of the block. /*/// Get average color of the block.
Color32 ColorBlock::averageColor() const Color32 ColorBlock::averageColor() const
{ {
uint r, g, b, a; 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 Color32(uint8(r / 16), uint8(g / 16), uint8(b / 16), uint8(a / 16));
} }*/
/// Return true if the block is not fully opaque. /// Return true if the block is not fully opaque.
bool ColorBlock::hasAlpha() const bool ColorBlock::hasAlpha() const
@ -235,6 +235,7 @@ bool ColorBlock::hasAlpha() const
return false; return false;
} }
#if 0
/// Get diameter color range. /// Get diameter color range.
void ColorBlock::diameterRange(Color32 * start, Color32 * end) const void ColorBlock::diameterRange(Color32 * start, Color32 * end) const
@ -367,9 +368,9 @@ void ColorBlock::boundsRangeAlpha(Color32 * start, Color32 * end) const
*start = minColor; *start = minColor;
*end = maxColor; *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() void ColorBlock::sortColorsByAbsoluteValue()
{ {
// Dummy selection sort. // Dummy selection sort.
@ -387,10 +388,10 @@ void ColorBlock::sortColorsByAbsoluteValue()
} }
swap( m_color[a], m_color[max] ); 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 void ColorBlock::computeRange(Vector3::Arg axis, Color32 * start, Color32 * end) const
{ {
nvDebugCheck(start != NULL); nvDebugCheck(start != NULL);
@ -419,10 +420,10 @@ void ColorBlock::computeRange(Vector3::Arg axis, Color32 * start, Color32 * end)
*start = m_color[mini]; *start = m_color[mini];
*end = m_color[maxi]; *end = m_color[maxi];
} }*/
/// Sort colors in the given axis. /*/// Sort colors in the given axis.
void ColorBlock::sortColors(const Vector3 & axis) void ColorBlock::sortColors(const Vector3 & axis)
{ {
float luma_array[16]; float luma_array[16];
@ -443,10 +444,10 @@ void ColorBlock::sortColors(const Vector3 & axis)
swap( luma_array[a], luma_array[min] ); swap( luma_array[a], luma_array[min] );
swap( m_color[a], m_color[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 float ColorBlock::volume() const
{ {
Box bounds; Box bounds;
@ -458,6 +459,47 @@ float ColorBlock::volume() const
} }
return bounds.volume(); 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)
{
}

@ -9,6 +9,7 @@
namespace nv namespace nv
{ {
class Image; class Image;
class FloatImage;
/// Uncompressed 4x4 color block. /// Uncompressed 4x4 color block.
struct ColorBlock struct ColorBlock
@ -27,20 +28,20 @@ namespace nv
bool isSingleColor() const; bool isSingleColor() const;
//bool isSingleColorNoAlpha() const; //bool isSingleColorNoAlpha() const;
uint countUniqueColors() const; uint countUniqueColors() const;
Color32 averageColor() const; //Color32 averageColor() const;
bool hasAlpha() const; bool hasAlpha() const;
void diameterRange(Color32 * start, Color32 * end) const; //void diameterRange(Color32 * start, Color32 * end) const;
void luminanceRange(Color32 * start, Color32 * end) const; //void luminanceRange(Color32 * start, Color32 * end) const;
void boundsRange(Color32 * start, Color32 * end) const; //void boundsRange(Color32 * start, Color32 * end) const;
void boundsRangeAlpha(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 computeRange(const Vector3 & axis, Color32 * start, Color32 * end) const;
void sortColors(const Vector3 & axis); //void sortColors(const Vector3 & axis);
float volume() const; //float volume() const;
// Accessors // Accessors
const Color32 * colors() const; const Color32 * colors() const;
@ -92,6 +93,25 @@ namespace nv
return m_color[y * 4 + x]; 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 } // nv namespace
#endif // NV_IMAGE_COLORBLOCK_H #endif // NV_IMAGE_COLORBLOCK_H

Loading…
Cancel
Save