4a2e2a458560 — Laurens Holst 5 years ago
PNGScanner: Support images whose scanlines do not fit in the buffer.

Like an RGBA image with width > 256.
1 files changed, 22 insertions(+), 5 deletions(-)

M src/PNGScanner.asm
M src/PNGScanner.asm +22 -5
@@ 64,10 64,6 @@ Not16Bpp:
 	ld (ix + PNGScanner.lineSize + 1),h
 	neg
 	ld (ix + PNGScanner.bytesPerPixelNegated),a
-	ld bc,PNGScanner_MAX_LINESIZE
-	scf
-	sbc hl,bc
-	jp nc,PNG_TerminateWithUnsupportedError
 	ld e,ixl
 	ld d,ixh
 	ret

          
@@ 331,9 327,29 @@ Done:
 ; iy = reader
 ; ix = this
 ; bc <- bytes read (nested 8-bit loop format)
-PNGScanner_ReadBlock:
+PNGScanner_ReadBlock: PROC
 	ld c,(ix + PNGScanner.lineSize)
 	ld b,(ix + PNGScanner.lineSize + 1)
+	ld hl,-PNGScanner_MAX_LINESIZE - 1
+	add hl,bc
+	jr nc,Read
+	inc hl
+	push hl
+	ld bc,PNGScanner_MAX_LINESIZE
+	call Read
+	pop hl
+	push bc
+	bit 4,(ix + PNGScanner.bitDepth)
+	jr z,No16Bpp
+	add hl,hl
+	call c,System_ThrowException
+No16Bpp:
+	ld c,l
+	ld b,h
+	call Reader_Skip_IY
+	pop bc
+	ret
+Read:
 	bit 4,(ix + PNGScanner.bitDepth)
 	jp nz,PNGScanner_ReadBlock16Bpp
 	call Reader_ReadBlock_IY

          
@@ 343,6 359,7 @@ PNGScanner_ReadBlock:
 	ld c,b
 	ld b,a
 	ret
+	ENDP
 
 ; bc = line size
 ; de = scanline