ReverseBox 0.19.2__tar.gz → 0.19.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. {reversebox-0.19.2 → reversebox-0.19.4}/PKG-INFO +5 -2
  2. {reversebox-0.19.2 → reversebox-0.19.4}/README.md +4 -1
  3. {reversebox-0.19.2 → reversebox-0.19.4}/ReverseBox.egg-info/PKG-INFO +5 -2
  4. {reversebox-0.19.2 → reversebox-0.19.4}/ReverseBox.egg-info/SOURCES.txt +1 -2
  5. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/common.py +3 -3
  6. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/image_decoder.py +10 -14
  7. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/image_formats.py +9 -7
  8. reversebox-0.19.2/reversebox/image/swizzling/swizzle_psvita.py → reversebox-0.19.4/reversebox/image/swizzling/swizzle_psvita_dreamcast.py +24 -13
  9. {reversebox-0.19.2 → reversebox-0.19.4}/setup.py +1 -1
  10. reversebox-0.19.2/reversebox/image/swizzling/swizzle_morton_dreamcast.py +0 -90
  11. {reversebox-0.19.2 → reversebox-0.19.4}/LICENSE +0 -0
  12. {reversebox-0.19.2 → reversebox-0.19.4}/ReverseBox.egg-info/dependency_links.txt +0 -0
  13. {reversebox-0.19.2 → reversebox-0.19.4}/ReverseBox.egg-info/requires.txt +0 -0
  14. {reversebox-0.19.2 → reversebox-0.19.4}/ReverseBox.egg-info/top_level.txt +0 -0
  15. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/__init__.py +0 -0
  16. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/__init__.py +0 -0
  17. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_adler32.py +0 -0
  18. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_fletcher16.py +0 -0
  19. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_fletcher32.py +0 -0
  20. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_internet_ipv4_header.py +0 -0
  21. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_sum8.py +0 -0
  22. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_sum8_2s_complement.py +0 -0
  23. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_unix_sum_bsd16.py +0 -0
  24. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_unix_sum_sysv.py +0 -0
  25. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/checksum/checksum_xor8.py +0 -0
  26. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/common/__init__.py +0 -0
  27. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/common/common.py +0 -0
  28. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/common/logger.py +0 -0
  29. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/__init__.py +0 -0
  30. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/compression_jcalg1.py +0 -0
  31. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/compression_lzo.py +0 -0
  32. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/compression_mio0.py +0 -0
  33. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/compression_refpack.py +0 -0
  34. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/compression/compression_zlib.py +0 -0
  35. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/__init__.py +0 -0
  36. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_arc.py +0 -0
  37. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_ccitt.py +0 -0
  38. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_dnp.py +0 -0
  39. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_ea_crcf.py +0 -0
  40. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_kermit.py +0 -0
  41. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_modbus.py +0 -0
  42. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc16_sick.py +0 -0
  43. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc32_asobo.py +0 -0
  44. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc32_iso_hdlc.py +0 -0
  45. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc64_asobo.py +0 -0
  46. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc64_go_iso.py +0 -0
  47. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc8.py +0 -0
  48. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/crc/crc_unix_cksum.py +0 -0
  49. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/__init__.py +0 -0
  50. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/encryption_rot13.py +0 -0
  51. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/encryption_xor_basic.py +0 -0
  52. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/encryption_xor_basic_key_guesser.py +0 -0
  53. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/encryption_xor_gianas_return_zda.py +0 -0
  54. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/encryption/encryption_xor_retro64_eco.py +0 -0
  55. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/__init__.py +0 -0
  56. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_ap.py +0 -0
  57. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_djb2.py +0 -0
  58. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_fnv.py +0 -0
  59. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_md2.py +0 -0
  60. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_md5.py +0 -0
  61. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_sdbm.py +0 -0
  62. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_sha1.py +0 -0
  63. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/hash/hash_sha2.py +0 -0
  64. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/__init__.py +0 -0
  65. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/compression/__init__.py +0 -0
  66. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/compression/compression_gst.py +0 -0
  67. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/decoders/__init__.py +0 -0
  68. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/decoders/bumpmap_decoder.py +0 -0
  69. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/decoders/n64_decoder.py +0 -0
  70. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/decoders/yuv_decoder.py +0 -0
  71. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/file_formats/__init__.py +0 -0
  72. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/file_formats/image_dds.py +0 -0
  73. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/image_encoder.py +0 -0
  74. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/palettes/__init__.py +0 -0
  75. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/palettes/palette_random.py +0 -0
  76. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/pillow_wrapper.py +0 -0
  77. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/__init__.py +0 -0
  78. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_3ds.py +0 -0
  79. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_bc.py +0 -0
  80. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_cmpr.py +0 -0
  81. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_gamecube.py +0 -0
  82. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_gst.py +0 -0
  83. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_morton.py +0 -0
  84. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_morton_ps4.py +0 -0
  85. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_ps2.py +0 -0
  86. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_psp.py +0 -0
  87. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_switch.py +0 -0
  88. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/image/swizzling/swizzle_x360.py +0 -0
  89. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/__init__.py +0 -0
  90. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/bytes_handler.py +0 -0
  91. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/bytes_helper_functions.py +0 -0
  92. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/check_file.py +0 -0
  93. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/file_handler.py +0 -0
  94. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/mod_handler.py +0 -0
  95. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/io_files/translation_text_handler.py +0 -0
  96. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/libs/__init__.py +0 -0
  97. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/libs/ea_swizzle.dll +0 -0
  98. {reversebox-0.19.2 → reversebox-0.19.4}/reversebox/libs/refpack.dll +0 -0
  99. {reversebox-0.19.2 → reversebox-0.19.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ReverseBox
3
- Version: 0.19.2
3
+ Version: 0.19.4
4
4
  Summary: A set of functions useful in reverse engineering.
5
5
  Home-page: https://github.com/bartlomiejduda/ReverseBox
6
6
  Author: Bartlomiej Duda
@@ -229,9 +229,9 @@ or software researchers).
229
229
  - PS2 Palette Swizzling/Twiddling ✔️
