#   pdf-segmented: Generate PDFs using separate compression for foreground and background
#   Copyright (C) 2025  Lee Yingtong Li
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.

from . import convert_file
from .compression import CompressionOptions

import argparse

# Parse CLI arguments
parser = argparse.ArgumentParser(
	prog='pdf-segmented',
	description='Generate PDFs using separate compression for foreground and background'
)
parser.add_argument('input_file')
parser.add_argument('output_file')
parser.add_argument('--input-format', choices=['xcf'])
parser.add_argument('--output-format', choices=['pdf', 'djvu'])
parser.add_argument('--fg-compression', choices=['jbig2', 'png', 'jb2'])
parser.add_argument('--bg-compression', choices=['jpeg', 'jp2', 'png', 'iw44'])
parser.add_argument('--jp2-lossless', action='store_true')
parser.add_argument('--jp2-rate', type=float)
parser.add_argument('--jpeg-quality', type=float)

args = parser.parse_args()

# Run app
convert_file(
	input_file=args.input_file,
	output_file=args.output_file,
	input_format=args.input_format,
	output_format=args.output_format,
	fg_compression=args.fg_compression,
	bg_compression=args.bg_compression,
	options=CompressionOptions(
		jp2_lossless=args.jp2_lossless,
		jp2_rate=args.jp2_rate,
		jpeg_quality=args.jpeg_quality
	)
)