From: Amine Khaldi Date: Fri, 20 Nov 2015 10:39:43 +0000 (+0000) Subject: [ICCVID] Sync with Wine Staging 1.7.55. CORE-10536 X-Git-Tag: ReactOS-0.4.0~104 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=cf938d6d214a803e95d912f8dc784ff56da9fbdb [ICCVID] Sync with Wine Staging 1.7.55. CORE-10536 svn path=/trunk/; revision=69956 --- diff --git a/reactos/dll/win32/iccvid/iccvid.c b/reactos/dll/win32/iccvid/iccvid.c index 5feefda4ad8..76bb15b7fa5 100644 --- a/reactos/dll/win32/iccvid/iccvid.c +++ b/reactos/dll/win32/iccvid/iccvid.c @@ -145,6 +145,15 @@ int uvr, uvg, uvb; } } +static inline long get_addr(BOOL inverted, unsigned long x, unsigned long y, + int frm_stride, int bpp, unsigned int out_height) +{ + /* Returns the starting position of a line from top-down or bottom-up */ + if (inverted) + return y * frm_stride + x * bpp; + else + return (out_height - 1 - y) * frm_stride + x * bpp; +} #define MAKECOLOUR32(r,g,b) (((r) << 16) | ((g) << 8) | (b)) /*#define MAKECOLOUR24(r,g,b) (((r) << 16) | ((g) << 8) | (b))*/ @@ -152,16 +161,18 @@ int uvr, uvg, uvb; #define MAKECOLOUR15(r,g,b) (((r) >> 3) << 10)| (((g) >> 3) << 5)| (((b) >> 3) << 0) /* ------------------------------------------------------------------------ */ -static void cvid_v1_32(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb) +static void cvid_v1_32(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb) { unsigned long *vptr = (unsigned long *)frm; -#ifndef ORIGINAL -int row_inc = -stride/4; -#else -int row_inc = stride/4; -#endif +int row_inc; int x, y; + if (!inverted) + row_inc = -stride/4; + else + row_inc = stride/4; + /* fill 4x4 block of pixels with colour values from codebook */ for (y = 0; y < 4; y++) { @@ -173,18 +184,19 @@ int x, y; /* ------------------------------------------------------------------------ */ -static void cvid_v4_32(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb0, - cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +static void cvid_v4_32(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb0, cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) { unsigned long *vptr = (unsigned long *)frm; -#ifndef ORIGINAL -int row_inc = -stride/4; -#else -int row_inc = stride/4; -#endif +int row_inc; int x, y; cvid_codebook * cb[] = {cb0,cb1,cb2,cb3}; + if (!inverted) + row_inc = -stride/4; + else + row_inc = stride/4; + /* fill 4x4 block of pixels with colour values from codebooks */ for (y = 0; y < 4; y++) { @@ -196,15 +208,17 @@ cvid_codebook * cb[] = {cb0,cb1,cb2,cb3}; /* ------------------------------------------------------------------------ */ -static void cvid_v1_24(unsigned char *vptr, unsigned char *limit, int stride, cvid_codebook *cb) +static void cvid_v1_24(unsigned char *vptr, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb) { -#ifndef ORIGINAL -int row_inc = -stride; -#else -int row_inc = stride; -#endif +int row_inc; int x, y; + if (!inverted) + row_inc = -stride; + else + row_inc = stride; + /* fill 4x4 block of pixels with colour values from codebook */ for (y = 0; y < 4; y++) { @@ -220,17 +234,18 @@ int x, y; /* ------------------------------------------------------------------------ */ -static void cvid_v4_24(unsigned char *vptr, unsigned char *limit, int stride, cvid_codebook *cb0, - cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +static void cvid_v4_24(unsigned char *vptr, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb0, cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) { -#ifndef ORIGINAL -int row_inc = -stride; -#else -int row_inc = stride; -#endif +int row_inc; cvid_codebook * cb[] = {cb0,cb1,cb2,cb3}; int x, y; + if (!inverted) + row_inc = -stride; + else + row_inc = stride; + /* fill 4x4 block of pixels with colour values from codebooks */ for (y = 0; y < 4; y++) { @@ -246,16 +261,18 @@ int x, y; /* ------------------------------------------------------------------------ */ -static void cvid_v1_16(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb) +static void cvid_v1_16(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb) { unsigned short *vptr = (unsigned short *)frm; -#ifndef ORIGINAL -int row_inc = -stride/2; -#else -int row_inc = stride/2; -#endif +int row_inc; int x, y; + if (!inverted) + row_inc = -stride/2; + else + row_inc = stride/2; + /* fill 4x4 block of pixels with colour values from codebook */ for (y = 0; y < 4; y++) { @@ -267,18 +284,19 @@ int x, y; /* ------------------------------------------------------------------------ */ -static void cvid_v4_16(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb0, - cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +static void cvid_v4_16(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb0, cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) { unsigned short *vptr = (unsigned short *)frm; -#ifndef ORIGINAL -int row_inc = -stride/2; -#else -int row_inc = stride/2; -#endif +int row_inc; cvid_codebook * cb[] = {cb0,cb1,cb2,cb3}; int x, y; + if (!inverted) + row_inc = -stride/2; + else + row_inc = stride/2; + /* fill 4x4 block of pixels with colour values from codebooks */ for (y = 0; y < 4; y++) { @@ -289,16 +307,18 @@ int x, y; } /* ------------------------------------------------------------------------ */ -static void cvid_v1_15(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb) +static void cvid_v1_15(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb) { unsigned short *vptr = (unsigned short *)frm; -#ifndef ORIGINAL -int row_inc = -stride/2; -#else -int row_inc = stride/2; -#endif +int row_inc; int x, y; + if (!inverted) + row_inc = -stride/2; + else + row_inc = stride/2; + /* fill 4x4 block of pixels with colour values from codebook */ for (y = 0; y < 4; y++) { @@ -310,18 +330,19 @@ int x, y; /* ------------------------------------------------------------------------ */ -static void cvid_v4_15(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb0, - cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +static void cvid_v4_15(unsigned char *frm, unsigned char *limit, int stride, BOOL inverted, + cvid_codebook *cb0, cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) { unsigned short *vptr = (unsigned short *)frm; -#ifndef ORIGINAL -int row_inc = -stride/2; -#else -int row_inc = stride/2; -#endif +int row_inc; cvid_codebook * cb[] = {cb0,cb1,cb2,cb3}; int x, y; + if (!inverted) + row_inc = -stride/2; + else + row_inc = stride/2; + /* fill 4x4 block of pixels with colour values from codebooks */ for (y = 0; y < 4; y++) { @@ -369,8 +390,9 @@ static void free_cvinfo( cinepak_info *cvinfo ) } typedef void (*fn_cvid_v1)(unsigned char *frm, unsigned char *limit, - int stride, cvid_codebook *cb); -typedef void (*fn_cvid_v4)(unsigned char *frm, unsigned char *limit, int stride, + int stride, BOOL inverted, cvid_codebook *cb); +typedef void (*fn_cvid_v4)(unsigned char *frm, unsigned char *limit, + int stride, BOOL inverted, cvid_codebook *cb0, cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3); @@ -380,33 +402,42 @@ typedef void (*fn_cvid_v4)(unsigned char *frm, unsigned char *limit, int stride, * context - the context created by decode_cinepak_init(). * buf - the input buffer to be decoded * size - the size of the input buffer - * frame - the output frame buffer (24 or 32 bit per pixel) - * width - the width of the output frame - * height - the height of the output frame + * output - the output frame buffer (24 or 32 bit per pixel) + * out_width - the width of the output frame + * out_height - the height of the output frame * bit_per_pixel - the number of bits per pixel allocated to the output * frame (only 24 or 32 bpp are supported) + * inverted - if true the output frame is written top-down */ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, - unsigned char *frame, unsigned int width, unsigned int height, int bit_per_pixel) + unsigned char *output, unsigned int out_width, unsigned int out_height, int bit_per_pixel, BOOL inverted) { cvid_codebook *v4_codebook, *v1_codebook, *codebook = NULL; - unsigned long x, y, y_bottom, frame_flags, strips, cv_width, cv_height, - cnum, strip_id, chunk_id, x0, y0, x1, y1, ci, flag, mask; - long len, top_size, chunk_size; + unsigned long x, y, y_bottom, cnum, strip_id, chunk_id, + x0, y0, x1, y1, ci, flag, mask; + long top_size, chunk_size; unsigned char *frm_ptr; - unsigned int i, cur_strip; + unsigned int i, cur_strip, addr; int d0, d1, d2, d3, frm_stride, bpp = 3; fn_cvid_v1 cvid_v1 = cvid_v1_24; fn_cvid_v4 cvid_v4 = cvid_v4_24; + struct frame_header + { + unsigned char flags; + unsigned long length; + unsigned short width; + unsigned short height; + unsigned short strips; + } frame; y = 0; y_bottom = 0; in_buffer = buf; - frame_flags = get_byte(); - len = get_byte() << 16; - len |= get_byte() << 8; - len |= get_byte(); + frame.flags = get_byte(); + frame.length = get_byte() << 16; + frame.length |= get_byte() << 8; + frame.length |= get_byte(); switch(bit_per_pixel) { @@ -432,32 +463,32 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, break; } - frm_stride = width * bpp; - frm_ptr = frame; + frm_stride = out_width * bpp; + frm_ptr = output; - if(len != size) + if(frame.length != size) { - if(len & 0x01) len++; /* AVIs tend to have a size mismatch */ - if(len != size) + if(frame.length & 0x01) frame.length++; /* AVIs tend to have a size mismatch */ + if(frame.length != size) { - ERR("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, len); + ERR("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, frame.length); /* return; */ } } - cv_width = get_word(); - cv_height = get_word(); - strips = get_word(); + frame.width = get_word(); + frame.height = get_word(); + frame.strips = get_word(); - if(strips > cvinfo->strip_num) + if(frame.strips > cvinfo->strip_num) { - if(strips >= MAX_STRIPS) + if(frame.strips >= MAX_STRIPS) { ERR("CVID: strip overflow (more than %d)\n", MAX_STRIPS); return; } - for(i = cvinfo->strip_num; i < strips; i++) + for(i = cvinfo->strip_num; i < frame.strips; i++) { if((cvinfo->v4_codebook[i] = heap_alloc(sizeof(cvid_codebook) * 260)) == NULL) { @@ -472,16 +503,17 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, } } } - cvinfo->strip_num = strips; + cvinfo->strip_num = frame.strips; - TRACE("CVID: <%ld,%ld> strips %ld\n", cv_width, cv_height, strips); + TRACE("CVID: %ux%u, strips %u, length %lu\n", + frame.width, frame.height, frame.strips, frame.length); - for(cur_strip = 0; cur_strip < strips; cur_strip++) + for(cur_strip = 0; cur_strip < frame.strips; cur_strip++) { v4_codebook = cvinfo->v4_codebook[cur_strip]; v1_codebook = cvinfo->v1_codebook[cur_strip]; - if((cur_strip > 0) && (!(frame_flags & 0x01))) + if((cur_strip > 0) && (!(frame.flags & 0x01))) { memcpy(cvinfo->v4_codebook[cur_strip], cvinfo->v4_codebook[cur_strip-1], 260 * sizeof(cvid_codebook)); memcpy(cvinfo->v1_codebook[cur_strip], cvinfo->v1_codebook[cur_strip-1], 260 * sizeof(cvid_codebook)); @@ -497,8 +529,8 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, y_bottom += y1; top_size -= 12; x = 0; - if(x1 != width) - WARN("CVID: Warning x1 (%ld) != width (%d)\n", x1, width); + if(x1 != out_width) + WARN("CVID: Warning x1 (%ld) != width (%d)\n", x1, out_width); TRACE(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld\n", cur_strip, strip_id, top_size, x0, y0, x1, y1, y_bottom); @@ -596,24 +628,20 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, d2 = get_byte(); d3 = get_byte(); chunk_size -= 4; -#ifdef ORIGINAL - cvid_v4(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); -#else - cvid_v4(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); -#endif + + addr = get_addr(inverted, x, y, frm_stride, bpp, out_height); + cvid_v4(frm_ptr + addr, output, frm_stride, inverted, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); } else /* 1 byte per block */ { -#ifdef ORIGINAL - cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte()); -#else - cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte()); -#endif + addr = get_addr(inverted, x, y, frm_stride, bpp, out_height); + cvid_v1(frm_ptr + addr, output, frm_stride, inverted, v1_codebook + get_byte()); + chunk_size--; } x += 4; - if(x >= width) + if(x >= out_width) { x = 0; y += 4; @@ -652,26 +680,22 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, d2 = get_byte(); d3 = get_byte(); chunk_size -= 4; -#ifdef ORIGINAL - cvid_v4(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); -#else - cvid_v4(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); -#endif + + addr = get_addr(inverted, x, y, frm_stride, bpp, out_height); + cvid_v4(frm_ptr + addr, output, frm_stride, inverted, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3); } else /* V1 */ { chunk_size--; -#ifdef ORIGINAL - cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte()); -#else - cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte()); -#endif + + addr = get_addr(inverted, x, y, frm_stride, bpp, out_height); + cvid_v1(frm_ptr + addr, output, frm_stride, inverted, v1_codebook + get_byte()); } } /* else SKIP */ mask >>= 1; x += 4; - if(x >= width) + if(x >= out_width) { x = 0; y += 4; @@ -685,14 +709,12 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, case 0x3200: /* each byte is a V1 codebook */ while((chunk_size > 0) && (y < y_bottom)) { -#ifdef ORIGINAL - cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte()); -#else - cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte()); -#endif + addr = get_addr(inverted, x, y, frm_stride, bpp, out_height); + cvid_v1(frm_ptr + addr, output, frm_stride, inverted, v1_codebook + get_byte()); + chunk_size--; x += 4; - if(x >= width) + if(x >= out_width) { x = 0; y += 4; @@ -709,10 +731,10 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, } } - if(len != size) + if(frame.length != size) { - if(len & 0x01) len++; /* AVIs tend to have a size mismatch */ - if(len != size) + if(frame.length & 0x01) frame.length++; /* AVIs tend to have a size mismatch */ + if(frame.length != size) { long xlen; skip_byte(); @@ -720,7 +742,7 @@ static void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size, xlen |= get_byte() << 8; xlen |= get_byte(); /* Read Len */ WARN("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n", - size, len, xlen); + size, frame.length, xlen); } } } @@ -777,7 +799,11 @@ static LRESULT ICCVID_DecompressQuery( ICCVID_Info *info, LPBITMAPINFO in, LPBIT if( in->bmiHeader.biPlanes != out->bmiHeader.biPlanes ) return ICERR_BADFORMAT; if( in->bmiHeader.biHeight != out->bmiHeader.biHeight ) - return ICERR_BADFORMAT; + { + if( in->bmiHeader.biHeight != -out->bmiHeader.biHeight ) + return ICERR_BADFORMAT; + TRACE("Detected inverted height for video output\n"); + } if( in->bmiHeader.biWidth != out->bmiHeader.biWidth ) return ICERR_BADFORMAT; @@ -869,6 +895,7 @@ static LRESULT ICCVID_DecompressBegin( ICCVID_Info *info, LPBITMAPINFO in, LPBIT static LRESULT ICCVID_Decompress( ICCVID_Info *info, ICDECOMPRESS *icd, DWORD size ) { LONG width, height; + BOOL inverted; TRACE("ICM_DECOMPRESS %p %p %d\n", info, icd, size); @@ -882,9 +909,10 @@ static LRESULT ICCVID_Decompress( ICCVID_Info *info, ICDECOMPRESS *icd, DWORD si width = icd->lpbiInput->biWidth; height = icd->lpbiInput->biHeight; + inverted = -icd->lpbiOutput->biHeight == height; decode_cinepak(info->cvinfo, icd->lpInput, icd->lpbiInput->biSizeImage, - icd->lpOutput, width, height, info->bits_per_pixel); + icd->lpOutput, width, height, info->bits_per_pixel, inverted); return ICERR_OK; } @@ -892,6 +920,7 @@ static LRESULT ICCVID_Decompress( ICCVID_Info *info, ICDECOMPRESS *icd, DWORD si static LRESULT ICCVID_DecompressEx( ICCVID_Info *info, ICDECOMPRESSEX *icd, DWORD size ) { LONG width, height; + BOOL inverted; TRACE("ICM_DECOMPRESSEX %p %p %d\n", info, icd, size); @@ -907,9 +936,10 @@ static LRESULT ICCVID_DecompressEx( ICCVID_Info *info, ICDECOMPRESSEX *icd, DWOR width = icd->lpbiSrc->biWidth; height = icd->lpbiSrc->biHeight; + inverted = -icd->lpbiDst->biHeight == height; decode_cinepak(info->cvinfo, icd->lpSrc, icd->lpbiSrc->biSizeImage, - icd->lpDst, width, height, info->bits_per_pixel); + icd->lpDst, width, height, info->bits_per_pixel, inverted); return ICERR_OK; } diff --git a/reactos/media/doc/README.WINE b/reactos/media/doc/README.WINE index 29b38587e23..34f1fbdfffb 100644 --- a/reactos/media/doc/README.WINE +++ b/reactos/media/doc/README.WINE @@ -74,7 +74,7 @@ reactos/dll/win32/hhctrl.ocx # Synced to WineStaging-1.7.47 reactos/dll/win32/hlink # Synced to WineStaging-1.7.47 reactos/dll/win32/hnetcfg # Synced to WineStaging-1.7.55 reactos/dll/win32/httpapi # Synced to WineStaging-1.7.47 -reactos/dll/win32/iccvid # Synced to WineStaging-1.7.47 +reactos/dll/win32/iccvid # Synced to WineStaging-1.7.55 reactos/dll/win32/icmp # Out of sync reactos/dll/win32/ieframe # Synced to WineStaging-1.7.55 reactos/dll/win32/imaadp32.acm # Synced to WineStaging-1.7.47