230
230
  - PS4 Swizzling/Twiddling ✔️
231
231
  - PSP Swizzling/Twiddling ✔️
232
+ - PS Vita Swizzling/Twiddling ✔️
232
233
  - XBOX 360 Swizzling/Twiddling ✔️
233
234
  - GameCube/WII Swizzling/Twiddling ✔️
234
- - PSVITA Swizzling/Twiddling ✔️
235
235
  - Switch Swizzling/Twiddling ✔️
236
236
  - XBOX/PS3 Swizzling/Twiddling (Morton Order) ✔️
237
237
  - Dreamcast Swizzling/Twiddling (Morton Order) ✔️
@@ -367,3 +367,6 @@ Check out list of tools written using ReverseBox:
367
367
  - [TPL Parser](https://github.com/bartlomiejduda/Tools/tree/master/NEW%20Tools/Mario%20Kart%20WII/TPL%20Parser)
368
368
  - [ImageHeat](https://github.com/bartlomiejduda/ImageHeat)
369
369
  - and more...
370
+
371
+ # Badges
372
+ ![PyPI Downloads](https://static.pepy.tech/badge/reversebox)
@@ -194,9 +194,9 @@ or software researchers).
194
194
  - PS2 Palette Swizzling/Twiddling ✔️
195
195
  - PS4 Swizzling/Twiddling ✔️
196
196
  - PSP Swizzling/Twiddling ✔️
197
+ - PS Vita Swizzling/Twiddling ✔️
197
198
  - XBOX 360 Swizzling/Twiddling ✔️
198
199
  - GameCube/WII Swizzling/Twiddling ✔️
199
- - PSVITA Swizzling/Twiddling ✔️
200
200
  - Switch Swizzling/Twiddling ✔️
201
201
  - XBOX/PS3 Swizzling/Twiddling (Morton Order) ✔️
202
202
  - Dreamcast Swizzling/Twiddling (Morton Order) ✔️
@@ -332,3 +332,6 @@ Check out list of tools written using ReverseBox:
332
332
  - [TPL Parser](https://github.com/bartlomiejduda/Tools/tree/master/NEW%20Tools/Mario%20Kart%20WII/TPL%20Parser)
333
333
  - [ImageHeat](https://github.com/bartlomiejduda/ImageHeat)
334
334
  - and more...
335
+
336
+ # Badges
337
+ ![PyPI Downloads](https://static.pepy.tech/badge/reversebox)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ReverseBox
3
- Version: 0.19.2
3
+ Version: 0.19.4
4
4
  Summary: A set of functions useful in reverse engineering.
5
5
  Home-page: https://github.com/bartlomiejduda/ReverseBox
6
6
  Author: Bartlomiej Duda
@@ -229,9 +229,9 @@ or software researchers).
229
229
  - PS2 Palette Swizzling/Twiddling ✔️
230
230
  - PS4 Swizzling/Twiddling ✔️
231
231
  - PSP Swizzling/Twiddling ✔️
232
+ - PS Vita Swizzling/Twiddling ✔️
232
233
  - XBOX 360 Swizzling/Twiddling ✔️
233
234
  - GameCube/WII Swizzling/Twiddling ✔️
234
- - PSVITA Swizzling/Twiddling ✔️
235
235
  - Switch Swizzling/Twiddling ✔️
236
236
  - XBOX/PS3 Swizzling/Twiddling (Morton Order) ✔️
237
237
  - Dreamcast Swizzling/Twiddling (Morton Order) ✔️
@@ -367,3 +367,6 @@ Check out list of tools written using ReverseBox:
367
367
  - [TPL Parser](https://github.com/bartlomiejduda/Tools/tree/master/NEW%20Tools/Mario%20Kart%20WII/TPL%20Parser)
368
368
  - [ImageHeat](https://github.com/bartlomiejduda/ImageHeat)
369
369
  - and more...
370
+
371
+ # Badges
372
+ ![PyPI Downloads](https://static.pepy.tech/badge/reversebox)
@@ -78,11 +78,10 @@ reversebox/image/swizzling/swizzle_cmpr.py
78
78
  reversebox/image/swizzling/swizzle_gamecube.py
79
79
  reversebox/image/swizzling/swizzle_gst.py
80
80
  reversebox/image/swizzling/swizzle_morton.py
81
- reversebox/image/swizzling/swizzle_morton_dreamcast.py
82
81
  reversebox/image/swizzling/swizzle_morton_ps4.py
83
82
  reversebox/image/swizzling/swizzle_ps2.py
84
83
  reversebox/image/swizzling/swizzle_psp.py
85
- reversebox/image/swizzling/swizzle_psvita.py
84
+ reversebox/image/swizzling/swizzle_psvita_dreamcast.py
86
85
  reversebox/image/swizzling/swizzle_switch.py
87
86
  reversebox/image/swizzling/swizzle_x360.py
88
87
  reversebox/io_files/__init__.py
@@ -73,7 +73,7 @@ def get_bpp_for_image_format(image_format: ImageFormats) -> int:
73
73
  if image_format in (ImageFormats.RGB121,
74
74
  ImageFormats.N64_CMPR,
75
75
  ImageFormats.N64_I4,
76
- ImageFormats.DXT1) or "pal4" in image_format.value.lower():
76
+ ImageFormats.BC1_DXT1) or "pal4" in image_format.value.lower():
77
77
  return 4
78
78
  elif image_format in (ImageFormats.RGBX2222,
79
79
  ImageFormats.RGBA2222,
@@ -83,8 +83,8 @@ def get_bpp_for_image_format(image_format: ImageFormats) -> int:
83
83
  ImageFormats.GRAY8,
84
84
  ImageFormats.N64_I8,
85
85
  ImageFormats.N64_IA4,
86
- ImageFormats.DXT3,
87
- ImageFormats.DXT5) or "pal8" in image_format.value.lower():
86
+ ImageFormats.BC2_DXT3,
87
+ ImageFormats.BC3_DXT5) or "pal8" in image_format.value.lower():
88
88
  return 8
89
89
  elif image_format in (ImageFormats.GRAY8A,
90
90
  ImageFormats.GRAY16,
@@ -243,13 +243,13 @@ class ImageDecoder:
243
243
 
244
244
  def _decode_bgrx8888_pixel(self, pixel_int: int) -> bytes:
245
245
  p = bytearray(4)
246
- p[0] = (pixel_int >> 8) & 0xff
247
- p[1] = (pixel_int >> 16) & 0xff
248
- p[2] = (pixel_int >> 24) & 0xff
246
+ p[0] = (pixel_int >> 16) & 0xFF
247
+ p[1] = (pixel_int >> 8) & 0xFF
248
+ p[2] = (pixel_int >> 0) & 0xFF
249
249
  p[3] = 0xFF
250
250
  return p
251
251
 
252
- def _decode_bgra8888_pixel(self, pixel_int: int) -> bytes:
252
+ def _decode_bgra8888_pixel(self, pixel_int: int) -> bytes: # TODO - fix this?
253
253
  p = bytearray(4)
254
254
  p[0] = (pixel_int >> 16) & 0xff
255
255
  p[1] = (pixel_int >> 8) & 0xff
@@ -275,13 +275,9 @@ class ImageDecoder:
275
275
 
276
276
  def _decode_xrgb8888_pixel(self, pixel_int: int) -> bytes:
277
277
  p = bytearray(4)
278
- R = (pixel_int >> 16) & 0xFF
279
- G = (pixel_int >> 8) & 0xFF
280
- B = pixel_int & 0xFF
281
-
282
- p[0] = R
283
- p[1] = G
284
- p[2] = B
278
+ p[0] = (pixel_int >> 8) & 0xff
279
+ p[1] = (pixel_int >> 16) & 0xff
280
+ p[2] = (pixel_int >> 24) & 0xff
285
281
  p[3] = 0xFF
286
282
  return p
287
283
 
@@ -534,9 +530,9 @@ class ImageDecoder:
534
530
 
535
531
  compressed_data_formats = {
536
532
  # image format: (decoder_name, decoder_arg)
537
- ImageFormats.DXT1: ("bcn", 1),
538
- ImageFormats.DXT3: ("bcn", 2),
539
- ImageFormats.DXT5: ("bcn", 3)
533
+ ImageFormats.BC1_DXT1: ("bcn", 1),
534
+ ImageFormats.BC2_DXT3: ("bcn", 2),
535
+ ImageFormats.BC3_DXT5: ("bcn", 3)
540
536
  }
541
537
 
542
538
  gst_data_formats = {
@@ -50,14 +50,14 @@ class ImageFormats(Enum):
50
50
  BGR888 = "bgr888" # PIX_FMT_BGR24 / packed RGB 8:8:8, 24bpp, BGRBGR
51
51
 
52
52
  # 32-bit
53
- RGBA8888 = "rgba8888" # PIX_FMT_RGBA / packed RGBA 8:8:8:8, 32bpp, RGBARGBA
54
- BGRA8888 = "bgra8888" # PIX_FMT_BGRA / packed BGRA 8:8:8:8, 32bpp, BGRABGRA
53
+ RGBA8888 = "rgba8888" # PIX_FMT_RGBA / packed RGBA 8:8:8:8, 32bpp, RGBARGBA (R8G8B8A8_UNORM)
54
+ BGRA8888 = "bgra8888" # PIX_FMT_BGRA / packed BGRA 8:8:8:8, 32bpp, BGRABGRA (B8G8R8A8_UNORM)
55
55
  ARGB8888 = "argb8888" # PIX_FMT_ARGB / packed ARGB 8:8:8:8, 32bpp, ARGBARGB
56
56
  ABGR8888 = "abgr8888" # PIX_FMT_ABGR / packed ABGR 8:8:8:8, 32bpp, ABGRABGR
57
57
  XRGB8888 = "xrgb8888" # PIX_FMT_0RGB / packed RGB 8:8:8, 32bpp, 0RGB0RGB...
58
58
  RGBX8888 = "rgbx8888" # PIX_FMT_RGB0 / packed RGB 8:8:8, 32bpp, RGB0RGB0...
59
59
  XBGR8888 = "xbgr8888" # PIX_FMT_0BGR / packed BGR 8:8:8, 32bpp, 0BGR0BGR...
60
- BGRX8888 = "bgrx8888" # PIX_FMT_BGR0 / packed BGR 8:8:8, 32bpp, BGR0BGR0...
60
+ BGRX8888 = "bgrx8888" # PIX_FMT_BGR0 / packed BGR 8:8:8, 32bpp, BGR0BGR0... (B8G8R8X8_UNORM)
61
61
 
62
62
  # 48-bit
63
63
  RGB48 = "rgb48" # PIX_FMT_RGB48LE / PIX_FMT_RGB48BE / packed RGB 16:16:16, 48bpp, 16R, 16G, 16B
@@ -108,10 +108,12 @@ class ImageFormats(Enum):
108
108
  N64_IA4 = "n64_ia4" # GRAY+ALPHA, 8bpp
109
109
  N64_IA8 = "n64_ia8" # GRAY+ALPHA, 16bpp
110
110
 
111
- # DXT Formats
112
- DXT1 = "dxt1" # BC1
113
- DXT3 = "dxt3" # BC2
114
- DXT5 = "dxt5" # BC3
111
+ # compressed Formats
112
+ BC1_DXT1 = "bc1_dxt1"
113
+ # BC2_DXT2 = "bc2_dxt2" # TODO - implement this
114
+ BC2_DXT3 = "bc2_dxt3"
115
+ # BC3_DXT4 = "bc3_dxt4" # TODO - implement this
116
+ BC3_DXT5 = "bc3_dxt5"
115
117
 
116
118
  # PS2 GS Texture Formats
117
119
  GST121 = "gst121"
@@ -5,6 +5,17 @@ License: GPL-3.0 License
5
5
 
6
6
  # fmt: off
7
7
 
8
+ # Morton Order Texture Swizzling (+ rotated by 90 degrees for console's CPU)
9
+ # https://en.wikipedia.org/wiki/Z-order_curve
10
+ # https://dreamcast.wiki/Twiddling
11
+
12
+ # Same algorithm is used in Dreamcast and PS Vita consoles
13
+ # I've seen it used in Dreamcast DTEX files and in PS Vita GXT files
14
+ # example games:
15
+ # - Danganronpa: Trigger Happy Havoc (PS Vita) (*.GXT)
16
+ # - Danganronpa 2: Goodbye Despair (PS Vita) (*.GXT)
17
+ # - Senran Kagura: Shinovi Versus (PS Vita) (*.GXT)
18
+
8
19
 
9
20
  def bsr(x: int) -> int:
10
21
  """bit scan reverse"""
@@ -23,7 +34,7 @@ def align(value: int, alignment: int) -> int:
23
34
  return (value + (alignment - 1)) & ~(alignment - 1)
24
35
 
25
36
 
26
- def get_morton_index_psvita(x: int, y: int, width: int, height: int) -> int:
37
+ def get_morton_index_psvita_dreamcast(x: int, y: int, width: int, height: int) -> int:
27
38
  logW = bsr(width)
28
39
  logH = bsr(height)
29
40
  d = min(logW, logH)
@@ -40,10 +51,10 @@ def get_morton_index_psvita(x: int, y: int, width: int, height: int) -> int:
40
51
  return index
41
52
 
42
53
 
43
- def _convert_psvita_4bpp(pixel_data: bytes, img_width: int, img_height: int, swizzle_flag: bool) -> bytes:
54
+ def _convert_psvita_dreamcast_4bpp(pixel_data: bytes, img_width: int, img_height: int, swizzle_flag: bool) -> bytes:
44
55
  converted_data: bytearray = bytearray(len(pixel_data))
45
- mx = get_morton_index_psvita(img_width - 1, 0, img_width, img_height)
46
- my = get_morton_index_psvita(0, img_height - 1, img_width, img_height)
56
+ mx = get_morton_index_psvita_dreamcast(img_width - 1, 0, img_width, img_height)
57
+ my = get_morton_index_psvita_dreamcast(0, img_height - 1, img_width, img_height)
47
58
 
48
59
  line_stride = align(img_width, 2)
49
60
 
@@ -73,13 +84,13 @@ def _convert_psvita_4bpp(pixel_data: bytes, img_width: int, img_height: int, swi
73
84
  return converted_data
74
85
 
75
86
 
76
- def _convert_psvita(pixel_data: bytes, img_width: int, img_height: int, bpp: int, swizzle_flag: bool) -> bytes:
87
+ def _convert_psvita_dreamcast(pixel_data: bytes, img_width: int, img_height: int, bpp: int, swizzle_flag: bool) -> bytes:
77
88
  converted_data: bytearray = bytearray(len(pixel_data))
78
89
  width_pow2 = enclosing_power_of_2(img_width)
79
90
  height_pow2 = enclosing_power_of_2(img_height)
80
91
 
81
- mx = get_morton_index_psvita(width_pow2 - 1, 0, width_pow2, height_pow2)
82
- my = get_morton_index_psvita(0, height_pow2 - 1, width_pow2, height_pow2)
92
+ mx = get_morton_index_psvita_dreamcast(width_pow2 - 1, 0, width_pow2, height_pow2)
93
+ my = get_morton_index_psvita_dreamcast(0, height_pow2 - 1, width_pow2, height_pow2)
83
94
 
84
95
  pixel_size = bpp // 8
85
96
 
@@ -100,13 +111,13 @@ def _convert_psvita(pixel_data: bytes, img_width: int, img_height: int, bpp: int
100
111
  return converted_data
101
112
 
102
113
 
103
- def unswizzle_psvita(pixel_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
114
+ def unswizzle_psvita_dreamcast(pixel_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
104
115
  if bpp == 4:
105
- return _convert_psvita_4bpp(pixel_data, img_width, img_height, False)
106
- return _convert_psvita(pixel_data, img_width, img_height, bpp, False)
116
+ return _convert_psvita_dreamcast_4bpp(pixel_data, img_width, img_height, False)
117
+ return _convert_psvita_dreamcast(pixel_data, img_width, img_height, bpp, False)
107
118
 
108
119
 
109
- def swizzle_psvita(pixel_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
120
+ def swizzle_psvita_dreamcast(pixel_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
110
121
  if bpp == 4:
111
- return _convert_psvita_4bpp(pixel_data, img_width, img_height, True)
112
- return _convert_psvita(pixel_data, img_width, img_height, bpp, True)
122
+ return _convert_psvita_dreamcast_4bpp(pixel_data, img_width, img_height, True)
123
+ return _convert_psvita_dreamcast(pixel_data, img_width, img_height, bpp, True)
@@ -7,7 +7,7 @@ import os
7
7
 
8
8
  import setuptools
9
9
 
10
- VERSION_NUM = "0.19.2"
10
+ VERSION_NUM = "0.19.4"
11
11
 
12
12
 
13
13
  def get_long_description() -> str:
@@ -1,90 +0,0 @@
1
- """
2
- Copyright © 2024 Bartłomiej Duda
3
- License: GPL-3.0 License
4
- """
5
-
6
- from reversebox.image.common import convert_bpp_to_bytes_per_pixel
7
-
8
- # Morton Order Texture Swizzling (+ rotated by 90 degrees for Dreamcast CPU)
9
- # https://en.wikipedia.org/wiki/Z-order_curve
10
- # https://dreamcast.wiki/Twiddling
11
- # Used in Dreamcast games
12
-
13
- # fmt: off
14
-
15
-
16
- def calculate_morton_index_dreamcast(p: int, w: int, h: int) -> int:
17
- ddx = 1
18
- ddy = w
19
- q = 0
20
-
21
- for i in range(16):
22
- h >>= 1
23
- if h:
24
- if p & 1:
25
- q |= ddy
26
- p >>= 1
27
- ddy <<= 1
28
- if w >> 1:
29
- if p & 1:
30
- q |= ddx
31
- p >>= 1
32
- ddx <<= 1
33
-
34
- return q
35
-
36
-
37
- def _convert_morton_dreamcast(image_data: bytes, img_width: int, img_height: int, bpp: int, swizzle_flag: bool) -> bytes:
38
- converted_data = bytearray(len(image_data))
39
- bytes_per_pixel: int = convert_bpp_to_bytes_per_pixel(bpp)
40
- source_index: int = 0
41
-
42
- for t in range(img_width * img_height):
43
- index = calculate_morton_index_dreamcast(t, img_width, img_height)
44
- destination_index = bytes_per_pixel * index
45
-
46
- if not swizzle_flag:
47
- converted_data[destination_index: destination_index + bytes_per_pixel] = image_data[source_index: source_index + bytes_per_pixel]
48
- else:
49
- converted_data[source_index: source_index + bytes_per_pixel] = image_data[destination_index: destination_index + bytes_per_pixel]
50
- source_index += bytes_per_pixel
51
-
52
- return converted_data
53
-
54
-
55
- def _convert_morton_dreamcast_4bit(input_buffer: bytes, width: int, height: int, bpp: int, swizzle_flag: bool) -> bytes:
56
- converted_data: bytearray = bytearray(len(input_buffer))
57
- input_pixels_8bpp = bytearray(width * height)
58
- buffer_byte_size = (width * height + 1) // 2
59
-
60
- # unpack 4bpp pixels to 8bpp
61
- for i in range(buffer_byte_size):
62
- byte_value = input_buffer[i]
63
- nybble_low = byte_value & 0xF
64
- nybble_high = byte_value >> 4
65
- input_pixels_8bpp[i * 2] = nybble_low
66
- input_pixels_8bpp[i * 2 + 1] = nybble_high
67
-
68
- # swizzle/unswizzle for 8bpp
69
- output_pixels_8bpp = _convert_morton_dreamcast(input_pixels_8bpp, width, height, bpp, swizzle_flag)
70
-
71
- # repack 8bpp pixels to 4bpp
72
- for i in range(buffer_byte_size):
73
- nybble_low = output_pixels_8bpp[i * 2]
74
- nybble_high = output_pixels_8bpp[i * 2 + 1]
75
- byte_value = (nybble_high << 4) | nybble_low
76
- converted_data[i] = byte_value
77
-
78
- return converted_data
79
-
80
-
81
- def unswizzle_morton_dreamcast(image_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
82
- if bpp == 4:
83
- return _convert_morton_dreamcast_4bit(image_data, img_width, img_height, bpp, False)
84
- return _convert_morton_dreamcast(image_data, img_width, img_height, bpp, False)
85
-
86
-
87
- def swizzle_morton_dreamcast(image_data: bytes, img_width: int, img_height: int, bpp: int) -> bytes:
88
- if bpp == 4:
89
- return _convert_morton_dreamcast_4bit(image_data, img_width, img_height, bpp, True)
90
- return _convert_morton_dreamcast(image_data, img_width, img_height, bpp, True)
File without changes
File without changes