From e875b458b67e670d7eb169f74b835f75008d01c2 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 24 Feb 2022 14:39:08 +0000 Subject: [PATCH 1/2] Fix compiler error that fails to honour post-increment order in inlined code The fix in consistent with other functions. The problem was corupted images cause by the compiler inlining code and not putting post-inrement in correct place at end of inline code. --- picojpeg.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/picojpeg.c b/picojpeg.c index 2fae2a9..d12a362 100644 --- a/picojpeg.c +++ b/picojpeg.c @@ -1733,7 +1733,10 @@ static void convertCb(uint8 dstOfs) *pDstG++ = subAndClamp(pDstG[0], cbG); cbB = (cb + ((cb * 198U) >> 8U)) - 227U; - *pDstB++ = addAndClamp(pDstB[0], cbB); + pDstB[0] = addAndClamp(pDstB[0], cbB); + + ++pDstG; + ++pDstB; } } /*----------------------------------------------------------------------------*/ @@ -1754,7 +1757,10 @@ static void convertCr(uint8 dstOfs) *pDstR++ = addAndClamp(pDstR[0], crR); crG = ((cr * 183U) >> 8U) - 91; - *pDstG++ = subAndClamp(pDstG[0], crG); + pDstG[0] = subAndClamp(pDstG[0], crG); + + ++pDstR; + ++pDstG; } } /*----------------------------------------------------------------------------*/ From 969e432ea0488bf279a082a4c6459cc64232aeba Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 24 Feb 2022 14:41:52 +0000 Subject: [PATCH 2/2] Correct edit error in pull request --- picojpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/picojpeg.c b/picojpeg.c index d12a362..a45bb95 100644 --- a/picojpeg.c +++ b/picojpeg.c @@ -1730,7 +1730,7 @@ static void convertCb(uint8 dstOfs) int16 cbG, cbB; cbG = ((cb * 88U) >> 8U) - 44U; - *pDstG++ = subAndClamp(pDstG[0], cbG); + pDstG[0] = subAndClamp(pDstG[0], cbG); cbB = (cb + ((cb * 198U) >> 8U)) - 227U; pDstB[0] = addAndClamp(pDstB[0], cbB); @@ -1754,7 +1754,7 @@ static void convertCr(uint8 dstOfs) int16 crR, crG; crR = (cr + ((cr * 103U) >> 8U)) - 179; - *pDstR++ = addAndClamp(pDstR[0], crR); + pDstR[0] = addAndClamp(pDstR[0], crR); crG = ((cr * 183U) >> 8U) - 91; pDstG[0] = subAndClamp(pDstG[0], crG);