Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect endianness on export #16

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions raviewer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import logging
from .src.core import (get_displayable, load_image, parse_image)
from .src.utils import save_image_as_file
from .image.color_format import AVAILABLE_FORMATS
from .image.color_format import AVAILABLE_FORMATS, Endianness
from .gui.gui_init import AppInit
from .format_recognition.detect import classify_top1, predict_resolution
from .format_recognition.detect import classify_top1, classify_all, predict_resolution
from tests import test_formats


Expand Down Expand Up @@ -66,7 +66,17 @@ def run(file_path, width, height, color_format, export, args):
color_format, _ = classify_top1(img)
if width == 0:
width, _ = predict_resolution(img, color_format)[0]
img = parse_image(img.data_buffer, color_format, width)
albfan marked this conversation as resolved.
Show resolved Hide resolved

if args["endianness"] == 'auto':
predictions, endianness = classify_all(img)
endianness = Endianness[endianness]
elif args["endianness"] == 'little':
endianness = Endianness.LITTLE_ENDIAN
else:
endianness = Endianness.BIG_ENDIAN

img = parse_image(img.data_buffer, color_format, width,
endianness.value)
if height < 1: height = img.height
save_image_as_file(get_displayable(img, height), export)

Expand Down Expand Up @@ -122,6 +132,14 @@ def main():
default=False,
help="Turn on/off debug mode")

parser.add_argument(
"--endianness",
choices=['little', 'big', 'auto'],
default='little',
help=
"Set endianness. little (default), big or auto (automatically calculated)"
),

args = vars(parser.parse_args())

if isinstance(args["FILE_PATH"], str):
Expand Down
Loading