feat(transcode): add dcraw_emu fallback for RAW image preview generation (#446)

This commit is contained in:
Yiling-J
2026-10-03 11:03:31 +08:00
committed by GitHub
parent 013c4a8156
commit 8805d5799a
11 changed files with 633 additions and 50 deletions
@@ -506,6 +506,26 @@ describe('TranscodeService', () => {
expect(info.mimeType).toBe('')
})
it('should prioritize rawWidth and rawHeight in getImageInfo when available', async () => {
const rawPath = path.join(tempDir, 'highres.arw')
const cleanupSpy = vi.fn()
vi.spyOn(rawExtract, 'extractAndValidateRawPreview').mockResolvedValueOnce({
previewPath: '/tmp/decoded-half.tiff',
cleanup: cleanupSpy,
width: 4752,
height: 3168,
rawWidth: 9504,
rawHeight: 6336,
orientation: undefined,
})
const info = await transcodeService.getImageInfo(rawPath)
expect(info.originalWidth).toBe(9504)
expect(info.originalHeight).toBe(6336)
expect(info.mimeType).toBe('jpeg')
expect(cleanupSpy).toHaveBeenCalled()
})
it('should transcode RAW image by extracting preview to temp file and feeding to sharp', async () => {
const rawPath = path.join(tempDir, 'sample.nef')
const outputFile = path.join(tempDir, 'output-raw.webp')
@@ -528,6 +548,31 @@ describe('TranscodeService', () => {
expect(cleanupSpy).toHaveBeenCalled()
})
it('should transcode RAW image from dcraw_emu fallback TIFF without double-rotating', async () => {
const rawPath = path.join(tempDir, 'fallback.dng')
const outputFile = path.join(tempDir, 'output-fallback.webp')
const cleanupSpy = vi.fn()
vi.spyOn(rawExtract, 'extractAndValidateRawPreview').mockResolvedValueOnce({
previewPath: '/tmp/decoded-dcraw.tiff',
cleanup: cleanupSpy,
width: 3168,
height: 4752,
rawWidth: 6336,
rawHeight: 9504,
orientation: undefined,
})
await transcodeService.transcodeImage(rawPath, outputFile, 1920, 85)
expect(sharp).toHaveBeenCalledWith('/tmp/decoded-dcraw.tiff', { limitInputPixels: false })
const mockSharp = vi.mocked(sharp).mock.results[vi.mocked(sharp).mock.results.length - 1].value
expect(mockSharp.rotate).not.toHaveBeenCalled()
expect(mockSharp.toColorspace).toHaveBeenCalledWith('srgb')
expect(mockSharp.webp).toHaveBeenCalledWith({ quality: 85 })
expect(mockSharp.toFile).toHaveBeenCalledWith(outputFile)
expect(cleanupSpy).toHaveBeenCalled()
})
it('should apply orientation rotation when transcoding RAW image', async () => {
const rawPath = path.join(tempDir, 'rotated.cr3')
const outputFile = path.join(tempDir, 'output-rotated.webp')