Skip to content

Commit

Permalink
feat: dds decoding custom
Browse files Browse the repository at this point in the history
  • Loading branch information
jvenin committed Apr 22, 2024
1 parent e6ac27e commit 1a797e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 103 deletions.
7 changes: 5 additions & 2 deletions lib/classes/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ class Model {
if (height == 0) {
return;
}
img.Image fullTexture =
img.Image(width: widthOffset, height: height, numChannels: 4);
img.Image fullTexture = img.Image(
width: widthOffset,
height: height,
numChannels: 4,
);

for (final p in fullTexture) {
for (var data in _texturesOffsets.entries) {
Expand Down
28 changes: 9 additions & 19 deletions lib/classes/texture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ class ModelTexture {
}

void applyAttributesToTexture(
img.Image imageToProcess, Color fillingColor, Color? partyColor) {
for (final frame in imageToProcess.frames) {
Color fillingColor,
Color? partyColor,
) {
if (imageData == null) {
return;
}
for (final frame in imageData!.frames) {
for (final p in frame) {
if (attribute.useHardAlpha) {
p.a = p.a <= 126 ? 0 : 255;
Expand Down Expand Up @@ -84,25 +89,10 @@ class ModelTexture {
if (_textureFile!.path.endsWith(".tga")) {
imageData = img.decodeTga(bytes);
} else {
final completer = Completer<Image>();
decodeImageFromList(bytes, completer.complete);
final test = await completer.future;
final uiBytes = await test.toByteData();

if (uiBytes == null) {
return null;
}

imageData = img.Image.fromBytes(
width: test.width,
height: test.height,
bytes: uiBytes.buffer,
numChannels: 4,
order: img.ChannelOrder.rgba,
);
imageData = img.decodeNamedImage(path, bytes);
}
if (imageData != null) {
applyAttributesToTexture(imageData!, fillingColor, partyColor);
applyAttributesToTexture(fillingColor, partyColor);
}
return imageData;
}
Expand Down
113 changes: 33 additions & 80 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
version: "2.5.0"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -93,10 +93,10 @@ packages:
dependency: "direct dev"
description:
name: build_runner
sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21"
sha256: "3ac61a79bfb6f6cc11f693591063a7f19a7af628dc52f141743edac5c16e8c22"
url: "https://pub.dev"
source: hosted
version: "2.4.8"
version: "2.4.9"
build_runner_core:
dependency: transitive
description:
Expand All @@ -117,10 +117,10 @@ packages:
dependency: transitive
description:
name: built_value
sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e
sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb
url: "https://pub.dev"
source: hosted
version: "8.9.1"
version: "8.9.2"
characters:
dependency: transitive
description:
Expand All @@ -137,22 +137,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
ci:
dependency: transitive
description:
name: ci
sha256: "145d095ce05cddac4d797a158bc4cf3b6016d1fe63d8c3d2fbd7212590adca13"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
url: "https://pub.dev"
source: hosted
version: "0.4.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -193,22 +177,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.3"
custom_lint:
dependency: transitive
description:
name: custom_lint
sha256: "445242371d91d2e24bd7b82e3583a2c05610094ba2d0575262484ad889c8f981"
url: "https://pub.dev"
source: hosted
version: "0.6.2"
custom_lint_core:
dependency: transitive
description:
name: custom_lint_core
sha256: ce5d6215f4e143f7780ce53f73dfa6fc503f39d2d30bef76c48be9ac1a09d9a6
sha256: a85e8f78f4c52f6c63cdaf8c872eb573db0231dcdf3c3a5906d493c1f8bc20e6
url: "https://pub.dev"
source: hosted
version: "0.6.2"
version: "0.6.3"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -253,10 +229,10 @@ packages:
dependency: "direct main"
description:
name: file_picker
sha256: caa6bc229eab3e32eb2f37b53a5f9d22a6981474afd210c512a7546c1e1a04f6
sha256: "1bbf65dd997458a08b531042ec3794112a6c39c07c37ff22113d2e7e4f81d4e4"
url: "https://pub.dev"
source: hosted
version: "6.2.0"
version: "6.2.1"
fixnum:
dependency: transitive
description:
Expand All @@ -282,10 +258,10 @@ packages:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
sha256: "8cf40eebf5dec866a6d1956ad7b4f7016e6c0cc69847ab946833b7d43743809f"
url: "https://pub.dev"
source: hosted
version: "2.0.17"
version: "2.0.19"
flutter_riverpod:
dependency: "direct main"
description:
Expand All @@ -308,10 +284,10 @@ packages:
dependency: "direct dev"
description:
name: freezed
sha256: "57247f692f35f068cae297549a46a9a097100685c6780fe67177503eea5ed4e5"
sha256: a434911f643466d78462625df76fd9eb13e57348ff43fe1f77bbe909522c67a1
url: "https://pub.dev"
source: hosted
version: "2.4.7"
version: "2.5.2"
freezed_annotation:
dependency: "direct main"
description:
Expand All @@ -324,10 +300,10 @@ packages:
dependency: transitive
description:
name: frontend_server_client
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "4.0.0"
gap:
dependency: "direct main"
description:
Expand Down Expand Up @@ -371,11 +347,12 @@ packages:
image:
dependency: "direct main"
description:
name: image
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
url: "https://pub.dev"
source: hosted
version: "4.1.7"
path: "."
ref: "9fb1ca17"
resolved-ref: "9fb1ca1757d98acc125d1809a2787b19f2a617a5"
url: "http://github.com/arceusVen1/image-with-dds"
source: git
version: "4.1.8"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -492,18 +469,18 @@ packages:
dependency: "direct main"
description:
name: path_provider
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.3"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668"
sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d
url: "https://pub.dev"
source: hosted
version: "2.2.2"
version: "2.2.4"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -564,10 +541,10 @@ packages:
dependency: transitive
description:
name: pointycastle
sha256: "70fe966348fe08c34bf929582f1d8247d9d9408130723206472b4687227e4333"
sha256: "79fbafed02cfdbe85ef3fd06c7f4bc2cbcba0177e61b765264853d4253b21744"
url: "https://pub.dev"
source: hosted
version: "3.8.0"
version: "3.9.0"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -624,14 +601,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.0"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.dev"
source: hosted
version: "0.27.7"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -669,14 +638,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -749,14 +710,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
uuid:
dependency: transitive
description:
name: uuid
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
url: "https://pub.dev"
source: hosted
version: "4.3.3"
vector_math:
dependency: "direct main"
description:
Expand Down Expand Up @@ -793,18 +746,18 @@ packages:
dependency: transitive
description:
name: web_socket_channel
sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2"
sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42"
url: "https://pub.dev"
source: hosted
version: "2.4.4"
version: "2.4.5"
win32:
dependency: transitive
description:
name: win32
sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480"
sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a"
url: "https://pub.dev"
source: hosted
version: "5.3.0"
version: "5.4.0"
xdg_directories:
dependency: transitive
description:
Expand All @@ -831,4 +784,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.10.0"
flutter: ">=3.16.0"
6 changes: 4 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ dependencies:
flutter_riverpod: ^2.4.10
freezed_annotation: ^2.4.1
gap: ^3.0.1
image: ^4.1.7

image:
git:
url: http://github.com/arceusVen1/image-with-dds
ref: 9fb1ca17
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 1a797e1

Please sign in to comment.