mirror of https://github.com/procxx/kepka.git
Fix glitches on macOS stickers.
This commit is contained in:
parent
96a26b44a9
commit
72a9d61b97
|
@ -254,12 +254,34 @@ void Encode(
|
||||||
EncodeAlpha(to, cache);
|
EncodeAlpha(to, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int YLineSize(int width) {
|
||||||
|
return ((width + kAlignStorage - 1) / kAlignStorage) * kAlignStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UVLineSize(int width) {
|
||||||
|
return (((width / 2) + kAlignStorage - 1) / kAlignStorage) * kAlignStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
int YSize(int width, int height) {
|
||||||
|
return YLineSize(width) * height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UVSize(int width, int height) {
|
||||||
|
return UVLineSize(width) * (height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ASize(int width, int height) {
|
||||||
|
return (width * height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EncodedStorage::allocate(int width, int height) {
|
void EncodedStorage::allocate(int width, int height) {
|
||||||
Expects((width % 2) == 0 && (height % 2) == 0);
|
Expects((width % 2) == 0 && (height % 2) == 0);
|
||||||
|
|
||||||
if (_width != width || _height != height) {
|
if (YSize(width, height) != YSize(_width, _height)
|
||||||
|
|| UVSize(width, height) != UVSize(_width, _height)
|
||||||
|
|| ASize(width, height) != ASize(_width, _height)) {
|
||||||
_width = width;
|
_width = width;
|
||||||
_height = height;
|
_height = height;
|
||||||
reallocate();
|
reallocate();
|
||||||
|
@ -267,8 +289,10 @@ void EncodedStorage::allocate(int width, int height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodedStorage::reallocate() {
|
void EncodedStorage::reallocate() {
|
||||||
const auto total = _width * _height * 2;
|
const auto total = YSize(_width, _height)
|
||||||
_data = QByteArray(total + kAlignStorage - 1, Qt::Uninitialized);
|
+ 2 * UVSize(_width, _height)
|
||||||
|
+ ASize(_width, _height);
|
||||||
|
_data = QByteArray(total + kAlignStorage - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::width() const {
|
int EncodedStorage::width() const {
|
||||||
|
@ -280,7 +304,9 @@ int EncodedStorage::height() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::size() const {
|
int EncodedStorage::size() const {
|
||||||
return _width * _height * 2;
|
return YSize(_width, _height)
|
||||||
|
+ 2 * UVSize(_width, _height)
|
||||||
|
+ ASize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *EncodedStorage::data() {
|
char *EncodedStorage::data() {
|
||||||
|
@ -304,39 +330,39 @@ const uint8_t *EncodedStorage::yData() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::yBytesPerLine() const {
|
int EncodedStorage::yBytesPerLine() const {
|
||||||
return _width;
|
return YLineSize(_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *EncodedStorage::uData() {
|
uint8_t *EncodedStorage::uData() {
|
||||||
return yData() + (_width * _height);
|
return yData() + YSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EncodedStorage::uData() const {
|
const uint8_t *EncodedStorage::uData() const {
|
||||||
return yData() + (_width * _height);
|
return yData() + YSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::uBytesPerLine() const {
|
int EncodedStorage::uBytesPerLine() const {
|
||||||
return _width / 2;
|
return UVLineSize(_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *EncodedStorage::vData() {
|
uint8_t *EncodedStorage::vData() {
|
||||||
return uData() + (_width * _height / 4);
|
return uData() + UVSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EncodedStorage::vData() const {
|
const uint8_t *EncodedStorage::vData() const {
|
||||||
return uData() + (_width * _height / 4);
|
return uData() + UVSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::vBytesPerLine() const {
|
int EncodedStorage::vBytesPerLine() const {
|
||||||
return _width / 2;
|
return UVLineSize(_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *EncodedStorage::aData() {
|
uint8_t *EncodedStorage::aData() {
|
||||||
return uData() + (_width * _height) / 2;
|
return uData() + 2 * UVSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EncodedStorage::aData() const {
|
const uint8_t *EncodedStorage::aData() const {
|
||||||
return uData() + (_width * _height) / 2;
|
return uData() + 2 * UVSize(_width, _height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncodedStorage::aBytesPerLine() const {
|
int EncodedStorage::aBytesPerLine() const {
|
||||||
|
|
|
@ -23,6 +23,17 @@ QByteArray ReadFile(const QString &filepath) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
QSize FrameRequest::size(const QSize &original) const {
|
||||||
|
Expects(!empty());
|
||||||
|
|
||||||
|
const auto result = original.scaled(box, Qt::KeepAspectRatio);
|
||||||
|
const auto skipw = result.width() % 8;
|
||||||
|
const auto skiph = result.height() % 8;
|
||||||
|
return QSize(
|
||||||
|
std::max(result.width() - skipw, 8),
|
||||||
|
std::max(result.height() - skiph, 8));
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray ReadContent(const QByteArray &data, const QString &filepath) {
|
QByteArray ReadContent(const QByteArray &data, const QString &filepath) {
|
||||||
return data.isEmpty() ? ReadFile(filepath) : base::duplicate(data);
|
return data.isEmpty() ? ReadFile(filepath) : base::duplicate(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,16 +39,7 @@ struct FrameRequest {
|
||||||
[[nodiscard]] bool empty() const {
|
[[nodiscard]] bool empty() const {
|
||||||
return box.isEmpty();
|
return box.isEmpty();
|
||||||
}
|
}
|
||||||
[[nodiscard]] QSize size(const QSize &original) const {
|
[[nodiscard]] QSize size(const QSize &original) const;
|
||||||
Expects(!empty());
|
|
||||||
|
|
||||||
const auto result = original.scaled(box, Qt::KeepAspectRatio);
|
|
||||||
const auto skipw = result.width() % 2;
|
|
||||||
const auto skiph = result.height() % 2;
|
|
||||||
return QSize(
|
|
||||||
std::max(result.width() - skipw, 2),
|
|
||||||
std::max(result.height() - skiph, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const FrameRequest &other) const {
|
[[nodiscard]] bool operator==(const FrameRequest &other) const {
|
||||||
return (box == other.box)
|
return (box == other.box)
|
||||||
|
|
Loading…
Reference in New Issue