mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Compare commits
2 Commits
831e86fda6
...
6831c3f6c9
Author | SHA1 | Date | |
---|---|---|---|
6831c3f6c9 | |||
639ce6ad14 |
@ -54,6 +54,7 @@ target_compile_definitions(test_quicktex PRIVATE -DCUSTOM_SYS_PATH="${CMAKE_HOME
|
|||||||
# enable openMP if available
|
# enable openMP if available
|
||||||
if (OpenMP_CXX_FOUND)
|
if (OpenMP_CXX_FOUND)
|
||||||
target_link_libraries(_quicktex PUBLIC OpenMP::OpenMP_CXX)
|
target_link_libraries(_quicktex PUBLIC OpenMP::OpenMP_CXX)
|
||||||
|
target_link_libraries(test_quicktex PUBLIC OpenMP::OpenMP_CXX)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Set module features, like C/C++ standards
|
# Set module features, like C/C++ standards
|
||||||
|
@ -123,7 +123,7 @@ class RawTexture : public Texture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
};
|
}
|
||||||
|
|
||||||
template <int N, int M> void SetBlock(int block_x, int block_y, const ColorBlock<N, M> &block) {
|
template <int N, int M> void SetBlock(int block_x, int block_y, const ColorBlock<N, M> &block) {
|
||||||
if (block_x < 0) throw std::invalid_argument("x value out of range.");
|
if (block_x < 0) throw std::invalid_argument("x value out of range.");
|
||||||
@ -145,7 +145,7 @@ class RawTexture : public Texture {
|
|||||||
for (int y = 0; y < M; y++) { SetPixel((pixel_x + x) % _width, (pixel_y + y) % _height, block.Get(x, y)); }
|
for (int y = 0; y < M; y++) { SetPixel((pixel_x + x) % _width, (pixel_y + y) % _height, block.Get(x, y)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
virtual const uint8_t *Data() const noexcept override { return reinterpret_cast<const uint8_t *>(_pixels); }
|
virtual const uint8_t *Data() const noexcept override { return reinterpret_cast<const uint8_t *>(_pixels); }
|
||||||
virtual uint8_t *Data() noexcept override { return reinterpret_cast<uint8_t *>(_pixels); }
|
virtual uint8_t *Data() noexcept override { return reinterpret_cast<uint8_t *>(_pixels); }
|
||||||
|
@ -36,7 +36,7 @@ ColorBlock<4, 4> BC1Decoder::DecodeBlock(const BC1Block &block, bool use_3color)
|
|||||||
const auto l = block.GetColor0Raw();
|
const auto l = block.GetColor0Raw();
|
||||||
const auto h = block.GetColor1Raw();
|
const auto h = block.GetColor1Raw();
|
||||||
const auto selectors = block.GetSelectors();
|
const auto selectors = block.GetSelectors();
|
||||||
const auto colors = _interpolator->InterpolateBC1(l, h, use_3color);
|
const auto colors = _interpolator->Interpolate565BC1(l, h, use_3color);
|
||||||
|
|
||||||
for (unsigned y = 0; y < 4; y++) {
|
for (unsigned y = 0; y < 4; y++) {
|
||||||
for (unsigned x = 0; x < 4; x++) {
|
for (unsigned x = 0; x < 4; x++) {
|
||||||
|
@ -50,7 +50,7 @@ uint8_t Interpolator::Interpolate6(uint8_t v0, uint8_t v1) const { return Interp
|
|||||||
uint8_t Interpolator::InterpolateHalf5(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale5To8(v0), scale5To8(v1)); }
|
uint8_t Interpolator::InterpolateHalf5(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale5To8(v0), scale5To8(v1)); }
|
||||||
uint8_t Interpolator::InterpolateHalf6(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale6To8(v0), scale6To8(v1)); }
|
uint8_t Interpolator::InterpolateHalf6(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale6To8(v0), scale6To8(v1)); }
|
||||||
|
|
||||||
std::array<Color, 4> Interpolator::InterpolateBC1(uint16_t low, uint16_t high, bool allow_3color) const {
|
std::array<Color, 4> Interpolator::Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color) const {
|
||||||
bool use_3color = allow_3color && (high >= low);
|
bool use_3color = allow_3color && (high >= low);
|
||||||
return InterpolateBC1(Color::Unpack565Unscaled(low), Color::Unpack565Unscaled(high), use_3color);
|
return InterpolateBC1(Color::Unpack565Unscaled(low), Color::Unpack565Unscaled(high), use_3color);
|
||||||
}
|
}
|
||||||
|
@ -94,10 +94,18 @@ class Interpolator {
|
|||||||
* Generates the 4 colors for a BC1 block from the given 5:6:5-packed colors
|
* Generates the 4 colors for a BC1 block from the given 5:6:5-packed colors
|
||||||
* @param low first 5:6:5 color for the block
|
* @param low first 5:6:5 color for the block
|
||||||
* @param high second 5:6:5 color for the block
|
* @param high second 5:6:5 color for the block
|
||||||
* @return and array of 4 Color values, with indices matching BC1 selectors
|
* @param allow_3color if true, a different interpolation mode will be used if high >= low
|
||||||
|
* @return an array of 4 Color values, with indices matching BC1 selectors
|
||||||
*/
|
*/
|
||||||
virtual std::array<Color, 4> InterpolateBC1(uint16_t low, uint16_t high, bool allow_3color = true) const;
|
std::array<Color, 4> Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color = true) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the 4 colors for a BC1 block from the given
|
||||||
|
* @param low the first color for the block, as a seperated 5:6:5 Color object
|
||||||
|
* @param high the second color for the block, as a seperated 5:6:5 Color object
|
||||||
|
* @param use_3color if the 3-color interpolation mode should be used
|
||||||
|
* @return an array of 4 Color values, with indices matching BC1 selectors
|
||||||
|
*/
|
||||||
virtual std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const;
|
virtual std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,27 +135,27 @@ class Interpolator {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class InterpolatorRound : public Interpolator {
|
class InterpolatorRound final : public Interpolator {
|
||||||
public:
|
public:
|
||||||
uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t Interpolate8(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate8(uint8_t v0, uint8_t v1) const override;
|
||||||
|
|
||||||
Type GetType() const noexcept override { return Type::IdealRound; }
|
virtual Type GetType() const noexcept override { return Type::IdealRound; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class InterpolatorNvidia : public Interpolator {
|
class InterpolatorNvidia final : public Interpolator {
|
||||||
public:
|
public:
|
||||||
uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
||||||
|
|
||||||
uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const override;
|
||||||
|
|
||||||
std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const override;
|
virtual std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const override;
|
||||||
|
|
||||||
Type GetType() const noexcept override { return Type::Nvidia; }
|
virtual Type GetType() const noexcept override { return Type::Nvidia; }
|
||||||
bool CanInterpolate8Bit() const noexcept override { return false; }
|
virtual bool CanInterpolate8Bit() const noexcept override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Color InterpolateColor565(const Color &c0, const Color &c1) const {
|
Color InterpolateColor565(const Color &c0, const Color &c1) const {
|
||||||
@ -159,16 +167,16 @@ class InterpolatorNvidia : public Interpolator {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class InterpolatorAMD : public Interpolator {
|
class InterpolatorAMD final : public Interpolator {
|
||||||
public:
|
public:
|
||||||
uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate5(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate6(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t Interpolate8(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t Interpolate8(uint8_t v0, uint8_t v1) const override;
|
||||||
|
|
||||||
uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const override;
|
||||||
uint8_t InterpolateHalf8(uint8_t v0, uint8_t v1) const override;
|
virtual uint8_t InterpolateHalf8(uint8_t v0, uint8_t v1) const override;
|
||||||
|
|
||||||
Type GetType() const noexcept override { return Type::AMD; }
|
virtual Type GetType() const noexcept override { return Type::AMD; }
|
||||||
};
|
};
|
||||||
} // namespace quicktex::s3tc
|
} // namespace quicktex::s3tc
|
Loading…
Reference in New Issue
Block a user