Fix segfault

faster-single-tables
Andrew Cassidy 3 years ago
parent 29daae2f27
commit eb4fa20d2f

@ -33,7 +33,7 @@ void BC1Decoder::DecodeBlock(Color4x4 dest, BC1Block *const block) const noexcep
const auto l = block->GetLowColor();
const auto h = block->GetHighColor();
const auto selectors = block->UnpackSelectors();
const auto colors = _interpolator.InterpolateBC1(l, h);
const auto colors = _interpolator->InterpolateBC1(l, h);
for (unsigned y = 0; y < 4; y++) {
for (unsigned x = 0; x < 4; x++) {

@ -19,24 +19,28 @@
#pragma once
#include <memory>
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../interpolator.h"
#include "../ndebug.h"
#include "../ColorBlock.h"
namespace rgbcx {
class BC1Decoder final : public BlockDecoder<BC1Block, 4, 4> {
public:
BC1Decoder(const Interpolator &interpolator = Interpolator(), bool write_alpha = false) : _interpolator(interpolator), _write_alpha(write_alpha) {}
using InterpolatorPtr = std::shared_ptr<Interpolator>;
BC1Decoder(const InterpolatorPtr interpolator = std::make_shared<Interpolator>(), bool write_alpha = false)
: _interpolator(interpolator), _write_alpha(write_alpha) {}
void DecodeBlock(Color4x4 dest, BC1Block *const block) const noexcept(ndebug) override;
constexpr const Interpolator &GetInterpolator() const { return _interpolator; }
InterpolatorPtr GetInterpolator() const { return _interpolator; }
constexpr bool WritesAlpha() const { return _write_alpha; }
private:
const Interpolator &_interpolator;
const InterpolatorPtr _interpolator;
const bool _write_alpha;
};
} // namespace rgbcx

@ -28,7 +28,7 @@
namespace rgbcx {
void BC3Decoder::DecodeBlock(Color4x4 dest, BC3Block *const block) const noexcept(ndebug) {
_bc1_decoder.DecodeBlock(dest, &(block->color_block));
_bc4_decoder.DecodeBlock(dest, &(block->alpha_block), 3);
_bc1_decoder->DecodeBlock(dest, &(block->color_block));
_bc4_decoder->DecodeBlock(dest, &(block->alpha_block), 3);
}
} // namespace rgbcx

@ -19,6 +19,8 @@
#pragma once
#include <memory>
#include "../BC1/BC1Decoder.h"
#include "../BC4/BC4Decoder.h"
#include "../BlockDecoder.h"
@ -30,13 +32,17 @@
namespace rgbcx {
class BC3Decoder : public BlockDecoder<BC3Block, 4, 4> {
public:
BC3Decoder(const Interpolator &interpolator = Interpolator()) : BC3Decoder(BC1Decoder(interpolator, false)) {}
BC3Decoder(const BC1Decoder &bc1_decoder, const BC4Decoder &bc4_decoder = BC4Decoder()) : _bc1_decoder(bc1_decoder), _bc4_decoder(bc4_decoder) {}
using InterpolatorPtr = std::shared_ptr<Interpolator>;
using BC1DecoderPtr = std::shared_ptr<BC1Decoder>;
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
BC3Decoder(InterpolatorPtr interpolator = std::make_shared<Interpolator>()) : BC3Decoder(std::make_shared<BC1Decoder>(interpolator)) {}
BC3Decoder(BC1DecoderPtr bc1_decoder, BC4DecoderPtr bc4_decoder = std::make_shared<BC4Decoder>()) : _bc1_decoder(bc1_decoder), _bc4_decoder(bc4_decoder) {}
void DecodeBlock(Color4x4 dest, BC3Block *const block) const noexcept(ndebug) override;
private:
const BC1Decoder &_bc1_decoder;
const BC4Decoder &_bc4_decoder;
const BC1DecoderPtr _bc1_decoder;
const BC4DecoderPtr _bc4_decoder;
};
} // namespace rgbcx

@ -27,7 +27,7 @@
namespace rgbcx {
void BC5Decoder::DecodeBlock(Color4x4 dest, BC5Block *const block) const noexcept(ndebug) {
_bc4_decoder.DecodeBlock(dest, &block->chan0_block, _chan0);
_bc4_decoder.DecodeBlock(dest, &block->chan1_block, _chan1);
_bc4_decoder->DecodeBlock(dest, &block->chan0_block, _chan0);
_bc4_decoder->DecodeBlock(dest, &block->chan1_block, _chan1);
}
} // namespace rgbcx

@ -20,18 +20,21 @@
#pragma once
#include <stddef.h>
#include <memory>
#include "../BC4/BC4Decoder.h"
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../ndebug.h"
#include "../blocks.h"
#include "../ndebug.h"
namespace rgbcx {
class BC5Decoder : public BlockDecoder<BC5Block, 4, 4> {
public:
BC5Decoder(size_t chan0 = 0, size_t chan1 = 1) : BC5Decoder(BC4Decoder(), chan0, chan1) {}
BC5Decoder(const BC4Decoder &bc4_decoder, size_t chan0 = 0, size_t chan1 = 1) : _bc4_decoder(bc4_decoder), _chan0(chan0), _chan1(chan1) {}
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
BC5Decoder(size_t chan0 = 0, size_t chan1 = 1) : BC5Decoder(std::make_shared<BC4Decoder>(), chan0, chan1) {}
BC5Decoder(BC4DecoderPtr bc4_decoder, size_t chan0 = 0, size_t chan1 = 1) : _bc4_decoder(bc4_decoder), _chan0(chan0), _chan1(chan1) {}
void DecodeBlock(Color4x4 dest, BC5Block *const block) const noexcept(ndebug) override;
@ -39,7 +42,7 @@ class BC5Decoder : public BlockDecoder<BC5Block, 4, 4> {
constexpr size_t GetChannel1() const { return _chan1; }
private:
const BC4Decoder &_bc4_decoder;
const BC4DecoderPtr _bc4_decoder;
const size_t _chan0;
const size_t _chan1;
};

@ -56,7 +56,7 @@ class Color {
void SetRGBA(const Color &other) { SetRGBA(other.r, other.g, other.b, other.a); }
void SetRGB(uint8_t vr, uint8_t vg, uint8_t vb);
void SetRGB(const Color &other) { SetRGB(other.r, other.g, other.a); }
void SetRGB(const Color &other) { SetRGB(other.r, other.g, other.b); }
uint16_t pack565();
uint16_t pack565Unscaled();
@ -67,6 +67,6 @@ class Color {
static Color min(const Color &A, const Color &B);
static Color max(const Color &A, const Color &B);
unsigned get_luma() const { return (13938U * r + 46869U * g + 4729U * b + 32768U) >> 16U; } // REC709 weightings
int get_luma() const { return (13938U * r + 46869U * g + 4729U * b + 32768U) >> 16U; } // REC709 weightings
};
#pragma pack(pop)

@ -264,9 +264,11 @@ class image_metrics {
const color_quad_u8 &ca = a(x, y);
const color_quad_u8 &cb = b(x, y);
if (!num_channels)
hist[iabs(ca.get_luma() - cb.get_luma())]++;
else {
if (!num_channels) {
// int luma_diff = ;
unsigned index = iabs(ca.get_luma() - cb.get_luma());
hist[index]++;
} else {
for (uint32_t c = 0; c < num_channels; c++) hist[iabs(ca[first_channel + c] - cb[first_channel + c])]++;
}
}

@ -38,6 +38,7 @@ template <typename S> constexpr void Assert6Bit(S x) {
}
template <typename S> constexpr auto iabs(S i) {
static_assert(!std::is_unsigned<S>::value);
using O = typename std::make_unsigned<S>::type;
return (i < 0) ? static_cast<O>(-i) : static_cast<O>(i);
}

Loading…
Cancel
Save