mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79295aa258 | ||
|
|
b721294e62 | ||
|
|
f3f7b69954 | ||
|
|
6980a32759 | ||
|
|
81e2a38829 | ||
|
|
d496a13d63 | ||
|
|
850f7f335a | ||
|
|
78a8f18375 | ||
|
|
696a677bc3 | ||
|
|
1ef781f072 | ||
|
|
2a41577d28 | ||
|
|
b3371b34d3 | ||
|
|
05c961fcac | ||
|
|
061968eeb8 | ||
|
|
9a02c7149b | ||
|
|
705dc88bbb | ||
|
|
3187e92d6b | ||
|
|
b4863dcae7 | ||
|
|
d416ad0318 | ||
|
|
8220d27370 | ||
|
|
43d7db671e | ||
|
|
6fb2c430af | ||
|
|
14f22a1b28 | ||
|
|
52d6613263 | ||
|
|
301212b278 | ||
|
|
07812e1f48 | ||
|
|
16cdf61406 | ||
|
|
e5da67340b | ||
|
|
750dae931e | ||
|
|
f05609904a | ||
|
|
f90871bd03 | ||
|
|
c578ab204b | ||
|
|
699e437511 | ||
|
|
8b7644d2bf | ||
|
|
aea54da07a | ||
|
|
18a5b27333 | ||
|
|
ddcb97be28 | ||
|
|
959f6584b2 | ||
|
|
8f4390a315 | ||
|
|
ccd0276d99 | ||
|
|
4064c799a7 | ||
|
|
093a810e30 | ||
|
|
20c835e821 | ||
|
|
243caa5bf8 | ||
|
|
958b831205 | ||
|
|
2085dbcce4 | ||
|
|
d6ad4d5a6f | ||
|
|
1a5ca1405e | ||
|
|
d5da591f92 | ||
|
|
dd129401c7 | ||
|
|
6855b6b287 | ||
|
|
0274cb1a05 | ||
|
|
e3e7779739 | ||
|
|
40326e20bc | ||
|
|
fa94774143 | ||
|
|
58b113e1e0 | ||
|
|
862995196f | ||
|
|
691796b919 | ||
|
|
a6f54dd9b1 | ||
|
|
fe93d46a6c | ||
|
|
7c6ac4ba0e | ||
|
|
977800b5bb | ||
|
|
f9c8dd980f | ||
|
|
aea23c3be6 | ||
|
|
6b65475bc1 | ||
|
|
4835e38ec6 | ||
|
|
874bef99eb | ||
|
|
6908984ff2 | ||
|
|
f012b3a4d9 | ||
|
|
541176ad79 | ||
|
|
a44a788060 | ||
|
|
5c937aca17 | ||
|
|
04b086c372 | ||
|
|
99b5d670f3 | ||
|
|
53beeff97e | ||
|
|
c566ecc668 | ||
|
|
3d3746e2d7 | ||
|
|
cd37722a53 | ||
|
|
7cea861443 | ||
|
|
fb48fa3b94 | ||
|
|
a6bc637d47 | ||
|
|
ba40e2c7d7 | ||
|
|
e2fba56e81 | ||
|
|
92d1909562 | ||
|
|
bb346aabbc | ||
|
|
18abd1731b | ||
|
|
b4ad9bcb39 | ||
|
|
e4c873b3b0 | ||
|
|
9c89b6fac5 | ||
|
|
ce581c0ea6 | ||
|
|
b992959c24 | ||
|
|
07c653873b | ||
|
|
03373afddb | ||
|
|
35ed50dc26 | ||
|
|
a5cfc5cbf7 | ||
|
|
dc1ecc5d46 | ||
|
|
89b76dafd3 | ||
|
|
56ba562fd5 | ||
|
|
1b2208b38a | ||
|
|
28e3a22265 | ||
|
|
5705e12af0 | ||
|
|
3e7eae579e | ||
|
|
7fb7530a37 | ||
|
|
b1dfd0b6d8 | ||
|
|
9259884731 | ||
|
|
4e1251649b | ||
|
|
26fcfb695e | ||
|
|
1c156c4cd3 | ||
|
|
c019bc5a04 | ||
|
|
099daf3044 | ||
|
|
5de28c63c3 | ||
|
|
f4d37ff16c | ||
|
|
61c3a861f7 | ||
|
|
437db55ae8 | ||
|
|
6ed0c07a83 | ||
|
|
54e3e20d0c | ||
|
|
1281377f2e | ||
|
|
7693de3ef9 | ||
|
|
4040a0a7a7 | ||
|
|
07d932c1a1 | ||
|
|
be63ebdb23 | ||
|
|
8458eb5866 | ||
|
|
19204e4dd2 | ||
|
|
8aa1840eb4 | ||
|
|
45267fc7fd | ||
|
|
3ad6884592 | ||
|
|
7c65daebaa | ||
|
|
068140150b | ||
|
|
5f2e7dc5c3 | ||
|
|
84eeba1e36 | ||
|
|
88c33f5dfa | ||
|
|
9555cbf25c | ||
|
|
cab5e7cfb8 | ||
|
|
2611088bd9 | ||
|
|
2256161eab | ||
|
|
d9cbcc48d8 | ||
|
|
113b793a6e | ||
|
|
fac3ca64df | ||
|
|
1485a246f1 | ||
|
|
81ecc464e5 | ||
|
|
d158e90448 | ||
|
|
7f3808b075 | ||
|
|
23c8e2c64a | ||
|
|
ea1c9c34ce | ||
|
|
d55e1e69a8 | ||
|
|
f6ea7a9269 | ||
|
|
07b0e7d407 | ||
|
|
56a70a2895 | ||
|
|
f967a521b0 | ||
|
|
4f775c4eff | ||
|
|
9a5da95897 | ||
|
|
4e037d8ddc | ||
|
|
5d2f86b18f | ||
|
|
d701ff24fc | ||
|
|
7be1d516f1 | ||
|
|
578a0633d1 | ||
|
|
94e4994027 | ||
|
|
74d081ca21 | ||
|
|
8e1792bfaf | ||
|
|
734f158f7f | ||
|
|
7aa9794941 | ||
|
|
9675ef0943 | ||
|
|
d4f7b94dea | ||
|
|
20d450ac1f | ||
|
|
2711b749db | ||
|
|
6465aa35c3 | ||
|
|
80d8c58d3a | ||
|
|
f8bee850bd | ||
|
|
eeb8866c41 | ||
|
|
129576d48e | ||
|
|
f28d991abe | ||
|
|
b1056490ec | ||
|
|
cab5cabc4e | ||
|
|
b0038a5184 | ||
|
|
6665fab8d9 | ||
|
|
6998127fe8 | ||
|
|
8f68931c40 | ||
|
|
eb9536456e |
No files matched your search
+251
@@ -0,0 +1,251 @@
|
||||
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
|
||||
# Remove the line below if you want to inherit .editorconfig settings from higher directories
|
||||
root = true
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
#### Core EditorConfig Options ####
|
||||
|
||||
# Indentation and spacing
|
||||
indent_size = 4
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
|
||||
# New line preferences
|
||||
end_of_line = crlf
|
||||
insert_final_newline =true
|
||||
|
||||
#### .NET Coding Conventions ####
|
||||
|
||||
# Organize usings
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = false
|
||||
|
||||
# this. and Me. preferences
|
||||
dotnet_style_qualification_for_event = false:silent
|
||||
dotnet_style_qualification_for_field = false:silent
|
||||
dotnet_style_qualification_for_method = false:silent
|
||||
dotnet_style_qualification_for_property = false:silent
|
||||
|
||||
# Language keywords vs BCL types preferences
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
|
||||
dotnet_style_predefined_type_for_member_access = true:suggestion
|
||||
|
||||
# Parentheses preferences
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
|
||||
|
||||
# Modifier preferences
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||
|
||||
# Expression-level preferences
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_object_initializer = false:suggestion
|
||||
dotnet_style_prefer_auto_properties = true:suggestion
|
||||
dotnet_style_prefer_compound_assignment = true:suggestion
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = false:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = false:silent
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
|
||||
|
||||
# Field preferences
|
||||
dotnet_style_readonly_field = true:suggestion
|
||||
|
||||
# Parameter preferences
|
||||
dotnet_code_quality_unused_parameters = all:suggestion
|
||||
|
||||
#### C# Coding Conventions ####
|
||||
|
||||
# var preferences
|
||||
csharp_style_var_elsewhere = false:warning
|
||||
csharp_style_var_for_built_in_types = false:warning
|
||||
csharp_style_var_when_type_is_apparent = false:suggestion
|
||||
|
||||
# Expression-bodied members
|
||||
csharp_style_expression_bodied_accessors = true:silent
|
||||
csharp_style_expression_bodied_constructors = false:silent
|
||||
csharp_style_expression_bodied_indexers = true:silent
|
||||
csharp_style_expression_bodied_lambdas = true:silent
|
||||
csharp_style_expression_bodied_local_functions = false:silent
|
||||
csharp_style_expression_bodied_methods = false:silent
|
||||
csharp_style_expression_bodied_operators = false:silent
|
||||
csharp_style_expression_bodied_properties = true:silent
|
||||
|
||||
# Pattern matching preferences
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
|
||||
csharp_style_prefer_switch_expression = true:suggestion
|
||||
|
||||
# Null-checking preferences
|
||||
csharp_style_conditional_delegate_call = true:suggestion
|
||||
|
||||
# Modifier preferences
|
||||
csharp_prefer_static_local_function = true:suggestion
|
||||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
|
||||
|
||||
# Code-block preferences
|
||||
csharp_prefer_braces = true:suggestion
|
||||
csharp_prefer_simple_using_statement = true:suggestion
|
||||
|
||||
# Expression-level preferences
|
||||
csharp_prefer_simple_default_expression = true:suggestion
|
||||
csharp_style_deconstructed_variable_declaration = true:suggestion
|
||||
csharp_style_inlined_variable_declaration = true:suggestion
|
||||
csharp_style_pattern_local_over_anonymous_function = true:suggestion
|
||||
csharp_style_prefer_index_operator = true:suggestion
|
||||
csharp_style_prefer_range_operator = true:suggestion
|
||||
csharp_style_throw_expression = true:suggestion
|
||||
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
|
||||
|
||||
# 'using' directive preferences
|
||||
csharp_using_directive_placement = outside_namespace:silent
|
||||
|
||||
#### C# Formatting Rules ####
|
||||
|
||||
# New line preferences
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
|
||||
# Indentation preferences
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = true
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
|
||||
# Space preferences
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
|
||||
# Wrapping preferences
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = true
|
||||
|
||||
#### Naming styles ####
|
||||
|
||||
# Naming rules
|
||||
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
|
||||
# Symbol specifications
|
||||
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
|
||||
# Naming styles
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
csharp_style_namespace_declarations = block_scoped:silent
|
||||
csharp_style_prefer_method_group_conversion = true:silent
|
||||
csharp_style_prefer_null_check_over_type_check = true:suggestion
|
||||
csharp_style_prefer_local_over_anonymous_function = true:suggestion
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
|
||||
csharp_style_prefer_tuple_swap = true:suggestion
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
|
||||
csharp_style_prefer_parameter_null_checking = true:suggestion
|
||||
csharp_style_prefer_pattern_matching = true:silent
|
||||
csharp_style_prefer_not_pattern = true:suggestion
|
||||
csharp_style_prefer_extended_property_pattern = true:suggestion
|
||||
csharp_style_prefer_top_level_statements = false:silent
|
||||
dotnet_diagnostic.CA1309.severity = error
|
||||
dotnet_diagnostic.CA1311.severity = suggestion
|
||||
dotnet_diagnostic.SYSLIB1054.severity = warning
|
||||
|
||||
[*.{cs,vb}]
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
|
||||
dotnet_style_prefer_auto_properties = true:suggestion
|
||||
dotnet_style_object_initializer = false:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
tab_width = 4
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = false:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = false:silent
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||
dotnet_style_prefer_compound_assignment = true:suggestion
|
||||
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
||||
dotnet_style_namespace_match_folder = true:suggestion
|
||||
dotnet_style_readonly_field = true:suggestion
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
|
||||
dotnet_style_predefined_type_for_member_access = true:suggestion
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
|
||||
dotnet_code_quality_unused_parameters = all:suggestion
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
|
||||
dotnet_style_qualification_for_field = false:silent
|
||||
dotnet_style_qualification_for_property = false:silent
|
||||
dotnet_style_qualification_for_method = false:silent
|
||||
dotnet_style_qualification_for_event = false:silent
|
||||
@@ -1,63 +0,0 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
||||
@@ -0,0 +1,18 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "nuget" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
# Workflow files stored in the
|
||||
# default location of `.github/workflows`
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -12,11 +12,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v1
|
||||
uses: actions/setup-dotnet@v3.2.0
|
||||
with:
|
||||
dotnet-version: 6.0.x
|
||||
dotnet-version: 7.0.x
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
|
||||
+4
-1
@@ -3,4 +3,7 @@ obj
|
||||
*.csproj.user
|
||||
.vs
|
||||
.idea
|
||||
.vscode
|
||||
.vscode
|
||||
launchSettings.json
|
||||
test.png
|
||||
textureformats/
|
||||
@@ -0,0 +1,25 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Benchmarks;
|
||||
|
||||
public class Argb32Decoding
|
||||
{
|
||||
private const int Width = 256;//ignoring smaller mips
|
||||
private const int Height = 256;//ignoring smaller mips
|
||||
private readonly byte[] inputData;
|
||||
private readonly byte[] outputData;
|
||||
|
||||
public Argb32Decoding()
|
||||
{
|
||||
inputData = File.ReadAllBytes(PathConstants.PathToTestFiles + "Rgb/" + "test.argb32");
|
||||
outputData = new byte[Width * Height * sizeof(uint)];
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int OriginalMethod() => RgbConverter.ARGB32ToBGRA32(inputData, Width, Height, outputData);
|
||||
|
||||
[Benchmark]
|
||||
public int GenericMethod() => RgbConverter.Convert<ColorARGB32, byte, ColorBGRA32, byte>(inputData, Width, Height, outputData);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder\AssetRipper.TextureDecoder.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AssetRipper.TextureDecoder.Benchmarks;
|
||||
|
||||
internal static class PathConstants
|
||||
{
|
||||
internal const string PathToRepositoryRoot = "../../../../../../../../";
|
||||
internal const string PathToTestFiles = PathToRepositoryRoot + "TestFiles/";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Benchmarks;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
BenchmarkRunner.Run(typeof(Program).Assembly);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Benchmarks;
|
||||
|
||||
public class Rgb9e5Decoding
|
||||
{
|
||||
private const int Width = 256;//ignoring smaller mips
|
||||
private const int Height = 256;//ignoring smaller mips
|
||||
private readonly byte[] inputData;
|
||||
private readonly byte[] outputData;
|
||||
|
||||
public Rgb9e5Decoding()
|
||||
{
|
||||
inputData = File.ReadAllBytes(PathConstants.PathToTestFiles + "Rgb/" + "test.rgb9e5float");
|
||||
outputData = new byte[Width * Height * sizeof(uint)];
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int OriginalMethod() => RgbConverter.RGB9e5FloatToBGRA32(inputData, Width, Height, outputData);
|
||||
|
||||
[Benchmark]
|
||||
public int GenericMethod() => RgbConverter.Convert<ColorRGB9e5, double, ColorBGRA32, byte>(inputData, Width, Height, outputData);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Text.SourceGeneration" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder.SourceGeneration.Common\AssetRipper.TextureDecoder.SourceGeneration.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,260 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.ColorGenerator;
|
||||
internal static class NumericConversionGenerator
|
||||
{
|
||||
private const string OutputNamespace = "AssetRipper.TextureDecoder.Rgb";
|
||||
private const string OutputDirectory = "../../../../AssetRipper.TextureDecoder/Rgb/";
|
||||
private const string ClassName = "NumericConversion";
|
||||
private const string ChangeSign = "ChangeSign";
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
Console.WriteLine(ClassName);
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputDirectory, ClassName);
|
||||
Write(writer);
|
||||
}
|
||||
|
||||
private static void Write(IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(OutputNamespace);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"static partial class {ClassName}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
WritePrimaryConvertMethod(writer);
|
||||
foreach (CSharpPrimitives.Data from in CSharpPrimitives.List)
|
||||
{
|
||||
WriteConvertMethod(writer, from);
|
||||
}
|
||||
WriteGetValueMethod(writer, "GetMinimumValue");
|
||||
WriteGetValueMethod(writer, "GetMaximumValue");
|
||||
WriteChangeSignMethods(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteChangeSignMethods(IndentedTextWriter writer)
|
||||
{
|
||||
foreach ((CSharpPrimitives.Data unsignedType, CSharpPrimitives.Data signedType) in GetIntegerTypes())
|
||||
{
|
||||
WriteMethod(writer, unsignedType, signedType, unsignedType);
|
||||
WriteMethod(writer, signedType, unsignedType, unsignedType);
|
||||
}
|
||||
|
||||
static void WriteMethod(IndentedTextWriter writer, CSharpPrimitives.Data parameterType, CSharpPrimitives.Data returnType, CSharpPrimitives.Data unsignedType)
|
||||
{
|
||||
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]");
|
||||
writer.WriteLine($"private static {returnType.LangName} {ChangeSign}({parameterType.LangName} value)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
string methodName = parameterType == unsignedType ? "ToSignedNumber" : "ToUnsignedNumber";
|
||||
writer.WriteLine($"return {methodName}<{parameterType.LangName}, {returnType.LangName}>(value);");
|
||||
}
|
||||
writer.WriteLineNoTabs();
|
||||
}
|
||||
|
||||
static IEnumerable<(CSharpPrimitives.Data, CSharpPrimitives.Data)> GetIntegerTypes()
|
||||
{
|
||||
foreach (CSharpPrimitives.Data data in CSharpPrimitives.List)
|
||||
{
|
||||
if (data.IsSignedInteger(out CSharpPrimitives.Data? unsignedData))
|
||||
{
|
||||
yield return (unsignedData, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WritePrimaryConvertMethod(IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]");
|
||||
writer.WriteLine($"public static TTo Convert<TFrom, TTo>(TFrom value) where TFrom : unmanaged where TTo : unmanaged");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("if (typeof(TFrom) == typeof(TTo))");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("return Unsafe.As<TFrom, TTo>(ref value);");
|
||||
}
|
||||
foreach (CSharpPrimitives.Data from in CSharpPrimitives.List)
|
||||
{
|
||||
writer.WriteLine($"else if (typeof(TFrom) == typeof({from.LangName}))");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"return {ConvertMethodName(from.Type)}<TTo>(Unsafe.As<TFrom, {from.LangName}>(ref value));");
|
||||
}
|
||||
}
|
||||
writer.WriteLine("else");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("return ThrowOrReturnDefault<TTo>();");
|
||||
}
|
||||
}
|
||||
writer.WriteLineNoTabs();
|
||||
}
|
||||
|
||||
private static void WriteConvertMethod(IndentedTextWriter writer, CSharpPrimitives.Data from)
|
||||
{
|
||||
string methodName = ConvertMethodName(from.Type);
|
||||
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]");
|
||||
writer.WriteLine($"private static TTo {methodName}<TTo>({from.LangName} value) where TTo : unmanaged");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
if (from.IsSignedInteger(out CSharpPrimitives.Data? unsignedFromData))
|
||||
{
|
||||
writer.WriteLine($"{unsignedFromData.LangName} unsigned = {ChangeSign}(value);");
|
||||
writer.WriteLine($"return {ConvertMethodName(unsignedFromData.Type)}<TTo>(unsigned);");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (CSharpPrimitives.Data to in CSharpPrimitives.List)
|
||||
{
|
||||
string ifOrElseIf = to == CSharpPrimitives.FirstData ? "if" : "else if";
|
||||
writer.WriteLine($"{ifOrElseIf} (typeof(TTo) == typeof({to.LangName}))");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
if (from == to)
|
||||
{
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref value);");
|
||||
}
|
||||
else if (to.IsSignedInteger(out CSharpPrimitives.Data? unsignedTo))
|
||||
{
|
||||
writer.WriteLine($"{to.LangName} converted = {ChangeSign}({methodName}<{unsignedTo.LangName}>(value));");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
else if (from.IsFloatingPoint)
|
||||
{
|
||||
if (to.IsFloatingPoint)
|
||||
{
|
||||
writer.WriteLine($"{to.LangName} converted = ({to.LangName})value;");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(to.IsUnsignedInteger);
|
||||
if (from.Type == typeof(Half))
|
||||
{
|
||||
writer.WriteComment("We use float because it has enough precision to convert from Half to any integer type.");
|
||||
writer.WriteLine($"return {ConvertMethodName(typeof(float))}<TTo>((float)value);");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteComment("x must be clamped because of rounding errors.");
|
||||
string minValue = to.MinValue;
|
||||
string maxValue = to.MaxValue;
|
||||
writer.WriteLine($"{from.LangName} x = value * ({from.LangName}){maxValue};");
|
||||
writer.WriteLine($"{to.LangName} converted = ({from.LangName}){maxValue} < x ? {maxValue} : (x > ({from.LangName}){minValue} ? ({to.LangName})x : {minValue});");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(from.IsUnsignedInteger);
|
||||
if (to.IsFloatingPoint)
|
||||
{
|
||||
if (to.Type == typeof(Half))
|
||||
{
|
||||
writer.WriteComment("There isn't enough precision to convert from anything bigger than byte to Half, so we convert to float first.");
|
||||
writer.WriteLine($"float x = {methodName}<float>(value);");
|
||||
writer.WriteLine("Half converted = (Half)x;");
|
||||
writer.WriteLine("return Unsafe.As<Half, TTo>(ref converted);");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteLine($"{to.LangName} converted = ({to.LangName})value / ({to.LangName}){from.MaxValue};");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(to.IsUnsignedInteger);
|
||||
writer.WriteComment("See https://github.com/AssetRipper/TextureDecoder/issues/19");
|
||||
if (from.Size < to.Size)
|
||||
{
|
||||
int divided = to.Size / from.Size;
|
||||
string conversionType = to.Size < sizeof(uint) ? "uint" : to.LangName;
|
||||
writer.WriteLine("unchecked");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.Write($"{to.LangName} converted = ({to.LangName})(");
|
||||
for (int i = divided - 1; i > 0; i--)
|
||||
{
|
||||
writer.Write($"(({conversionType})value << {i * from.Size * 8}) | ");
|
||||
}
|
||||
writer.WriteLine("value);");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(from.Size > to.Size);
|
||||
if (from.Type == typeof(ushort) && to.Type == typeof(byte))
|
||||
{
|
||||
writer.WriteComment("This is a special case where we already know an optimal algorithm.");
|
||||
writer.WriteLine("uint x = (value * 255u + 32895u) >> 16;");
|
||||
writer.WriteLine("byte converted = unchecked((byte)x);");
|
||||
writer.WriteLine("return Unsafe.As<byte, TTo>(ref converted);");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteComment($"There are more accurate ways to map {from.TypeName} onto {to.TypeName}, but this is the simplest.");
|
||||
string conversionType = from.Size < sizeof(uint) ? "uint" : from.LangName;
|
||||
writer.WriteLine("unchecked");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
int offset = (from.Size / to.Size - 1) * to.Size * 8;
|
||||
writer.WriteLine($"{to.LangName} converted = ({to.LangName})(({conversionType})value >> {offset});");
|
||||
writer.WriteLine($"return Unsafe.As<{to.LangName}, TTo>(ref converted);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.WriteLine("else");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("return ThrowOrReturnDefault<TTo>();");
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.WriteLineNoTabs();
|
||||
}
|
||||
|
||||
private static void WriteGetValueMethod(IndentedTextWriter writer, string methodName)
|
||||
{
|
||||
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]");
|
||||
writer.WriteLine($"public static T {methodName}<T>() where T : unmanaged");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
foreach (CSharpPrimitives.Data from in CSharpPrimitives.List)
|
||||
{
|
||||
string ifOrElseIf = from == CSharpPrimitives.FirstData ? "if" : "else if";
|
||||
writer.WriteLine($"{ifOrElseIf} (typeof(T) == typeof({from.LangName}))");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"{from.LangName} value = {methodName}Safe<{from.LangName}>();");
|
||||
writer.WriteLine($"return Unsafe.As<{from.LangName}, T>(ref value);");
|
||||
}
|
||||
}
|
||||
writer.WriteLine("else");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("return ThrowOrReturnDefault<T>();");
|
||||
}
|
||||
}
|
||||
writer.WriteLineNoTabs();
|
||||
}
|
||||
|
||||
private static string ConvertMethodName(Type from)
|
||||
{
|
||||
return $"Convert{from.Name}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.ColorGenerator;
|
||||
|
||||
internal static partial class Program
|
||||
{
|
||||
private const string AttributeNamespace = "AssetRipper.TextureDecoder.Attributes";
|
||||
private const string OutputNamespace = "AssetRipper.TextureDecoder.Rgb.Formats";
|
||||
private const string OutputFolder = "../../../../AssetRipper.TextureDecoder/Rgb/Formats/";
|
||||
|
||||
/// <summary>
|
||||
/// Name, Type, Red, Blue, Green, Alpha, Fully Utilized
|
||||
/// </summary>
|
||||
private static readonly List<(string, Type, bool, bool, bool, bool, bool)> CustomColors = new()
|
||||
{
|
||||
( "ColorARGB16", typeof(byte), true, true, true, true, false ),
|
||||
( "ColorARGB32", typeof(byte), true, true, true, true, true ),
|
||||
( "ColorBGRA32", typeof(byte), true, true, true, true, true ),
|
||||
( "ColorRGB16", typeof(byte), true, true, true, false, false ),
|
||||
( "ColorRGB9e5", typeof(double), true, true, true, false, false ),
|
||||
( "ColorRGBA16", typeof(byte), true, true, true, true, false ),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Name, Red, Blue, Green, Alpha
|
||||
/// </summary>
|
||||
private static readonly List<(string, bool, bool, bool, bool)> GenericColors = new()
|
||||
{
|
||||
( "ColorR", true, false, false, false ),
|
||||
( "ColorRG", true, true, false, false ),
|
||||
( "ColorRGB", true, true, true, false ),
|
||||
( "ColorRGBA", true, true, true, true ),
|
||||
( "ColorA", false, false, false, true ),
|
||||
};
|
||||
|
||||
static void Main()
|
||||
{
|
||||
foreach (var customColor in CustomColors)
|
||||
{
|
||||
WriteCustomColor(customColor);
|
||||
}
|
||||
foreach (var genericColor in GenericColors)
|
||||
{
|
||||
WriteGenericColor(genericColor);
|
||||
}
|
||||
NumericConversionGenerator.Run();
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void WriteCustomColor((string, Type, bool, bool, bool, bool, bool) details)
|
||||
{
|
||||
(string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized) = details;
|
||||
Console.WriteLine(name);
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, name);
|
||||
WriteCustomColor(writer, name, type, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized);
|
||||
}
|
||||
|
||||
private static void WriteGenericColor((string, bool, bool, bool, bool) details)
|
||||
{
|
||||
(string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha) = details;
|
||||
Console.WriteLine(name);
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, name);
|
||||
WriteGenericColor(writer, name, hasRed, hasGreen, hasBlue, hasAlpha);
|
||||
}
|
||||
|
||||
private static void WriteCustomColor(IndentedTextWriter writer, string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized)
|
||||
{
|
||||
string typeName = CSharpPrimitives.Dictionary[type].LangName;
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
using (new Namespace(writer, OutputNamespace))
|
||||
{
|
||||
writer.WriteLine($"public partial struct {name} : IColor<{typeName}>");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
WriteColorBaseStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized, typeName);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteToString(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
|
||||
{
|
||||
writer.WriteLine("public override string ToString()");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.Append("return $\"{{ ");
|
||||
bool first = true;
|
||||
if (hasRed)
|
||||
{
|
||||
sb.Append("R: {R}");
|
||||
first = false;
|
||||
}
|
||||
if (hasGreen)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append("G: {G}");
|
||||
first = false;
|
||||
}
|
||||
if (hasBlue)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append("B: {B}");
|
||||
first = false;
|
||||
}
|
||||
if (hasAlpha)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append("A: {A}");
|
||||
}
|
||||
sb.Append(" }}\";");
|
||||
writer.WriteLine(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteColorBaseStaticProperties(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized, string typeName)
|
||||
{
|
||||
writer.WriteLine($"static bool IColorBase.HasRedChannel => {hasRed.ToLowerString()};");
|
||||
writer.WriteLine($"static bool IColorBase.HasGreenChannel => {hasGreen.ToLowerString()};");
|
||||
writer.WriteLine($"static bool IColorBase.HasBlueChannel => {hasBlue.ToLowerString()};");
|
||||
writer.WriteLine($"static bool IColorBase.HasAlphaChannel => {hasAlpha.ToLowerString()};");
|
||||
writer.WriteLine($"static bool IColorBase.ChannelsAreFullyUtilized => {fullyUtilized.ToLowerString()};");
|
||||
writer.WriteLine($"static Type IColorBase.ChannelType => typeof({typeName});");
|
||||
}
|
||||
|
||||
private static void WriteGenericColor(IndentedTextWriter writer, string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
|
||||
{
|
||||
const string typeName = "T";
|
||||
const string minValue = $"NumericConversion.GetMinimumValueSafe<T>()";
|
||||
const string maxValue = $"NumericConversion.GetMaximumValueSafe<T>()";
|
||||
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLineNoTabs();
|
||||
|
||||
writer.WriteFileScopedNamespace(OutputNamespace);
|
||||
writer.WriteLineNoTabs();
|
||||
|
||||
string constraints = hasRed && hasGreen && hasBlue && hasAlpha
|
||||
? "unmanaged"
|
||||
: "unmanaged, INumberBase<T>, IMinMaxValue<T>";
|
||||
writer.WriteLine($"public partial struct {name}<T> : IColor<{typeName}> where T : {constraints}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
WriteProperty(writer, hasRed, typeName, 'R', minValue);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteProperty(writer, hasGreen, typeName, 'G', minValue);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteProperty(writer, hasBlue, typeName, 'B', minValue);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteProperty(writer, hasAlpha, typeName, 'A', maxValue);
|
||||
writer.WriteLineNoTabs();
|
||||
|
||||
WriteGetChannels(writer, typeName);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteSetChannels(writer, typeName, hasRed, hasGreen, hasBlue, hasAlpha);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteColorBaseStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, true, typeName);
|
||||
writer.WriteLineNoTabs();
|
||||
WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteGetChannels(IndentedTextWriter writer, string typeName)
|
||||
{
|
||||
writer.WriteLine($"public readonly void GetChannels(out {typeName} r, out {typeName} g, out {typeName} b, out {typeName} a)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("r = R;");
|
||||
writer.WriteLine("g = G;");
|
||||
writer.WriteLine("b = B;");
|
||||
writer.WriteLine("a = A;");
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSetChannels(IndentedTextWriter writer, string typeName, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
|
||||
{
|
||||
writer.WriteLine($"public void SetChannels({typeName} r, {typeName} g, {typeName} b, {typeName} a)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
if (hasRed)
|
||||
{
|
||||
writer.WriteLine("R = r;");
|
||||
}
|
||||
if (hasGreen)
|
||||
{
|
||||
writer.WriteLine("G = g;");
|
||||
}
|
||||
if (hasBlue)
|
||||
{
|
||||
writer.WriteLine("B = b;");
|
||||
}
|
||||
if (hasAlpha)
|
||||
{
|
||||
writer.WriteLine("A = a;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteProperty(IndentedTextWriter writer, bool hasColor, string typeName, char channel, string defaultValue)
|
||||
{
|
||||
if (hasColor)
|
||||
{
|
||||
writer.WriteLine($"public {typeName} {channel} {{ get; set; }}");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteLine($"public readonly {typeName} {channel} ");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"get => {defaultValue};");
|
||||
writer.WriteLine("set { }");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string ToLowerString(this bool value)
|
||||
{
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StbImageWriteSharp" Version="1.16.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder\AssetRipper.TextureDecoder.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,132 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using StbImageWriteSharp;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.ConsoleApp;
|
||||
|
||||
public readonly struct DirectBitmap<TColor, TColorArg>
|
||||
where TColorArg : unmanaged
|
||||
where TColor : unmanaged, IColor<TColorArg>
|
||||
{
|
||||
private static readonly ImageWriter imageWriter = new();
|
||||
public DirectBitmap(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
Data = new byte[CalculateByteSize(width, height)];
|
||||
}
|
||||
|
||||
public DirectBitmap(int width, int height, byte[] data)
|
||||
{
|
||||
if (data.Length < CalculateByteSize(width, height))
|
||||
{
|
||||
throw new ArgumentException("Data does not have enough space.", nameof(data));
|
||||
}
|
||||
|
||||
Width = width;
|
||||
Height = height;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public void FlipY()
|
||||
{
|
||||
Span<TColor> pixels = Pixels;
|
||||
for (int row = 0, irow = Height - 1; row < irow; row++, irow--)
|
||||
{
|
||||
Span<TColor> rowTop = pixels.Slice(row * Width, Width);
|
||||
Span<TColor> rowBottom = pixels.Slice(irow * Width, Width);
|
||||
for (int i = 0; i < Width; i++)
|
||||
{
|
||||
(rowTop[i], rowBottom[i]) = (rowBottom[i], rowTop[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveAsBmp(string path)
|
||||
{
|
||||
GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components);
|
||||
using Stream stream = File.OpenWrite(path);
|
||||
lock (imageWriter)
|
||||
{
|
||||
imageWriter.WriteBmp(data, Width, Height, components, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveAsHdr(string path)
|
||||
{
|
||||
GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components);
|
||||
using Stream stream = File.OpenWrite(path);
|
||||
lock (imageWriter)
|
||||
{
|
||||
imageWriter.WriteHdr(data, Width, Height, components, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveAsJpg(string path)
|
||||
{
|
||||
GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components);
|
||||
using Stream stream = File.OpenWrite(path);
|
||||
lock (imageWriter)
|
||||
{
|
||||
imageWriter.WriteJpg(data, Width, Height, components, stream, default);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveAsPng(string path)
|
||||
{
|
||||
GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components);
|
||||
using Stream stream = File.OpenWrite(path);
|
||||
lock (imageWriter)
|
||||
{
|
||||
imageWriter.WritePng(data, Width, Height, components, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveAsTga(string path)
|
||||
{
|
||||
GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components);
|
||||
using Stream stream = File.OpenWrite(path);
|
||||
lock (imageWriter)
|
||||
{
|
||||
imageWriter.WriteTga(data, Width, Height, components, stream);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components)
|
||||
{
|
||||
if (typeof(TColor) == typeof(ColorRGBA<byte>))
|
||||
{
|
||||
data = Data;
|
||||
components = ColorComponents.RedGreenBlueAlpha;
|
||||
}
|
||||
else if (typeof(TColor) == typeof(ColorRGB<byte>))
|
||||
{
|
||||
data = Data;
|
||||
components = ColorComponents.RedGreenBlue;
|
||||
}
|
||||
else if (TColor.HasAlphaChannel)
|
||||
{
|
||||
RgbConverter.Convert<TColor, TColorArg, ColorRGBA<byte>, byte>(Bits, Width, Height, out data);
|
||||
components = ColorComponents.RedGreenBlueAlpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
RgbConverter.Convert<TColor, TColorArg, ColorRGB<byte>, byte>(Bits, Width, Height, out data);
|
||||
components = ColorComponents.RedGreenBlue;
|
||||
}
|
||||
}
|
||||
|
||||
public int Height { get; }
|
||||
public int Width { get; }
|
||||
public int ByteSize => CalculateByteSize(Width, Height);
|
||||
public Span<byte> Bits => new Span<byte>(Data, 0, ByteSize);
|
||||
public Span<TColor> Pixels => MemoryMarshal.Cast<byte, TColor>(Bits);
|
||||
private byte[] Data { get; }
|
||||
|
||||
private static int CalculateByteSize(int width, int height)
|
||||
{
|
||||
return width * height * Unsafe.SizeOf<TColor>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
using AssetRipper.TextureDecoder.Astc;
|
||||
using AssetRipper.TextureDecoder.Atc;
|
||||
using AssetRipper.TextureDecoder.Bc;
|
||||
using AssetRipper.TextureDecoder.Dxt;
|
||||
using AssetRipper.TextureDecoder.Etc;
|
||||
using AssetRipper.TextureDecoder.Pvrtc;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using AssetRipper.TextureDecoder.Yuy2;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.ConsoleApp;
|
||||
|
||||
internal static partial class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length < 4)
|
||||
{
|
||||
Console.WriteLine("Format: {path} {inputType} {outputType} {width} {height} {args5} {args6}");
|
||||
return;
|
||||
}
|
||||
string path = args[0];
|
||||
string inputType = args[1].ToLowerInvariant();
|
||||
string outputType = args[2].ToLowerInvariant();
|
||||
int width = int.Parse(args[3]);
|
||||
int height = int.Parse(args[4]);
|
||||
string args5 = args.GetArgument(5);
|
||||
string args6 = args.GetArgument(6);
|
||||
byte[] data = File.ReadAllBytes(path);
|
||||
|
||||
DirectBitmap<ColorBGRA32, byte> bitmap = new DirectBitmap<ColorBGRA32, byte>(width, height);
|
||||
switch (inputType)
|
||||
{
|
||||
case "astc":
|
||||
DecodeAstc(data, width, height, args5, args6, bitmap.Bits);
|
||||
break;
|
||||
case "atc":
|
||||
DecodeAtc(data, width, height, args5, bitmap.Bits);
|
||||
break;
|
||||
case "bc":
|
||||
DecodeBc(data, width, height, args5, args6, bitmap.Bits);
|
||||
break;
|
||||
case "dxt":
|
||||
DecodeDxt(data, width, height, args5, bitmap.Bits);
|
||||
break;
|
||||
case "etc":
|
||||
DecodeEtc(data, width, height, args5, bitmap.Bits);
|
||||
break;
|
||||
case "pvrtc":
|
||||
DecodePvrtc(data, width, height, args5, bitmap.Bits);
|
||||
break;
|
||||
case "rgb":
|
||||
DecodeRgb(data, width, height, args5, bitmap.Bits);
|
||||
break;
|
||||
case "yuy2":
|
||||
Yuy2Decoder.DecompressYUY2(data, width, height, bitmap.Bits);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException(inputType);
|
||||
}
|
||||
|
||||
string dirPath = Path.GetDirectoryName(path) ?? Environment.CurrentDirectory;
|
||||
string name = Path.GetFileName(path);
|
||||
|
||||
switch (outputType)
|
||||
{
|
||||
case "png":
|
||||
{
|
||||
string newPath = Path.Combine(dirPath, name + ".png");
|
||||
bitmap.FlipY();
|
||||
bitmap.SaveAsPng(newPath);
|
||||
}
|
||||
break;
|
||||
case "bgra":
|
||||
{
|
||||
string newPath = Path.Combine(dirPath, name + ".bgra");
|
||||
WriteAllBytes(newPath, bitmap.Bits);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException(outputType);
|
||||
}
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static string GetArgument(this string[] args, int index)
|
||||
{
|
||||
return index < args.Length ? args[index] : string.Empty;
|
||||
}
|
||||
|
||||
private static void DecodeAstc(ReadOnlySpan<byte> input, int width, int height, string blockXSizeString, string blockYSizeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : blockXSize");
|
||||
Console.WriteLine("Arg at index 6 : blockYSize");
|
||||
int blockXSize = int.Parse(blockXSizeString);
|
||||
int blockYSize = int.Parse(blockYSizeString);
|
||||
AstcDecoder.DecodeASTC(input, width, height, blockXSize, blockYSize, output);
|
||||
}
|
||||
|
||||
private static void DecodeAtc(ReadOnlySpan<byte> input, int width, int height, string modeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : mode");
|
||||
Console.WriteLine(" 0 - ATC RGB4");
|
||||
Console.WriteLine(" 1 - ATC RGBA8");
|
||||
int mode = int.Parse(modeString);
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
AtcDecoder.DecompressAtcRgb4(input, width, height, output);
|
||||
break;
|
||||
case 1:
|
||||
AtcDecoder.DecompressAtcRgba8(input, width, height, output);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(mode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void DecodeBc(ReadOnlySpan<byte> input, int width, int height, string modeString, string isSignedString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : mode");
|
||||
Console.WriteLine(" 1 - BC1");
|
||||
Console.WriteLine(" 2 - BC2");
|
||||
Console.WriteLine(" 3 - BC3");
|
||||
Console.WriteLine(" 4 - BC4");
|
||||
Console.WriteLine(" 5 - BC5");
|
||||
Console.WriteLine(" 6 - BC6H");
|
||||
Console.WriteLine(" 7 - BC7");
|
||||
Console.WriteLine("Arg at index 6 : isSigned (BC6H only)");
|
||||
int mode = int.Parse(modeString);
|
||||
switch (mode)
|
||||
{
|
||||
case 1:
|
||||
Bc1.Decompress(input, width, height, output);
|
||||
break;
|
||||
case 2:
|
||||
Bc2.Decompress(input, width, height, output);
|
||||
break;
|
||||
case 3:
|
||||
Bc3.Decompress(input, width, height, output);
|
||||
break;
|
||||
case 4:
|
||||
Bc4.Decompress(input, width, height, output);
|
||||
break;
|
||||
case 5:
|
||||
Bc5.Decompress(input, width, height, output);
|
||||
break;
|
||||
case 6:
|
||||
Bc6h.Decompress(input, width, height, bool.Parse(isSignedString), output);
|
||||
break;
|
||||
case 7:
|
||||
Bc7.Decompress(input, width, height, output);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(mode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void DecodeDxt(ReadOnlySpan<byte> input, int width, int height, string modeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : mode");
|
||||
Console.WriteLine(" 0 - DXT1");
|
||||
Console.WriteLine(" 1 - DXT3");
|
||||
Console.WriteLine(" 2 - DXT5");
|
||||
int mode = int.Parse(modeString);
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
DxtDecoder.DecompressDXT1(input, width, height, output);
|
||||
break;
|
||||
case 1:
|
||||
DxtDecoder.DecompressDXT3(input, width, height, output);
|
||||
break;
|
||||
case 2:
|
||||
DxtDecoder.DecompressDXT5(input, width, height, output);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(mode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void DecodeEtc(ReadOnlySpan<byte> input, int width, int height, string modeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : mode");
|
||||
Console.WriteLine(" 0 - ETC");
|
||||
Console.WriteLine(" 1 - ETC2");
|
||||
Console.WriteLine(" 2 - ETC2a1");
|
||||
Console.WriteLine(" 3 - ETC2a8");
|
||||
Console.WriteLine(" 4 - EAC R");
|
||||
Console.WriteLine(" 5 - EAC signed R");
|
||||
Console.WriteLine(" 6 - EAC RG");
|
||||
Console.WriteLine(" 7 - EAC signed RG");
|
||||
int mode = int.Parse(modeString);
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
EtcDecoder.DecompressETC(input, width, height, output);
|
||||
break;
|
||||
case 1:
|
||||
EtcDecoder.DecompressETC2(input, width, height, output);
|
||||
break;
|
||||
case 2:
|
||||
EtcDecoder.DecompressETC2A1(input, width, height, output);
|
||||
break;
|
||||
case 3:
|
||||
EtcDecoder.DecompressETC2A8(input, width, height, output);
|
||||
break;
|
||||
case 4:
|
||||
EtcDecoder.DecompressEACRUnsigned(input, width, height, output);
|
||||
break;
|
||||
case 5:
|
||||
EtcDecoder.DecompressEACRSigned(input, width, height, output);
|
||||
break;
|
||||
case 6:
|
||||
EtcDecoder.DecompressEACRGUnsigned(input, width, height, output);
|
||||
break;
|
||||
case 7:
|
||||
EtcDecoder.DecompressEACRGSigned(input, width, height, output);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(mode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void DecodePvrtc(ReadOnlySpan<byte> input, int width, int height, string do2bitModeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : 2bitMode");
|
||||
bool do2bit = bool.Parse(do2bitModeString);
|
||||
PvrtcDecoder.DecompressPVRTC(input, width, height, do2bit, output);
|
||||
}
|
||||
|
||||
public static void WriteAllBytes(string path, ReadOnlySpan<byte> bytes)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(path, nameof(path));
|
||||
using Microsoft.Win32.SafeHandles.SafeFileHandle sfh = File.OpenHandle(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
RandomAccess.Write(sfh, bytes, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.ConsoleApp;
|
||||
static partial class Program
|
||||
{
|
||||
private static void DecodeRgb(ReadOnlySpan<byte> input, int width, int height, string modeString, Span<byte> output)
|
||||
{
|
||||
Console.WriteLine("Arg at index 5 : mode");
|
||||
Console.WriteLine(" 0 - R8SByte");
|
||||
Console.WriteLine(" 1 - RG8SByte");
|
||||
Console.WriteLine(" 2 - RGB8SByte");
|
||||
Console.WriteLine(" 3 - RGBA8SByte");
|
||||
Console.WriteLine(" 4 - A8SByte");
|
||||
Console.WriteLine(" 5 - R8Byte");
|
||||
Console.WriteLine(" 6 - RG8Byte");
|
||||
Console.WriteLine(" 7 - RGB8Byte");
|
||||
Console.WriteLine(" 8 - RGBA8Byte");
|
||||
Console.WriteLine(" 9 - A8Byte");
|
||||
Console.WriteLine(" 10 - R16Int16");
|
||||
Console.WriteLine(" 11 - RG16Int16");
|
||||
Console.WriteLine(" 12 - RGB16Int16");
|
||||
Console.WriteLine(" 13 - RGBA16Int16");
|
||||
Console.WriteLine(" 14 - A16Int16");
|
||||
Console.WriteLine(" 15 - R16UInt16");
|
||||
Console.WriteLine(" 16 - RG16UInt16");
|
||||
Console.WriteLine(" 17 - RGB16UInt16");
|
||||
Console.WriteLine(" 18 - RGBA16UInt16");
|
||||
Console.WriteLine(" 19 - A16UInt16");
|
||||
Console.WriteLine(" 20 - R32Int32");
|
||||
Console.WriteLine(" 21 - RG32Int32");
|
||||
Console.WriteLine(" 22 - RGB32Int32");
|
||||
Console.WriteLine(" 23 - RGBA32Int32");
|
||||
Console.WriteLine(" 24 - A32Int32");
|
||||
Console.WriteLine(" 25 - R32UInt32");
|
||||
Console.WriteLine(" 26 - RG32UInt32");
|
||||
Console.WriteLine(" 27 - RGB32UInt32");
|
||||
Console.WriteLine(" 28 - RGBA32UInt32");
|
||||
Console.WriteLine(" 29 - A32UInt32");
|
||||
Console.WriteLine(" 30 - R64Int64");
|
||||
Console.WriteLine(" 31 - RG64Int64");
|
||||
Console.WriteLine(" 32 - RGB64Int64");
|
||||
Console.WriteLine(" 33 - RGBA64Int64");
|
||||
Console.WriteLine(" 34 - A64Int64");
|
||||
Console.WriteLine(" 35 - R64UInt64");
|
||||
Console.WriteLine(" 36 - RG64UInt64");
|
||||
Console.WriteLine(" 37 - RGB64UInt64");
|
||||
Console.WriteLine(" 38 - RGBA64UInt64");
|
||||
Console.WriteLine(" 39 - A64UInt64");
|
||||
Console.WriteLine(" 40 - R128Int128");
|
||||
Console.WriteLine(" 41 - RG128Int128");
|
||||
Console.WriteLine(" 42 - RGB128Int128");
|
||||
Console.WriteLine(" 43 - RGBA128Int128");
|
||||
Console.WriteLine(" 44 - A128Int128");
|
||||
Console.WriteLine(" 45 - R128UInt128");
|
||||
Console.WriteLine(" 46 - RG128UInt128");
|
||||
Console.WriteLine(" 47 - RGB128UInt128");
|
||||
Console.WriteLine(" 48 - RGBA128UInt128");
|
||||
Console.WriteLine(" 49 - A128UInt128");
|
||||
Console.WriteLine(" 50 - R16Half");
|
||||
Console.WriteLine(" 51 - RG16Half");
|
||||
Console.WriteLine(" 52 - RGB16Half");
|
||||
Console.WriteLine(" 53 - RGBA16Half");
|
||||
Console.WriteLine(" 54 - A16Half");
|
||||
Console.WriteLine(" 55 - R32Single");
|
||||
Console.WriteLine(" 56 - RG32Single");
|
||||
Console.WriteLine(" 57 - RGB32Single");
|
||||
Console.WriteLine(" 58 - RGBA32Single");
|
||||
Console.WriteLine(" 59 - A32Single");
|
||||
Console.WriteLine(" 60 - R64Double");
|
||||
Console.WriteLine(" 61 - RG64Double");
|
||||
Console.WriteLine(" 62 - RGB64Double");
|
||||
Console.WriteLine(" 63 - RGBA64Double");
|
||||
Console.WriteLine(" 64 - A64Double");
|
||||
Console.WriteLine(" 65 - R128Decimal");
|
||||
Console.WriteLine(" 66 - RG128Decimal");
|
||||
Console.WriteLine(" 67 - RGB128Decimal");
|
||||
Console.WriteLine(" 68 - RGBA128Decimal");
|
||||
Console.WriteLine(" 69 - A128Decimal");
|
||||
Console.WriteLine(" 70 - ARGB16");
|
||||
Console.WriteLine(" 71 - ARGB32");
|
||||
Console.WriteLine(" 72 - BGRA32");
|
||||
Console.WriteLine(" 73 - RGB16");
|
||||
Console.WriteLine(" 74 - RGB9e5");
|
||||
Console.WriteLine(" 75 - RGBA16");
|
||||
int mode = int.Parse(modeString);
|
||||
switch(mode)
|
||||
{
|
||||
case 0:
|
||||
RgbConverter.Convert<ColorR<sbyte>, sbyte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 1:
|
||||
RgbConverter.Convert<ColorRG<sbyte>, sbyte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 2:
|
||||
RgbConverter.Convert<ColorRGB<sbyte>, sbyte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 3:
|
||||
RgbConverter.Convert<ColorRGBA<sbyte>, sbyte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 4:
|
||||
RgbConverter.Convert<ColorA<sbyte>, sbyte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 5:
|
||||
RgbConverter.Convert<ColorR<byte>, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 6:
|
||||
RgbConverter.Convert<ColorRG<byte>, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 7:
|
||||
RgbConverter.Convert<ColorRGB<byte>, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 8:
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 9:
|
||||
RgbConverter.Convert<ColorA<byte>, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 10:
|
||||
RgbConverter.Convert<ColorR<short>, short, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 11:
|
||||
RgbConverter.Convert<ColorRG<short>, short, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 12:
|
||||
RgbConverter.Convert<ColorRGB<short>, short, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 13:
|
||||
RgbConverter.Convert<ColorRGBA<short>, short, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 14:
|
||||
RgbConverter.Convert<ColorA<short>, short, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 15:
|
||||
RgbConverter.Convert<ColorR<ushort>, ushort, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 16:
|
||||
RgbConverter.Convert<ColorRG<ushort>, ushort, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 17:
|
||||
RgbConverter.Convert<ColorRGB<ushort>, ushort, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 18:
|
||||
RgbConverter.Convert<ColorRGBA<ushort>, ushort, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 19:
|
||||
RgbConverter.Convert<ColorA<ushort>, ushort, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 20:
|
||||
RgbConverter.Convert<ColorR<int>, int, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 21:
|
||||
RgbConverter.Convert<ColorRG<int>, int, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 22:
|
||||
RgbConverter.Convert<ColorRGB<int>, int, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 23:
|
||||
RgbConverter.Convert<ColorRGBA<int>, int, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 24:
|
||||
RgbConverter.Convert<ColorA<int>, int, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 25:
|
||||
RgbConverter.Convert<ColorR<uint>, uint, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 26:
|
||||
RgbConverter.Convert<ColorRG<uint>, uint, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 27:
|
||||
RgbConverter.Convert<ColorRGB<uint>, uint, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 28:
|
||||
RgbConverter.Convert<ColorRGBA<uint>, uint, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 29:
|
||||
RgbConverter.Convert<ColorA<uint>, uint, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 30:
|
||||
RgbConverter.Convert<ColorR<long>, long, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 31:
|
||||
RgbConverter.Convert<ColorRG<long>, long, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 32:
|
||||
RgbConverter.Convert<ColorRGB<long>, long, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 33:
|
||||
RgbConverter.Convert<ColorRGBA<long>, long, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 34:
|
||||
RgbConverter.Convert<ColorA<long>, long, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 35:
|
||||
RgbConverter.Convert<ColorR<ulong>, ulong, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 36:
|
||||
RgbConverter.Convert<ColorRG<ulong>, ulong, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 37:
|
||||
RgbConverter.Convert<ColorRGB<ulong>, ulong, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 38:
|
||||
RgbConverter.Convert<ColorRGBA<ulong>, ulong, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 39:
|
||||
RgbConverter.Convert<ColorA<ulong>, ulong, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 40:
|
||||
RgbConverter.Convert<ColorR<Int128>, Int128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 41:
|
||||
RgbConverter.Convert<ColorRG<Int128>, Int128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 42:
|
||||
RgbConverter.Convert<ColorRGB<Int128>, Int128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 43:
|
||||
RgbConverter.Convert<ColorRGBA<Int128>, Int128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 44:
|
||||
RgbConverter.Convert<ColorA<Int128>, Int128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 45:
|
||||
RgbConverter.Convert<ColorR<UInt128>, UInt128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 46:
|
||||
RgbConverter.Convert<ColorRG<UInt128>, UInt128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 47:
|
||||
RgbConverter.Convert<ColorRGB<UInt128>, UInt128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 48:
|
||||
RgbConverter.Convert<ColorRGBA<UInt128>, UInt128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 49:
|
||||
RgbConverter.Convert<ColorA<UInt128>, UInt128, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 50:
|
||||
RgbConverter.Convert<ColorR<Half>, Half, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 51:
|
||||
RgbConverter.Convert<ColorRG<Half>, Half, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 52:
|
||||
RgbConverter.Convert<ColorRGB<Half>, Half, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 53:
|
||||
RgbConverter.Convert<ColorRGBA<Half>, Half, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 54:
|
||||
RgbConverter.Convert<ColorA<Half>, Half, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 55:
|
||||
RgbConverter.Convert<ColorR<float>, float, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 56:
|
||||
RgbConverter.Convert<ColorRG<float>, float, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 57:
|
||||
RgbConverter.Convert<ColorRGB<float>, float, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 58:
|
||||
RgbConverter.Convert<ColorRGBA<float>, float, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 59:
|
||||
RgbConverter.Convert<ColorA<float>, float, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 60:
|
||||
RgbConverter.Convert<ColorR<double>, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 61:
|
||||
RgbConverter.Convert<ColorRG<double>, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 62:
|
||||
RgbConverter.Convert<ColorRGB<double>, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 63:
|
||||
RgbConverter.Convert<ColorRGBA<double>, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 64:
|
||||
RgbConverter.Convert<ColorA<double>, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 65:
|
||||
RgbConverter.Convert<ColorR<decimal>, decimal, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 66:
|
||||
RgbConverter.Convert<ColorRG<decimal>, decimal, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 67:
|
||||
RgbConverter.Convert<ColorRGB<decimal>, decimal, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 68:
|
||||
RgbConverter.Convert<ColorRGBA<decimal>, decimal, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 69:
|
||||
RgbConverter.Convert<ColorA<decimal>, decimal, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 70:
|
||||
RgbConverter.Convert<ColorARGB16, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 71:
|
||||
RgbConverter.Convert<ColorARGB32, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 72:
|
||||
RgbConverter.Convert<ColorBGRA32, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 73:
|
||||
RgbConverter.Convert<ColorRGB16, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 74:
|
||||
RgbConverter.Convert<ColorRGB9e5, double, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
case 75:
|
||||
RgbConverter.Convert<ColorRGBA16, byte, ColorBGRA32, byte>(input, width, height, output);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException(mode.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AssetRipper.TextureDecoder.Paths;
|
||||
|
||||
public static class ProjectFolders
|
||||
{
|
||||
public const string ThisProject = "../../../";
|
||||
public const string RepositoryRoot = ThisProject + "../";
|
||||
public const string TestProject = RepositoryRoot + "AssetRipper.TextureDecoder.Tests/";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace AssetRipper.TextureDecoder.Paths;
|
||||
|
||||
public static class TestFileFolders
|
||||
{
|
||||
public const string TestFiles = ProjectFolders.RepositoryRoot + "TestFiles/";
|
||||
public const string AstcTestFiles = TestFiles + "Astc/";
|
||||
public const string AtcTestFiles = TestFiles + "Atc/";
|
||||
public const string BcTestFiles = TestFiles + "Bc/";
|
||||
public const string DxtTestFiles = TestFiles + "Dxt/";
|
||||
public const string EtcTestFiles = TestFiles + "Etc/";
|
||||
public const string PvrtcTestFiles = TestFiles + "Pvrtc/";
|
||||
public const string RgbTestFiles = TestFiles + "Rgb/";
|
||||
public const string Yuy2TestFiles = TestFiles + "Yuy2/";
|
||||
public const string AndroidTestFiles = TestFiles + "Android/";
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,187 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
|
||||
public static class CSharpPrimitives
|
||||
{
|
||||
public static IReadOnlyDictionary<Type, Data> Dictionary { get; } = new Dictionary<Type, Data>()
|
||||
{
|
||||
{ typeof(sbyte), new Data<sbyte>() },
|
||||
{ typeof(byte), new Data<byte>() },
|
||||
{ typeof(short), new Data<short>() },
|
||||
{ typeof(ushort), new Data<ushort>() },
|
||||
{ typeof(int), new Data<int>() },
|
||||
{ typeof(uint), new Data<uint>() },
|
||||
{ typeof(long), new Data<long>() },
|
||||
{ typeof(ulong), new Data<ulong>() },
|
||||
{ typeof(Int128), new Data<Int128>() },
|
||||
{ typeof(UInt128), new Data<UInt128>() },
|
||||
{ typeof(Half), new Data<Half>() },
|
||||
{ typeof(float), new Data<float>() },
|
||||
{ typeof(double), new Data<double>() },
|
||||
{ typeof(decimal), new Data<decimal>() },
|
||||
};
|
||||
|
||||
public static IReadOnlyList<Data> List { get; } = Dictionary.Values.ToList();
|
||||
|
||||
public static IReadOnlyList<Type> Types { get; } = Dictionary.Keys.ToList();
|
||||
|
||||
public static Type FirstType => Types[0];
|
||||
|
||||
public static Data FirstData => List[0];
|
||||
|
||||
public static bool IsFloatingPoint(Type type)
|
||||
{
|
||||
return type == typeof(Half) || type == typeof(float) || type == typeof(double) || type == typeof(decimal);
|
||||
}
|
||||
|
||||
public static bool IsUnsignedInteger(Type type)
|
||||
{
|
||||
return type == typeof(byte) || type == typeof(ushort) || type == typeof(uint) || type == typeof(ulong) || type == typeof(UInt128);
|
||||
}
|
||||
|
||||
public static bool IsSignedInteger(Type type, [NotNullWhen(true)] out Type? unsignedType)
|
||||
{
|
||||
if (type == typeof(sbyte))
|
||||
{
|
||||
unsignedType = typeof(byte);
|
||||
}
|
||||
else if (type == typeof(short))
|
||||
{
|
||||
unsignedType = typeof(ushort);
|
||||
}
|
||||
else if (type == typeof(int))
|
||||
{
|
||||
unsignedType = typeof(uint);
|
||||
}
|
||||
else if (type == typeof(long))
|
||||
{
|
||||
unsignedType = typeof(ulong);
|
||||
}
|
||||
else if (type == typeof(Int128))
|
||||
{
|
||||
unsignedType = typeof(UInt128);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsignedType = null;
|
||||
}
|
||||
return unsignedType is not null;
|
||||
}
|
||||
|
||||
public static bool CanBeConstant(Type type)
|
||||
{
|
||||
return type == typeof(byte)
|
||||
|| type == typeof(sbyte)
|
||||
|| type == typeof(ushort)
|
||||
|| type == typeof(short)
|
||||
|| type == typeof(uint)
|
||||
|| type == typeof(int)
|
||||
|| type == typeof(ulong)
|
||||
|| type == typeof(long)
|
||||
|| type == typeof(float)
|
||||
|| type == typeof(double)
|
||||
|| type == typeof(bool)
|
||||
|| type == typeof(char)
|
||||
|| type == typeof(string);
|
||||
}
|
||||
|
||||
public static string GetLangName(Type type)
|
||||
{
|
||||
if (type == typeof(sbyte))
|
||||
{
|
||||
return "sbyte";
|
||||
}
|
||||
else if (type == typeof(byte))
|
||||
{
|
||||
return "byte";
|
||||
}
|
||||
else if (type == typeof(short))
|
||||
{
|
||||
return "short";
|
||||
}
|
||||
else if (type == typeof(ushort))
|
||||
{
|
||||
return "ushort";
|
||||
}
|
||||
else if (type == typeof(int))
|
||||
{
|
||||
return "int";
|
||||
}
|
||||
else if (type == typeof(uint))
|
||||
{
|
||||
return "uint";
|
||||
}
|
||||
else if (type == typeof(long))
|
||||
{
|
||||
return "long";
|
||||
}
|
||||
else if (type == typeof(ulong))
|
||||
{
|
||||
return "ulong";
|
||||
}
|
||||
else if (type == typeof(float))
|
||||
{
|
||||
return "float";
|
||||
}
|
||||
else if (type == typeof(double))
|
||||
{
|
||||
return "double";
|
||||
}
|
||||
else if (type == typeof(decimal))
|
||||
{
|
||||
return "decimal";
|
||||
}
|
||||
else if (type == typeof(char))
|
||||
{
|
||||
return "char";
|
||||
}
|
||||
else if (type == typeof(bool))
|
||||
{
|
||||
return "bool";
|
||||
}
|
||||
else if (type == typeof(string))
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
else
|
||||
{
|
||||
return type.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Data
|
||||
{
|
||||
public abstract Type Type { get; }
|
||||
public string TypeName => Type.Name;
|
||||
public string LangName => GetLangName(Type);
|
||||
public bool CanBeConstant => CanBeConstant(Type);
|
||||
public bool IsFloatingPoint => IsFloatingPoint(Type);
|
||||
public bool IsUnsignedInteger => IsUnsignedInteger(Type);
|
||||
public bool IsSignedInteger([NotNullWhen(true)] out Data? unsignedData)
|
||||
{
|
||||
if (CSharpPrimitives.IsSignedInteger(Type, out Type? unsignedType))
|
||||
{
|
||||
unsignedData = Dictionary[unsignedType];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsignedData = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public abstract int Size { get; }
|
||||
public override string ToString() => TypeName;
|
||||
public string MinValue => IsFloatingPoint ? $"{LangName}.Zero" : $"{LangName}.MinValue";
|
||||
public string MaxValue => IsFloatingPoint ? $"{LangName}.One" : $"{LangName}.MaxValue";
|
||||
}
|
||||
|
||||
private sealed class Data<T> : Data
|
||||
{
|
||||
public override Type Type => typeof(T);
|
||||
|
||||
public override int Size => Unsafe.SizeOf<T>();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder.Paths\AssetRipper.TextureDecoder.Paths.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder.SourceGeneration.Common\AssetRipper.TextureDecoder.SourceGeneration.Common.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder\AssetRipper.TextureDecoder.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Text.SourceGeneration" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,74 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.TestGenerator
|
||||
{
|
||||
internal readonly struct GenerationData
|
||||
{
|
||||
public Type ColorType { get; private init; }
|
||||
public Type ChannelType { get; private init; }
|
||||
public int ColorSize { get; private init; }
|
||||
|
||||
public bool RedChannel { get; private init; }
|
||||
public bool GreenChannel { get; private init; }
|
||||
public bool BlueChannel { get; private init; }
|
||||
public bool AlphaChannel { get; private init; }
|
||||
public bool FullyUtilizedChannels { get; private init; }
|
||||
|
||||
public bool IsFloatingPoint => CSharpPrimitives.IsFloatingPoint(ChannelType);
|
||||
|
||||
public int BitSizePerChannel => CSharpPrimitives.Dictionary[ChannelType].Size * 8;
|
||||
|
||||
public string ChannelTypeName => CSharpPrimitives.Dictionary[ChannelType].LangName;
|
||||
|
||||
public static GenerationData Create<T>(int colorSize) where T : IColorBase
|
||||
{
|
||||
return new GenerationData()
|
||||
{
|
||||
ColorType = typeof(T),
|
||||
ChannelType = T.ChannelType,
|
||||
ColorSize = colorSize,
|
||||
RedChannel = T.HasRedChannel,
|
||||
GreenChannel = T.HasGreenChannel,
|
||||
BlueChannel = T.HasBlueChannel,
|
||||
AlphaChannel = T.HasAlphaChannel,
|
||||
FullyUtilizedChannels = T.ChannelsAreFullyUtilized,
|
||||
};
|
||||
}
|
||||
|
||||
public bool Contains(GenerationData other)
|
||||
{
|
||||
if (!FullyUtilizedChannels)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsFloatingPoint != other.IsFloatingPoint)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.RedChannel && !RedChannel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.GreenChannel && !GreenChannel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.BlueChannel && !BlueChannel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.AlphaChannel && !AlphaChannel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return BitSizePerChannel >= other.BitSizePerChannel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.TestGenerator
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
internal static readonly List<GenerationData> dataList = new()
|
||||
{
|
||||
GenerationData.Create<ColorARGB16>(2),
|
||||
GenerationData.Create<ColorARGB32>(4),
|
||||
GenerationData.Create<ColorBGRA32>(4),
|
||||
GenerationData.Create<ColorRGB16>(2),
|
||||
GenerationData.Create<ColorRGB9e5>(4),
|
||||
GenerationData.Create<ColorRGBA16>(2),
|
||||
};
|
||||
|
||||
static void Main()
|
||||
{
|
||||
TestClassGenerator.GenerateTestClasses();
|
||||
GenerateRgbConsoleMethod();
|
||||
TextureDataClassGenerator.Generate();
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void GenerateRgbConsoleMethod()
|
||||
{
|
||||
Console.WriteLine("Program");
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create("../../../../AssetRipper.TextureDecoder.ConsoleApp", "Program");
|
||||
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"using {typeof(RgbConverter).Namespace};");
|
||||
writer.WriteLine($"using {typeof(ColorBGRA32).Namespace};");
|
||||
writer.WriteLine();
|
||||
|
||||
writer.WriteFileScopedNamespace("AssetRipper.TextureDecoder.ConsoleApp");
|
||||
writer.WriteLine("static partial class Program");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("private static void DecodeRgb(ReadOnlySpan<byte> input, int width, int height, string modeString, Span<byte> output)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
List<(string, string, string)> list = GetColorNames().ToList();
|
||||
writer.WriteLine("Console.WriteLine(\"Arg at index 5 : mode\");");
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
writer.WriteLine($"Console.WriteLine(\" {i} - {list[i].Item1.Substring(5)}\");");
|
||||
}
|
||||
writer.WriteLine("int mode = int.Parse(modeString);");
|
||||
writer.WriteLine("switch(mode)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
for (int i = 0 ; i < list.Count; i++)
|
||||
{
|
||||
(string prettyName, string colorName, string channelName) = list[i];
|
||||
writer.WriteLine($"case {i}:");
|
||||
using (new Indented(writer))
|
||||
{
|
||||
writer.WriteLine($"RgbConverter.Convert<{colorName}, {channelName}, ColorBGRA32, byte>(input, width, height, output);");
|
||||
writer.WriteLine("break;");
|
||||
}
|
||||
}
|
||||
{
|
||||
writer.WriteLine("default:");
|
||||
using (new Indented(writer))
|
||||
{
|
||||
writer.WriteLine("throw new NotSupportedException(mode.ToString());");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<(string, string, string)> GetColorNames()
|
||||
{
|
||||
foreach (CSharpPrimitives.Data primitiveData in CSharpPrimitives.List)
|
||||
{
|
||||
int primitiveBitSize = primitiveData.Size * 8;
|
||||
foreach (string genericColorName in TestClassGenerator.GetGenericColorNames())
|
||||
{
|
||||
string prettyName = $"{genericColorName}{primitiveBitSize}{primitiveData.TypeName}";
|
||||
yield return (prettyName, $"{genericColorName}<{primitiveData.LangName}>", primitiveData.LangName);
|
||||
}
|
||||
}
|
||||
foreach (GenerationData data in dataList)
|
||||
{
|
||||
yield return (data.ColorType.Name, data.ColorType.Name, data.ChannelTypeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using AssetRipper.TextureDecoder.SourceGeneration.Common;
|
||||
using AssetRipper.TextureDecoder.TestGenerator;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
internal static class TestClassGenerator
|
||||
{
|
||||
private const string OutputNamespace = "AssetRipper.TextureDecoder.Tests.Formats";
|
||||
private const string OutputFolder = "../../../../AssetRipper.TextureDecoder.Tests/Formats/";
|
||||
private const string GenericOutputNamespace = OutputNamespace + ".Generic";
|
||||
private const string GenericOutputFolder = OutputFolder + "Generic/";
|
||||
|
||||
private static readonly char[] channels = new char[] { 'R', 'G', 'B', 'A' };
|
||||
|
||||
internal static void GenerateTestClasses()
|
||||
{
|
||||
Directory.CreateDirectory(OutputFolder);
|
||||
MakeGenericColorTests();
|
||||
MakeLosslessColorTests();
|
||||
foreach (GenerationData data in Program.dataList)
|
||||
{
|
||||
using StringWriter streamWriter = new();
|
||||
using IndentedTextWriter textWriter = new IndentedTextWriter(streamWriter, "\t");
|
||||
streamWriter.NewLine = "\n";
|
||||
textWriter.NewLine = "\n";
|
||||
textWriter.WriteGeneratedCodeWarning();
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteNamespaceUsings(data.ColorType.Namespace);
|
||||
textWriter.WriteFileScopedNamespace();
|
||||
textWriter.WriteClassDefinitionOpen(data);
|
||||
textWriter.Indent++;
|
||||
textWriter.WriteCorrectSizeTest(data);
|
||||
textWriter.WriteLineNoTabs();
|
||||
if (data.ColorType != typeof(ColorRGB9e5))//Rounding errors cause these to fail
|
||||
{
|
||||
textWriter.WritePropertySymmetryTests(data);
|
||||
textWriter.WriteIndependenceTests(data);
|
||||
}
|
||||
textWriter.WriteGetMethodMatchesProperties();
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteMethodSymmetryTest();
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteMakeRandomColor(data);
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteMakeRandomValue(data);
|
||||
|
||||
foreach (GenerationData otherData in Program.dataList)
|
||||
{
|
||||
if (otherData.Contains(data))
|
||||
{
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data, otherData);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (CSharpPrimitives.Data channelData in CSharpPrimitives.List)
|
||||
{
|
||||
Type channelType = channelData.Type;
|
||||
string channelTypeName = channelData.LangName;
|
||||
|
||||
if (CSharpPrimitives.IsFloatingPoint(channelType) != CSharpPrimitives.IsFloatingPoint(data.ChannelType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channelType == typeof(decimal) || data.ChannelType == typeof(decimal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channelData.Size < CSharpPrimitives.Dictionary[data.ChannelType].Size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRGBA<byte>)}<{channelTypeName}>", channelTypeName);
|
||||
|
||||
if (!data.AlphaChannel)
|
||||
{
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRGB<byte>)}<{channelTypeName}>", channelTypeName);
|
||||
if (!data.BlueChannel)
|
||||
{
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRG<byte>)}<{channelTypeName}>", channelTypeName);
|
||||
if (!data.GreenChannel)
|
||||
{
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorR<byte>)}<{channelTypeName}>", channelTypeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!data.RedChannel && !data.GreenChannel && !data.BlueChannel)
|
||||
{
|
||||
textWriter.WriteLineNoTabs();
|
||||
textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorA<byte>)}<{channelTypeName}>", channelTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
textWriter.Indent--;
|
||||
textWriter.WriteClassDefinitionClose();
|
||||
|
||||
textWriter.Flush();
|
||||
streamWriter.Flush();
|
||||
|
||||
string outputFilePath = $"{OutputFolder}{data.ColorType.Name}Tests.g.cs";
|
||||
File.WriteAllText(outputFilePath, streamWriter.ToString());
|
||||
Console.WriteLine(data.ColorType.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MakeGenericColorTests()
|
||||
{
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(GenericOutputFolder, "GenericColorTests");
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteUsing(typeof(ColorR<>).Namespace!);
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(GenericOutputNamespace);
|
||||
|
||||
foreach (string channeName in CSharpPrimitives.List.Select(d => d.LangName))
|
||||
{
|
||||
foreach (string colorName in GetGenericColorNames())
|
||||
{
|
||||
writer.WriteLine($"[TestFixture(TypeArgs = new Type[] {{ typeof({colorName}<{channeName}>), typeof({channeName}) }})]");
|
||||
}
|
||||
}
|
||||
writer.WriteLine("partial class GenericColorTests<TColor, TChannel>");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal static IEnumerable<string> GetGenericColorNames()
|
||||
{
|
||||
yield return nameof(ColorR<byte>);
|
||||
yield return nameof(ColorRG<byte>);
|
||||
yield return nameof(ColorRGB<byte>);
|
||||
yield return nameof(ColorRGBA<byte>);
|
||||
yield return nameof(ColorA<byte>);
|
||||
}
|
||||
|
||||
private static void MakeLosslessColorTests()
|
||||
{
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(GenericOutputFolder, "LosslessColorTests");
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteUsing(typeof(ColorR<>).Namespace!);
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(GenericOutputNamespace);
|
||||
|
||||
foreach (CSharpPrimitives.Data t1 in CSharpPrimitives.List)
|
||||
{
|
||||
foreach (CSharpPrimitives.Data t2 in CSharpPrimitives.List)
|
||||
{
|
||||
if (t1.IsFloatingPoint != t2.IsFloatingPoint)
|
||||
{
|
||||
// one is floating point, the other is not
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t1.Type == typeof(decimal) || t2.Type == typeof(decimal))
|
||||
{
|
||||
// decimal has rounding errors when converting to/from double and float
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t1.Size > t2.Size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
writer.WriteLine($"[TestFixture(TypeArgs = new Type[] {{ typeof({t1.LangName}), typeof({t2.LangName}) }})]");
|
||||
}
|
||||
}
|
||||
writer.WriteLine("partial class LosslessColorTests<T1, T2>");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteClassDefinitionClose(this IndentedTextWriter textWriter)
|
||||
{
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WriteClassDefinitionOpen(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
textWriter.WriteLine($"public partial class {data.ColorType.Name}Tests");
|
||||
textWriter.WriteLine("{");
|
||||
}
|
||||
|
||||
private static void WriteCorrectSizeTest(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
textWriter.WriteLine("[Test]");
|
||||
textWriter.WriteLine("public void CorrectSizeTest()");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
textWriter.WriteLine($"Assert.That(Unsafe.SizeOf<{data.ColorType.Name}>(), Is.EqualTo({data.ColorSize}));");
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WriteFileScopedNamespace(this IndentedTextWriter textWriter)
|
||||
{
|
||||
textWriter.WriteLine($"namespace {OutputNamespace};");
|
||||
textWriter.WriteLine();//An empty line after the namespace declaration
|
||||
}
|
||||
|
||||
private static void WriteGetMethodMatchesProperties(this IndentedTextWriter textWriter)
|
||||
{
|
||||
textWriter.WriteLine("[Test]");
|
||||
textWriter.WriteLine($"public void GetMethodMatchesProperties()");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
textWriter.WriteLine("var color = MakeRandomColor();");
|
||||
textWriter.WriteLine("color.GetChannels(out var r, out var g, out var b, out var a);");
|
||||
textWriter.WriteLine("Assert.Multiple(() =>");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
foreach (char channel in channels)
|
||||
{
|
||||
textWriter.WriteLine($"Assert.That(color.{channel}, Is.EqualTo({char.ToLowerInvariant(channel)}));");
|
||||
}
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("});");
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WriteIndependenceTest(this IndentedTextWriter textWriter, GenerationData data, char channel)
|
||||
{
|
||||
textWriter.WriteLine("[Test]");
|
||||
textWriter.WriteLine($"public void ChannelsAreIndependent_{channel}()");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
textWriter.WriteLine("var color = MakeRandomColor();");
|
||||
foreach (char otherChannel in channels.Where(c => c != channel))
|
||||
{
|
||||
textWriter.WriteLine($"var {char.ToLowerInvariant(otherChannel)} = color.{otherChannel};");
|
||||
}
|
||||
textWriter.WriteLine($"color.{channel} = MakeRandomValue();");
|
||||
|
||||
textWriter.WriteLine("Assert.Multiple(() =>");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
foreach (char otherChannel in channels.Where(c => c != channel))
|
||||
{
|
||||
textWriter.WriteLine($"Assert.That(color.{otherChannel}, Is.EqualTo({char.ToLowerInvariant(otherChannel)}));");
|
||||
}
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("});");
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WriteIndependenceTests(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
foreach (char channel in channels)
|
||||
{
|
||||
textWriter.WriteIndependenceTest(data, channel);
|
||||
textWriter.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteLosslessConversionTest(this IndentedTextWriter textWriter, GenerationData currentData, GenerationData containingData)
|
||||
{
|
||||
textWriter.WriteLosslessConversionTest(currentData.ColorType.Name, currentData.ChannelTypeName, containingData.ColorType.Name, containingData.ChannelTypeName);
|
||||
}
|
||||
|
||||
private static void WriteLosslessConversionTest(this IndentedTextWriter writer, string t1Color, string t1Channel, string t2Color, string t2Channel)
|
||||
{
|
||||
writer.WriteLine("[Test]");
|
||||
writer.WriteLine($"public void ConversionIsLosslessTo{t2Color.Replace("<","_").Replace(">", "")}()");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"LosslessConversion.Assert<{t1Color}, {t1Channel}, {t2Color}, {t2Channel}>();");
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteMakeRandomColor(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
textWriter.WriteLine($"public static {data.ColorType.Name} MakeRandomColor() => ColorRandom<{data.ColorType.Name}, {data.ChannelTypeName}>.MakeRandomColor();");
|
||||
}
|
||||
|
||||
private static void WriteMakeRandomValue(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
textWriter.WriteLine($"public static {data.ChannelTypeName} MakeRandomValue() => ColorRandom<{data.ColorType.Name}, {data.ChannelTypeName}>.MakeRandomValue();");
|
||||
}
|
||||
|
||||
private static void WriteMethodSymmetryTest(this IndentedTextWriter textWriter)
|
||||
{
|
||||
textWriter.WriteLine("[Test]");
|
||||
textWriter.WriteLine($"public void MethodsAreSymmetric()");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
textWriter.WriteLine("var color = MakeRandomColor();");
|
||||
textWriter.WriteLine("color.GetChannels(out var r, out var g, out var b, out var a);");
|
||||
textWriter.WriteLine("color.SetChannels(r, g, b, a);");
|
||||
textWriter.WriteLine("Assert.Multiple(() =>");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
|
||||
foreach (char channel in channels)
|
||||
{
|
||||
textWriter.WriteLine($"Assert.That(color.{channel}, Is.EqualTo({char.ToLowerInvariant(channel)}));");
|
||||
}
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("});");
|
||||
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WriteNamespaceUsings(this IndentedTextWriter textWriter, string? colorNamespace)
|
||||
{
|
||||
textWriter.WriteLine($"using {colorNamespace};");
|
||||
textWriter.WriteLine($"using {typeof(System.Runtime.CompilerServices.Unsafe).Namespace};");
|
||||
textWriter.WriteLine();//An empty line after the usings
|
||||
}
|
||||
|
||||
private static void WritePropertySymmetryTest(this IndentedTextWriter textWriter, GenerationData data, char channel)
|
||||
{
|
||||
textWriter.WriteLine("[Test]");
|
||||
textWriter.WriteLine($"public void PropertyIsSymmetric_{channel}()");
|
||||
textWriter.WriteLine("{");
|
||||
textWriter.Indent += 1;
|
||||
textWriter.WriteLine("var color = MakeRandomColor();");
|
||||
char variableName = char.ToLowerInvariant(channel);
|
||||
textWriter.WriteLine($"var {variableName} = color.{channel};");
|
||||
textWriter.WriteLine($"color.{channel} = {variableName};");
|
||||
textWriter.WriteLine($"Assert.That(color.{channel}, Is.EqualTo({variableName}));");
|
||||
textWriter.Indent -= 1;
|
||||
textWriter.WriteLine("}");
|
||||
}
|
||||
|
||||
private static void WritePropertySymmetryTests(this IndentedTextWriter textWriter, GenerationData data)
|
||||
{
|
||||
foreach (char channel in channels)
|
||||
{
|
||||
textWriter.WritePropertySymmetryTest(data, channel);
|
||||
textWriter.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.TestGenerator;
|
||||
|
||||
internal static class TextureDataClassGenerator
|
||||
{
|
||||
private const string TestFilesFolder = $"{nameof(TestFileFolders)}.{nameof(TestFileFolders.AndroidTestFiles)}";
|
||||
private const string TextureType = "TextureType";
|
||||
private const string TextureFormat = "TextureFormat";
|
||||
private const string ITexture = "ITexture";
|
||||
private const string Namespace = "AssetRipper.TextureDecoder.Tests";
|
||||
|
||||
public static void Generate()
|
||||
{
|
||||
IReadOnlyList<TextureMetadata> metadataList = LoadMetadata(TestFileFolders.AndroidTestFiles);
|
||||
GenerateTextureType(metadataList);
|
||||
GenerateTextureFormat(metadataList);
|
||||
GenerateITexture();
|
||||
GenerateAndroidTextures(metadataList);
|
||||
}
|
||||
|
||||
private static void GenerateTextureType(IReadOnlyList<TextureMetadata> metadataList)
|
||||
{
|
||||
GenerateEnum(TextureType, metadataList.Select(m => m.Type).Distinct().Order());
|
||||
}
|
||||
|
||||
private static void GenerateTextureFormat(IReadOnlyList<TextureMetadata> metadataList)
|
||||
{
|
||||
GenerateEnum(TextureFormat, metadataList.Select(m => m.Format).Distinct().Order());
|
||||
}
|
||||
|
||||
private static void GenerateEnum(string name, IEnumerable<string?> values)
|
||||
{
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(ProjectFolders.TestProject, name);
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(Namespace);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"public enum {name}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
foreach (string? value in values)
|
||||
{
|
||||
writer.WriteLine($"{value},");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateITexture()
|
||||
{
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(ProjectFolders.TestProject, ITexture);
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(Namespace);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"public partial interface {ITexture}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"static abstract {TextureType} {nameof(TextureMetadata.Type)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract {TextureFormat} {nameof(TextureMetadata.Format)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract int {nameof(TextureMetadata.FileSize)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract int {nameof(TextureMetadata.ImageSize)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract int {nameof(TextureMetadata.ImageCount)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract bool {nameof(TextureMetadata.Mips)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract int {nameof(TextureMetadata.Width)} {{ get; }}");
|
||||
writer.WriteLine($"static abstract int {nameof(TextureMetadata.Height)} {{ get; }}");
|
||||
writer.WriteLine("static abstract string Path { get; }");
|
||||
writer.WriteLine("static abstract byte[] Data { get; }");
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<TextureMetadata> LoadMetadata(string directory)
|
||||
{
|
||||
string[] jsonFiles = Directory.GetFiles(directory, "*.json");
|
||||
List<TextureMetadata> metadataList = new(jsonFiles.Length);
|
||||
foreach (string jsonFile in jsonFiles)
|
||||
{
|
||||
metadataList.Add(TextureMetadata.FromFile(jsonFile));
|
||||
}
|
||||
return metadataList;
|
||||
}
|
||||
|
||||
private static void GenerateAndroidTextures(IReadOnlyList<TextureMetadata> metadataList)
|
||||
{
|
||||
const string AndroidTextures = "AndroidTextures";
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(ProjectFolders.TestProject, AndroidTextures);
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLine();
|
||||
writer.WriteFileScopedNamespace(Namespace);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"public static partial class {AndroidTextures}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
foreach (TextureMetadata metadata in metadataList)
|
||||
{
|
||||
string withOrWithout = metadata.Mips ? "with" : "without";
|
||||
writer.WriteSummaryDocumentation($"{metadata.Format} {metadata.Width}x{metadata.Height} {withOrWithout} mips");
|
||||
writer.WriteLine($"public sealed class {metadata.Name} : {ITexture}");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine($"public const {TextureType} {nameof(TextureMetadata.Type)} = {TextureType}.{metadata.Type};");
|
||||
writer.WriteLine($"public const {TextureFormat} {nameof(TextureMetadata.Format)} = {TextureFormat}.{metadata.Format};");
|
||||
writer.WriteLine($"public const int {nameof(TextureMetadata.FileSize)} = {metadata.FileSize};");
|
||||
writer.WriteLine($"public const int {nameof(TextureMetadata.ImageSize)} = {metadata.ImageSize};");
|
||||
writer.WriteLine($"public const int {nameof(TextureMetadata.ImageCount)} = {metadata.ImageCount};");
|
||||
writer.WriteLine($"public const bool {nameof(TextureMetadata.Mips)} = {metadata.Mips.ToString().ToLowerInvariant()};");
|
||||
writer.WriteLine($"public const int {nameof(TextureMetadata.Width)} = {metadata.Width};");
|
||||
writer.WriteLine($"public const int {nameof(TextureMetadata.Height)} = {metadata.Height};");
|
||||
writer.WriteLine($"public const string Path = {TestFilesFolder} + \"{metadata.Name}\";");
|
||||
writer.WriteSummaryDocumentation($"Length: {metadata.FileSize}");
|
||||
writer.WriteLine("public static byte[] Data => File.ReadAllBytes(Path);");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine($"private {metadata.Name}() {{ }}");
|
||||
writer.WriteLine($"static {TextureType} {ITexture}.{nameof(TextureMetadata.Type)} => {nameof(TextureMetadata.Type)};");
|
||||
writer.WriteLine($"static {TextureFormat} {ITexture}.{nameof(TextureMetadata.Format)} => {nameof(TextureMetadata.Format)};");
|
||||
writer.WriteLine($"static int {ITexture}.{nameof(TextureMetadata.FileSize)} => {nameof(TextureMetadata.FileSize)};");
|
||||
writer.WriteLine($"static int {ITexture}.{nameof(TextureMetadata.ImageSize)} => {nameof(TextureMetadata.ImageSize)};");
|
||||
writer.WriteLine($"static int {ITexture}.{nameof(TextureMetadata.ImageCount)} => {nameof(TextureMetadata.ImageCount)};");
|
||||
writer.WriteLine($"static bool {ITexture}.{nameof(TextureMetadata.Mips)} => {nameof(TextureMetadata.Mips)};");
|
||||
writer.WriteLine($"static int {ITexture}.{nameof(TextureMetadata.Width)} => {nameof(TextureMetadata.Width)};");
|
||||
writer.WriteLine($"static int {ITexture}.{nameof(TextureMetadata.Height)} => {nameof(TextureMetadata.Height)};");
|
||||
writer.WriteLine($"static string {ITexture}.Path => Path;");
|
||||
}
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.TestGenerator;
|
||||
|
||||
public sealed class TextureMetadata
|
||||
{
|
||||
[JsonIgnore]
|
||||
public string? Name { get; set; }
|
||||
public string? Type { get; set; }
|
||||
public string? Format { get; set; }
|
||||
public int FileSize { get; set; }
|
||||
public int ImageSize { get; set; }
|
||||
public int ImageCount { get; set; }
|
||||
public bool Mips { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public static TextureMetadata FromFile(string path)
|
||||
{
|
||||
using FileStream stream = File.OpenRead(path);
|
||||
TextureMetadata result = JsonSerializer.Deserialize(stream, TextureMetadataSerializerContext.Default.TextureMetadata)
|
||||
?? throw new NullReferenceException(nameof(TextureMetadata));
|
||||
result.Name = Path.GetFileNameWithoutExtension(path);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.TestGenerator;
|
||||
|
||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||
[JsonSerializable(typeof(TextureMetadata))]
|
||||
internal sealed partial class TextureMetadataSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using AssetRipper.TextureDecoder.Paths;
|
||||
@@ -0,0 +1,720 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
public static partial class AndroidTextures
|
||||
{
|
||||
/// <summary>
|
||||
/// BGRA32_14 512x512 without mips
|
||||
/// </summary>
|
||||
public sealed class Logo_00 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.BGRA32_14;
|
||||
public const int FileSize = 1048576;
|
||||
public const int ImageSize = 1048576;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = false;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_00";
|
||||
/// <summary>
|
||||
/// Length: 1048576
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_00() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_12x12 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_01 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_12x12;
|
||||
public const int FileSize = 40112;
|
||||
public const int ImageSize = 40112;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_01";
|
||||
/// <summary>
|
||||
/// Length: 40112
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_01() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_RGB_10x10 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_02 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_RGB_10x10;
|
||||
public const int FileSize = 57952;
|
||||
public const int ImageSize = 57952;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_02";
|
||||
/// <summary>
|
||||
/// Length: 57952
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_02() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_RGB_8x8 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_03 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_RGB_8x8;
|
||||
public const int FileSize = 87424;
|
||||
public const int ImageSize = 87424;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_03";
|
||||
/// <summary>
|
||||
/// Length: 87424
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_03() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_6x6 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_04 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_6x6;
|
||||
public const int FileSize = 158432;
|
||||
public const int ImageSize = 158432;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_04";
|
||||
/// <summary>
|
||||
/// Length: 158432
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_04() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_5x5 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_05 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_5x5;
|
||||
public const int FileSize = 227680;
|
||||
public const int ImageSize = 227680;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_05";
|
||||
/// <summary>
|
||||
/// Length: 227680
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_05() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_RGB_4x4 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_06 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_RGB_4x4;
|
||||
public const int FileSize = 349552;
|
||||
public const int ImageSize = 349552;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_06";
|
||||
/// <summary>
|
||||
/// Length: 349552
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_06() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ETC2_RGBA8 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_07 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ETC2_RGBA8;
|
||||
public const int FileSize = 349552;
|
||||
public const int ImageSize = 349552;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_07";
|
||||
/// <summary>
|
||||
/// Length: 349552
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_07() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ETC2_RGBA1 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_08 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ETC2_RGBA1;
|
||||
public const int FileSize = 174776;
|
||||
public const int ImageSize = 174776;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_08";
|
||||
/// <summary>
|
||||
/// Length: 174776
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_08() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PVRTC_4BPP_RGBA 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_09 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.PVRTC_4BPP_RGBA;
|
||||
public const int FileSize = 174848;
|
||||
public const int ImageSize = 174848;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_09";
|
||||
/// <summary>
|
||||
/// Length: 174848
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_09() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PVRTC_RGBA2 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_10 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.PVRTC_RGBA2;
|
||||
public const int FileSize = 87488;
|
||||
public const int ImageSize = 87488;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_10";
|
||||
/// <summary>
|
||||
/// Length: 87488
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_10() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ETC2_RGB 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_11 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ETC2_RGB;
|
||||
public const int FileSize = 174776;
|
||||
public const int ImageSize = 174776;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_11";
|
||||
/// <summary>
|
||||
/// Length: 174776
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_11() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ETC_RGB4 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_12 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ETC_RGB4;
|
||||
public const int FileSize = 174776;
|
||||
public const int ImageSize = 174776;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_12";
|
||||
/// <summary>
|
||||
/// Length: 174776
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_12() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PVRTC_4BPP_RGB 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_13 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.PVRTC_4BPP_RGB;
|
||||
public const int FileSize = 174848;
|
||||
public const int ImageSize = 174848;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_13";
|
||||
/// <summary>
|
||||
/// Length: 174848
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_13() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PVRTC_2BPP_RGB 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_14 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.PVRTC_2BPP_RGB;
|
||||
public const int FileSize = 87488;
|
||||
public const int ImageSize = 87488;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_14";
|
||||
/// <summary>
|
||||
/// Length: 87488
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_14() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EAC_RG 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_15 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.EAC_RG;
|
||||
public const int FileSize = 349552;
|
||||
public const int ImageSize = 349552;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_15";
|
||||
/// <summary>
|
||||
/// Length: 349552
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_15() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EAC_R 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_16 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.EAC_R;
|
||||
public const int FileSize = 174776;
|
||||
public const int ImageSize = 174776;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_16";
|
||||
/// <summary>
|
||||
/// Length: 174776
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_16() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_12x12 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_17 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_12x12;
|
||||
public const int FileSize = 40112;
|
||||
public const int ImageSize = 40112;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_17";
|
||||
/// <summary>
|
||||
/// Length: 40112
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_17() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_10x10 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_18 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_10x10;
|
||||
public const int FileSize = 57952;
|
||||
public const int ImageSize = 57952;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_18";
|
||||
/// <summary>
|
||||
/// Length: 57952
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_18() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_8x8 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_19 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_8x8;
|
||||
public const int FileSize = 87424;
|
||||
public const int ImageSize = 87424;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_19";
|
||||
/// <summary>
|
||||
/// Length: 87424
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_19() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_6x6 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_20 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_6x6;
|
||||
public const int FileSize = 158432;
|
||||
public const int ImageSize = 158432;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_20";
|
||||
/// <summary>
|
||||
/// Length: 158432
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_20() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_5x5 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_21 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_5x5;
|
||||
public const int FileSize = 227680;
|
||||
public const int ImageSize = 227680;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_21";
|
||||
/// <summary>
|
||||
/// Length: 227680
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_21() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASTC_HDR_4x4 512x512 with mips
|
||||
/// </summary>
|
||||
public sealed class Logo_22 : ITexture
|
||||
{
|
||||
public const TextureType Type = TextureType.Texture2D;
|
||||
public const TextureFormat Format = TextureFormat.ASTC_HDR_4x4;
|
||||
public const int FileSize = 349552;
|
||||
public const int ImageSize = 349552;
|
||||
public const int ImageCount = 1;
|
||||
public const bool Mips = true;
|
||||
public const int Width = 512;
|
||||
public const int Height = 512;
|
||||
public const string Path = TestFileFolders.AndroidTestFiles + "Logo_22";
|
||||
/// <summary>
|
||||
/// Length: 349552
|
||||
/// </summary>
|
||||
public static byte[] Data => File.ReadAllBytes(Path);
|
||||
|
||||
private Logo_22() { }
|
||||
static TextureType ITexture.Type => Type;
|
||||
static TextureFormat ITexture.Format => Format;
|
||||
static int ITexture.FileSize => FileSize;
|
||||
static int ITexture.ImageSize => ImageSize;
|
||||
static int ITexture.ImageCount => ImageCount;
|
||||
static bool ITexture.Mips => Mips;
|
||||
static int ITexture.Width => Width;
|
||||
static int ITexture.Height => Height;
|
||||
static string ITexture.Path => Path;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.8.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder.Paths\AssetRipper.TextureDecoder.Paths.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.TextureDecoder\AssetRipper.TextureDecoder.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,77 @@
|
||||
using AssetRipper.TextureDecoder.Astc;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
public sealed class AstcTests
|
||||
{
|
||||
private const double MaxMeanDeviation4x4 = 0.2;
|
||||
private const double MaxStandardDeviation4x4 = 1;
|
||||
|
||||
private const double MaxMeanDeviation5x5 = 0.2;
|
||||
private const double MaxStandardDeviation5x5 = 1;
|
||||
|
||||
private const double MaxMeanDeviation6x6 = 0.2;
|
||||
private const double MaxStandardDeviation6x6 = 1;
|
||||
|
||||
private const double MaxMeanDeviation8x8 = 0.2;
|
||||
private const double MaxStandardDeviation8x8 = 2;
|
||||
|
||||
private const double MaxMeanDeviation10x10 = 0.2;
|
||||
private const double MaxStandardDeviation10x10 = 2.5;
|
||||
|
||||
private const double MaxMeanDeviation12x12 = 0.3;
|
||||
private const double MaxStandardDeviation12x12 = 3;
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc4x4() => AssertCorrectDecompression<AndroidTextures.Logo_06>(4, 4, MaxMeanDeviation4x4, MaxStandardDeviation4x4);
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc5x5() => AssertCorrectDecompression<AndroidTextures.Logo_05>(5, 5, MaxMeanDeviation5x5, MaxStandardDeviation5x5);
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc6x6() => AssertCorrectDecompression<AndroidTextures.Logo_04>(6, 6, MaxMeanDeviation6x6, MaxStandardDeviation6x6);
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc8x8() => AssertCorrectDecompression<AndroidTextures.Logo_03>(8, 8, MaxMeanDeviation8x8, MaxStandardDeviation8x8);
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc10x10() => AssertCorrectDecompression<AndroidTextures.Logo_02>(10, 10, MaxMeanDeviation10x10, MaxStandardDeviation10x10);
|
||||
|
||||
[Test]
|
||||
public void DecompressAstc12x12() => AssertCorrectDecompression<AndroidTextures.Logo_01>(12, 12, MaxMeanDeviation12x12, MaxStandardDeviation12x12);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc4x4HDR() => AssertCorrectDecompression<AndroidTextures.Logo_22>(4, 4, MaxMeanDeviation4x4, MaxStandardDeviation4x4);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc5x5HDR() => AssertCorrectDecompression<AndroidTextures.Logo_21>(5, 5, MaxMeanDeviation5x5, MaxStandardDeviation5x5);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc6x6HDR() => AssertCorrectDecompression<AndroidTextures.Logo_20>(6, 6, MaxMeanDeviation6x6, MaxStandardDeviation6x6);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc8x8HDR() => AssertCorrectDecompression<AndroidTextures.Logo_19>(8, 8, MaxMeanDeviation8x8, MaxStandardDeviation8x8);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc10x10HDR() => AssertCorrectDecompression<AndroidTextures.Logo_18>(10, 10, MaxMeanDeviation10x10, MaxStandardDeviation10x10);
|
||||
|
||||
[Test]
|
||||
[Ignore("High dynamic range textures are not supported yet.")]
|
||||
public void DecompressAstc12x12HDR() => AssertCorrectDecompression<AndroidTextures.Logo_17>(4, 4, MaxMeanDeviation12x12, MaxStandardDeviation12x12);
|
||||
|
||||
private static void AssertCorrectDecompression<T>(int blockWidth, int blockHeight, double maxMeanDeviation, double maxStandardDeviation) where T : ITexture
|
||||
{
|
||||
ReadOnlySpan<byte> data = T.Data;
|
||||
int bytesRead = AstcDecoder.DecodeASTC(data, T.Width, T.Height, blockWidth, blockHeight, out byte[] decompressedData);
|
||||
if (!T.Mips)
|
||||
{
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
ByteArrayDeviation.AssertMinimalDeviation(decompressedData, AndroidTextures.Logo_00.Data, maxMeanDeviation, maxStandardDeviation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class AtcTests
|
||||
{
|
||||
[Test]
|
||||
public void DecompressAtcRgb4Test()
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(TestFileFolders.AtcTestFiles + "test.atc_rgb4");
|
||||
int bytesRead = Atc.AtcDecoder.DecompressAtcRgb4(data, 256, 256, out byte[] decodedData);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
Assert.That(decodedData, Is.EqualTo(File.ReadAllBytes(TestFileFolders.AtcTestFiles + "test.atc_rgb4_decoded")));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressAtcRgba8Test()
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(TestFileFolders.AtcTestFiles + "test.atc_rgba8");
|
||||
int bytesRead = Atc.AtcDecoder.DecompressAtcRgba8(data, 256, 256, out byte[] decodedData);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
Assert.That(decodedData, Is.EqualTo(File.ReadAllBytes(TestFileFolders.AtcTestFiles + "test.atc_rgba8_decoded")));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using AssetRipper.TextureDecoder.Bc;
|
||||
using AssetRipper.TextureDecoder.Dxt;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class BcTests
|
||||
{
|
||||
private const double MaxMeanDeviationBc6h = 0.5;
|
||||
private const double MaxMeanDeviationBc7 = 0.1;//Bc7 is more accurate than Bc6h
|
||||
private const double MaxStandardDeviationBc6h = 0.8;
|
||||
private const double MaxStandardDeviationBc7 = 0.8;
|
||||
|
||||
private static byte[] originalBgra32LogoData = Array.Empty<byte>();
|
||||
|
||||
[SetUp]
|
||||
public void InitializeOriginalData()
|
||||
{
|
||||
originalBgra32LogoData = File.ReadAllBytes(TestFileFolders.BcTestFiles + "test.bgra32");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressDXT1Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt1");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4 }) //mipmaps 2 and 1 cause a buffer overrun for the output
|
||||
{
|
||||
int bytesRead = Bc1.Decompress(data.Slice(totalBytesRead), size, size, out byte[] bcDecodedData);
|
||||
DxtDecoder.DecompressDXT1(data.Slice(totalBytesRead), size, size, out byte[] dxtDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
AssertAlmostEqual(dxtDecodedData, bcDecodedData);
|
||||
}
|
||||
Assert.That(totalBytesRead + 16, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressDXT3Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt3");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4 }) //mipmaps 2 and 1 cause a buffer overrun for the output
|
||||
{
|
||||
int bytesRead = Bc2.Decompress(data.Slice(totalBytesRead), size, size, out byte[] bcDecodedData);
|
||||
DxtDecoder.DecompressDXT3(data.Slice(totalBytesRead), size, size, out byte[] dxtDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
AssertAlmostEqual(dxtDecodedData, bcDecodedData);
|
||||
}
|
||||
Assert.That(totalBytesRead + 32, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressDXT5Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt5");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4 }) //mipmaps 2 and 1 cause a buffer overrun for the output
|
||||
{
|
||||
int bytesRead = Bc3.Decompress(data.Slice(totalBytesRead), size, size, out byte[] bcDecodedData);
|
||||
DxtDecoder.DecompressDXT5(data.Slice(totalBytesRead), size, size, out byte[] dxtDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
AssertAlmostEqual(dxtDecodedData, bcDecodedData);
|
||||
}
|
||||
Assert.That(totalBytesRead + 32, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC4Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.BcTestFiles + "test.bc4");
|
||||
int bytesRead = Bc4.Decompress(data, 512, 512, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC5Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.BcTestFiles + "test.bc5");
|
||||
int bytesRead = Bc5.Decompress(data, 512, 512, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC6HFastTest()
|
||||
{
|
||||
AssertCorrectBC6HDecompression(TestFileFolders.BcTestFiles + "test.bc6h_fast", 512, 512, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC6HNormalTest()
|
||||
{
|
||||
AssertCorrectBC6HDecompression(TestFileFolders.BcTestFiles + "test.bc6h_normal", 512, 512, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC6HBestTest()
|
||||
{
|
||||
AssertCorrectBC6HDecompression(TestFileFolders.BcTestFiles + "test.bc6h_best", 512, 512, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC7FastTest()
|
||||
{
|
||||
AssertCorrectBC7Decompression(TestFileFolders.BcTestFiles + "test.bc7_fast", 512, 512);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC7NormalTest()
|
||||
{
|
||||
AssertCorrectBC7Decompression(TestFileFolders.BcTestFiles + "test.bc7_normal", 512, 512);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressBC7BestTest()
|
||||
{
|
||||
AssertCorrectBC7Decompression(TestFileFolders.BcTestFiles + "test.bc7_best", 512, 512);
|
||||
}
|
||||
|
||||
private static void AssertCorrectBC6HDecompression(string path, int width, int height, bool isSigned)
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(path);
|
||||
int bytesRead = Bc6h.Decompress(data, width, height, isSigned, out byte[] decodedData);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
ByteArrayDeviation.AssertMinimalDeviation(decodedData, originalBgra32LogoData, MaxMeanDeviationBc6h, MaxStandardDeviationBc6h);
|
||||
}
|
||||
|
||||
private static void AssertCorrectBC7Decompression(string path, int width, int height)
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(path);
|
||||
int bytesRead = Bc7.Decompress(data, width, height, out byte[] decodedData);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
ByteArrayDeviation.AssertMinimalDeviation(decodedData, originalBgra32LogoData, MaxMeanDeviationBc7, MaxStandardDeviationBc7);
|
||||
}
|
||||
|
||||
private static void AssertAlmostEqual(byte[] array1, byte[] array2, int maxDifference = 2)
|
||||
{
|
||||
if (array1.Length != array2.Length)
|
||||
{
|
||||
Assert.Fail($"Differing array lengths\nArray 1 length {array1.Length}\nArray 2 length {array2.Length}");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < array1.Length; i++)
|
||||
{
|
||||
int difference = Math.Abs(array1[i] - array2[i]);
|
||||
if (difference > maxDifference)
|
||||
{
|
||||
Assert.Fail($"Differing values at index {i}\nArray 1: {array1[i]}\nArray 2: {array2[i]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
internal static class ByteArrayDeviation
|
||||
{
|
||||
internal static void AssertMinimalDeviation(byte[] decoded, byte[] original, double maxMeanDeviation, double maxStandardDeviation)
|
||||
{
|
||||
if (decoded.Length != original.Length)
|
||||
{
|
||||
Assert.Fail($"Differing array lengths\nDecoded length {decoded.Length}\nOriginal length {original.Length}");
|
||||
return;
|
||||
}
|
||||
|
||||
long differenceSum = 0;
|
||||
|
||||
for (int i = 0; i < decoded.Length; i++)
|
||||
{
|
||||
differenceSum += decoded[i] - original[i];
|
||||
}
|
||||
|
||||
double mean = differenceSum / (double)decoded.Length;
|
||||
|
||||
double sumOfSquaredDeviations = 0;
|
||||
|
||||
for (int i = 0; i < decoded.Length; i++)
|
||||
{
|
||||
double deviation = decoded[i] - original[i] - mean;
|
||||
sumOfSquaredDeviations += deviation * deviation;
|
||||
}
|
||||
|
||||
double standardDeviation = Math.Sqrt(sumOfSquaredDeviations / (decoded.Length - 1));
|
||||
//Not sure if Bessel's correction is needed here, but it doesn't hurt, especially since length is around 1 million in the current use.
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mean, Is.LessThan(maxMeanDeviation), "Mean too far positive");
|
||||
Assert.That(mean, Is.GreaterThan(-maxMeanDeviation), "Mean too far negative");
|
||||
Assert.That(standardDeviation, Is.LessThan(maxStandardDeviation), "Standard deviation too large");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class DxtTests
|
||||
{
|
||||
[Test]
|
||||
public void DecompressDXT1Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt1");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Dxt.DxtDecoder.DecompressDXT1(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressDXT3Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt3");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Dxt.DxtDecoder.DecompressDXT3(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressDXT5Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.DxtTestFiles + "test.dxt5");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Dxt.DxtDecoder.DecompressDXT5(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class EtcTests
|
||||
{
|
||||
[Test]
|
||||
public void DecompressETCTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressETC(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressETC2Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressETC2(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressETC2A1Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2a1");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressETC2A1(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressETC2A8Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2a8");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressETC2A8(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressEACRSignedTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_r");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressEACRSigned(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressEACRUnsignedTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_r");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressEACRUnsigned(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressEACRGSignedTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_rg");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressEACRGSigned(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecompressEACRGUnsignedTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_rg");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Etc.EtcDecoder.DecompressEACRGUnsigned(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorARGB16Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorARGB16>(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorARGB16 MakeRandomColor() => ColorRandom<ColorARGB16, byte>.MakeRandomColor();
|
||||
|
||||
public static byte MakeRandomValue() => ColorRandom<ColorARGB16, byte>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorARGB32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorARGB32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorBGRA32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorBGRA32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB16, byte, ColorRGBA<UInt128>, UInt128>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorARGB32Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorARGB32>(), Is.EqualTo(4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorARGB32 MakeRandomColor() => ColorRandom<ColorARGB32, byte>.MakeRandomColor();
|
||||
|
||||
public static byte MakeRandomValue() => ColorRandom<ColorARGB32, byte>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorARGB32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorARGB32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorBGRA32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorBGRA32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorARGB32, byte, ColorRGBA<UInt128>, UInt128>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorBGRA32Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorBGRA32>(), Is.EqualTo(4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorBGRA32 MakeRandomColor() => ColorRandom<ColorBGRA32, byte>.MakeRandomColor();
|
||||
|
||||
public static byte MakeRandomValue() => ColorRandom<ColorBGRA32, byte>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorARGB32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorARGB32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorBGRA32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorBGRA32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorBGRA32, byte, ColorRGBA<UInt128>, UInt128>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorRGB16Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorRGB16>(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorRGB16 MakeRandomColor() => ColorRandom<ColorRGB16, byte>.MakeRandomColor();
|
||||
|
||||
public static byte MakeRandomValue() => ColorRandom<ColorRGB16, byte>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorARGB32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorARGB32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorBGRA32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorBGRA32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGBA<UInt128>, UInt128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB16, byte, ColorRGB<UInt128>, UInt128>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorRGB9e5Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorRGB9e5>(), Is.EqualTo(4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorRGB9e5 MakeRandomColor() => ColorRandom<ColorRGB9e5, double>.MakeRandomColor();
|
||||
|
||||
public static double MakeRandomValue() => ColorRandom<ColorRGB9e5, double>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_double()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB9e5, double, ColorRGBA<double>, double>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGB_double()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGB9e5, double, ColorRGB<double>, double>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
|
||||
public partial class ColorRGBA16Tests
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<ColorRGBA16>(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var b = color.B;
|
||||
var a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
var b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
var color = MakeRandomColor();
|
||||
color.GetChannels(out var r, out var g, out var b, out var a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
public static ColorRGBA16 MakeRandomColor() => ColorRandom<ColorRGBA16, byte>.MakeRandomColor();
|
||||
|
||||
public static byte MakeRandomValue() => ColorRandom<ColorRGBA16, byte>.MakeRandomValue();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorARGB32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorARGB32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorBGRA32()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorBGRA32, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_sbyte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<sbyte>, sbyte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_byte()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<byte>, byte>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_short()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<short>, short>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ushort()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<ushort>, ushort>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_int()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<int>, int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_uint()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<uint>, uint>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_long()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<long>, long>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_ulong()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<ulong>, ulong>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_Int128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<Int128>, Int128>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLosslessToColorRGBA_UInt128()
|
||||
{
|
||||
LosslessConversion.Assert<ColorRGBA16, byte, ColorRGBA<UInt128>, UInt128>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
internal static class ColorRandom<TColor, TChannel> where TColor : unmanaged, IColor<TChannel> where TChannel : unmanaged
|
||||
{
|
||||
public static TChannel MakeRandomValue()
|
||||
{
|
||||
ulong value = TestContext.CurrentContext.Random.NextULong();
|
||||
return NumericConversion.Convert<ulong, TChannel>(value);
|
||||
}
|
||||
|
||||
public static TColor MakeRandomColor()
|
||||
{
|
||||
TColor color = default;
|
||||
color.SetChannels(MakeRandomValue(), MakeRandomValue(), MakeRandomValue(), MakeRandomValue());
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
|
||||
|
||||
internal partial class GenericColorTests<TColor, TChannel> where TColor : unmanaged, IColor<TChannel> where TChannel : unmanaged
|
||||
{
|
||||
[Test]
|
||||
public void CorrectSizeTest()
|
||||
{
|
||||
Assert.That(Unsafe.SizeOf<TColor>(), Is.EqualTo(Color.GetChannelCount<TColor>() * Unsafe.SizeOf<TChannel>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_R()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel r = color.R;
|
||||
color.R = r;
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_G()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel g = color.G;
|
||||
color.G = g;
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_B()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel b = color.B;
|
||||
color.B = b;
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyIsSymmetric_A()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel a = color.A;
|
||||
color.A = a;
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_R()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel g = color.G;
|
||||
TChannel b = color.B;
|
||||
TChannel a = color.A;
|
||||
color.R = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_G()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel r = color.R;
|
||||
TChannel b = color.B;
|
||||
TChannel a = color.A;
|
||||
color.G = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_B()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel r = color.R;
|
||||
TChannel g = color.G;
|
||||
TChannel a = color.A;
|
||||
color.B = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChannelsAreIndependent_A()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
TChannel r = color.R;
|
||||
TChannel g = color.G;
|
||||
TChannel b = color.B;
|
||||
color.A = MakeRandomValue();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodMatchesProperties()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
color.GetChannels(out TChannel r, out TChannel g, out TChannel b, out TChannel a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsAreSymmetric()
|
||||
{
|
||||
TColor color = MakeRandomColor();
|
||||
color.GetChannels(out TChannel r, out TChannel g, out TChannel b, out TChannel a);
|
||||
color.SetChannels(r, g, b, a);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(color.R, Is.EqualTo(r));
|
||||
Assert.That(color.G, Is.EqualTo(g));
|
||||
Assert.That(color.B, Is.EqualTo(b));
|
||||
Assert.That(color.A, Is.EqualTo(a));
|
||||
});
|
||||
}
|
||||
|
||||
private static TChannel MakeRandomValue() => ColorRandom<TColor, TChannel>.MakeRandomValue();
|
||||
|
||||
private static TColor MakeRandomColor() => ColorRandom<TColor, TChannel>.MakeRandomColor();
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<sbyte>), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<sbyte>), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<sbyte>), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<sbyte>), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<sbyte>), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<byte>), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<byte>), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<byte>), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<byte>), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<byte>), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<short>), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<short>), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<short>), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<short>), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<short>), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<ushort>), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<ushort>), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<ushort>), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<ushort>), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<ushort>), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<int>), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<int>), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<int>), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<int>), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<int>), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<uint>), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<uint>), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<uint>), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<uint>), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<uint>), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<long>), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<long>), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<long>), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<long>), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<long>), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<ulong>), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<ulong>), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<ulong>), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<ulong>), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<ulong>), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<Int128>), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<Int128>), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<Int128>), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<Int128>), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<Int128>), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<UInt128>), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<UInt128>), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<UInt128>), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<UInt128>), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<UInt128>), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<Half>), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<Half>), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<Half>), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<Half>), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<Half>), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<float>), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<float>), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<float>), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<float>), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<float>), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<double>), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<double>), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<double>), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<double>), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<double>), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorR<decimal>), typeof(decimal) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRG<decimal>), typeof(decimal) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<decimal>), typeof(decimal) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<decimal>), typeof(decimal) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<decimal>), typeof(decimal) })]
|
||||
partial class GenericColorTests<TColor, TChannel>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Numerics;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for lossless color conversions.
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">The "smaller" type that can be losslessly converted into <typeparamref name="T2"/>.</typeparam>
|
||||
/// <typeparam name="T2">The "larger" type capable of storing <typeparamref name="T1"/> losslessly.</typeparam>
|
||||
internal partial class LosslessColorTests<T1, T2>
|
||||
where T1 : unmanaged, INumberBase<T1>, IMinMaxValue<T1>
|
||||
where T2 : unmanaged, INumberBase<T2>, IMinMaxValue<T2>
|
||||
{
|
||||
[Test]
|
||||
public void ConversionIsLossless_R_T1_R_T2() => LosslessConversion.Assert<ColorR<T1>, T1, ColorR<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_R_T1_RG_T2() => LosslessConversion.Assert<ColorR<T1>, T1, ColorRG<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_R_T1_RGB_T2() => LosslessConversion.Assert<ColorR<T1>, T1, ColorRGB<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_R_T1_RGBA_T2() => LosslessConversion.Assert<ColorR<T1>, T1, ColorRGBA<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_RG_T1_RGB_T2() => LosslessConversion.Assert<ColorRG<T1>, T1, ColorRGB<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_RG_T1_RGBA_T2() => LosslessConversion.Assert<ColorRG<T1>, T1, ColorRGBA<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_RGB_T1_RGBA_T2() => LosslessConversion.Assert<ColorRGB<T1>, T1, ColorRGBA<T2>, T2>();
|
||||
|
||||
[Test]
|
||||
public void ConversionIsLossless_A_T1_RGBA_T2() => LosslessConversion.Assert<ColorA<T1>, T1, ColorRGBA<T2>, T2>();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(sbyte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(byte), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(short) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ushort), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(int) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(uint), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(long), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(long), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(long), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(long), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ulong), typeof(long) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ulong), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ulong), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(ulong), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Int128), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Int128), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(UInt128), typeof(Int128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(UInt128), typeof(UInt128) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Half), typeof(Half) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Half), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Half), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(float), typeof(float) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(float), typeof(double) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(double), typeof(double) })]
|
||||
partial class LosslessColorTests<T1, T2>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using System.Numerics;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
|
||||
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(sbyte), typeof(byte) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(short), typeof(ushort) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(int), typeof(uint) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(long), typeof(ulong) })]
|
||||
[TestFixture(TypeArgs = new Type[] { typeof(Int128), typeof(UInt128) })]
|
||||
internal class NumericConversionExtremesTests<TSigned, TUnsigned>
|
||||
where TSigned : unmanaged, IMinMaxValue<TSigned>
|
||||
where TUnsigned : unmanaged, IMinMaxValue<TUnsigned>
|
||||
{
|
||||
[Test]
|
||||
public void SignedToUnsignedExtremesAreCorrect()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(NumericConversion.Convert<TSigned, TUnsigned>(TSigned.MinValue), Is.EqualTo(TUnsigned.MinValue));
|
||||
Assert.That(NumericConversion.Convert<TSigned, TUnsigned>(TSigned.MaxValue), Is.EqualTo(TUnsigned.MaxValue));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnsignedToSignedExtremesAreCorrect()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(NumericConversion.Convert<TUnsigned, TSigned>(TUnsigned.MinValue), Is.EqualTo(TSigned.MinValue));
|
||||
Assert.That(NumericConversion.Convert<TUnsigned, TSigned>(TUnsigned.MaxValue), Is.EqualTo(TSigned.MaxValue));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests.Formats;
|
||||
internal static class LosslessConversion
|
||||
{
|
||||
internal static void Assert<TColor1, TChannel1, TColor2, TChannel2>()
|
||||
where TChannel1 : unmanaged
|
||||
where TChannel2 : unmanaged
|
||||
where TColor1 : unmanaged, IColor<TChannel1>
|
||||
where TColor2 : unmanaged, IColor<TChannel2>
|
||||
{
|
||||
TColor1 original = ColorRandom<TColor1, TChannel1>.MakeRandomColor();
|
||||
TColor2 converted = original.Convert<TColor1, TChannel1, TColor2, TChannel2>();
|
||||
TColor1 convertedBack = converted.Convert<TColor2, TChannel2, TColor1, TChannel1>();
|
||||
NUnit.Framework.Assert.That(convertedBack, Is.EqualTo(original));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
public partial interface ITexture
|
||||
{
|
||||
static abstract TextureType Type { get; }
|
||||
static abstract TextureFormat Format { get; }
|
||||
static abstract int FileSize { get; }
|
||||
static abstract int ImageSize { get; }
|
||||
static abstract int ImageCount { get; }
|
||||
static abstract bool Mips { get; }
|
||||
static abstract int Width { get; }
|
||||
static abstract int Height { get; }
|
||||
static abstract string Path { get; }
|
||||
static abstract byte[] Data { get; }
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class NewRgbTests
|
||||
{
|
||||
[Test]
|
||||
public void ConvertA8Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.alpha8");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.A8ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorA<byte>, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertARGB16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.argb4444");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.Convert<ColorARGB16, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB24Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb24");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.RGB24ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGB<byte>, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBA32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba32");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.RGBA32ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertARGB32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.argb32");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.ARGB32ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorARGB32, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb565");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.RGB16ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGB16, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertR16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.r16");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.Convert<ColorR<ushort>, ushort, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBA16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba4444");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.Convert<ColorRGBA16, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRG16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg16");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.RG16ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRG<byte>, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertR8Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.r8");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = RgbConverter.R8ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorR<byte>, byte, ColorBGRA32, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData);
|
||||
totalBytesRead += bytesRead;
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rhalf");
|
||||
RgbConverter.RHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorR<Half>, Half, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rghalf");
|
||||
RgbConverter.RGHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRG<Half>, Half, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBAHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbahalf");
|
||||
RgbConverter.RGBAHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGBA<Half>, Half, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rfloat");
|
||||
RgbConverter.RFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorR<float>, float, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgfloat");
|
||||
RgbConverter.RGFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRG<float>, float, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBAFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbafloat");
|
||||
RgbConverter.RGBAFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGBA<float>, float, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB9e5FloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb9e5float");
|
||||
RgbConverter.RGB9e5FloatToBGRA32(data, 256, 256, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGB9e5, double, ColorBGRA32, byte>(data, 256, 256, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRG32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg32");
|
||||
RgbConverter.RG32ToBGRA32(data, 512, 512, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRG<ushort>, ushort, ColorBGRA32, byte>(data, 512, 512, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB48Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb48");
|
||||
RgbConverter.RGB48ToBGRA32(data, 512, 512, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGB<ushort>, ushort, ColorBGRA32, byte>(data, 512, 512, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBA64Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba64");
|
||||
RgbConverter.RGBA64ToBGRA32(data, 512, 512, out byte[] originalDecodedData);
|
||||
RgbConverter.Convert<ColorRGBA<ushort>, ushort, ColorBGRA32, byte>(data, 512, 512, out byte[] newDecodedData);
|
||||
Assert.That(originalDecodedData, Is.EqualTo(newDecodedData));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class PvrtcTests
|
||||
{
|
||||
[Test]
|
||||
public void DecompressPVRTCTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.PvrtcTestFiles + "test.pvrtc4");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 512, 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Pvrtc.PvrtcDecoder.DecompressPVRTC(data, size, size, false, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class RgbTests
|
||||
{
|
||||
[Test]
|
||||
public void ConvertA8Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.alpha8");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.A8ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB24Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb24");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.RGB24ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBA32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba32");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.RGBA32ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertARGB32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.argb32");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.ARGB32ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb565");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.RGB16ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRG16Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg16");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.RG16ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertR8Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.r8");
|
||||
int totalBytesRead = 0;
|
||||
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
|
||||
{
|
||||
int bytesRead = Rgb.RgbConverter.R8ToBGRA32(data.Slice(totalBytesRead), size, size, out _);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rhalf");
|
||||
int bytesRead = Rgb.RgbConverter.RHalfToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rghalf");
|
||||
int bytesRead = Rgb.RgbConverter.RGHalfToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBAHalfTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbahalf");
|
||||
int bytesRead = Rgb.RgbConverter.RGBAHalfToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rfloat");
|
||||
int bytesRead = Rgb.RgbConverter.RFloatToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgfloat");
|
||||
int bytesRead = Rgb.RgbConverter.RGFloatToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBAFloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbafloat");
|
||||
int bytesRead = Rgb.RgbConverter.RGBAFloatToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB9e5FloatTest()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb9e5float");
|
||||
int bytesRead = Rgb.RgbConverter.RGB9e5FloatToBGRA32(data, 256, 256, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRG32Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg32");
|
||||
int bytesRead = Rgb.RgbConverter.RG32ToBGRA32(data, 512, 512, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGB48Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb48");
|
||||
int bytesRead = Rgb.RgbConverter.RGB48ToBGRA32(data, 512, 512, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertRGBA64Test()
|
||||
{
|
||||
ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba64");
|
||||
int bytesRead = Rgb.RgbConverter.RGBA64ToBGRA32(data, 512, 512, out _);
|
||||
Assert.That(bytesRead, Is.EqualTo(data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
public enum TextureFormat
|
||||
{
|
||||
ASTC_12x12,
|
||||
ASTC_5x5,
|
||||
ASTC_6x6,
|
||||
ASTC_HDR_10x10,
|
||||
ASTC_HDR_12x12,
|
||||
ASTC_HDR_4x4,
|
||||
ASTC_HDR_5x5,
|
||||
ASTC_HDR_6x6,
|
||||
ASTC_HDR_8x8,
|
||||
ASTC_RGB_10x10,
|
||||
ASTC_RGB_4x4,
|
||||
ASTC_RGB_8x8,
|
||||
BGRA32_14,
|
||||
EAC_R,
|
||||
EAC_RG,
|
||||
ETC_RGB4,
|
||||
ETC2_RGB,
|
||||
ETC2_RGBA1,
|
||||
ETC2_RGBA8,
|
||||
PVRTC_2BPP_RGB,
|
||||
PVRTC_4BPP_RGB,
|
||||
PVRTC_4BPP_RGBA,
|
||||
PVRTC_RGBA2,
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests;
|
||||
|
||||
public enum TextureType
|
||||
{
|
||||
Texture2D,
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
global using AssetRipper.TextureDecoder.Paths;
|
||||
global using NUnit.Framework;
|
||||
@@ -0,0 +1,21 @@
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using AssetRipper.TextureDecoder.Yuy2;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Tests
|
||||
{
|
||||
public sealed class Yuy2Tests
|
||||
{
|
||||
private const int TestImageWidth = 256;
|
||||
private const int TestImageHeight = 256;
|
||||
|
||||
[Test]
|
||||
public void DecompressYUY2Test()
|
||||
{
|
||||
byte[] input = File.ReadAllBytes(TestFileFolders.Yuy2TestFiles + "test.yuy2");
|
||||
int bytesRead = Yuy2Decoder.DecompressYUY2(input, TestImageWidth, TestImageHeight, out byte[] originalOutput);
|
||||
Assert.That(bytesRead, Is.EqualTo(input.Length));
|
||||
Yuy2Decoder.DecompressYUY2<ColorBGRA32, byte>(input, TestImageWidth, TestImageHeight, out byte[] genericOutput);
|
||||
Assert.That(originalOutput, Is.EqualTo(genericOutput));
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-15
@@ -1,37 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<RootNamespace>AssetRipper.TextureDecoder</RootNamespace>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<PackageId>TextureDecoder</PackageId>
|
||||
<Version>2.0.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.TextureDecoder</PackageId>
|
||||
<PackageTags>C# Texture</PackageTags>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/TextureDecoder</RepositoryUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageProjectUrl>https://github.com/AssetRipper/TextureDecoder</PackageProjectUrl>
|
||||
<Copyright>Copyright (c) 2022 ds5678</Copyright>
|
||||
<Copyright>Copyright (c) 2022 - 2023 ds5678</Copyright>
|
||||
<Description>Managed library for decoding textures in multiple formats.</Description>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<DocumentationFile>bin\TextureDecoder.xml</DocumentationFile>
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
|
||||
<PackageReference Include="Half" Version="1.0.0" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PolySharp" Version="1.13.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DocumentationFile>bin\TextureDecoder.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace AssetRipper.TextureDecoder.Astc
|
||||
{
|
||||
public static partial class AstcDecoder
|
||||
{
|
||||
private unsafe struct BlockData
|
||||
{
|
||||
public int bw;
|
||||
public int bh;
|
||||
public int width;
|
||||
public int height;
|
||||
public int part_num;
|
||||
public int dual_plane;
|
||||
public int plane_selector;
|
||||
public int weight_range;
|
||||
/// <summary>
|
||||
/// max: 120
|
||||
/// </summary>
|
||||
public int weight_num;
|
||||
public fixed int cem[4];
|
||||
public int cem_range;
|
||||
/// <summary>
|
||||
/// max: 32
|
||||
/// </summary>
|
||||
public int endpoint_value_num;
|
||||
public fixed int endpoints[4 * 8];
|
||||
public fixed int weights[144 * 2];
|
||||
public fixed int partition[144];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AssetRipper.TextureDecoder.Astc
|
||||
{
|
||||
public static partial class AstcDecoder
|
||||
{
|
||||
private struct IntSeqData
|
||||
{
|
||||
public int bits;
|
||||
public int nonbits;
|
||||
}
|
||||
}
|
||||
}
|
||||
+376
-299
File diff suppressed because it is too large.
Load diff
@@ -1,106 +1,86 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Buffers.Binary;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TextureDecoder.Atc
|
||||
namespace AssetRipper.TextureDecoder.Atc
|
||||
{
|
||||
public static class AtcDecoder
|
||||
{
|
||||
public static byte[] DecompressAtcRgb4(byte[] input, int width, int height)
|
||||
public static int DecompressAtcRgb4(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressAtcRgb4(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressAtcRgb4(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressAtcRgb4(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressAtcRgb4(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressAtcRgb4(byte* input, int width, int height, byte* output)
|
||||
public static int DecompressAtcRgb4(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeAtcRgb4Block(input, buf);
|
||||
DecodeAtcRgb4Block(input.Slice(inputOffset, 8), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
int outputOffset = t * 16 * width + s * 16 + i * width * sizeof(uint);
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(output.Slice(outputOffset + j * sizeof(uint)), buf[j + 4 * i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressAtcRgba8(byte[] input, int width, int height)
|
||||
public static int DecompressAtcRgba8(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressAtcRgba8(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressAtcRgba8(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressAtcRgba8(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressAtcRgba8(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressAtcRgba8(byte* input, int width, int height, byte* output)
|
||||
public static int DecompressAtcRgba8(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 16)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 16)
|
||||
{
|
||||
DecodeAtcRgba8Block(input, buf);
|
||||
DecodeAtcRgba8Block(input.Slice(inputOffset, 16), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
int outputOffset = t * 16 * width + s * 16 + i * width * sizeof(uint);
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(output.Slice(outputOffset + j * sizeof(uint)), buf[j + 4 * i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
private unsafe static void DecodeAtcRgb4Block(byte* input, uint* output)
|
||||
private static void DecodeAtcRgb4Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
int* colors = stackalloc int[16];
|
||||
int c0 = *((ushort*)(input + 0));
|
||||
int c1 = *((ushort*)(input + 2));
|
||||
uint cindex = *((uint*)(input + 4));
|
||||
Span<int> colors = stackalloc int[16];
|
||||
int c0 = input.ReadAtOffset<ushort>(0);
|
||||
int c1 = input.ReadAtOffset<ushort>(2);
|
||||
uint cindex = input.ReadAtOffset<uint>(4);
|
||||
|
||||
DecodeColors(colors, c0, c1);
|
||||
|
||||
for (int i = 0; i < 4 * 4; i++)
|
||||
{
|
||||
uint cidx = cindex & 3;
|
||||
int cidx = unchecked((int)(cindex & 3));
|
||||
int cb = colors[cidx * 4 + 0];
|
||||
int cg = colors[cidx * 4 + 1];
|
||||
int cr = colors[cidx * 4 + 2];
|
||||
@@ -109,18 +89,18 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeAtcRgba8Block(byte* input, uint* output)
|
||||
private static void DecodeAtcRgba8Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
int* alphas = stackalloc int[16];
|
||||
ulong avalue = *((ulong*)input);
|
||||
Span<int> alphas = stackalloc int[16];
|
||||
ulong avalue = BinaryPrimitives.ReadUInt64LittleEndian(input);
|
||||
int a0 = unchecked((int)(avalue >> 0) & 0xFF);
|
||||
int a1 = unchecked((int)(avalue >> 8) & 0xFF);
|
||||
ulong aindex = avalue >> 16;
|
||||
|
||||
int* colors = stackalloc int[16];
|
||||
int c0 = *((ushort*)(input + 8));
|
||||
int c1 = *((ushort*)(input + 10));
|
||||
uint cindex = *((uint*)(input + 12));
|
||||
Span<int> colors = stackalloc int[16];
|
||||
int c0 = input.ReadAtOffset<ushort>(8);
|
||||
int c1 = input.ReadAtOffset<ushort>(10);
|
||||
uint cindex = input.ReadAtOffset<uint>(12);
|
||||
|
||||
DecodeColors(colors, c0, c1);
|
||||
DecodeAlphas(alphas, a0, a1);
|
||||
@@ -139,8 +119,14 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static void DecodeColors(int* colors, int c0, int c1)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static T ReadAtOffset<T>(this ReadOnlySpan<byte> input, int offset) where T : unmanaged
|
||||
{
|
||||
return MemoryMarshal.Read<T>(input.Slice(offset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeColors(Span<int> colors, int c0, int c1)
|
||||
{
|
||||
if ((c0 & 0x8000) == 0)
|
||||
{
|
||||
@@ -180,8 +166,8 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static void DecodeAlphas(int* alphas, int a0, int a1)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeAlphas(Span<int> alphas, int a0, int a1)
|
||||
{
|
||||
alphas[0] = a0;
|
||||
alphas[1] = a1;
|
||||
@@ -205,14 +191,14 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int Extend(int value, int from, int to)
|
||||
{
|
||||
// bit-pattern replicating scaling (can at most double the bits)
|
||||
return (value << (to - from)) | (value >> (from * 2 - to));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Color(int r, int g, int b, int a)
|
||||
{
|
||||
return unchecked((uint)(r << 16 | g << 8 | b | a << 24));
|
||||
@@ -0,0 +1,33 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc1
|
||||
{
|
||||
internal const int BlockSize = 8;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int outputOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRGBA<byte>>();
|
||||
BcHelpers.DecompressBc1(input.Slice(inputOffset, BlockSize), output.Slice(outputOffset), width * 4);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(output, width, height, output);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc2
|
||||
{
|
||||
internal const int BlockSize = 16;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int outputOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRGBA<byte>>();
|
||||
BcHelpers.DecompressBc2(input.Slice(inputOffset), output.Slice(outputOffset), width * 4);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(output, width, height, output);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc3
|
||||
{
|
||||
internal const int BlockSize = 16;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int outputOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRGBA<byte>>();
|
||||
BcHelpers.DecompressBc3(input.Slice(inputOffset), output.Slice(outputOffset), width * 4);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(output, width, height, output);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Buffers;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc4
|
||||
{
|
||||
internal const int BlockSize = 8;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int bufferSize = width * height * Unsafe.SizeOf<ColorR<byte>>();
|
||||
byte[] bufferArray = ArrayPool<byte>.Shared.Rent(bufferSize);
|
||||
Span<byte> buffer = new Span<byte>(bufferArray, 0, bufferSize);
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int bufferOffset = ((i * width) + j) * Unsafe.SizeOf<ColorR<byte>>();
|
||||
BcHelpers.DecompressBc4(input.Slice(inputOffset), buffer.Slice(bufferOffset), width);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorR<byte>, byte, ColorBGRA32, byte>(buffer, width, height, output);
|
||||
ArrayPool<byte>.Shared.Return(bufferArray);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Buffers;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc5
|
||||
{
|
||||
internal const int BlockSize = 16;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int bufferSize = width * height * Unsafe.SizeOf<ColorRG<byte>>();
|
||||
byte[] bufferArray = ArrayPool<byte>.Shared.Rent(bufferSize);
|
||||
Span<byte> buffer = new Span<byte>(bufferArray, 0, bufferSize);
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int bufferOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRG<byte>>();
|
||||
BcHelpers.DecompressBc5(input.Slice(inputOffset), buffer.Slice(bufferOffset), width * 2);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRG<byte>, byte, ColorBGRA32, byte>(buffer, width, height, output);
|
||||
ArrayPool<byte>.Shared.Return(bufferArray);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
using System.Buffers;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc6h
|
||||
{
|
||||
internal const int BlockSize = 16;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, bool isSigned, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, isSigned, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, bool isSigned, Span<byte> output)
|
||||
{
|
||||
int bufferSize = width * height * Unsafe.SizeOf<ColorRGB<Half>>();
|
||||
byte[] bufferArray = ArrayPool<byte>.Shared.Rent(bufferSize);
|
||||
Span<byte> buffer = new Span<byte>(bufferArray, 0, bufferSize);
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int outputOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRGB<Half>>();
|
||||
BcHelpers.DecompressBc6h(
|
||||
input.Slice(inputOffset, BlockSize),
|
||||
buffer.Slice(outputOffset),
|
||||
width * 3,
|
||||
isSigned);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRGB<Half>, Half, ColorBGRA32, byte>(buffer, width, height, output);
|
||||
ArrayPool<byte>.Shared.Return(bufferArray);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
internal static class Bc6hTables
|
||||
{
|
||||
internal static byte[][] ActualBitsCount { get; } = new byte[4][]
|
||||
{
|
||||
new byte[14] {10, 7, 11, 11, 11, 9, 8, 8, 8, 6, 10, 11, 12, 16},
|
||||
new byte[14] {5, 6, 5, 4, 4, 5, 6, 5, 5, 6, 10, 9, 8, 4},
|
||||
new byte[14] {5, 6, 4, 5, 4, 5, 5, 6, 5, 6, 10, 9, 8, 4},
|
||||
new byte[14] {5, 6, 4, 4, 5, 5, 5, 5, 6, 6, 10, 9, 8, 4}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// There are 32 possible partition sets for a two-region tile.
|
||||
/// Each 4x4 block represents a single shape.
|
||||
/// Here also every fix-up index has MSB bit set.
|
||||
/// </summary>
|
||||
internal static byte[][][] PartitionSets { get; } = new byte[32][][]
|
||||
{
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {129, 1, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {129, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {129, 1, 1, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
}
|
||||
};
|
||||
|
||||
internal static int[] AWeight3 { get; } = new int[8] { 0, 9, 18, 27, 37, 46, 55, 64 };
|
||||
|
||||
internal static int[] AWeight4 { get; } = new int[16] { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 };
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using AssetRipper.TextureDecoder.Rgb;
|
||||
using AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
public static class Bc7
|
||||
{
|
||||
internal const int BlockSize = 16;
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * Unsafe.SizeOf<ColorBGRA32>()];
|
||||
return Decompress(input, width, height, output);
|
||||
}
|
||||
|
||||
public static int Decompress(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int inputOffset = 0;
|
||||
for (int i = 0; i < height; i += 4)
|
||||
{
|
||||
for (int j = 0; j < width; j += 4)
|
||||
{
|
||||
int outputOffset = ((i * width) + j) * Unsafe.SizeOf<ColorRGBA<byte>>();
|
||||
BcHelpers.DecompressBc7(
|
||||
input.Slice(inputOffset, BlockSize),
|
||||
output.Slice(outputOffset),
|
||||
width * 4);
|
||||
inputOffset += BlockSize;
|
||||
}
|
||||
}
|
||||
RgbConverter.Convert<ColorRGBA<byte>, byte, ColorBGRA32, byte>(output, width, height, output);
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
internal static int GetCompressedSize(int w, int h) => ((w) >> 2) * ((h) >> 2) * BlockSize;
|
||||
}
|
||||
@@ -0,0 +1,929 @@
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
internal static class Bc7Tables
|
||||
{
|
||||
internal static byte[][] ActualBitsCount { get; } = new byte[2][]
|
||||
{
|
||||
new byte[8] { 4, 6, 5, 7, 5, 7, 7, 5 },
|
||||
new byte[8] { 0, 0, 0, 0, 6, 8, 7, 5 }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// There are 64 possible partition sets for a two-region tile.
|
||||
/// Each 4x4 block represents a single shape.
|
||||
/// Here also every fix-up index has MSB bit set.
|
||||
/// </summary>
|
||||
internal static byte[][][][] PartitionSets { get; } = new byte[2][][][]
|
||||
{
|
||||
new byte[64][][]
|
||||
{
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {129, 1, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {129, 0, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {129, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {129, 1, 1, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 1},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {0, 1, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 1},
|
||||
new byte[4] {1, 0, 129, 0},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {1, 0, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {129, 1, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 1},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {129, 0, 1, 0},
|
||||
new byte[4] {1, 0, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 1},
|
||||
new byte[4] {1, 0, 1, 0},
|
||||
new byte[4] {1, 0, 1, 0},
|
||||
new byte[4] {0, 1, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {129, 1, 0, 0},
|
||||
new byte[4] {1, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 1, 0},
|
||||
new byte[4] {0, 1, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {1, 0, 1, 1},
|
||||
new byte[4] {1, 1, 0, 1},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 0},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {0, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 1, 129, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 0},
|
||||
new byte[4] {1, 1, 129, 0},
|
||||
new byte[4] {0, 1, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 0},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 0, 1, 0},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 129, 0},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 0, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 1, 0, 0},
|
||||
new byte[4] {129, 1, 1, 0},
|
||||
new byte[4] {0, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 129, 0},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 1, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {1, 0, 0, 1},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {0, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {1, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {1, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 0},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 1},
|
||||
new byte[4] {1, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 0},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 129, 0},
|
||||
new byte[4] {0, 0, 1, 0},
|
||||
new byte[4] {1, 1, 1, 0},
|
||||
new byte[4] {1, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 0},
|
||||
new byte[4] {0, 1, 0, 0},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
}
|
||||
},
|
||||
new byte[64][][]
|
||||
{
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 129},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 2, 2, 1},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 129},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {130, 2, 1, 1},
|
||||
new byte[4] {2, 2, 2, 1}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {2, 0, 0, 1},
|
||||
new byte[4] {130, 2, 1, 1},
|
||||
new byte[4] {2, 2, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 130},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 1, 2, 2},
|
||||
new byte[4] {1, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 129},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 0, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 130},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {130, 2, 1, 1},
|
||||
new byte[4] {2, 2, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {129, 1, 1, 1},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 1, 1},
|
||||
new byte[4] {129, 1, 1, 1},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 129, 1},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 2},
|
||||
new byte[4] {0, 0, 129, 2},
|
||||
new byte[4] {0, 0, 1, 2},
|
||||
new byte[4] {0, 0, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 2},
|
||||
new byte[4] {0, 1, 129, 2},
|
||||
new byte[4] {0, 1, 1, 2},
|
||||
new byte[4] {0, 1, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 2, 2},
|
||||
new byte[4] {0, 129, 2, 2},
|
||||
new byte[4] {0, 1, 2, 2},
|
||||
new byte[4] {0, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 129},
|
||||
new byte[4] {0, 1, 1, 2},
|
||||
new byte[4] {1, 1, 2, 2},
|
||||
new byte[4] {1, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 129},
|
||||
new byte[4] {2, 0, 0, 1},
|
||||
new byte[4] {130, 2, 0, 0},
|
||||
new byte[4] {2, 2, 2, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 129},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 1, 1, 2},
|
||||
new byte[4] {1, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 129},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {130, 0, 0, 1},
|
||||
new byte[4] {2, 2, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 2, 2},
|
||||
new byte[4] {129, 1, 2, 2},
|
||||
new byte[4] {1, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 130},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {1, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 129},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 2, 2, 2},
|
||||
new byte[4] {0, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 129},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {130, 2, 2, 1},
|
||||
new byte[4] {2, 2, 2, 1}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 129, 1},
|
||||
new byte[4] {0, 1, 2, 2},
|
||||
new byte[4] {0, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 0, 0},
|
||||
new byte[4] {130, 2, 129, 0},
|
||||
new byte[4] {2, 2, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 2, 130},
|
||||
new byte[4] {0, 129, 2, 2},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 2},
|
||||
new byte[4] {0, 0, 1, 2},
|
||||
new byte[4] {129, 1, 2, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {1, 2, 130, 1},
|
||||
new byte[4] {129, 2, 2, 1},
|
||||
new byte[4] {0, 1, 1, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 1, 129, 0},
|
||||
new byte[4] {1, 2, 130, 1},
|
||||
new byte[4] {1, 2, 2, 1}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 2},
|
||||
new byte[4] {1, 1, 0, 2},
|
||||
new byte[4] {129, 1, 0, 2},
|
||||
new byte[4] {0, 0, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {0, 129, 1, 0},
|
||||
new byte[4] {2, 0, 0, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {0, 1, 2, 2},
|
||||
new byte[4] {0, 1, 130, 2},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {2, 0, 0, 0},
|
||||
new byte[4] {130, 2, 1, 1},
|
||||
new byte[4] {2, 2, 2, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 2},
|
||||
new byte[4] {129, 1, 2, 2},
|
||||
new byte[4] {1, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 130},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 0, 1, 2},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 129},
|
||||
new byte[4] {0, 0, 1, 2},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 2, 0},
|
||||
new byte[4] {0, 129, 2, 0},
|
||||
new byte[4] {0, 1, 130, 0},
|
||||
new byte[4] {0, 1, 2, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {1, 1, 129, 1},
|
||||
new byte[4] {2, 2, 130, 2},
|
||||
new byte[4] {0, 0, 0, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 2, 0},
|
||||
new byte[4] {1, 2, 0, 1},
|
||||
new byte[4] {130, 0, 129, 2},
|
||||
new byte[4] {0, 1, 2, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 2, 0},
|
||||
new byte[4] {2, 0, 1, 2},
|
||||
new byte[4] {129, 130, 0, 1},
|
||||
new byte[4] {0, 1, 2, 0}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {2, 2, 0, 0},
|
||||
new byte[4] {1, 1, 130, 2},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 1, 1},
|
||||
new byte[4] {1, 1, 130, 2},
|
||||
new byte[4] {2, 2, 0, 0},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 129},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {130, 1, 2, 1},
|
||||
new byte[4] {2, 1, 2, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 2},
|
||||
new byte[4] {1, 129, 2, 2},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {1, 1, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 130},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 2, 2},
|
||||
new byte[4] {0, 0, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 0},
|
||||
new byte[4] {1, 2, 130, 1},
|
||||
new byte[4] {0, 2, 2, 0},
|
||||
new byte[4] {1, 2, 2, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 1},
|
||||
new byte[4] {2, 2, 130, 2},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {0, 1, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {2, 1, 2, 1},
|
||||
new byte[4] {130, 1, 2, 1},
|
||||
new byte[4] {2, 1, 2, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 129},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {0, 1, 0, 1},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 130},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 2, 2, 2},
|
||||
new byte[4] {0, 1, 1, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 2},
|
||||
new byte[4] {1, 129, 1, 2},
|
||||
new byte[4] {0, 0, 0, 2},
|
||||
new byte[4] {1, 1, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {2, 129, 1, 2},
|
||||
new byte[4] {2, 1, 1, 2},
|
||||
new byte[4] {2, 1, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 2},
|
||||
new byte[4] {0, 129, 1, 1},
|
||||
new byte[4] {0, 1, 1, 1},
|
||||
new byte[4] {0, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 2},
|
||||
new byte[4] {1, 1, 1, 2},
|
||||
new byte[4] {129, 1, 1, 2},
|
||||
new byte[4] {0, 0, 0, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {0, 129, 1, 0},
|
||||
new byte[4] {0, 1, 1, 0},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {2, 1, 129, 2},
|
||||
new byte[4] {2, 1, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 0},
|
||||
new byte[4] {0, 129, 1, 0},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 2},
|
||||
new byte[4] {0, 0, 1, 1},
|
||||
new byte[4] {0, 0, 129, 1},
|
||||
new byte[4] {0, 0, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 2, 2},
|
||||
new byte[4] {1, 1, 2, 2},
|
||||
new byte[4] {129, 1, 2, 2},
|
||||
new byte[4] {0, 0, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {0, 0, 0, 0},
|
||||
new byte[4] {2, 129, 1, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 0, 0, 130},
|
||||
new byte[4] {0, 0, 0, 1},
|
||||
new byte[4] {0, 0, 0, 2},
|
||||
new byte[4] {0, 0, 0, 129}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 2, 2, 2},
|
||||
new byte[4] {1, 2, 2, 2},
|
||||
new byte[4] {0, 2, 2, 2},
|
||||
new byte[4] {129, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 0, 129},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {2, 2, 2, 2},
|
||||
new byte[4] {2, 2, 2, 130}
|
||||
},
|
||||
new byte[4][]
|
||||
{
|
||||
new byte[4] {128, 1, 1, 129},
|
||||
new byte[4] {2, 0, 1, 1},
|
||||
new byte[4] {130, 2, 0, 1},
|
||||
new byte[4] {2, 2, 2, 0}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
internal static int[] AWeight2 { get; } = new int[4] { 0, 21, 43, 64 };
|
||||
|
||||
internal static int[] AWeight3 { get; } = new int[8] { 0, 9, 18, 27, 37, 46, 55, 64 };
|
||||
|
||||
internal static int[] AWeight4 { get; } = new int[16] { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 };
|
||||
|
||||
internal const byte bcdec_bc7_sModeHasPBits = 0b11001011;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,45 @@
|
||||
namespace AssetRipper.TextureDecoder.Bc;
|
||||
|
||||
internal struct BitStream
|
||||
{
|
||||
public ulong low;
|
||||
public ulong high;
|
||||
|
||||
public int ReadBits(int numBits)
|
||||
{
|
||||
uint mask = (uint)((1 << numBits) - 1);
|
||||
// Read the low N bits
|
||||
uint bits = (uint)(this.low & mask);
|
||||
|
||||
this.low >>= numBits;
|
||||
// Put the low N bits of "high" into the high 64-N bits of "low".
|
||||
this.low |= (this.high & mask) << ((sizeof(ulong) * 8) - numBits);
|
||||
this.high >>= numBits;
|
||||
|
||||
return (int)bits;
|
||||
}
|
||||
|
||||
public int ReadBit()
|
||||
{
|
||||
return this.ReadBits(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reversed bits pulling, used in BC6H decoding
|
||||
/// </summary>
|
||||
/// <param name="numBits"></param>
|
||||
/// <returns></returns>
|
||||
public int ReadBitsReversed(int numBits)
|
||||
{
|
||||
int bits = this.ReadBits(numBits);
|
||||
// Reverse the bits.
|
||||
int result = 0;
|
||||
while (numBits-- != 0)
|
||||
{
|
||||
result <<= 1;
|
||||
result |= bits & 1;
|
||||
bits >>= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* bcdec.h - v0.94
|
||||
provides functions to decompress blocks of BC compressed images
|
||||
written by Sergii "iOrange" Kudlai in 2022
|
||||
This library does not allocate memory and is trying to use as less stack as possible
|
||||
The library was never optimized specifically for speed but for the overall size
|
||||
it has zero external dependencies and is not using any runtime functions
|
||||
Supported BC formats:
|
||||
BC1 (also known as DXT1) + it's "binary alpha" variant BC1A (DXT1A)
|
||||
BC2 (also known as DXT3)
|
||||
BC3 (also known as DXT5)
|
||||
BC4 (also known as ATI1N)
|
||||
BC5 (also known as ATI2N)
|
||||
BC6H (HDR format)
|
||||
BC7
|
||||
BC1/BC2/BC3/BC7 are expected to decompress into 4*4 RGBA blocks 8bit per component (32bit pixel)
|
||||
BC4/BC5 are expected to decompress into 4*4 R/RG blocks 8bit per component (8bit and 16bit pixel)
|
||||
BC6H is expected to decompress into 4*4 RGB blocks of either 32bit float or 16bit "half" per
|
||||
component (96bit or 48bit pixel)
|
||||
For more info, issues and suggestions please visit https://github.com/iOrange/bcdec
|
||||
CREDITS:
|
||||
Aras Pranckevicius (@aras-p) - BC1/BC3 decoders optimizations (up to 3x the speed)
|
||||
- BC6H/BC7 bits pulling routines optimizations
|
||||
- Split BC6H decompression function into 'half' and
|
||||
'float' variants
|
||||
LICENSE: See end of file for license information.
|
||||
*/
|
||||
|
||||
|
||||
/* Used information sources:
|
||||
https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression
|
||||
https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc6h-format
|
||||
https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc7-format
|
||||
https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc7-format-mode-reference
|
||||
! WARNING ! Khronos's BPTC partitions tables contain mistakes, do not use them!
|
||||
https://www.khronos.org/registry/DataFormat/specs/1.1/dataformat.1.1.html#BPTC
|
||||
! Use tables from here instead !
|
||||
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_compression_bptc.txt
|
||||
Leaving it here as it's a nice read
|
||||
https://fgiesen.wordpress.com/2021/10/04/gpu-bcn-decoding/
|
||||
Fast half to float function from here
|
||||
https://gist.github.com/rygorous/2144712
|
||||
*/
|
||||
@@ -0,0 +1,297 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Dxt
|
||||
{
|
||||
public static class DxtDecoder
|
||||
{
|
||||
/// <summary>
|
||||
/// Decompress a DXT1 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer of size 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT1(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * sizeof(uint)];
|
||||
return DecompressDXT1(input, width, height, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a DXT1 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT1(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
ThrowHelper.ThrowIfNotEnoughSpace(output, width, height);
|
||||
|
||||
int offset = 0;
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint[] buffer = new uint[16];
|
||||
int[] colors = new int[4];
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, offset += 8)
|
||||
{
|
||||
int q0 = input[offset + 0] | input[offset + 1] << 8;
|
||||
int q1 = input[offset + 2] | input[offset + 3] << 8;
|
||||
Rgb565(q0, out int r0, out int g0, out int b0);
|
||||
Rgb565(q1, out int r1, out int g1, out int b1);
|
||||
colors[0] = Color(r0, g0, b0, 255);
|
||||
colors[1] = Color(r1, g1, b1, 255);
|
||||
if (q0 > q1)
|
||||
{
|
||||
colors[2] = Color((r0 * 2 + r1) / 3, (g0 * 2 + g1) / 3, (b0 * 2 + b1) / 3, 255);
|
||||
colors[3] = Color((r0 + r1 * 2) / 3, (g0 + g1 * 2) / 3, (b0 + b1 * 2) / 3, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
colors[2] = Color((r0 + r1) / 2, (g0 + g1) / 2, (b0 + b1) / 2, 255);
|
||||
}
|
||||
|
||||
uint d = ToUInt32(input, offset + 4);
|
||||
for (int i = 0; i < 16; i++, d >>= 2)
|
||||
{
|
||||
buffer[i] = unchecked((uint)colors[d & 3]);
|
||||
}
|
||||
|
||||
int clen = (s < bcw - 1 ? 4 : clen_last) * 4;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
ReadOnlySpan<byte> bufferSpan = MemoryMarshal.Cast<uint, byte>(new ReadOnlySpan<uint>(buffer));
|
||||
BlockCopy(bufferSpan, i * 4 * 4, output, (y * width + s * 4) * 4, clen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a DXT3 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer of size 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT3(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * sizeof(uint)];
|
||||
return DecompressDXT3(input, width, height, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a DXT3 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT3(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
ThrowHelper.ThrowIfNotEnoughSpace(output, width, height);
|
||||
|
||||
int offset = 0;
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint[] buffer = new uint[16];
|
||||
int[] colors = new int[4];
|
||||
int[] alphas = new int[16];
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, offset += 16)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int alpha = input[offset + i * 2] | input[offset + i * 2 + 1] << 8;
|
||||
alphas[i * 4 + 0] = (((alpha >> 0) & 0xF) * 0x11) << 24;
|
||||
alphas[i * 4 + 1] = (((alpha >> 4) & 0xF) * 0x11) << 24;
|
||||
alphas[i * 4 + 2] = (((alpha >> 8) & 0xF) * 0x11) << 24;
|
||||
alphas[i * 4 + 3] = (((alpha >> 12) & 0xF) * 0x11) << 24;
|
||||
}
|
||||
|
||||
int q0 = input[offset + 8] | input[offset + 9] << 8;
|
||||
int q1 = input[offset + 10] | input[offset + 11] << 8;
|
||||
Rgb565(q0, out int r0, out int g0, out int b0);
|
||||
Rgb565(q1, out int r1, out int g1, out int b1);
|
||||
colors[0] = Color(r0, g0, b0, 0);
|
||||
colors[1] = Color(r1, g1, b1, 0);
|
||||
if (q0 > q1)
|
||||
{
|
||||
colors[2] = Color((r0 * 2 + r1) / 3, (g0 * 2 + g1) / 3, (b0 * 2 + b1) / 3, 0);
|
||||
colors[3] = Color((r0 + r1 * 2) / 3, (g0 + g1 * 2) / 3, (b0 + b1 * 2) / 3, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
colors[2] = Color((r0 + r1) / 2, (g0 + g1) / 2, (b0 + b1) / 2, 0);
|
||||
}
|
||||
|
||||
uint d = ToUInt32(input, offset + 12);
|
||||
for (int i = 0; i < 16; i++, d >>= 2)
|
||||
{
|
||||
buffer[i] = unchecked((uint)(colors[d & 3] | alphas[i]));
|
||||
}
|
||||
|
||||
int clen = (s < bcw - 1 ? 4 : clen_last) * 4;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
ReadOnlySpan<byte> bufferSpan = MemoryMarshal.Cast<uint, byte>(new ReadOnlySpan<uint>(buffer));
|
||||
BlockCopy(bufferSpan, i * 4 * 4, output, (y * width + s * 4) * 4, clen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a DXT5 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer of size 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT5(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * sizeof(uint)];
|
||||
return DecompressDXT5(input, width, height, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a DXT5 image
|
||||
/// </summary>
|
||||
/// <param name="input">Input buffer containing the compressed image.</param>
|
||||
/// <param name="width">Pixel width of the image.</param>
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
public static int DecompressDXT5(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
ThrowHelper.ThrowIfNotEnoughSpace(output, width, height);
|
||||
|
||||
int offset = 0;
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint[] buffer = new uint[16];
|
||||
int[] colors = new int[4];
|
||||
int[] alphas = new int[8];
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, offset += 16)
|
||||
{
|
||||
alphas[0] = input[offset + 0];
|
||||
alphas[1] = input[offset + 1];
|
||||
if (alphas[0] > alphas[1])
|
||||
{
|
||||
alphas[2] = (alphas[0] * 6 + alphas[1]) / 7;
|
||||
alphas[3] = (alphas[0] * 5 + alphas[1] * 2) / 7;
|
||||
alphas[4] = (alphas[0] * 4 + alphas[1] * 3) / 7;
|
||||
alphas[5] = (alphas[0] * 3 + alphas[1] * 4) / 7;
|
||||
alphas[6] = (alphas[0] * 2 + alphas[1] * 5) / 7;
|
||||
alphas[7] = (alphas[0] + alphas[1] * 6) / 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
alphas[2] = (alphas[0] * 4 + alphas[1]) / 5;
|
||||
alphas[3] = (alphas[0] * 3 + alphas[1] * 2) / 5;
|
||||
alphas[4] = (alphas[0] * 2 + alphas[1] * 3) / 5;
|
||||
alphas[5] = (alphas[0] + alphas[1] * 4) / 5;
|
||||
alphas[7] = 255;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
alphas[i] <<= 24;
|
||||
}
|
||||
|
||||
int q0 = input[offset + 8] | input[offset + 9] << 8;
|
||||
int q1 = input[offset + 10] | input[offset + 11] << 8;
|
||||
Rgb565(q0, out int r0, out int g0, out int b0);
|
||||
Rgb565(q1, out int r1, out int g1, out int b1);
|
||||
colors[0] = Color(r0, g0, b0, 0);
|
||||
colors[1] = Color(r1, g1, b1, 0);
|
||||
if (q0 > q1)
|
||||
{
|
||||
colors[2] = Color((r0 * 2 + r1) / 3, (g0 * 2 + g1) / 3, (b0 * 2 + b1) / 3, 0);
|
||||
colors[3] = Color((r0 + r1 * 2) / 3, (g0 + g1 * 2) / 3, (b0 + b1 * 2) / 3, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
colors[2] = Color((r0 + r1) / 2, (g0 + g1) / 2, (b0 + b1) / 2, 0);
|
||||
}
|
||||
|
||||
ulong da = ToUInt64(input, offset) >> 16;
|
||||
uint dc = ToUInt32(input, offset + 12);
|
||||
for (int i = 0; i < 16; i++, da >>= 3, dc >>= 2)
|
||||
{
|
||||
buffer[i] = unchecked((uint)(alphas[da & 7] | colors[dc & 3]));
|
||||
}
|
||||
|
||||
int clen = (s < bcw - 1 ? 4 : clen_last) * 4;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
ReadOnlySpan<byte> bufferSpan = MemoryMarshal.Cast<uint, byte>(new ReadOnlySpan<uint>(buffer));
|
||||
BlockCopy(bufferSpan, i * 4 * 4, output, (y * width + s * 4) * 4, clen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void Rgb565(int c, out int r, out int g, out int b)
|
||||
{
|
||||
r = (c & 0xf800) >> 8;
|
||||
g = (c & 0x07e0) >> 3;
|
||||
b = (c & 0x001f) << 3;
|
||||
r |= r >> 5;
|
||||
g |= g >> 6;
|
||||
b |= b >> 5;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int Color(int r, int g, int b, int a)
|
||||
{
|
||||
return r << 16 | g << 8 | b | a << 24;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Based on <see cref="Buffer.BlockCopy(Array, int, Array, int, int)"/>
|
||||
/// </summary>
|
||||
/// <param name="source">The source buffer.</param>
|
||||
/// <param name="sourceOffset">The zero-based byte offset into source.</param>
|
||||
/// <param name="destination">The destination buffer.</param>
|
||||
/// <param name="destinationOffset">The zero-based byte offset into destination.</param>
|
||||
/// <param name="count">The number of bytes to copy.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void BlockCopy(ReadOnlySpan<byte> source, int sourceOffset, Span<byte> destination, int destinationOffset, int count)
|
||||
{
|
||||
source.Slice(sourceOffset, count).CopyTo(destination.Slice(destinationOffset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ToUInt32(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt32LittleEndian(input.Slice(offset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static ulong ToUInt64(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(input.Slice(offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,373 +1,423 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TextureDecoder.Etc
|
||||
namespace AssetRipper.TextureDecoder.Etc
|
||||
{
|
||||
public static class EtcDecoder
|
||||
{
|
||||
public static byte[] DecompressETC(byte[] input, int width, int height)
|
||||
public static int DecompressETC(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressETC(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressETC(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressETC(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 8;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressETC(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressETC(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressETC(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeEtc1Block(input, buf);
|
||||
DecodeEtc1Block(input.Slice(inputOffset, 8), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressETC2(byte[] input, int width, int height)
|
||||
public static int DecompressETC2(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressETC2(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressETC2(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressETC2(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 8;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressETC2(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressETC2(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressETC2(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeEtc2Block(input, buf);
|
||||
DecodeEtc2Block(input.Slice(inputOffset, 8), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressETC2A1(byte[] input, int width, int height)
|
||||
public static int DecompressETC2A1(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressETC2A1(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressETC2A1(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2A1(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressETC2A1(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 8;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressETC2A1(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressETC2A1(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2A1(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressETC2A1(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int width4 = width * 4;
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeEtc2a1Block(input, buf);
|
||||
DecodeEtc2a1Block(input.Slice(inputOffset, 8), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressETC2A8(byte[] input, int width, int height)
|
||||
public static int DecompressETC2A8(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressETC2A8(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressETC2A8(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2A8(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressETC2A8(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 16;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressETC2A8(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressETC2A8(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressETC2A8(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressETC2A8(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 16)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 16)
|
||||
{
|
||||
DecodeEtc2Block(input + 8, buf);
|
||||
DecodeEtc2a8Block(input, buf);
|
||||
DecodeEtc2Block(input.Slice(inputOffset + 8, 8), buf);
|
||||
DecodeEtc2a8Block(input.Slice(inputOffset + 0, 8), buf);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressEACRUnsigned(byte[] input, int width, int height)
|
||||
public static int DecompressEACRUnsigned(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressEACRUnsigned(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressEACRUnsigned(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRUnsigned(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressEACRUnsigned(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 8;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressEACRUnsigned(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressEACRUnsigned(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRUnsigned(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressEACRUnsigned(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
buf[i] = 0xFF000000;
|
||||
}
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeEacUnsignedBlock(input, buf, 2);
|
||||
DecodeEacUnsignedBlock(input.Slice(inputOffset, 8), buf, 2);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressEACRSigned(byte[] input, int width, int height)
|
||||
public static int DecompressEACRSigned(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressEACRSigned(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressEACRSigned(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRSigned(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressEACRSigned(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 8;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressEACRSigned(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressEACRSigned(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRSigned(byte* input, int width, int height, byte* output)
|
||||
|
||||
private unsafe static int DecompressEACRSigned(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
buf[i] = 0xFF000000;
|
||||
}
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 8)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 8)
|
||||
{
|
||||
DecodeEacSignedBlock(input, buf, 2);
|
||||
DecodeEacSignedBlock(input.Slice(inputOffset, 8), buf, 2);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressEACRGUnsigned(byte[] input, int width, int height)
|
||||
public static int DecompressEACRGUnsigned(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressEACRGUnsigned(input, width, height, output);
|
||||
return output;
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressEACRGUnsigned(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRGUnsigned(byte[] input, int width, int height, byte[] output)
|
||||
public unsafe static int DecompressEACRGUnsigned(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
|
||||
if (input.Length < bcw * bch * 16)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {bcw * bch * 16}", nameof(input));
|
||||
}
|
||||
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
buf[i] = 0xFF000000;
|
||||
}
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 16)
|
||||
{
|
||||
DecompressEACRGUnsigned(inputPtr, width, height, outputPtr);
|
||||
DecodeEacUnsignedBlock(input.Slice(inputOffset + 0, 8), buf, 2);
|
||||
DecodeEacUnsignedBlock(input.Slice(inputOffset + 8, 8), buf, 1);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
int outputOffset = t * 16 * width + s * 16;
|
||||
Span<uint> outputPtr = MemoryMarshal.Cast<byte, uint>(output.Slice(outputOffset));
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j + i * width] = buf[j + 4 * i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static int DecompressEACRGSigned(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return DecompressEACRGSigned(input, width, height, output);
|
||||
}
|
||||
|
||||
public unsafe static int DecompressEACRGSigned(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int requiredLength = ((width + 3) / 4) * ((height + 3) / 4) * 16;
|
||||
if (input.Length < requiredLength)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(input)} has length {input.Length} which is less than the required length {requiredLength}", nameof(input));
|
||||
}
|
||||
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
return DecompressEACRGSigned(input, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRGUnsigned(byte* input, int width, int height, byte* output)
|
||||
private unsafe static int DecompressEACRGSigned(ReadOnlySpan<byte> input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
Span<uint> buf = stackalloc uint[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
buf[i] = 0xFF000000;
|
||||
}
|
||||
int inputOffset = 0;
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 16)
|
||||
for (int s = 0; s < bcw; s++, inputOffset += 16)
|
||||
{
|
||||
DecodeEacUnsignedBlock(input + 0, buf, 2);
|
||||
DecodeEacUnsignedBlock(input + 8, buf, 1);
|
||||
DecodeEacSignedBlock(input.Slice(inputOffset + 0, 8), buf, 2);
|
||||
DecodeEacSignedBlock(input.Slice(inputOffset + 8, 8), buf, 1);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
for (int j = 0; j < clen; j++)
|
||||
{
|
||||
outputPtr[j] = buf[j + 4 * i];
|
||||
}
|
||||
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputOffset;
|
||||
}
|
||||
|
||||
public static byte[] DecompressEACRGSigned(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
DecompressEACRGSigned(input, width, height, output);
|
||||
return output;
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRGSigned(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
{
|
||||
fixed (byte* outputPtr = output)
|
||||
{
|
||||
DecompressEACRGSigned(inputPtr, width, height, outputPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void DecompressEACRGSigned(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
int bch = (height + 3) / 4;
|
||||
int clen_last = (width + 3) % 4 + 1;
|
||||
uint* buf = stackalloc uint[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
buf[i] = 0xFF000000;
|
||||
}
|
||||
for (int t = 0; t < bch; t++)
|
||||
{
|
||||
for (int s = 0; s < bcw; s++, input += 16)
|
||||
{
|
||||
DecodeEacSignedBlock(input + 0, buf, 2);
|
||||
DecodeEacSignedBlock(input + 8, buf, 1);
|
||||
int clen = s < bcw - 1 ? 4 : clen_last;
|
||||
uint* outputPtr = (uint*)(output + (t * 16 * width + s * 16));
|
||||
uint* bufPtr = buf;
|
||||
for (int i = 0, y = t * 4; i < 4 && y < height; i++, y++)
|
||||
{
|
||||
for (int j = 0; j < clen; j++) outputPtr[j] = bufPtr[j];
|
||||
outputPtr += width;
|
||||
bufPtr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEtc1Block(byte* input, uint* output)
|
||||
/// <summary>
|
||||
/// Parses an 8-byte Etc1 block from <paramref name="input"/>.
|
||||
/// </summary>
|
||||
private static void DecodeEtc1Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
byte i3 = input[3];
|
||||
int* code = stackalloc int[2];
|
||||
code[0] = (i3 >> 5) * 4;
|
||||
code[1] = (i3 >> 2 & 7) * 4;
|
||||
byte* c = stackalloc byte[6];
|
||||
ReadOnlySpan<int> code = stackalloc int[2]
|
||||
{
|
||||
(i3 >> 5) * 4,
|
||||
(i3 >> 2 & 7) * 4
|
||||
};
|
||||
Span<byte> c = stackalloc byte[6];
|
||||
int ti = (i3 & 1) * 16;
|
||||
if ((i3 & 2) != 0)
|
||||
{
|
||||
@@ -414,11 +464,11 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEtc2Block(byte* input, uint* output)
|
||||
private static void DecodeEtc2Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
int j = input[6] << 8 | input[7];
|
||||
int k = input[4] << 8 | input[5];
|
||||
byte* c = stackalloc byte[3 * 3];
|
||||
Span<byte> c = stackalloc byte[3 * 3];
|
||||
|
||||
if ((input[3] & 2) != 0)
|
||||
{
|
||||
@@ -438,7 +488,7 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
int ti = input[3] >> 1 & 6 | input[3] & 1;
|
||||
byte d = Etc2DistanceTable[ti];
|
||||
uint* color_set = stackalloc uint[]
|
||||
ReadOnlySpan<uint> color_set = stackalloc uint[]
|
||||
{
|
||||
ApplicateColorRaw(c, 0),
|
||||
ApplicateColor(c, 1, d),
|
||||
@@ -479,7 +529,7 @@ namespace TextureDecoder.Etc
|
||||
++di;
|
||||
}
|
||||
byte d = Etc2DistanceTable[di];
|
||||
uint* color_set = stackalloc uint[]
|
||||
ReadOnlySpan<uint> color_set = stackalloc uint[]
|
||||
{
|
||||
ApplicateColor(c, 0, d),
|
||||
ApplicateColor(c, 0, -d),
|
||||
@@ -519,9 +569,9 @@ namespace TextureDecoder.Etc
|
||||
{
|
||||
for (int x = 0; x < 4; x++, i++)
|
||||
{
|
||||
int ri = Clamp255((x * (c[1 * 3 + 0] - c[0 * 3 + 0]) + y * (c[2 * 3 + 0] - c[0 * 3 + 0]) + 4 * c[0 * 3 + 0] + 2) >> 2);
|
||||
int gi = Clamp255((x * (c[1 * 3 + 1] - c[0 * 3 + 1]) + y * (c[2 * 3 + 1] - c[0 * 3 + 1]) + 4 * c[0 * 3 + 1] + 2) >> 2);
|
||||
int bi = Clamp255((x * (c[1 * 3 + 2] - c[0 * 3 + 2]) + y * (c[2 * 3 + 2] - c[0 * 3 + 2]) + 4 * c[0 * 3 + 2] + 2) >> 2);
|
||||
byte ri = Clamp255((x * (c[1 * 3 + 0] - c[0 * 3 + 0]) + y * (c[2 * 3 + 0] - c[0 * 3 + 0]) + 4 * c[0 * 3 + 0] + 2) >> 2);
|
||||
byte gi = Clamp255((x * (c[1 * 3 + 1] - c[0 * 3 + 1]) + y * (c[2 * 3 + 1] - c[0 * 3 + 1]) + 4 * c[0 * 3 + 1] + 2) >> 2);
|
||||
byte bi = Clamp255((x * (c[1 * 3 + 2] - c[0 * 3 + 2]) + y * (c[2 * 3 + 2] - c[0 * 3 + 2]) + 4 * c[0 * 3 + 2] + 2) >> 2);
|
||||
output[i] = Color(ri, gi, bi, 255);
|
||||
}
|
||||
}
|
||||
@@ -529,7 +579,7 @@ namespace TextureDecoder.Etc
|
||||
else
|
||||
{
|
||||
// differential
|
||||
int* code = stackalloc int[2];
|
||||
Span<int> code = stackalloc int[2];
|
||||
code[0] = (input[3] >> 5) * 4;
|
||||
code[1] = (input[3] >> 2 & 7) * 4;
|
||||
int ti = (input[3] & 1) * 16;
|
||||
@@ -562,9 +612,11 @@ namespace TextureDecoder.Etc
|
||||
else
|
||||
{
|
||||
// individual
|
||||
int* code = stackalloc int[2];
|
||||
code[0] = (input[3] >> 5) * 4;
|
||||
code[1] = (input[3] >> 2 & 7) * 4;
|
||||
ReadOnlySpan<int> code = stackalloc int[2]
|
||||
{
|
||||
(input[3] >> 5) * 4,
|
||||
(input[3] >> 2 & 7) * 4
|
||||
};
|
||||
int ti = (input[3] & 1) * 16;
|
||||
unchecked
|
||||
{
|
||||
@@ -588,8 +640,8 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static void DecodeEtc2a1Block(byte* input, uint* output)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEtc2a1Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
if ((input[3] & 2) != 0)
|
||||
{
|
||||
@@ -602,11 +654,11 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEtc2PunchThrowBlock(byte* input, uint* output)
|
||||
private static void DecodeEtc2PunchThrowBlock(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
int j = input[6] << 8 | input[7];
|
||||
int k = input[4] << 8 | input[5];
|
||||
byte* c = stackalloc byte[3 * 3];
|
||||
Span<byte> c = stackalloc byte[3 * 3];
|
||||
int r = input[0] & 0xf8;
|
||||
int dr = (input[0] << 3 & 0x18) - (input[0] << 3 & 0x20);
|
||||
if (r + dr < 0 || r + dr > 255)
|
||||
@@ -623,7 +675,7 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
int ti = input[3] >> 1 & 6 | input[3] & 1;
|
||||
byte d = Etc2DistanceTable[ti];
|
||||
uint* color_set = stackalloc uint[]
|
||||
ReadOnlySpan<uint> color_set = stackalloc uint[4]
|
||||
{
|
||||
ApplicateColorRaw(c, 0),
|
||||
ApplicateColor(c, 1, d),
|
||||
@@ -665,7 +717,7 @@ namespace TextureDecoder.Etc
|
||||
++di;
|
||||
}
|
||||
byte d = Etc2DistanceTable[di];
|
||||
uint* color_set = stackalloc uint[]
|
||||
ReadOnlySpan<uint> color_set = stackalloc uint[4]
|
||||
{
|
||||
ApplicateColor(c, 0, d),
|
||||
ApplicateColor(c, 0, -d),
|
||||
@@ -706,9 +758,9 @@ namespace TextureDecoder.Etc
|
||||
{
|
||||
for (int x = 0; x < 4; x++, i++)
|
||||
{
|
||||
int ri = Clamp255((x * (c[1 * 3 + 0] - c[0 * 3 + 0]) + y * (c[2 * 3 + 0] - c[0 * 3 + 0]) + 4 * c[0 * 3 + 0] + 2) >> 2);
|
||||
int gi = Clamp255((x * (c[1 * 3 + 1] - c[0 * 3 + 1]) + y * (c[2 * 3 + 1] - c[0 * 3 + 1]) + 4 * c[0 * 3 + 1] + 2) >> 2);
|
||||
int bi = Clamp255((x * (c[1 * 3 + 2] - c[0 * 3 + 2]) + y * (c[2 * 3 + 2] - c[0 * 3 + 2]) + 4 * c[0 * 3 + 2] + 2) >> 2);
|
||||
byte ri = Clamp255((x * (c[1 * 3 + 0] - c[0 * 3 + 0]) + y * (c[2 * 3 + 0] - c[0 * 3 + 0]) + 4 * c[0 * 3 + 0] + 2) >> 2);
|
||||
byte gi = Clamp255((x * (c[1 * 3 + 1] - c[0 * 3 + 1]) + y * (c[2 * 3 + 1] - c[0 * 3 + 1]) + 4 * c[0 * 3 + 1] + 2) >> 2);
|
||||
byte bi = Clamp255((x * (c[1 * 3 + 2] - c[0 * 3 + 2]) + y * (c[2 * 3 + 2] - c[0 * 3 + 2]) + 4 * c[0 * 3 + 2] + 2) >> 2);
|
||||
output[i] = Color(ri, gi, bi, 255);
|
||||
}
|
||||
}
|
||||
@@ -716,9 +768,11 @@ namespace TextureDecoder.Etc
|
||||
else
|
||||
{
|
||||
// differential (Etc1Block + mask + specific mod table)
|
||||
int* code = stackalloc int[2];
|
||||
code[0] = (input[3] >> 5) * 4;
|
||||
code[1] = (input[3] >> 2 & 7) * 4;
|
||||
ReadOnlySpan<int> code = stackalloc int[2]
|
||||
{
|
||||
(input[3] >> 5) * 4,
|
||||
(input[3] >> 2 & 7) * 4
|
||||
};
|
||||
int ti = (input[3] & 1) * 16;
|
||||
unchecked
|
||||
{
|
||||
@@ -748,7 +802,7 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEtc2a8Block(byte* input, uint* output)
|
||||
private static void DecodeEtc2a8Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
int @base = input[0];
|
||||
int data1 = input[1];
|
||||
@@ -757,53 +811,53 @@ namespace TextureDecoder.Etc
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
DecodeEac11Block((byte*)output + 3, @base);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(3), @base);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int table = data1 & 0xF;
|
||||
ulong l = Get6SwapedBytes(input);
|
||||
DecodeEac11Block((byte*)output + 3, @base, table, mul, l);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(3), @base, table, mul, l);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEacUnsignedBlock(byte* input, uint* output, int channel)
|
||||
private static void DecodeEacUnsignedBlock(ReadOnlySpan<byte> input, Span<uint> output, int channel)
|
||||
{
|
||||
int @base = input[0];
|
||||
int data1 = input[1];
|
||||
int mul = data1 >> 4;
|
||||
if (mul == 0)
|
||||
{
|
||||
DecodeEac11Block((byte*)output + channel, @base);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(channel), @base);
|
||||
}
|
||||
else
|
||||
{
|
||||
int table = data1 & 0xF;
|
||||
ulong l = Get6SwapedBytes(input);
|
||||
DecodeEac11Block((byte*)output + channel, @base, table, mul, l);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(channel), @base, table, mul, l);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void DecodeEacSignedBlock(byte* input, uint* output, int channel)
|
||||
private static void DecodeEacSignedBlock(ReadOnlySpan<byte> input, Span<uint> output, int channel)
|
||||
{
|
||||
int @base = 127 + unchecked((sbyte)input[0]);
|
||||
int data1 = input[1];
|
||||
int mul = data1 >> 4;
|
||||
if (mul == 0)
|
||||
{
|
||||
DecodeEac11Block((byte*)output + channel, @base);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(channel), @base);
|
||||
}
|
||||
else
|
||||
{
|
||||
int table = data1 & 0xF;
|
||||
ulong l = Get6SwapedBytes(input);
|
||||
DecodeEac11Block((byte*)output + channel, @base, table, mul, l);
|
||||
DecodeEac11Block(MemoryMarshal.Cast<uint, byte>(output).Slice(channel), @base, table, mul, l);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static void DecodeEac11Block(byte* output, int @base)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEac11Block(Span<byte> output, int @base)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
@@ -811,51 +865,49 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static void DecodeEac11Block(byte* output, int @base, int ti, int mul, ulong l)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEac11Block(Span<byte> output, int @base, int ti, int mul, ulong l)
|
||||
{
|
||||
fixed (sbyte* table = &Etc2AlphaModTable[ti * 8])
|
||||
ReadOnlySpan<sbyte> table = Etc2AlphaModTable.AsSpan(ti * 8, 8);
|
||||
for (int i = 0; i < 16; i++, l >>= 3)
|
||||
{
|
||||
for (int i = 0; i < 16; i++, l >>= 3)
|
||||
{
|
||||
int val = @base + mul * table[l & 7];
|
||||
output[WriteOrderTableRev[i] * 4] = (byte)(Clamp255(val));
|
||||
}
|
||||
int val = @base + mul * table[unchecked((int)(l & 0b111))];
|
||||
output[WriteOrderTableRev[i] * 4] = Clamp255(val);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Color(int r, int g, int b, int a)
|
||||
{
|
||||
return unchecked((uint)(r << 16 | g << 8 | b | a << 24));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int Clamp255(int n)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte Clamp255(int n)
|
||||
{
|
||||
return n < 0 ? 0 : n > 255 ? 255 : n;
|
||||
return n < 0 ? (byte)0 : n > 255 ? (byte)255 : unchecked((byte)n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static uint ApplicateColor(byte* c, int o, int m)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColor(ReadOnlySpan<byte> c, int o, int m)
|
||||
{
|
||||
return Color(Clamp255(c[o * 3 + 0] + m), Clamp255(c[o * 3 + 1] + m), Clamp255(c[o * 3 + 2] + m), 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static uint ApplicateColor(int* c, int o, int m)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColor(ReadOnlySpan<int> c, int o, int m)
|
||||
{
|
||||
return Color(Clamp255(c[o * 3 + 0] + m), Clamp255(c[o * 3 + 1] + m), Clamp255(c[o * 3 + 2] + m), 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static uint ApplicateColorRaw(byte* c, int o)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColorRaw(ReadOnlySpan<byte> c, int o)
|
||||
{
|
||||
return Color(c[o * 3 + 0], c[o * 3 + 1], c[o * 3 + 2], 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe static ulong Get6SwapedBytes(byte* data)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
|
||||
{
|
||||
return data[7] | (uint)data[6] << 8 | (uint)data[5] << 16 | (uint)data[4] << 24 | (ulong)data[3] << 32 | (ulong)data[2] << 40;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
global using System;
|
||||
global using System.Diagnostics.CodeAnalysis;
|
||||
global using System.Numerics;
|
||||
global using System.Runtime.CompilerServices;
|
||||
@@ -0,0 +1,25 @@
|
||||
//#define DISABLE_TWINDDLING_ROUTINE
|
||||
#define ASSUME_IMAGE_TILING
|
||||
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
{
|
||||
public static partial class PvrtcDecoder
|
||||
{
|
||||
/// <summary>
|
||||
/// 8 bytes
|
||||
/// </summary>
|
||||
private struct AmtcBlock
|
||||
{
|
||||
public AmtcBlock(uint v0, uint v1)
|
||||
{
|
||||
PackedData0 = v0;
|
||||
PackedData1 = v1;
|
||||
}
|
||||
|
||||
// Uses 64 bits pre block
|
||||
public readonly uint PackedData0;
|
||||
public readonly uint PackedData1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//#define DISABLE_TWINDDLING_ROUTINE
|
||||
#define ASSUME_IMAGE_TILING
|
||||
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
{
|
||||
public static partial class PvrtcDecoder
|
||||
{
|
||||
/// <summary>
|
||||
/// Low precision colours extracted from the blocks
|
||||
/// </summary>
|
||||
private unsafe struct Colours5554
|
||||
{
|
||||
public fixed int Reps[2 * 4];
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
-62
@@ -1,34 +1,26 @@
|
||||
//#define DISABLE_TWINDDLING_ROUTINE
|
||||
#define ASSUME_IMAGE_TILING
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TextureDecoder.Pvrtc
|
||||
namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
{
|
||||
public static class PvrtcDecoder
|
||||
public static partial class PvrtcDecoder
|
||||
{
|
||||
private struct AmtcBlock
|
||||
{
|
||||
public AmtcBlock(uint v0, uint v1)
|
||||
{
|
||||
PackedData0 = v0;
|
||||
PackedData1 = v1;
|
||||
}
|
||||
|
||||
// Uses 64 bits pre block
|
||||
public readonly uint PackedData0;
|
||||
public readonly uint PackedData1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Low precision colours extracted from the blocks
|
||||
/// Decompresses PVRTC to RGBA 8888
|
||||
/// </summary>
|
||||
private unsafe struct Colours5554
|
||||
/// <param name="input">The PVRTC texture data to decompress</param>
|
||||
/// <param name="xDim">X dimension (width) of the texture</param>
|
||||
/// <param name="yDim">Y dimension (height) of the texture</param>
|
||||
/// <param name="output">The decompressed texture data</param>
|
||||
/// <param name="do2bitMode">Signifies whether the data is PVRTC2 or PVRTC4</param>
|
||||
/// <returns>The number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressPVRTC(ReadOnlySpan<byte> input, int xDim, int yDim, bool do2bitMode, out byte[] output)
|
||||
{
|
||||
public fixed int Reps[2 * 4];
|
||||
output = new byte[xDim * yDim * sizeof(uint)];
|
||||
return DecompressPVRTC(input, xDim, yDim, do2bitMode, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,16 +31,9 @@ namespace TextureDecoder.Pvrtc
|
||||
/// <param name="yDim">Y dimension (height) of the texture</param>
|
||||
/// <param name="output">The decompressed texture data</param>
|
||||
/// <param name="do2bitMode">Signifies whether the data is PVRTC2 or PVRTC4</param>
|
||||
/// <returns></returns>
|
||||
public unsafe static void DecompressPVRTC(byte[] input, int xDim, int yDim, byte[] output, bool do2bitMode)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
{
|
||||
PVRDecompress(inputPtr, do2bitMode, xDim, yDim, output);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe static void PVRDecompress(byte* compressedData, bool do2bitMode, int xDim, int yDim, byte[] output)
|
||||
/// <returns>The number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressPVRTC(ReadOnlySpan<byte> input, int xDim, int yDim, bool do2bitMode, Span<byte> output)
|
||||
{
|
||||
int xBlockSize = do2bitMode ? BlockX2bpp : BlockX4bpp;
|
||||
// for MBX don't allow the sizes to get too small
|
||||
@@ -60,13 +45,17 @@ namespace TextureDecoder.Pvrtc
|
||||
uint pblocki10 = uint.MaxValue;
|
||||
uint pblocki11 = uint.MaxValue;
|
||||
|
||||
Colours5554* m_colors = stackalloc Colours5554[2 * 2];
|
||||
uint maxBlockIndexRead = uint.MinValue;
|
||||
|
||||
Span<Colours5554> m_colors = stackalloc Colours5554[2 * 2];
|
||||
// interpolated A colors for the pixel
|
||||
int* aSig = stackalloc int[4];
|
||||
Span<int> aSig = stackalloc int[4];
|
||||
// interpolated B colors for the pixel
|
||||
int* bSig = stackalloc int[4];
|
||||
int* modulationVals = stackalloc int[8 * 16];
|
||||
int* modulationModes = stackalloc int[8 * 16];
|
||||
Span<int> bSig = stackalloc int[4];
|
||||
Span<int> modulationVals = stackalloc int[8 * 16];
|
||||
Span<int> modulationModes = stackalloc int[8 * 16];
|
||||
|
||||
ReadOnlySpan<AmtcBlock> blocks = MemoryMarshal.Cast<byte, AmtcBlock>(input);
|
||||
|
||||
// step through the pixels of the image decompressing each one in turn.
|
||||
// Note that this is a hideously inefficient way to do this!
|
||||
@@ -95,28 +84,30 @@ namespace TextureDecoder.Pvrtc
|
||||
bool changed = blocki00 != pblocki00 || blocki01 != pblocki01 || blocki10 != pblocki10 || blocki11 != pblocki11;
|
||||
if (changed)
|
||||
{
|
||||
AmtcBlock* block00 = &((AmtcBlock*)compressedData)[blocki00];
|
||||
Unpack5554Colour(block00, m_colors[0].Reps);
|
||||
AmtcBlock block00 = blocks[(int)blocki00];
|
||||
Unpack5554Colour(block00, m_colors.GetIntSpanForColor(0));
|
||||
UnpackModulations(block00, do2bitMode, modulationVals, modulationModes, 0, 0);
|
||||
AmtcBlock* block01 = &((AmtcBlock*)compressedData)[blocki01];
|
||||
Unpack5554Colour(block01, m_colors[1].Reps);
|
||||
AmtcBlock block01 = blocks[(int)blocki01];
|
||||
Unpack5554Colour(block01, m_colors.GetIntSpanForColor(1));
|
||||
UnpackModulations(block01, do2bitMode, modulationVals, modulationModes, xBlockSize, 0);
|
||||
AmtcBlock* block10 = &((AmtcBlock*)compressedData)[blocki10];
|
||||
Unpack5554Colour(block10, m_colors[2].Reps);
|
||||
AmtcBlock block10 = blocks[(int)blocki10];
|
||||
Unpack5554Colour(block10, m_colors.GetIntSpanForColor(2));
|
||||
UnpackModulations(block10, do2bitMode, modulationVals, modulationModes, 0, BlockYSize);
|
||||
AmtcBlock* block11 = &((AmtcBlock*)compressedData)[blocki11];
|
||||
Unpack5554Colour(block11, m_colors[3].Reps);
|
||||
AmtcBlock block11 = blocks[(int)blocki11];
|
||||
Unpack5554Colour(block11, m_colors.GetIntSpanForColor(3));
|
||||
UnpackModulations(block11, do2bitMode, modulationVals, modulationModes, xBlockSize, BlockYSize);
|
||||
|
||||
pblocki00 = blocki00;
|
||||
pblocki01 = blocki01;
|
||||
pblocki10 = blocki10;
|
||||
pblocki11 = blocki11;
|
||||
|
||||
maxBlockIndexRead = Math.Max(maxBlockIndexRead, Math.Max(Math.Max(blocki00, blocki01), Math.Max(blocki10, blocki11)));
|
||||
}
|
||||
|
||||
// decompress the pixel. First compute the interpolated A and B signals
|
||||
InterpolateColours(m_colors[0].Reps, m_colors[1].Reps, m_colors[2].Reps, m_colors[3].Reps, 0, do2bitMode, x, y, aSig);
|
||||
InterpolateColours(m_colors[0].Reps, m_colors[1].Reps, m_colors[2].Reps, m_colors[3].Reps, 1, do2bitMode, x, y, bSig);
|
||||
InterpolateColours(m_colors.GetIntSpanForColor(0), m_colors.GetIntSpanForColor(1), m_colors.GetIntSpanForColor(2), m_colors.GetIntSpanForColor(3), 0, do2bitMode, x, y, aSig);
|
||||
InterpolateColours(m_colors.GetIntSpanForColor(0), m_colors.GetIntSpanForColor(1), m_colors.GetIntSpanForColor(2), m_colors.GetIntSpanForColor(3), 1, do2bitMode, x, y, bSig);
|
||||
GetModulationValue(x, y, do2bitMode, modulationVals, modulationModes, out int mod, out bool doPT);
|
||||
|
||||
// compute the modulated color. Swap red and blue channel
|
||||
@@ -127,6 +118,8 @@ namespace TextureDecoder.Pvrtc
|
||||
output[position + 3] = doPT ? (byte)0 : (byte)((aSig[3] * 8 + mod * (bSig[3] - aSig[3])) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
return ((int)maxBlockIndexRead + 1) * Unsafe.SizeOf<AmtcBlock>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,15 +203,14 @@ namespace TextureDecoder.Pvrtc
|
||||
/// <summary>
|
||||
/// Get the modulation value as a numerator of a fraction of 8ths
|
||||
/// </summary>
|
||||
private unsafe static void GetModulationValue(int x, int y, bool do2bitMode, int* modulationVals, int* modulationModes, out int mod, out bool doPT)
|
||||
private static void GetModulationValue(int x, int y, bool do2bitMode, ReadOnlySpan<int> modulationVals, ReadOnlySpan<int> modulationModes, out int mod, out bool doPT)
|
||||
{
|
||||
// Map X and Y into the local 2x2 block
|
||||
y = (y & 0x3) | ((~y & 0x2) << 1);
|
||||
|
||||
if (do2bitMode)
|
||||
x = (x & 0x7) | ((~x & 0x4) << 1);
|
||||
else
|
||||
x = (x & 0x3) | ((~x & 0x2) << 1);
|
||||
x = do2bitMode
|
||||
? (x & 0x7) | ((~x & 0x4) << 1)
|
||||
: (x & 0x3) | ((~x & 0x2) << 1);
|
||||
|
||||
// assume no PT for now
|
||||
doPT = false;
|
||||
@@ -267,7 +259,7 @@ namespace TextureDecoder.Pvrtc
|
||||
/// This performs a HW bit accurate interpolation of either the A or B colours for a particular pixel
|
||||
/// <para>NOTE: It is assumed that the source colours are in ARGB 5554 format - This means that some "preparation" of the values will be necessary</para>
|
||||
/// </summary>
|
||||
private unsafe static void InterpolateColours(int* colorP, int* colorQ, int* colorR, int* colorS, int ci, bool do2bitMode, int x, int y, int* result)
|
||||
private static void InterpolateColours(ReadOnlySpan<int> colorP, ReadOnlySpan<int> colorQ, ReadOnlySpan<int> colorR, ReadOnlySpan<int> colorS, int ci, bool do2bitMode, int x, int y, Span<int> result)
|
||||
{
|
||||
// put the x and y values into the right range and get the u and v scale amounts
|
||||
int v = ((y & 0x3) | ((~y & 0x2) << 1)) - BlockYSize / 2;
|
||||
@@ -333,10 +325,10 @@ namespace TextureDecoder.Pvrtc
|
||||
/// <summary>
|
||||
/// Given the block and the texture type and it's relative position in the 2x2 group of blocks, extract the bit patterns for the fully defined pixels.
|
||||
/// </summary>
|
||||
private unsafe static void UnpackModulations(AmtcBlock* block, bool do2bitMode, int* modulationVals, int* modulationModes, int startX, int startY)
|
||||
private static void UnpackModulations(AmtcBlock block, bool do2bitMode, Span<int> modulationVals, Span<int> modulationModes, int startX, int startY)
|
||||
{
|
||||
int blockModMode = (int)(block->PackedData1 & 1);
|
||||
uint modulationBits = block->PackedData0;
|
||||
int blockModMode = (int)(block.PackedData1 & 1);
|
||||
uint modulationBits = block.PackedData0;
|
||||
|
||||
// if it's in an interpolated mode
|
||||
if (do2bitMode && (blockModMode != 0))
|
||||
@@ -404,14 +396,14 @@ namespace TextureDecoder.Pvrtc
|
||||
/// <summary>
|
||||
/// Given a block, extract the colour information and convert to 5554 formats
|
||||
/// </summary>
|
||||
private unsafe static void Unpack5554Colour(AmtcBlock* block, int* abColors)
|
||||
private static void Unpack5554Colour(AmtcBlock block, Span<int> abColors)
|
||||
{
|
||||
uint* rawBits = stackalloc uint[2];
|
||||
Span<uint> rawBits = stackalloc uint[2];
|
||||
// extract A and B
|
||||
// 15 bits (shifted up by one)
|
||||
rawBits[0] = block->PackedData1 & (0xFFFE);
|
||||
rawBits[0] = block.PackedData1 & (0xFFFE);
|
||||
// 16 bits
|
||||
rawBits[1] = block->PackedData1 >> 16;
|
||||
rawBits[1] = block.PackedData1 >> 16;
|
||||
|
||||
// step through both colours
|
||||
for (int i = 0; i < 2; i++)
|
||||
@@ -463,12 +455,18 @@ namespace TextureDecoder.Pvrtc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static Span<int> GetIntSpanForColor(this Span<Colours5554> colorSpan, int index)
|
||||
{
|
||||
return MemoryMarshal.Cast<Colours5554, int>(colorSpan.Slice(index, 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check that a number is an integer power of two, i.e. 1, 2, 4, 8, ... etc. Returns false for zero
|
||||
/// </summary>
|
||||
/// <param name="input">A number</param>
|
||||
/// <returns>True if the number is an integer power of two, else false</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static bool IsPowerOf2(uint input)
|
||||
{
|
||||
if (input == 0)
|
||||
@@ -483,7 +481,7 @@ namespace TextureDecoder.Pvrtc
|
||||
/// <summary>
|
||||
/// Define an expression to either wrap or clamp large or small vals to the legal coordinate range
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int LimitCoord(int value, int size)
|
||||
{
|
||||
#if ASSUME_IMAGE_TILING
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb;
|
||||
|
||||
public static class Color
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void SetConvertedChannels<TThis, TThisChannel, TSourceChannel>(this ref TThis color, TSourceChannel r, TSourceChannel g, TSourceChannel b)
|
||||
where TThisChannel : unmanaged
|
||||
where TSourceChannel : unmanaged
|
||||
where TThis : unmanaged, IColor<TThisChannel>
|
||||
{
|
||||
color.SetChannels(
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(r),
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(g),
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(b),
|
||||
NumericConversion.GetMaximumValue<TThisChannel>());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void SetConvertedChannels<TThis, TThisChannel, TSourceChannel>(this ref TThis color, TSourceChannel r, TSourceChannel g, TSourceChannel b, TSourceChannel a)
|
||||
where TThisChannel : unmanaged
|
||||
where TSourceChannel : unmanaged
|
||||
where TThis : unmanaged, IColor<TThisChannel>
|
||||
{
|
||||
color.SetChannels(
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(r),
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(g),
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(b),
|
||||
NumericConversion.Convert<TSourceChannel, TThisChannel>(a));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int GetChannelCount<T>() where T : IColorBase
|
||||
{
|
||||
return (T.HasRedChannel ? 1 : 0) + (T.HasGreenChannel ? 1 : 0) + (T.HasBlueChannel ? 1 : 0) + (T.HasAlphaChannel ? 1 : 0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static TTarget Convert<TThis, TThisChannel, TTarget, TTargetChannel>(this TThis color)
|
||||
where TThisChannel : unmanaged
|
||||
where TTargetChannel : unmanaged
|
||||
where TThis : unmanaged, IColor<TThisChannel>
|
||||
where TTarget : unmanaged, IColor<TTargetChannel>
|
||||
{
|
||||
if (typeof(TThis) == typeof(TTarget))
|
||||
{
|
||||
return Unsafe.As<TThis, TTarget>(ref color);
|
||||
}
|
||||
else
|
||||
{
|
||||
TTarget destination = default;
|
||||
color.GetChannels(out TThisChannel r, out TThisChannel g, out TThisChannel b, out TThisChannel a);
|
||||
destination.SetConvertedChannels<TTarget, TTargetChannel, TThisChannel>(r, g, b, a);
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb
|
||||
{
|
||||
internal static class DefaultColorMethods
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void GetChannels<T, TArg>(T color, out TArg r, out TArg g, out TArg b, out TArg a)
|
||||
where TArg : unmanaged
|
||||
where T : unmanaged, IColor<TArg>
|
||||
{
|
||||
r = color.R;
|
||||
g = color.G;
|
||||
b = color.B;
|
||||
a = color.A;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void SetChannels<T, TArg>(ref T color, TArg r, TArg g, TArg b, TArg a)
|
||||
where TArg : unmanaged
|
||||
where T : unmanaged, IColor<TArg>
|
||||
{
|
||||
color.R = r;
|
||||
color.G = g;
|
||||
color.B = b;
|
||||
color.A = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
public partial struct ColorA<T> : IColor<T> where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
|
||||
{
|
||||
public readonly T R
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly T G
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly T B
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public T A { get; set; }
|
||||
|
||||
public readonly void GetChannels(out T r, out T g, out T b, out T a)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
a = A;
|
||||
}
|
||||
|
||||
public void SetChannels(T r, T g, T b, T a)
|
||||
{
|
||||
A = a;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => false;
|
||||
static bool IColorBase.HasGreenChannel => false;
|
||||
static bool IColorBase.HasBlueChannel => false;
|
||||
static bool IColorBase.HasAlphaChannel => true;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(T);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ A: {A} }}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB16 : IColor<byte>
|
||||
{
|
||||
private UInt4Pair gb;
|
||||
private UInt4Pair ar;
|
||||
|
||||
public byte B
|
||||
{
|
||||
readonly get => gb.LowValue;
|
||||
set => gb.LowValue = value;
|
||||
}
|
||||
|
||||
public byte G
|
||||
{
|
||||
readonly get => gb.HighValue;
|
||||
set => gb.HighValue = value;
|
||||
}
|
||||
|
||||
public byte R
|
||||
{
|
||||
readonly get => ar.LowValue;
|
||||
set => ar.LowValue = value;
|
||||
}
|
||||
|
||||
public byte A
|
||||
{
|
||||
readonly get => ar.HighValue;
|
||||
set => ar.HighValue = value;
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out byte r, out byte g, out byte b, out byte a)
|
||||
{
|
||||
DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);
|
||||
}
|
||||
|
||||
public void SetChannels(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
DefaultColorMethods.SetChannels(ref this, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB16 : IColor<byte>
|
||||
{
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => true;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => false;
|
||||
static Type IColorBase.ChannelType => typeof(byte);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B}, A: {A} }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB32 : IColor<byte>
|
||||
{
|
||||
public byte A { get; set; }
|
||||
public byte R { get; set; }
|
||||
public byte G { get; set; }
|
||||
public byte B { get; set; }
|
||||
|
||||
public readonly void GetChannels(out byte r, out byte g, out byte b, out byte a)
|
||||
{
|
||||
DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);
|
||||
}
|
||||
|
||||
public void SetChannels(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
DefaultColorMethods.SetChannels(ref this, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB32 : IColor<byte>
|
||||
{
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => true;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(byte);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B}, A: {A} }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorBGRA32 : IColor<byte>
|
||||
{
|
||||
public byte B { get; set; }
|
||||
public byte G { get; set; }
|
||||
public byte R { get; set; }
|
||||
public byte A { get; set; }
|
||||
|
||||
public readonly void GetChannels(out byte r, out byte g, out byte b, out byte a)
|
||||
{
|
||||
DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);
|
||||
}
|
||||
|
||||
public void SetChannels(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
DefaultColorMethods.SetChannels(ref this, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorBGRA32 : IColor<byte>
|
||||
{
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => true;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(byte);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B}, A: {A} }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
public partial struct ColorR<T> : IColor<T> where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
|
||||
{
|
||||
public T R { get; set; }
|
||||
|
||||
public readonly T G
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly T B
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly T A
|
||||
{
|
||||
get => NumericConversion.GetMaximumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out T r, out T g, out T b, out T a)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
a = A;
|
||||
}
|
||||
|
||||
public void SetChannels(T r, T g, T b, T a)
|
||||
{
|
||||
R = r;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => false;
|
||||
static bool IColorBase.HasBlueChannel => false;
|
||||
static bool IColorBase.HasAlphaChannel => false;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(T);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R} }}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
public partial struct ColorRG<T> : IColor<T> where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
|
||||
{
|
||||
public T R { get; set; }
|
||||
|
||||
public T G { get; set; }
|
||||
|
||||
public readonly T B
|
||||
{
|
||||
get => NumericConversion.GetMinimumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly T A
|
||||
{
|
||||
get => NumericConversion.GetMaximumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out T r, out T g, out T b, out T a)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
a = A;
|
||||
}
|
||||
|
||||
public void SetChannels(T r, T g, T b, T a)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => false;
|
||||
static bool IColorBase.HasAlphaChannel => false;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(T);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G} }}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
public partial struct ColorRGB<T> : IColor<T> where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
|
||||
{
|
||||
public T R { get; set; }
|
||||
|
||||
public T G { get; set; }
|
||||
|
||||
public T B { get; set; }
|
||||
|
||||
public readonly T A
|
||||
{
|
||||
get => NumericConversion.GetMaximumValueSafe<T>();
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out T r, out T g, out T b, out T a)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
a = A;
|
||||
}
|
||||
|
||||
public void SetChannels(T r, T g, T b, T a)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => false;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(T);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B} }}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Also called RGB 565
|
||||
/// </summary>
|
||||
public partial struct ColorRGB16 : IColor<byte>
|
||||
{
|
||||
private ushort bits;
|
||||
|
||||
/// <summary>
|
||||
/// 5 bits
|
||||
/// </summary>
|
||||
public byte R
|
||||
{
|
||||
readonly get => (byte)(((uint)bits >> 8) & 0xF8);
|
||||
set
|
||||
{
|
||||
bits = (ushort)((((uint)value << 8) & 0xF800u) | (bits & ~0xF800u));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 6 bits
|
||||
/// </summary>
|
||||
public byte G
|
||||
{
|
||||
readonly get => (byte)(((uint)bits >> 3) & 0xFC);
|
||||
set
|
||||
{
|
||||
bits = (ushort)((((uint)value << 3) & 0x07E0u) | (bits & ~0x07E0u));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 5 bits
|
||||
/// </summary>
|
||||
public byte B
|
||||
{
|
||||
readonly get => (byte)(((uint)bits << 3) & 0xF8);
|
||||
set
|
||||
{
|
||||
bits = (ushort)((((uint)value >> 3) & 0x001Fu) | (bits & ~0x001Fu));
|
||||
}
|
||||
}
|
||||
|
||||
public readonly byte A
|
||||
{
|
||||
get => byte.MaxValue;
|
||||
set { }
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out byte r, out byte g, out byte b, out byte a)
|
||||
{
|
||||
DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);
|
||||
}
|
||||
|
||||
public void SetChannels(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
bits = (ushort)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | ((b & 0xF8u) >> 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGB16 : IColor<byte>
|
||||
{
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => false;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => false;
|
||||
static Type IColorBase.ChannelType => typeof(byte);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B} }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// 9 bits each for RGB and 5 bits for an exponent
|
||||
/// </summary>
|
||||
public partial struct ColorRGB9e5 : IColor<double>
|
||||
{
|
||||
private uint bits;
|
||||
|
||||
public double R
|
||||
{
|
||||
readonly get => RBits * Scale;
|
||||
set
|
||||
{
|
||||
GetChannels(out _, out double g, out double b, out _);
|
||||
SetChannels(value, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
public double G
|
||||
{
|
||||
readonly get => GBits * Scale;
|
||||
set
|
||||
{
|
||||
GetChannels(out double r, out _, out double b, out _);
|
||||
SetChannels(r, value, b);
|
||||
}
|
||||
}
|
||||
|
||||
public double B
|
||||
{
|
||||
readonly get => BBits * Scale;
|
||||
set
|
||||
{
|
||||
GetChannels(out double r, out double g, out _, out _);
|
||||
SetChannels(r, g, value);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly double A
|
||||
{
|
||||
get => 1;
|
||||
set { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public readonly void GetChannels(out double r, out double g, out double b, out double a)
|
||||
{
|
||||
double scale = Scale;
|
||||
r = RBits * scale;
|
||||
g = GBits * scale;
|
||||
b = BBits * scale;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public void SetChannels(double r, double g, double b, double a)
|
||||
{
|
||||
SetChannels(r, g, b);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public void SetChannels(double r, double g, double b)
|
||||
{
|
||||
int exponent = CalculateExponent(r, g, b);
|
||||
double scale = double.Pow(2, exponent);
|
||||
uint rBits = (uint)(r / scale) & ChannelBitMask;
|
||||
uint gBits = (uint)(g / scale) & ChannelBitMask;
|
||||
uint bBits = (uint)(b / scale) & ChannelBitMask;
|
||||
uint exponentBits = unchecked((uint)(exponent + 24));
|
||||
bits = (exponentBits << ExponentOffset) | (bBits << BlueOffset) | (gBits << GreenOffset) | (rBits << RedOffset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Range: -24 to 7 inclusive
|
||||
/// </summary>
|
||||
private readonly int Exponent => unchecked((int)(bits >> ExponentOffset) - 24);
|
||||
private readonly double Scale => double.Pow(2, Exponent);
|
||||
private readonly uint RBits => (bits >> RedOffset) & ChannelBitMask;
|
||||
private readonly uint GBits => (bits >> GreenOffset) & ChannelBitMask;
|
||||
private readonly uint BBits => (bits >> BlueOffset) & ChannelBitMask;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int CalculateExponent(double r, double g, double b)
|
||||
{
|
||||
double maxChannel = double.Max(r, double.Max(g, b));
|
||||
double minExponent = double.Log2(maxChannel / ChannelBitMask);
|
||||
return (int)double.Ceiling(minExponent);
|
||||
}
|
||||
|
||||
private const int ChannelBitMask = 0x1FF;
|
||||
private const int RedOffset = 0;
|
||||
private const int GreenOffset = 9;
|
||||
private const int BlueOffset = 18;
|
||||
private const int ExponentOffset = 27;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGB9e5 : IColor<double>
|
||||
{
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => false;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => false;
|
||||
static Type IColorBase.ChannelType => typeof(double);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B} }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Auto-generated code. Do not modify manually.
|
||||
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats;
|
||||
|
||||
public partial struct ColorRGBA<T> : IColor<T> where T : unmanaged
|
||||
{
|
||||
public T R { get; set; }
|
||||
|
||||
public T G { get; set; }
|
||||
|
||||
public T B { get; set; }
|
||||
|
||||
public T A { get; set; }
|
||||
|
||||
public readonly void GetChannels(out T r, out T g, out T b, out T a)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
a = A;
|
||||
}
|
||||
|
||||
public void SetChannels(T r, T g, T b, T a)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = a;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => true;
|
||||
static bool IColorBase.HasGreenChannel => true;
|
||||
static bool IColorBase.HasBlueChannel => true;
|
||||
static bool IColorBase.HasAlphaChannel => true;
|
||||
static bool IColorBase.ChannelsAreFullyUtilized => true;
|
||||
static Type IColorBase.ChannelType => typeof(T);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ R: {R}, G: {G}, B: {B}, A: {A} }}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGBA16 : IColor<byte>
|
||||
{
|
||||
private UInt4Pair ba;
|
||||
private UInt4Pair rg;
|
||||
|
||||
public byte R
|
||||
{
|
||||
readonly get => rg.HighValue;
|
||||
set => rg.HighValue = value;
|
||||
}
|
||||
|
||||
public byte G
|
||||
{
|
||||
readonly get => rg.LowValue;
|
||||
set => rg.LowValue = value;
|
||||
}
|
||||
|
||||
public byte B
|
||||
{
|
||||
readonly get => ba.HighValue;
|
||||
set => ba.HighValue = value;
|
||||
}
|
||||
|
||||
public byte A
|
||||
{
|
||||
readonly get => ba.LowValue;
|
||||
set => ba.LowValue = value;
|
||||
}
|
||||
|
||||
public readonly void GetChannels(out byte r, out byte g, out byte b, out byte a)
|
||||
{
|
||||
DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);
|
||||
}
|
||||
|
||||
public void SetChannels(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
DefaultColorMethods.SetChannels(ref this, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 233 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user