From 283f51f64b37e0b3625041646b93b105e6dee3a0 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sat, 26 Apr 2014 18:13:05 +0000 Subject: [PATCH] [MSRLE32] * Sync with Wine 1.7.17. CORE-8080 svn path=/trunk/; revision=63001 --- reactos/dll/win32/msrle32/msrle32.c | 79 ++++++++--------------- reactos/dll/win32/msrle32/msrle_private.h | 3 +- reactos/media/doc/README.WINE | 2 +- 3 files changed, 29 insertions(+), 55 deletions(-) diff --git a/reactos/dll/win32/msrle32/msrle32.c b/reactos/dll/win32/msrle32/msrle32.c index 16daa80644a..146f7e7d534 100644 --- a/reactos/dll/win32/msrle32/msrle32.c +++ b/reactos/dll/win32/msrle32/msrle32.c @@ -39,7 +39,6 @@ static HINSTANCE MSRLE32_hModule = 0; #define ABS(a) ((a) < 0 ? -(a) : (a)) #define SQR(a) ((a) * (a)) -#define QUALITY_to_DIST(q) (ICQUALITY_HIGH - q) static inline WORD ColorCmp(WORD clr1, WORD clr2) { UINT a = clr1 - clr2; @@ -257,7 +256,7 @@ static LONG MSRLE32_GetMaxCompressedSize(LPCBITMAPINFOHEADER lpbi) } size = (2 + a * (2 + ((a + 2) & ~2)) + b * (2 + ((b + 2) & ~2))); - return size * lpbi->biHeight; + return size * lpbi->biHeight + 2; } /* lpP => current pos in previous frame @@ -457,8 +456,7 @@ static INT MSRLE32_CompressRLE4Line(const CodecInfo *pi, const WORD *lpP, static INT MSRLE32_CompressRLE8Line(const CodecInfo *pi, const WORD *lpP, const WORD *lpC, LPCBITMAPINFOHEADER lpbi, - const BYTE *lpIn, LONG lDist, - INT x, LPBYTE *ppOut, + const BYTE *lpIn, INT x, LPBYTE *ppOut, DWORD *lpSizeImage) { LPBYTE lpOut = *ppOut; @@ -472,13 +470,13 @@ static INT MSRLE32_CompressRLE8Line(const CodecInfo *pi, const WORD *lpP, pos = x; clr = lpC[pos++]; for (count = 1; pos < lpbi->biWidth; count++) { - if (ColorCmp(clr, lpC[pos++]) > lDist) + if (ColorCmp(clr, lpC[pos++]) > 0) break; } if (count < 2) { /* add some more pixels for absoluting if possible */ - count += countDiffRLE8(lpP, lpC - 1, lpC, pos-1, lDist, lpbi->biWidth); + count += countDiffRLE8(lpP, lpC - 1, lpC, pos-1, 0, lpbi->biWidth); assert(count > 0); @@ -547,7 +545,7 @@ LRESULT MSRLE32_CompressRLE4(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, LPBYTE lpOut, BOOL isKey) { LPWORD lpC; - LONG lLine, lInLine, lDist; + LONG lLine, lInLine; LPBYTE lpOutStart = lpOut; /* pre-conditions */ @@ -556,7 +554,6 @@ LRESULT MSRLE32_CompressRLE4(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, assert(pi->pCurFrame != NULL); lpC = pi->pCurFrame; - lDist = QUALITY_to_DIST(pi->dwQuality); lInLine = DIBWIDTHBYTES(*lpbiIn); lLine = WIDTHBYTES(lpbiOut->biWidth * 16) / 2; @@ -569,7 +566,7 @@ LRESULT MSRLE32_CompressRLE4(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, x = 0; do { - x = MSRLE32_CompressRLE4Line(pi, NULL, lpC, lpbiIn, lpIn, lDist, x, + x = MSRLE32_CompressRLE4Line(pi, NULL, lpC, lpbiIn, lpIn, 0, x, &lpOut, &lpbiOut->biSizeImage); } while (x < lpbiOut->biWidth); @@ -603,7 +600,7 @@ LRESULT MSRLE32_CompressRLE4(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, if (jumpx == -1) jumpx = x; for (count = 0, pos = x; pos < lpbiOut->biWidth; pos++, count++) { - if (ColorCmp(lpP[pos], lpC[pos]) > lDist) + if (ColorCmp(lpP[pos], lpC[pos]) > 0) break; } @@ -663,7 +660,7 @@ LRESULT MSRLE32_CompressRLE4(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, if (x < lpbiOut->biWidth) { /* skipped the 'same' things corresponding to previous frame */ - x = MSRLE32_CompressRLE4Line(pi, lpP, lpC, lpbiIn, lpIn, lDist, x, + x = MSRLE32_CompressRLE4Line(pi, lpP, lpC, lpbiIn, lpIn, 0, x, &lpOut, &lpbiOut->biSizeImage); } } while (x < lpbiOut->biWidth); @@ -701,7 +698,7 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, LPBYTE lpOut, BOOL isKey) { LPWORD lpC; - LONG lDist, lInLine, lLine; + LONG lInLine, lLine; LPBYTE lpOutStart = lpOut; assert(pi != NULL && lpbiOut != NULL); @@ -709,7 +706,6 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, assert(pi->pCurFrame != NULL); lpC = pi->pCurFrame; - lDist = QUALITY_to_DIST(pi->dwQuality); lInLine = DIBWIDTHBYTES(*lpbiIn); lLine = WIDTHBYTES(lpbiOut->biWidth * 16) / 2; @@ -722,7 +718,7 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, x = 0; do { - x = MSRLE32_CompressRLE8Line(pi, NULL, lpC, lpbiIn, lpIn, lDist, x, + x = MSRLE32_CompressRLE8Line(pi, NULL, lpC, lpbiIn, lpIn, x, &lpOut, &lpbiOut->biSizeImage); assert(lpOut == (lpOutStart + lpbiOut->biSizeImage)); } while (x < lpbiOut->biWidth); @@ -757,7 +753,7 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, if (jumpx == -1) jumpx = x; for (count = 0, pos = x; pos < lpbiOut->biWidth; pos++, count++) { - if (ColorCmp(lpP[pos], lpC[pos]) > lDist) + if (ColorCmp(lpP[pos], lpC[pos]) > 0) break; } @@ -804,7 +800,7 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, if (x < lpbiOut->biWidth) { /* skip the 'same' things corresponding to previous frame */ - x = MSRLE32_CompressRLE8Line(pi, lpP, lpC, lpbiIn, lpIn, lDist, x, + x = MSRLE32_CompressRLE8Line(pi, lpP, lpC, lpbiIn, lpIn, x, &lpOut, &lpbiOut->biSizeImage); assert(lpOut == (lpOutStart + lpbiOut->biSizeImage)); } @@ -823,14 +819,16 @@ LRESULT MSRLE32_CompressRLE8(const CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, } } - /* add EOL -- will be changed to EOI */ + /* add EOL */ lpbiOut->biSizeImage += 2; *((LPWORD)lpOut) = 0; lpOut += sizeof(WORD); } - /* change EOL to EOI -- end of image */ - lpOut[-1] = 1; + /* add EOI -- end of image */ + lpbiOut->biSizeImage += 2; + *lpOut++ = 0; + *lpOut++ = 1; assert(lpOut == (lpOutStart + lpbiOut->biSizeImage)); return ICERR_OK; @@ -1144,7 +1142,6 @@ static CodecInfo* Open(LPICOPEN icinfo) pi->fccHandler = icinfo->fccHandler; pi->bCompress = FALSE; - pi->dwQuality = MSRLE32_DEFAULTQUALITY; pi->nPrevFrame = -1; pi->pPrevFrame = pi->pCurFrame = NULL; @@ -1195,21 +1192,6 @@ static LRESULT GetInfo(const CodecInfo *pi, ICINFO *icinfo, DWORD dwSize) return sizeof(ICINFO); } -static LRESULT SetQuality(CodecInfo *pi, LONG lQuality) -{ - /* pre-condition */ - assert(pi != NULL); - - if (lQuality == -1) - lQuality = MSRLE32_DEFAULTQUALITY; - else if (ICQUALITY_LOW > lQuality || lQuality > ICQUALITY_HIGH) - return ICERR_BADPARAM; - - pi->dwQuality = (DWORD)lQuality; - - return ICERR_OK; -} - static LRESULT Configure(const CodecInfo *pi, HWND hWnd) { /* pre-condition */ @@ -1438,6 +1420,7 @@ static LRESULT CompressBegin(CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn, static LRESULT Compress(CodecInfo *pi, ICCOMPRESS* lpic, DWORD dwSize) { + BOOL is_key; int i; TRACE("(%p,%p,%u)\n",pi,lpic,dwSize); @@ -1486,24 +1469,22 @@ static LRESULT Compress(CodecInfo *pi, ICCOMPRESS* lpic, DWORD dwSize) computeInternalFrame(pi, lpic->lpbiPrev, lpic->lpPrev); /* swap buffers for current and previous frame */ - /* Don't free and alloc new -- costs to much time and they are of equal size ! */ + /* Don't free and alloc new -- costs too much time and they are of equal size ! */ pTmp = pi->pPrevFrame; pi->pPrevFrame = pi->pCurFrame; pi->pCurFrame = pTmp; pi->nPrevFrame = lpic->lFrameNum; } - for (i = 0; i < 3; i++) { - SetQuality(pi, lpic->dwQuality); + is_key = (lpic->dwFlags & ICCOMPRESS_KEYFRAME) != 0; + for (i = 0; i < 3; i++) { lpic->lpbiOutput->biSizeImage = 0; if (lpic->lpbiOutput->biBitCount == 4) - MSRLE32_CompressRLE4(pi, lpic->lpbiInput, lpic->lpInput, - lpic->lpbiOutput, lpic->lpOutput, (lpic->dwFlags & ICCOMPRESS_KEYFRAME) != 0); + MSRLE32_CompressRLE4(pi, lpic->lpbiInput, lpic->lpInput, lpic->lpbiOutput, lpic->lpOutput, is_key); else - MSRLE32_CompressRLE8(pi, lpic->lpbiInput, lpic->lpInput, - lpic->lpbiOutput, lpic->lpOutput, (lpic->dwFlags & ICCOMPRESS_KEYFRAME) != 0); + MSRLE32_CompressRLE8(pi, lpic->lpbiInput, lpic->lpInput, lpic->lpbiOutput, lpic->lpOutput, is_key); if (lpic->dwFrameSize == 0 || lpic->lpbiOutput->biSizeImage < lpic->dwFrameSize) @@ -1520,7 +1501,7 @@ static LRESULT Compress(CodecInfo *pi, ICCOMPRESS* lpic, DWORD dwSize) if (lpic->dwFrameSize == 0 || lpic->lpbiOutput->biSizeImage < lpic->dwFrameSize) { WARN("switched to keyframe, was small enough!\n"); - *lpic->lpdwFlags |= ICCOMPRESS_KEYFRAME; + is_key = TRUE; *lpic->lpckid = MAKEAVICKID(cktypeDIBbits, StreamFromFOURCC(*lpic->lpckid)); break; @@ -1534,7 +1515,7 @@ static LRESULT Compress(CodecInfo *pi, ICCOMPRESS* lpic, DWORD dwSize) } { /* swap buffer for current and previous frame */ - /* Don't free and alloc new -- costs to much time and they are of equal size ! */ + /* Don't free and alloc new -- costs too much time and they are of equal size ! */ LPWORD pTmp = pi->pPrevFrame; pi->pPrevFrame = pi->pCurFrame; @@ -1542,6 +1523,8 @@ static LRESULT Compress(CodecInfo *pi, ICCOMPRESS* lpic, DWORD dwSize) pi->nPrevFrame = lpic->lFrameNum; } + /* FIXME: What is AVIIF_TWOCC? */ + *lpic->lpdwFlags |= AVIIF_TWOCC | (is_key ? AVIIF_KEYFRAME : 0); return ICERR_OK; } @@ -1850,14 +1833,6 @@ LRESULT CALLBACK MSRLE32_DriverProc(DWORD_PTR dwDrvID, HDRVR hDrv, UINT uMsg, return ICERR_OK; } break; - case ICM_GETQUALITY: - if ((LPVOID)lParam1 != NULL) { - *((LPDWORD)lParam1) = pi->dwQuality; - return ICERR_OK; - } - break; - case ICM_SETQUALITY: - return SetQuality(pi, *(LPLONG)lParam1); case ICM_COMPRESS_GET_FORMAT: return CompressGetFormat(pi, (LPCBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2); diff --git a/reactos/dll/win32/msrle32/msrle_private.h b/reactos/dll/win32/msrle32/msrle_private.h index 58bb7b4a78a..88b90740261 100644 --- a/reactos/dll/win32/msrle32/msrle_private.h +++ b/reactos/dll/win32/msrle32/msrle_private.h @@ -38,7 +38,7 @@ #define IDS_DESCRIPTION 101 #define IDS_ABOUT 102 -#define MSRLE32_DEFAULTQUALITY (75 * ICQUALITY_HIGH) / 100 +#define MSRLE32_DEFAULTQUALITY (85 * ICQUALITY_HIGH) / 100 #define FOURCC_RLE mmioFOURCC('R','L','E',' ') #define FOURCC_RLE4 mmioFOURCC('R','L','E','4') @@ -50,7 +50,6 @@ typedef struct _CodecInfo { FOURCC fccHandler; - DWORD dwQuality; BOOL bCompress; LONG nPrevFrame; diff --git a/reactos/media/doc/README.WINE b/reactos/media/doc/README.WINE index 1d01668a39f..2fde1fda0af 100644 --- a/reactos/media/doc/README.WINE +++ b/reactos/media/doc/README.WINE @@ -125,7 +125,7 @@ reactos/dll/win32/msimtf # Synced to Wine-1.7.1 reactos/dll/win32/msisip # Synced to Wine-1.7.1 reactos/dll/win32/msisys.ocx # Synced to Wine-1.7.1 reactos/dll/win32/msnet32 # Synced to Wine-1.7.1 -reactos/dll/win32/msrle32 # Synced to Wine-1.7.1 +reactos/dll/win32/msrle32 # Synced to Wine-1.7.17 reactos/dll/win32/mssign32 # Synced to Wine-1.7.1 reactos/dll/win32/mssip32 # Synced to Wine-1.7.1 reactos/dll/win32/mstask # Synced to Wine-1.7.1