Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bf10bd

Browse files
committed
. b Fix DNG conversion hanging and double size issues
1 parent 7bc4d46 commit 7bf10bd

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

src/eir/build_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Build-time constants generated by build script."""
22

3-
VERSION = "0.2.51"
3+
VERSION = "0.3.3"
44
NAME = "eir"
55
LICENSE = "MIT"
66
KEYWORDS = ["exif", "images", "pictures", "rename", "convert"]

src/eir/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def main():
4040
command_line_options.handle_options()
4141
asyncio.run(
4242
run_pipeline(
43-
logger=command_line_options.logger, image_dir=command_line_options.options.dir
43+
logger=command_line_options.logger,
44+
image_dir=command_line_options.options.dir,
45+
dng_compression=command_line_options.options.dng_compression,
46+
dng_preview=command_line_options.options.dng_preview,
4447
)
4548
)
4649

src/eir/clo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ def handle_options(self) -> None:
6666
parser.add_argument(
6767
"-v", "--version", action="store_true", help="Show version info and exit"
6868
)
69+
parser.add_argument(
70+
"--dng-compression",
71+
choices=["lossless", "uncompressed"],
72+
default="lossless",
73+
help="DNG compression method: lossless (default) or uncompressed",
74+
)
75+
parser.add_argument(
76+
"--dng-preview",
77+
action="store_true",
78+
default=False,
79+
help="Embed JPEG preview in DNG files (increases file size)",
80+
)
6981
self.options = parser.parse_args()
7082

7183
if self.options.version:

src/eir/processor.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ class ImageProcessor:
9090
EXIF_UNKNOWN = "unknown"
9191
EXIF_TAGS = [ExifTag.CREATE_DATE.value, ExifTag.MAKE.value, ExifTag.MODEL.value]
9292

93-
def __init__(self, logger: logging.Logger, op_dir: str):
93+
def __init__(
94+
self,
95+
logger: logging.Logger,
96+
op_dir: str,
97+
dng_compression: str = "lossless",
98+
dng_preview: bool = False,
99+
):
94100
"""Initialize ImageProcessor."""
95101
self._logger = logger or logging.getLogger(__name__)
96102
self._op_dir = op_dir
103+
self._dng_compression = dng_compression
104+
self._dng_preview = dng_preview
97105
self._current_dir = None
98106
self._supported_raw_image_ext_list = list(
99107
set([ext for exts in self.SUPPORTED_RAW_IMAGE_EXT.values() for ext in exts])
@@ -196,11 +204,15 @@ async def patched_get_compat_path(path):
196204
# Also patch the convert_file method to add proper error handling
197205
from pydngconverter import main as pydng_main
198206

207+
# Capture our compression settings for the patch
208+
dng_compression = self._dng_compression
209+
dng_preview = self._dng_preview
210+
199211
async def patched_convert_file(self, *, destination: str = None, job=None, log=None):
200212
"""Enhanced convert_file with better error handling and logging."""
201213
from pydngconverter import compat
202214

203-
log = log or self._logger
215+
log = log or logging.getLogger(__name__)
204216
log.debug("starting conversion: %s", job.source.name)
205217
source_path = await compat.get_compat_path(job.source)
206218
log.debug("determined source path: %s", source_path)
@@ -219,10 +231,12 @@ async def patched_convert_file(self, *, destination: str = None, job=None, log=N
219231
output_file = Path(destination) / f"{Path(source_path).stem}.dng"
220232
dng_args = [
221233
"convert",
222-
"--compression",
223-
"lossless",
234+
"-c",
235+
dng_compression, # Use captured compression setting
224236
"--dng-preview",
225-
"true",
237+
"true" if dng_preview else "false",
238+
"--embed-raw",
239+
"false", # CRITICAL: Don't embed original RAW to prevent double size
226240
str(source_path),
227241
str(output_file),
228242
]
@@ -232,7 +246,7 @@ async def patched_convert_file(self, *, destination: str = None, job=None, log=N
232246

233247
# Log the full command being executed
234248
full_command = f"{self.bin_exec} {' '.join(dng_args)}"
235-
log.debug(
249+
log.info(
236250
"Executing %s command: %s",
237251
"DNGLab" if is_dnglab else "Adobe DNG Converter",
238252
full_command,
@@ -244,7 +258,9 @@ async def patched_convert_file(self, *, destination: str = None, job=None, log=N
244258
log.debug("Destination directory exists: %s", Path(destination).exists())
245259
log.debug("Current working directory: %s", Path.cwd())
246260

247-
log.debug("converting: %s => %s", job.source.name, job.destination_filename)
261+
log.info(
262+
"Starting conversion: %s => %s", job.source.name, job.destination_filename
263+
)
248264

249265
try:
250266
proc = await asyncio.create_subprocess_exec(
@@ -254,6 +270,7 @@ async def patched_convert_file(self, *, destination: str = None, job=None, log=N
254270
stderr=asyncio.subprocess.PIPE,
255271
)
256272
stdout, stderr = await proc.communicate()
273+
log.info("DNGLab process completed with return code: %d", proc.returncode)
257274

258275
# Check return code and log any errors
259276
if proc.returncode != 0:
@@ -737,12 +754,21 @@ async def _handle_raw_conversion(self, value: dict[str, list[dict[str, Any]]]) -
737754

738755

739756
@function_trace
740-
async def run_pipeline(logger: logging.Logger, image_dir: str) -> None:
757+
async def run_pipeline(
758+
logger: logging.Logger,
759+
image_dir: str,
760+
dng_compression: str = "lossless",
761+
dng_preview: bool = False,
762+
) -> None:
741763
"""Main entry point for reactive image processing pipeline.
742764
743765
Args:
744766
logger: Logger instance
745767
image_dir: Directory containing images to process
768+
dng_compression: DNG compression method ('lossless' or 'uncompressed')
769+
dng_preview: Whether to embed JPEG preview in DNG files
746770
"""
747-
processor = ImageProcessor(logger=logger, op_dir=image_dir)
771+
processor = ImageProcessor(
772+
logger=logger, op_dir=image_dir, dng_compression=dng_compression, dng_preview=dng_preview
773+
)
748774
await processor.process_images_reactive()

0 commit comments

Comments
 (0)