Added cropping support to texture tool

This commit is contained in:
2023-06-26 14:05:46 -07:00
parent bf93740c20
commit 723e09e182
45 changed files with 299 additions and 122 deletions

View File

@ -1,13 +1,13 @@
<prefab name="EthPrefab" extend="prefabs/EthPrefabBase" type="">
<item>
<MeshRenderer />
<QuadMeshHost xy0="-0.78236397748, 1" xy1="0.78236397748, -1" />
<QuadMeshHost xy0="-0.39118198874, .66439962476547842402" xy1="0.39118198874, 0" />
<SimpleTexturedMaterial ref="bodyMaterial" />
</item>
<item>
<MeshRenderer />
<QuadMeshHost xy0="-0.78236397748, 1" xy1="0.78236397748, -1" />
<QuadMeshHost xy0="-0.39118198874, 1" xy1="0.39118198874, .66439962476547842402" />
<SimpleTexturedMaterial ref="faceMaterial" />
</item>
</prefab>

View File

@ -3,21 +3,24 @@
<asset type="texture" name="texture_eth_face_day_anger" ref="faceDayAnger" />
<asset type="texture" name="texture_eth_face_day_confused" ref="faceDayConfused" />
<asset type="texture" name="texture_eth_pose_day_back" ref="poseDayBack" />
<asset type="texture" name="texture_eth_pose_day_cross" ref="poseDayCross" />
<events>
<set property="eth->faceMaterial->texture" to="&faceDayConfused->texture" type="Texture*" />
<set property="eth->bodyMaterial->texture" to="&poseDayBack->texture" type="Texture*" />
<text>
<string lang="en"><font style="italics">There is a bucket.</font></string>
<string lang="en"><font style="italics">Confused to Angry</font></string>
</text>
<set property="eth->faceMaterial->texture" to="&faceDayAnger->texture" type="Texture*" />
<text>
<string lang="en">It sways above your head like the mouth of a god. You are on Angelwood's best stage, and they are cheering for you, calling you their Queen, their Prom Queen.</string>
<string lang="en">Angry to Cross</string>
</text>
<set property="eth->bodyMaterial->texture" to="&poseDayCross->texture" type="Texture*" />
<text>
<string lang="en">And you are dead soon.</string>
</text>

View File

@ -3,16 +3,16 @@
<Camera ref="backCamera" />
</item>
<!-- <item position="0, 0, -10">
<item position="0, 0, -10">
<MeshRenderer />
<QuadMeshHost xy0="-500, -500" xy1="500, 500" />
<SimpleTexturedMaterial color="COLOR_BLACK" />
</item> -->
</item>
<item ref="eth" prefab="prefabs/EthPrefab" />
<item lookAt="0, 0.075, 2.5, 0, 0.075, 0">
<Camera ref="camera" />
<item lookAt="0, 0.65, 1.8, 0, .65, 0">
<Camera ref="camera" fov="0.610865" />
<CameraTexture ref="camTexture" camera="camera" />
</item>

View File

@ -3,7 +3,7 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(LIMINIAL_CHARACTER_SCALE 0.20)
set(LIMINIAL_CHARACTER_SCALE 0.2)
include("${CMAKE_CURRENT_LIST_DIR}/eth/CMakeLists.txt")

View File

@ -3,5 +3,14 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(ETH_FACE_TEXTURE_OPTIONS
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
CROP_END_Y=2833
)
include(${CMAKE_CURRENT_LIST_DIR}/day/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/day-alt/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night-alt/CMakeLists.txt)

View File

