Skip to content

Commit a9603d4

Browse files
committed
[gctex] cmpr: Add NormalizeFrameIMG
1 parent 9fc330c commit a9603d4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

source/gctex/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/gctex/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "gctex"
33
license = "GPL-2.0-or-later"
4-
version = "0.1.10"
4+
version = "0.1.11"
55
edition = "2021"
66
description = "gctex is a Rust crate designed for encoding and decoding texture formats used in the Nintendo GameCube and Wii games. The library provides C bindings, making it useful in both Rust and C/C++ based projects."
77
homepage = "https://github.com/riidefi/RiiStudio/tree/master/source/gctex"

source/gctex/src/CmprEncoder.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,34 @@ CalcImageBlock(u32 width, u32 height,
425425
*img_size = size;
426426
}
427427

428+
void NormalizeFrameIMG(u32 width, u32 height, u32 xwidth, u32 xheight,
429+
u8* data) {
430+
const u32 cell_size = 4;
431+
432+
if (width > 0 && xwidth > width) {
433+
const u32 fill_size = (xwidth - width) * cell_size;
434+
u8* row = data + width * cell_size;
435+
u32 ih = height;
436+
while (ih-- > 0) {
437+
u8* src = row - cell_size;
438+
u8* dest = row;
439+
u8* end = row + fill_size;
440+
while (dest < end)
441+
*dest++ = *src++;
442+
row += xwidth * cell_size;
443+
}
444+
}
445+
446+
if (height > 0 && xheight > height) {
447+
const u32 line_size = xwidth * cell_size;
448+
u8* dest = data + height * line_size;
449+
u8* end = data + xheight * line_size;
450+
u8* src = dest - line_size;
451+
while (dest < end)
452+
*dest++ = *src++;
453+
}
454+
}
455+
428456
void EncodeDXT1(u8* dest_img, const u8* source_img, u32 width, u32 height) {
429457
assert(dest_img);
430458
assert(source_img);
@@ -450,6 +478,8 @@ void EncodeDXT1(u8* dest_img, const u8* source_img, u32 width, u32 height) {
450478
}
451479
}
452480

481+
NormalizeFrameIMG(width, height, xwidth, xheight, tmp);
482+
453483
const u32 bits_per_pixel = 4;
454484
const u32 block_width = 8;
455485
const u32 block_height = 8;

0 commit comments

Comments
 (0)