@ -0,0 +1,50 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
tool_texture(texture_eth_face_day_alt_anger
FILE="${CMAKE_CURRENT_LIST_DIR}/anger.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_confused
FILE="${CMAKE_CURRENT_LIST_DIR}/confused.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_eyeroll
FILE="${CMAKE_CURRENT_LIST_DIR}/eyeroll.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_fear
FILE="${CMAKE_CURRENT_LIST_DIR}/fear.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_happy
FILE="${CMAKE_CURRENT_LIST_DIR}/happy.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_haughty
FILE="${CMAKE_CURRENT_LIST_DIR}/haughty.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_sad
FILE="${CMAKE_CURRENT_LIST_DIR}/sad.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_alt_surprised
FILE="${CMAKE_CURRENT_LIST_DIR}/surprised.png"
${ETH_FACE_TEXTURE_OPTIONS}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

View File

@ -3,66 +3,47 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
tool_texture(texture_eth_face_day_anger
FILE="${CMAKE_CURRENT_LIST_DIR}/anger.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_confused
FILE="${CMAKE_CURRENT_LIST_DIR}/confused.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_eyeroll
FILE="${CMAKE_CURRENT_LIST_DIR}/eyeroll.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_fear
FILE="${CMAKE_CURRENT_LIST_DIR}/fear.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_happy
FILE="${CMAKE_CURRENT_LIST_DIR}/happy.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_haughty
FILE="${CMAKE_CURRENT_LIST_DIR}/haughty.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_sad
FILE="${CMAKE_CURRENT_LIST_DIR}/sad.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_day_surprised
FILE="${CMAKE_CURRENT_LIST_DIR}/surprised.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)

View File

@ -0,0 +1,50 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
tool_texture(texture_eth_face_night_alt_anger
FILE="${CMAKE_CURRENT_LIST_DIR}/anger.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_confused
FILE="${CMAKE_CURRENT_LIST_DIR}/confused.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_eyeroll
FILE="${CMAKE_CURRENT_LIST_DIR}/eyeroll.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_fear
FILE="${CMAKE_CURRENT_LIST_DIR}/fear.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_happy
FILE="${CMAKE_CURRENT_LIST_DIR}/happy.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_haughty
FILE="${CMAKE_CURRENT_LIST_DIR}/haughty.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_sad
FILE="${CMAKE_CURRENT_LIST_DIR}/sad.png"
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_alt_surprised
FILE="${CMAKE_CURRENT_LIST_DIR}/surprised.png"
${ETH_FACE_TEXTURE_OPTIONS}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -6,63 +6,45 @@
tool_texture(texture_eth_face_night_anger
FILE="${CMAKE_CURRENT_LIST_DIR}/anger.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_confused
FILE="${CMAKE_CURRENT_LIST_DIR}/confused.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_eyeroll
FILE="${CMAKE_CURRENT_LIST_DIR}/eyeroll.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_fear
FILE="${CMAKE_CURRENT_LIST_DIR}/fear.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_happy
FILE="${CMAKE_CURRENT_LIST_DIR}/happy.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_haughty
FILE="${CMAKE_CURRENT_LIST_DIR}/haughty.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_sad
FILE="${CMAKE_CURRENT_LIST_DIR}/sad.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_face_night_surprised
FILE="${CMAKE_CURRENT_LIST_DIR}/surprised.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_FACE_TEXTURE_OPTIONS}
)

View File

@ -3,5 +3,14 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(ETH_POSE_TEXTURE_OPTIONS
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
CROP_START_Y=1431
)
include(${CMAKE_CURRENT_LIST_DIR}/day/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/day-alt/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/night-alt/CMakeLists.txt)

View File

@ -0,0 +1,29 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
tool_texture(texture_eth_pose_day_alt_back
FILE="${CMAKE_CURRENT_LIST_DIR}/back.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_alt_cross
FILE="${CMAKE_CURRENT_LIST_DIR}/cross.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_alt_front
FILE="${CMAKE_CURRENT_LIST_DIR}/front.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_alt_hips
FILE="${CMAKE_CURRENT_LIST_DIR}/hips.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_alt_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
${ETH_POSE_TEXTURE_OPTIONS}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

View File

@ -5,35 +5,25 @@
tool_texture(texture_eth_pose_day_back
FILE="${CMAKE_CURRENT_LIST_DIR}/back.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_cross
FILE="${CMAKE_CURRENT_LIST_DIR}/cross.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_front
FILE="${CMAKE_CURRENT_LIST_DIR}/front.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_hips
FILE="${CMAKE_CURRENT_LIST_DIR}/hips.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_day_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)

View File

@ -0,0 +1,29 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
tool_texture(texture_eth_pose_night_alt_back
FILE="${CMAKE_CURRENT_LIST_DIR}/back.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_alt_cross
FILE="${CMAKE_CURRENT_LIST_DIR}/cross.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_alt_front
FILE="${CMAKE_CURRENT_LIST_DIR}/front.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_alt_hips
FILE="${CMAKE_CURRENT_LIST_DIR}/hips.png"
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_alt_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
${ETH_POSE_TEXTURE_OPTIONS}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

View File

@ -5,35 +5,25 @@
tool_texture(texture_eth_pose_night_back
FILE="${CMAKE_CURRENT_LIST_DIR}/back.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_cross
FILE="${CMAKE_CURRENT_LIST_DIR}/cross.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_front
FILE="${CMAKE_CURRENT_LIST_DIR}/front.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_hips
FILE="${CMAKE_CURRENT_LIST_DIR}/hips.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)
tool_texture(texture_eth_pose_night_neutral
FILE="${CMAKE_CURRENT_LIST_DIR}/neutral.png"
SCALE=${LIMINIAL_CHARACTER_SCALE}
FILTER_MIN=nearest
FILTER_MAG=nearest
${ETH_POSE_TEXTURE_OPTIONS}
)

View File

@ -1 +0,0 @@
9Test6

View File

@ -46,6 +46,10 @@ function(tool_texture target)
set(WRAP_X "")
set(WRAP_Y "")
set(SCALE "")
set(CROP_START_X "")
set(CROP_START_Y "")
set(CROP_END_X "")
set(CROP_END_Y "")
# Parse Args
foreach(_PAIR IN LISTS ARGN)
@ -75,6 +79,10 @@ function(tool_texture target)
--filterMin="${FILTER_MIN}"
--filterMag="${FILTER_MIN}"
--scale="${SCALE}"
--cropStartX="${CROP_START_X}"
--cropStartY="${CROP_START_Y}"
--cropEndX="${CROP_END_X}"
--cropEndY="${CROP_END_Y}"
COMMENT "Generating texture ${target} from ${FILE}"
DEPENDS ${DEPS}
)

View File

@ -21,7 +21,11 @@ std::map<std::string, std::string> TextureTool::getOptionalFlags() {
{ "scaleWrapX", "clamp" },
{ "scaleWrapY", "clamp" },
{ "scaleFilterX", "nearest" },
{ "scaleFilterY", "nearest" }
{ "scaleFilterY", "nearest" },
{ "cropStartX", "" },
{ "cropStartY", "" },
{ "cropEndX", "" },
{ "cropEndY", "" }
};
}
@ -36,41 +40,84 @@ int32_t TextureTool::start() {
std::cout << "Failed to open input file " << in.filename << std::endl;
return 1;
}
int w, h, channels;
auto imageRaw = stbi_load_from_file(in.file, &w, &h, &channels, STBI_rgb_alpha);
if(imageRaw == NULL) {
int32_t originalWidth, originalHeight, channels;
auto bufferCurrent = stbi_load_from_file(
in.file,
&originalWidth,
&originalHeight,
&channels,
STBI_rgb_alpha
);
if(bufferCurrent == NULL) {
std::cout << "Failed to load input texture!" << std::endl;
return 1;
}
in.close();
// Buffer to output
size_t len = STBI_rgb_alpha * w * h;
uint8_t *dataImage = (uint8_t*)malloc(sizeof(uint8_t) * len);
// Create a temporary buffer to hold pixels.
size_t len = STBI_rgb_alpha * originalWidth * originalHeight;
uint8_t *bufferTemporary = (uint8_t*)malloc(sizeof(uint8_t) * len);
int32_t currentWidth = originalWidth;
int32_t currentHeight = originalHeight;
float_t scale = 1;
if(!flags["scale"].empty()) {
scale = std::stof(flags["scale"]);
// Crop
int32_t cropStartX = 0;
int32_t cropStartY = 0;
int32_t cropEndX = 0;
int32_t cropEndY = 0;
if(!flags["cropStartX"].empty()) cropStartX = std::stoi(flags["cropStartX"]);
if(!flags["cropStartY"].empty()) cropStartY = std::stoi(flags["cropStartY"]);
if(!flags["cropEndX"].empty()) cropEndX = std::stoi(flags["cropEndX"]);
if(!flags["cropEndY"].empty()) cropEndY = std::stoi(flags["cropEndY"]);
if(cropStartX > 0 || cropStartY > 0 || cropEndX > 0 || cropEndY > 0) {
int32_t cropWidth = originalWidth - cropStartX - cropEndX;
int32_t cropHeight = originalHeight - cropStartY - cropEndY;
float_t s0, t0, s1, t1;
s0 = (float_t)cropStartX / (float_t)originalWidth;
t0 = (float_t)cropStartY / (float_t)originalHeight;
s1 = 1.0f - ((float_t)cropEndX / (float_t)originalWidth);
t1 = 1.0f - ((float_t)cropEndY / (float_t)originalHeight);
stbir_resize_region(
bufferCurrent, currentWidth, currentHeight, 0,
bufferTemporary, cropWidth, cropHeight, 0,
STBIR_TYPE_UINT8,
STBI_rgb_alpha, -1, 0,
STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
STBIR_FILTER_BOX, STBIR_FILTER_BOX,
STBIR_COLORSPACE_LINEAR, NULL,
s0, t0, s1, t1
);
memcpy(bufferCurrent, bufferTemporary, sizeof(uint8_t) * len);
currentWidth = cropWidth;
currentHeight = cropHeight;
}
if(scale != 1) {
// Scale
if(!flags["scale"].empty()) {
float_t scale = std::stof(flags["scale"]);
int32_t scaleWidth = currentWidth * scale;
int32_t scaleHeight = currentHeight * scale;
stbir_resize_uint8_generic(
imageRaw, w, h, 0,
dataImage, w * scale, h * scale, 0,
bufferCurrent, currentWidth, currentHeight, 0,
bufferTemporary, scaleWidth, scaleHeight, 0,
STBI_rgb_alpha, -1, 0,
STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR,
NULL
);
w = w * scale;
h = h * scale;
printf("Changing size to %ix%i\n", w, h);
} else {
memcpy(dataImage, imageRaw, len);
memcpy(bufferCurrent, bufferTemporary, sizeof(uint8_t) * len);
currentWidth = scaleWidth;
currentHeight = scaleHeight;
}
stbi_image_free(imageRaw);
// Wrapping Settings
std::function<int32_t(std::string)> wrapFromString = [&](std::string wr) {
if(wr == "repeat") return 0;
if(wr == "mirror") return 1;
@ -94,8 +141,8 @@ int32_t TextureTool::start() {
// Write info
char headerBuffer[256];
size_t headerBufferLength = sprintf((char *)headerBuffer, "DT_2.00|%i|%i|%i|%i|%i|%i|%i|",
w,
h,
currentWidth,
currentHeight,
4, // RGBA,
wrapX, // WRAPX
wrapY, // WRAPY
@ -119,11 +166,12 @@ int32_t TextureTool::start() {
}
// Write texture
if(!out.writeRaw((char *)dataImage, sizeof(uint8_t) * len)) {
if(!out.writeRaw((char*)bufferCurrent, sizeof(uint8_t) * len)) {
std::cout << "Failed to write texture data for " << out.filename << std::endl;
return 1;
}
free(dataImage);
free(bufferCurrent);
free(bufferTemporary);
return 0;
}