diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index dbafce602..59ccc7ca6 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -1175,15 +1175,18 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, return FALSE; } - nsc_process_message(xfc->codecs->nsc, cmd->bpp, cmd->width, cmd->height, - cmd->bitmapData, cmd->bitmapDataLength); + if (!nsc_process_message(xfc->codecs->nsc, cmd->bpp, cmd->width, cmd->height, + cmd->bitmapData, cmd->bitmapDataLength, + xfc->bitmap_buffer, xfc->format, 0, 0, 0, cmd->width, cmd->height)) + { + xf_unlock_x11(xfc, FALSE); + return FALSE; + } + XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); pSrcData = xfc->codecs->nsc->BitmapData; pDstData = xfc->bitmap_buffer; - freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - cmd->width, cmd->height, pSrcData, - PIXEL_FORMAT_BGRX32_VF, -1, 0, 0, xfc->palette); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) pDstData, cmd->width, cmd->height, xfc->scanline_pad, 0); XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, diff --git a/include/freerdp/codec/clear.h b/include/freerdp/codec/clear.h index 1485dfd2b..15d139a54 100644 --- a/include/freerdp/codec/clear.h +++ b/include/freerdp/codec/clear.h @@ -55,6 +55,8 @@ struct _CLEAR_CONTEXT UINT32 seqNumber; BYTE* TempBuffer; UINT32 TempSize; + UINT32 nTempStep; + UINT32 TempFormat; UINT32 format; CLEAR_GLYPH_ENTRY GlyphCache[4000]; UINT32 VBarStorageCursor; diff --git a/include/freerdp/codec/color.h b/include/freerdp/codec/color.h index 1b72f9617..92810981d 100644 --- a/include/freerdp/codec/color.h +++ b/include/freerdp/codec/color.h @@ -644,7 +644,6 @@ static INLINE UINT32 ReadColor(const BYTE* src, UINT32 format) case 16: case 15: color = ((UINT32)src[1] << 8) | src[0]; - color = ((color >> 11) & 0x1F) | (color & 0x7E0) | ((color & 0x1F) << 11); break; case 8: @@ -679,7 +678,6 @@ static INLINE BOOL WriteColor(BYTE* dst, UINT32 format, UINT32 color) case 16: case 15: - color = ((color >> 11) & 0x1F) | (color & 0x7E0) | ((color & 0x1F) << 11); dst[1] = color >> 8; dst[0] = color; break; diff --git a/include/freerdp/codec/nsc.h b/include/freerdp/codec/nsc.h index ab832de5c..10a9d8e67 100644 --- a/include/freerdp/codec/nsc.h +++ b/include/freerdp/codec/nsc.h @@ -89,7 +89,10 @@ FREERDP_API BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, UINT32 pixel_format); FREERDP_API BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT32 width, UINT32 height, - const BYTE* data, UINT32 length); + const BYTE* data, UINT32 length, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStride, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight); FREERDP_API BOOL nsc_compose_message(NSC_CONTEXT* context, wStream* s, const BYTE* bmpdata, UINT32 width, UINT32 height, UINT32 rowstride); diff --git a/include/freerdp/codec/planar.h b/include/freerdp/codec/planar.h index 8b9eaed77..59c840bc6 100644 --- a/include/freerdp/codec/planar.h +++ b/include/freerdp/codec/planar.h @@ -94,6 +94,9 @@ struct _BITMAP_PLANAR_CONTEXT BYTE* rlePlanes[4]; BYTE* rlePlanesBuffer; + + BYTE* pTempData; + UINT32 nTempStep; }; #ifdef __cplusplus diff --git a/include/freerdp/codec/progressive.h b/include/freerdp/codec/progressive.h index c7d9d5839..440429920 100644 --- a/include/freerdp/codec/progressive.h +++ b/include/freerdp/codec/progressive.h @@ -234,16 +234,19 @@ struct _PROGRESSIVE_CONTEXT extern "C" { #endif -FREERDP_API int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize); +FREERDP_API int progressive_compress(PROGRESSIVE_CONTEXT* progressive, + BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize); -FREERDP_API UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, - const BYTE* pSrcData, UINT32 SrcSize, - BYTE* pDstData, UINT32 DstFormat, - UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId); +FREERDP_API INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId); -FREERDP_API int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, UINT32 width, UINT32 height); -FREERDP_API int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId); +FREERDP_API INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* + progressive, UINT16 surfaceId, UINT32 width, UINT32 height); +FREERDP_API int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* + progressive, UINT16 surfaceId); FREERDP_API BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* progressive); diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c index 9f1ece978..8bde9c959 100644 --- a/libfreerdp/codec/clear.c +++ b/libfreerdp/codec/clear.c @@ -56,9 +56,9 @@ static BYTE CLEAR_8BIT_MASKS[9] = }; static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat, - UINT32 nXDst, UINT32 nYDst, - const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat, - UINT32 nWidth, UINT32 nHeight) + UINT32 nXDst, UINT32 nYDst, + const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat, + UINT32 nWidth, UINT32 nHeight) { UINT32 x, y; @@ -75,38 +75,29 @@ static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat, &pDstLine[(nXDst + x) * GetBytesPerPixel(DstFormat)]; UINT32 color = ReadColor(pSrcPixel, SrcFormat); color = ConvertColor(color, SrcFormat, - DstFormat, NULL); + DstFormat, NULL); WriteColor(pDstPixel, DstFormat, color); } } } static BOOL clear_decompress_nscodec(NSC_CONTEXT* nsc, UINT32 width, - UINT32 height, - const BYTE* bitmapData, UINT32 bitmapDataByteCount, - BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, - UINT32 nXDstRel, UINT32 nYDstRel) + UINT32 height, + const BYTE* bitmapData, UINT32 bitmapDataByteCount, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDstRel, UINT32 nYDstRel) { - UINT32 nSrcStep; - - if (nsc_process_message(nsc, 32, width, height, bitmapData, - bitmapDataByteCount) < 0) - return FALSE; - - nSrcStep = width * GetBytesPerPixel(nsc->format); - convert_color(pDstData, nDstStep, DstFormat, - nXDstRel, nYDstRel, - nsc->BitmapData, nSrcStep, nsc->format, - width, height); - return TRUE; + return nsc_process_message(nsc, 32, width, height, bitmapData, + bitmapDataByteCount, pDstData, DstFormat, + nDstStep, nXDstRel, nYDstRel, width, height); } static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, - UINT32 bitmapDataByteCount, - UINT32 width, UINT32 height, - BYTE* tmpBuffer, UINT32 nTmpBufferSize, - BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, - UINT32 nXDstRel, UINT32 nYDstRel) + UINT32 bitmapDataByteCount, + UINT32 width, UINT32 height, + BYTE* tmpBuffer, UINT32 nTmpBufferSize, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDstRel, UINT32 nYDstRel) { UINT32 i; UINT32 SrcFormat = PIXEL_FORMAT_BGR24; @@ -132,10 +123,10 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, for (i = 0; i < paletteCount; i++) { UINT32 color = GetColor(SrcFormat, - pSrcPixel8[2], - pSrcPixel8[1], - pSrcPixel8[0], - 0xFF); + pSrcPixel8[2], + pSrcPixel8[1], + pSrcPixel8[0], + 0xFF); palette[i] = color; pSrcPixel8 += GetBytesPerPixel(SrcFormat); } @@ -154,7 +145,7 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, stopIndex = bitmapData[bitmapDataOffset] & CLEAR_8BIT_MASKS[numBits]; suiteDepth = (bitmapData[bitmapDataOffset] >> numBits) & CLEAR_8BIT_MASKS[(8 - - numBits)]; + numBits)]; startIndex = stopIndex - suiteDepth; bitmapDataOffset++; runLengthFactor = (UINT32) bitmapData[bitmapDataOffset]; @@ -217,18 +208,18 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, return -1055; convert_color(pDstData, nDstStep, DstFormat, - nXDstRel, nYDstRel, - tmpBuffer, nSrcStep, SrcFormat, - width, height); + nXDstRel, nYDstRel, + tmpBuffer, nSrcStep, SrcFormat, + width, height); return TRUE; } static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, - const BYTE* residualData, - UINT32 residualByteCount, UINT32 SrcSize, - UINT32 nWidth, UINT32 nHeight, - BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, - UINT32 nXDst, UINT32 nYDst) + const BYTE* residualData, + UINT32 residualByteCount, UINT32 SrcSize, + UINT32 nWidth, UINT32 nHeight, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst) { UINT32 i; UINT32 nSrcStep; @@ -264,8 +255,8 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, return -1015; color = GetColor(clear->format, residualData[suboffset + 2], - residualData[suboffset + 1], - residualData[suboffset + 0], 0xFF); + residualData[suboffset + 1], + residualData[suboffset + 0], 0xFF); suboffset += 3; runLengthFactor = residualData[suboffset]; suboffset++; @@ -306,18 +297,18 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, return -1019; convert_color(pDstData, nDstStep, DstFormat, - nXDst, nYDst, - clear->TempBuffer, nSrcStep, clear->format, - nWidth, nHeight); + nXDst, nYDst, + clear->TempBuffer, nSrcStep, clear->format, + nWidth, nHeight); return TRUE; } static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, - const BYTE* bandsData, - UINT32 bandsByteCount, UINT32 SrcSize, - UINT32 nWidth, UINT32 nHeight, - BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, - UINT32 nXDst, UINT32 nYDst) + const BYTE* bandsData, + UINT32 bandsByteCount, UINT32 SrcSize, + UINT32 nWidth, UINT32 nHeight, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst) { UINT32 i, y; UINT32 count; @@ -359,9 +350,9 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, yEnd = *((UINT16*) &bandsData[suboffset + 6]); suboffset += 8; colorBkg = GetColor(clear->format, bandsData[suboffset + 2], - bandsData[suboffset + 1], - bandsData[suboffset + 0], - 0xFF); + bandsData[suboffset + 1], + bandsData[suboffset + 0], + 0xFF); suboffset += 3; if (xEnd < xStart) @@ -437,8 +428,8 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, BYTE* tmp; vBarShortEntry->size = vBarShortEntry->count; tmp = (BYTE*) realloc( - vBarShortEntry->pixels, - vBarShortEntry->count * GetBytesPerPixel(clear->format)); + vBarShortEntry->pixels, + vBarShortEntry->count * GetBytesPerPixel(clear->format)); if (!tmp) return -1; @@ -454,10 +445,10 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, BYTE* dstBuffer = &vBarShortEntry->pixels[y * GetBytesPerPixel(clear->format)]; UINT32 color = GetColor(clear->format, - pSrcPixel8[2], - pSrcPixel8[1], - pSrcPixel8[0], - 0xFF); + pSrcPixel8[2], + pSrcPixel8[1], + pSrcPixel8[0], + 0xFF); WriteColor(dstBuffer, clear->format, color); pSrcPixel8 += 3; } @@ -499,7 +490,7 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, BYTE* tmp; vBarEntry->size = vBarEntry->count; tmp = (BYTE*) realloc(vBarEntry->pixels, - vBarEntry->count * GetBytesPerPixel(clear->format)); + vBarEntry->count * GetBytesPerPixel(clear->format)); if (!tmp) return -1; @@ -535,13 +526,13 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; pSrcPixel = &vBarShortEntry->pixels[(y - vBarYOn) * GetBytesPerPixel( - clear->format)]; + clear->format)]; for (x = 0; x < count; x++) { UINT32 color; color = ReadColor(&vBarShortEntry->pixels[x * GetBytesPerPixel(clear->format)], - clear->format); + clear->format); WriteColor(dstBuffer, clear->format, color); dstBuffer += GetBytesPerPixel(clear->format); } @@ -571,10 +562,10 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, for (y = 0; y < count; y++) { BYTE* pDstPixel8 = &pDstData[((nYDstRel + y) * nDstStep) + - ((nXDstRel + i) * GetBytesPerPixel(DstFormat))]; + ((nXDstRel + i) * GetBytesPerPixel(DstFormat))]; UINT32 color = ReadColor(pSrcPixel, clear->format); color = ConvertColor(color, clear->format, - DstFormat, NULL); + DstFormat, NULL); WriteColor(pDstPixel8, DstFormat, color); pSrcPixel += GetBytesPerPixel(clear->format); } @@ -585,9 +576,9 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, } INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, - UINT32 SrcSize, - BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, - UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight) + UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight) { BYTE seqNumber; BYTE glyphFlags; @@ -658,9 +649,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, nSrcStep = nWidth * GetBytesPerPixel(clear->format); convert_color(pDstData, nDstStep, DstFormat, - nXDst, nYDst, - glyphData, nSrcStep, clear->format, - nWidth, nHeight); + nXDst, nYDst, + glyphData, nSrcStep, clear->format, + nWidth, nHeight); return 1; /* Finish */ } } @@ -677,9 +668,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, if (residualByteCount > 0) { if (!clear_decompress_residual_data(clear, - &pSrcData[offset], residualByteCount, - SrcSize - offset, nWidth, nHeight, - pDstData, DstFormat, nDstStep, nXDst, nYDst)) + &pSrcData[offset], residualByteCount, + SrcSize - offset, nWidth, nHeight, + pDstData, DstFormat, nDstStep, nXDst, nYDst)) return -1111; offset += residualByteCount; @@ -688,9 +679,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, if (bandsByteCount > 0) { if (!clear_decompress_bands_data(clear, - &pSrcData[offset], bandsByteCount, - SrcSize - offset, nWidth, nHeight, - pDstData, DstFormat, nDstStep, nXDst, nYDst)) + &pSrcData[offset], bandsByteCount, + SrcSize - offset, nWidth, nHeight, + pDstData, DstFormat, nDstStep, nXDst, nYDst)) return FALSE; offset += bandsByteCount; @@ -762,27 +753,27 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, return -1045; convert_color(pDstData, nDstStep, DstFormat, - nXDstRel, nYDstRel, - bitmapData, nSrcStep, - PIXEL_FORMAT_BGR24, - width, height); + nXDstRel, nYDstRel, + bitmapData, nSrcStep, + PIXEL_FORMAT_BGR24, + width, height); } else if (subcodecId == 1) /* NSCodec */ { if (!clear_decompress_nscodec(clear->nsc, width, height, - bitmapData, bitmapDataByteCount, - pDstData, DstFormat, nDstStep, - nXDstRel, nYDstRel)) + bitmapData, bitmapDataByteCount, + pDstData, DstFormat, nDstStep, + nXDstRel, nYDstRel)) return -1046; } else if (subcodecId == 2) /* CLEARCODEC_SUBCODEC_RLEX */ { if (!clear_decompress_subcode_rlex(bitmapData, - bitmapDataByteCount, - width, height, - clear->TempBuffer, clear->TempSize, - pDstData, DstFormat, nDstStep, - nXDstRel, nYDstRel)) + bitmapDataByteCount, + width, height, + clear->TempBuffer, clear->TempSize, + pDstData, DstFormat, nDstStep, + nXDstRel, nYDstRel)) return -1047; } else @@ -820,9 +811,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, glyphData = (BYTE*) glyphEntry->pixels; nSrcStep = nWidth * GetBytesPerPixel(clear->format); convert_color(pDstData, nDstStep, DstFormat, - nXDst, nYDst, - glyphData, nSrcStep, clear->format, - nWidth, nHeight); + nXDst, nYDst, + glyphData, nSrcStep, clear->format, + nWidth, nHeight); } if (offset != SrcSize) @@ -832,7 +823,7 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, } int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, UINT32* pDstSize) + BYTE** ppDstData, UINT32* pDstSize) { return 1; } diff --git a/libfreerdp/codec/h264.c b/libfreerdp/codec/h264.c index a9b93729f..2686e9237 100644 --- a/libfreerdp/codec/h264.c +++ b/libfreerdp/codec/h264.c @@ -1483,7 +1483,6 @@ static BOOL avc_yuv_to_rgb(H264_CONTEXT* h264, const RECTANGLE_16* regionRects, roi.width = width; roi.height = height; - // TODO: Color format converstion support!!! if (use444) { if (prims->YUV444ToRGB_8u_P3AC4R( diff --git a/libfreerdp/codec/nsc.c b/libfreerdp/codec/nsc.c index e566389d8..972251c54 100644 --- a/libfreerdp/codec/nsc.c +++ b/libfreerdp/codec/nsc.c @@ -46,35 +46,25 @@ static void nsc_decode(NSC_CONTEXT* context) { UINT16 x; UINT16 y; - UINT16 rw; - BYTE shift; - BYTE* yplane; - BYTE* coplane; - BYTE* cgplane; - BYTE* aplane; - INT16 y_val; - INT16 co_val; - INT16 cg_val; - INT16 r_val; - INT16 g_val; - INT16 b_val; - BYTE* bmpdata; - bmpdata = context->BitmapData; - rw = ROUND_UP_TO(context->width, 8); - shift = context->ColorLossLevel - 1; /* colorloss recovery + YCoCg shift */ - WLog_Print(context->priv->log, WLOG_DEBUG, - "NscDecode: width: %d height: %d ChromaSubsamplingLevel: %d", - context->width, context->height, context->ChromaSubsamplingLevel); + UINT16 rw = ROUND_UP_TO(context->width, 8); + BYTE shift = context->ColorLossLevel - 1; /* colorloss recovery + YCoCg shift */; + + BYTE* bmpdata = context->BitmapData; for (y = 0; y < context->height; y++) { + const BYTE* yplane; + const BYTE* coplane; + const BYTE* cgplane; + const BYTE* aplane = context->priv->PlaneBuffers[3] + y * context->width; /* A */; + if (context->ChromaSubsamplingLevel) { yplane = context->priv->PlaneBuffers[0] + y * rw; /* Y */ coplane = context->priv->PlaneBuffers[1] + (y >> 1) * (rw >> - 1); /* Co, supersampled */ + 1); /* Co, supersampled */ cgplane = context->priv->PlaneBuffers[2] + (y >> 1) * (rw >> - 1); /* Cg, supersampled */ + 1); /* Cg, supersampled */ } else { @@ -83,16 +73,15 @@ static void nsc_decode(NSC_CONTEXT* context) cgplane = context->priv->PlaneBuffers[2] + y * context->width; /* Cg */ } - aplane = context->priv->PlaneBuffers[3] + y * context->width; /* A */ - for (x = 0; x < context->width; x++) { - y_val = (INT16) * yplane; - co_val = (INT16)(INT8)(*coplane << shift); - cg_val = (INT16)(INT8)(*cgplane << shift); - r_val = y_val + co_val - cg_val; - g_val = y_val + cg_val; - b_val = y_val - co_val - cg_val; + INT16 y_val = (INT16) * yplane; + INT16 co_val = (INT16)(INT8)(*coplane << shift); + INT16 cg_val = (INT16)(INT8)(*cgplane << shift); + INT16 r_val = y_val + co_val - cg_val; + INT16 g_val = y_val + cg_val; + INT16 b_val = y_val - co_val - cg_val; + *bmpdata++ = MINMAX(b_val, 0, 0xFF); *bmpdata++ = MINMAX(g_val, 0, 0xFF); *bmpdata++ = MINMAX(r_val, 0, 0xFF); @@ -187,7 +176,7 @@ static BOOL nsc_stream_initialize(NSC_CONTEXT* context, wStream* s) Stream_Read_UINT8(s, context->ColorLossLevel); /* ColorLossLevel (1 byte) */ Stream_Read_UINT8(s, - context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ + context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ Stream_Seek(s, 2); /* Reserved (2 bytes) */ context->Planes = Stream_Pointer(s); return TRUE; @@ -306,10 +295,10 @@ NSC_CONTEXT* nsc_context_new(void) goto error_PlanePool; PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, - "nsc_rle_decompress_data"); + "nsc_rle_decompress_data"); PROFILER_CREATE(context->priv->prof_nsc_decode, "nsc_decode"); PROFILER_CREATE(context->priv->prof_nsc_rle_compress_data, - "nsc_rle_compress_data"); + "nsc_rle_compress_data"); PROFILER_CREATE(context->priv->prof_nsc_encode, "nsc_encode"); /* Default encoding parameters */ context->ColorLossLevel = 3; @@ -356,8 +345,12 @@ BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, UINT32 pixel_format) } BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, - UINT32 width, UINT32 height, const BYTE* data, - UINT32 length) + UINT32 width, UINT32 height, + const BYTE* data, UINT32 length, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStride, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight) { wStream* s; BOOL ret; @@ -366,6 +359,9 @@ BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, if (!s) return FALSE; + if (nDstStride == 0) + nDstStride = nWidth * GetBytesPerPixel(DstFormat); + switch (bpp) { case 32: @@ -408,5 +404,11 @@ BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, PROFILER_ENTER(context->priv->prof_nsc_decode); context->decode(context); PROFILER_EXIT(context->priv->prof_nsc_decode); + + if (!freerdp_image_copy(pDstData, DstFormat, nDstStride, nXDst, nYDst, + width, height, context->BitmapData, + PIXEL_FORMAT_BGRA32, -1, 0, 0, NULL)) + return FALSE; + return TRUE; } diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index 836a220b0..a59d098d4 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -34,7 +34,7 @@ #define TAG FREERDP_TAG("codec") static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, - int nWidth, int nHeight) + int nWidth, int nHeight) { int x, y; int cRawBytes; @@ -83,10 +83,10 @@ static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, } static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, - BYTE* pDstData, INT32 nDstStep, - UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, - UINT32 nChannel, BOOL vFlip) + BYTE* pDstData, INT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + UINT32 nChannel, BOOL vFlip) { UINT32 x, y; BYTE* dstp; @@ -218,9 +218,9 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, } static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], - BYTE* pDstData, UINT32 DstFormat, - UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, - BOOL alpha, BOOL vFlip) + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, + BOOL alpha, BOOL vFlip) { INT32 x, y; INT32 beg, end, inc; @@ -247,7 +247,7 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], for (y = beg; y != end; y += inc) { BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( - DstFormat))]; + DstFormat))]; for (x = 0; x < nWidth; x++) { @@ -262,7 +262,7 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], for (y = beg; y != end; y += inc) { BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( - DstFormat))]; + DstFormat))]; for (x = 0; x < nWidth; x++) { @@ -277,10 +277,10 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], } INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, - const BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, UINT32 DstFormat, - INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, BOOL vFlip) + const BYTE* pSrcData, UINT32 SrcSize, + BYTE** ppDstData, UINT32 DstFormat, + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, BOOL vFlip) { BOOL cs; BOOL rle; @@ -405,28 +405,28 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, { planes[3] = srcp; rleSizes[3] = planar_skip_plane_rle(planes[3], SrcSize - (planes[3] - pSrcData), - rawWidths[3], rawHeights[3]); /* AlphaPlane */ + rawWidths[3], rawHeights[3]); /* AlphaPlane */ if (rleSizes[3] < 0) return -1; planes[0] = planes[3] + rleSizes[3]; rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData), - rawWidths[0], rawHeights[0]); /* RedPlane */ + rawWidths[0], rawHeights[0]); /* RedPlane */ if (rleSizes[0] < 0) return -1; planes[1] = planes[0] + rleSizes[0]; rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData), - rawWidths[1], rawHeights[1]); /* GreenPlane */ + rawWidths[1], rawHeights[1]); /* GreenPlane */ if (rleSizes[1] < 1) return -1; planes[2] = planes[1] + rleSizes[1]; rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData), - rawWidths[2], rawHeights[2]); /* BluePlane */ + rawWidths[2], rawHeights[2]); /* BluePlane */ if (rleSizes[2] < 1) return -1; @@ -435,21 +435,21 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, { planes[0] = srcp; rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData), - rawWidths[0], rawHeights[0]); /* RedPlane */ + rawWidths[0], rawHeights[0]); /* RedPlane */ if (rleSizes[0] < 0) return -1; planes[1] = planes[0] + rleSizes[0]; rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData), - rawWidths[1], rawHeights[1]); /* GreenPlane */ + rawWidths[1], rawHeights[1]); /* GreenPlane */ if (rleSizes[1] < 1) return -1; planes[2] = planes[1] + rleSizes[1]; rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData), - rawWidths[2], rawHeights[2]); /* BluePlane */ + rawWidths[2], rawHeights[2]); /* BluePlane */ if (rleSizes[2] < 1) return -1; @@ -463,13 +463,13 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, if (alpha) { planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3]; } else /* NoAlpha */ { planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2]; } @@ -478,63 +478,64 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, } else /* RLE */ { - UINT32 TempFormat = PIXEL_FORMAT_ARGB32; + UINT32 TempFormat; BYTE* pTempData = pDstData; UINT32 nTempStep = nDstStep; + if (alpha) + TempFormat = PIXEL_FORMAT_BGRA32; + else + TempFormat = PIXEL_FORMAT_BGRX32; + if (DstFormat != TempFormat) { - pTempData = malloc(nWidth * nHeight * 4); - - if (!pTempData) - return -1; + pTempData = planar->pTempData; + nTempStep = planar->nTempStep; } if (alpha) { status = planar_decompress_plane_rle(planes[3], rleSizes[3], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, - vFlip); /* AlphaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, + vFlip); /* AlphaPlane */ status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, - vFlip); /* RedPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* RedPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, - vFlip); /* GreenPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* GreenPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, - vFlip); /* BluePlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* BluePlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3]; } else /* NoAlpha */ { status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, - vFlip); /* RedPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* RedPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, - vFlip); /* GreenPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* GreenPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, - vFlip); /* BluePlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* BluePlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2]; } if (pTempData != pDstData) { freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, - pTempData, - TempFormat, nTempStep, nXDst, nYDst, NULL); - free(pTempData); + pTempData, + TempFormat, nTempStep, nXDst, nYDst, NULL); } } } else /* YCoCg */ { - BYTE* pTempData; - UINT32 nTempStep = nDstStep; + BYTE* pTempData = planar->pTempData; + UINT32 nTempStep = planar->nTempStep; UINT32 TempFormat = PIXEL_FORMAT_RGBA32; - pTempData = malloc(UncompressedSize); if (!pTempData) return -1; @@ -542,7 +543,6 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, if (cs) { WLog_ERR(TAG, "Chroma subsampling unimplemented"); - free(pTempData); return -1; } @@ -551,13 +551,13 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, if (alpha) { planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3]; } else /* NoAlpha */ { planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2]; } @@ -569,37 +569,36 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, if (alpha) { status = planar_decompress_plane_rle(planes[3], rleSizes[3], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, - vFlip); /* AlphaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, + vFlip); /* AlphaPlane */ status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, - vFlip); /* LumaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* LumaPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, - vFlip); /* OrangeChromaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* OrangeChromaPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, - vFlip); /* GreenChromaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* GreenChromaPlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3]; } else /* NoAlpha */ { status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, - vFlip); /* LumaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* LumaPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, - vFlip); /* OrangeChromaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* OrangeChromaPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, - vFlip); /* GreenChromaPlane */ + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* GreenChromaPlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2]; } } prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, pDstData, DstFormat, nDstStep, - nWidth, nHeight, cll, alpha); - free(pTempData); + nWidth, nHeight, cll, alpha); } status = (SrcSize == (srcp - pSrcData)) ? 1 : -1; @@ -607,8 +606,8 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, } static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format, - UINT32 width, UINT32 height, - UINT32 scanline, BYTE** planes) + UINT32 width, UINT32 height, + UINT32 scanline, BYTE** planes) { INT32 i, j, k; UINT32* pixel; @@ -621,7 +620,7 @@ static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format, for (j = 0; j < width; j++) { *pixel = GetColor(format, planes[1][k], planes[2][k], - planes[3][k], planes[0][k]); + planes[3][k], planes[0][k]); pixel++; k++; } @@ -745,9 +744,9 @@ static UINT32 freerdp_bitmap_planar_write_rle_bytes( } static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer, - UINT32 inBufferSize, - BYTE* pOutBuffer, - UINT32 outBufferSize) + UINT32 inBufferSize, + BYTE* pOutBuffer, + UINT32 outBufferSize) { BYTE symbol; const BYTE* pInput; @@ -789,9 +788,9 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer, { pBytes = pInput - (cRawBytes + nRunLength + 1); nBytesWritten = freerdp_bitmap_planar_write_rle_bytes( - pBytes, cRawBytes, - nRunLength, pOutput, - outBufferSize); + pBytes, cRawBytes, + nRunLength, pOutput, + outBufferSize); nRunLength = 0; if (!nBytesWritten || (nBytesWritten > outBufferSize)) @@ -813,7 +812,7 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer, { pBytes = pInput - (cRawBytes + nRunLength); nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, - cRawBytes, nRunLength, pOutput, outBufferSize); + cRawBytes, nRunLength, pOutput, outBufferSize); if (!nBytesWritten) return 0; @@ -828,8 +827,8 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer, } BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane, - UINT32 width, UINT32 height, - BYTE* outPlane, UINT32* dstSize) + UINT32 width, UINT32 height, + BYTE* outPlane, UINT32* dstSize) { UINT32 index; const BYTE* pInput; @@ -859,7 +858,7 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane, while (outBufferSize) { nBytesWritten = freerdp_bitmap_planar_encode_rle_bytes( - pInput, width, pOutput, outBufferSize); + pInput, width, pOutput, outBufferSize); if ((!nBytesWritten) || (nBytesWritten > outBufferSize)) return NULL; @@ -894,7 +893,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle( dstSizes[0] = outPlanesSize; if (!freerdp_bitmap_planar_compress_plane_rle( - inPlanes[0], width, height, outPlanes, &dstSizes[0])) + inPlanes[0], width, height, outPlanes, &dstSizes[0])) return 0; outPlanes += dstSizes[0]; @@ -905,7 +904,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle( dstSizes[1] = outPlanesSize; if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, - outPlanes, &dstSizes[1])) + outPlanes, &dstSizes[1])) return 0; outPlanes += dstSizes[1]; @@ -914,7 +913,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle( dstSizes[2] = outPlanesSize; if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, - outPlanes, &dstSizes[2])) + outPlanes, &dstSizes[2])) return 0; outPlanes += dstSizes[2]; @@ -923,7 +922,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle( dstSizes[3] = outPlanesSize; if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, - outPlanes, &dstSizes[3])) + outPlanes, &dstSizes[3])) return 0; outPlanes += dstSizes[3]; @@ -932,8 +931,8 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle( } BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane, - UINT32 width, UINT32 height, - BYTE* outPlane) + UINT32 width, UINT32 height, + BYTE* outPlane) { char s2c; INT32 delta; @@ -968,15 +967,15 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane, } BOOL freerdp_bitmap_planar_delta_encode_planes(const BYTE** inPlanes, - UINT32 width, UINT32 height, - BYTE* outPlanes[4]) + UINT32 width, UINT32 height, + BYTE* outPlanes[4]) { UINT32 i; for (i = 0; i < 4; i++) { outPlanes[i] = freerdp_bitmap_planar_delta_encode_plane( - inPlanes[i], width, height, outPlanes[i]); + inPlanes[i], width, height, outPlanes[i]); if (!outPlanes[i]) return FALSE; @@ -986,9 +985,9 @@ BOOL freerdp_bitmap_planar_delta_encode_planes(const BYTE** inPlanes, } BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, - const BYTE* data, UINT32 format, - UINT32 width, UINT32 height, UINT32 scanline, - BYTE* dstData, UINT32* pDstSize) + const BYTE* data, UINT32 format, + UINT32 width, UINT32 height, UINT32 scanline, + BYTE* dstData, UINT32* pDstSize) { UINT32 size; BYTE* dstp; @@ -1002,20 +1001,20 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, planeSize = width * height; if (!freerdp_split_color_planes(data, format, width, height, scanline, - context->planes)) + context->planes)) return NULL; if (context->AllowRunLengthEncoding) { if (!freerdp_bitmap_planar_delta_encode_planes( - (const BYTE**)context->planes, width, height, - context->deltaPlanes)) + (const BYTE**)context->planes, width, height, + context->deltaPlanes)) return NULL;; if (freerdp_bitmap_planar_compress_planes_rle( - (const BYTE**)context->deltaPlanes, width, height, - context->rlePlanesBuffer, dstSizes, - context->AllowSkipAlpha) > 0) + (const BYTE**)context->deltaPlanes, width, height, + context->rlePlanesBuffer, dstSizes, + context->AllowSkipAlpha) > 0) { int offset = 0; FormatHeader |= PLANAR_FORMAT_HEADER_RLE; @@ -1167,9 +1166,11 @@ BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new( context->maxHeight = maxHeight; context->maxPlaneSize = context->maxWidth * context->maxHeight; context->planesBuffer = malloc(context->maxPlaneSize * 4); + context->nTempStep = maxWidth * 4; + context->pTempData = malloc(context->maxPlaneSize * 4); - if (!context->planesBuffer) - goto error_planesBuffer; + if (!context->planesBuffer || !context->planesBuffer) + goto error; context->planes[0] = &context->planesBuffer[context->maxPlaneSize * 0]; context->planes[1] = &context->planesBuffer[context->maxPlaneSize * 1]; @@ -1178,27 +1179,26 @@ BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new( context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4); if (!context->deltaPlanesBuffer) - goto error_deltaPlanesBuffer; + goto error; context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize * - 0]; + 0]; context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize * - 1]; + 1]; context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize * - 2]; + 2]; context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize * - 3]; + 3]; context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4); if (!context->rlePlanesBuffer) - goto error_rlePlanesBuffer; + goto error; return context; -error_rlePlanesBuffer: +error: + free(context->pTempData); free(context->deltaPlanesBuffer); -error_deltaPlanesBuffer: free(context->planesBuffer); -error_planesBuffer: free(context); return NULL; } @@ -1208,6 +1208,7 @@ void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context) if (!context) return; + free(context->pTempData); free(context->planesBuffer); free(context->deltaPlanesBuffer); free(context->rlePlanesBuffer); diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index 105327f52..efab10d28 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -81,7 +81,7 @@ static const char* progressive_get_block_type_string(UINT16 blockType) } static void progressive_component_codec_quant_read(const BYTE* block, - RFX_COMPONENT_CODEC_QUANT* quantVal) + RFX_COMPONENT_CODEC_QUANT* quantVal) { quantVal->LL3 = block[0] & 0x0F; quantVal->HL3 = block[0] >> 4; @@ -110,8 +110,8 @@ static void progressive_rfx_quant_ladd(RFX_COMPONENT_CODEC_QUANT* q, int val) } static void progressive_rfx_quant_add(RFX_COMPONENT_CODEC_QUANT* q1, - RFX_COMPONENT_CODEC_QUANT* q2, - RFX_COMPONENT_CODEC_QUANT* dst) + RFX_COMPONENT_CODEC_QUANT* q2, + RFX_COMPONENT_CODEC_QUANT* dst) { dst->HL1 = q1->HL1 + q2->HL1; /* HL1 */ dst->LH1 = q1->LH1 + q2->LH1; /* LH1 */ @@ -140,8 +140,8 @@ static void progressive_rfx_quant_lsub(RFX_COMPONENT_CODEC_QUANT* q, int val) } static void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, - RFX_COMPONENT_CODEC_QUANT* q2, - RFX_COMPONENT_CODEC_QUANT* dst) + RFX_COMPONENT_CODEC_QUANT* q2, + RFX_COMPONENT_CODEC_QUANT* dst) { dst->HL1 = q1->HL1 - q2->HL1; /* HL1 */ dst->LH1 = q1->LH1 - q2->LH1; /* LH1 */ @@ -156,97 +156,150 @@ static void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, } static BOOL progressive_rfx_quant_lcmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q, - int val) + int val) { if (q->HL1 > val) return FALSE; /* HL1 */ + if (q->LH1 > val) return FALSE; /* LH1 */ + if (q->HH1 > val) return FALSE; /* HH1 */ + if (q->HL2 > val) return FALSE; /* HL2 */ + if (q->LH2 > val) return FALSE; /* LH2 */ + if (q->HH2 > val) return FALSE; /* HH2 */ + if (q->HL3 > val) return FALSE; /* HL3 */ + if (q->LH3 > val) return FALSE; /* LH3 */ + if (q->HH3 > val) return FALSE; /* HH3 */ + if (q->LL3 > val) return FALSE; /* LL3 */ + return TRUE; } static BOOL progressive_rfx_quant_cmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q1, - RFX_COMPONENT_CODEC_QUANT* q2) + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 > q2->HL1) return FALSE; /* HL1 */ + if (q1->LH1 > q2->LH1) return FALSE; /* LH1 */ + if (q1->HH1 > q2->HH1) return FALSE; /* HH1 */ + if (q1->HL2 > q2->HL2) return FALSE; /* HL2 */ + if (q1->LH2 > q2->LH2) return FALSE; /* LH2 */ + if (q1->HH2 > q2->HH2) return FALSE; /* HH2 */ + if (q1->HL3 > q2->HL3) return FALSE; /* HL3 */ + if (q1->LH3 > q2->LH3) return FALSE; /* LH3 */ + if (q1->HH3 > q2->HH3) return FALSE; /* HH3 */ + if (q1->LL3 > q2->LL3) return FALSE; /* LL3 */ + return TRUE; } -static BOOL progressive_rfx_quant_lcmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q, - int val) +static BOOL progressive_rfx_quant_lcmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* + q, + int val) { if (q->HL1 < val) return FALSE; /* HL1 */ + if (q->LH1 < val) return FALSE; /* LH1 */ + if (q->HH1 < val) return FALSE; /* HH1 */ + if (q->HL2 < val) return FALSE; /* HL2 */ + if (q->LH2 < val) return FALSE; /* LH2 */ + if (q->HH2 < val) return FALSE; /* HH2 */ + if (q->HL3 < val) return FALSE; /* HL3 */ + if (q->LH3 < val) return FALSE; /* LH3 */ + if (q->HH3 < val) return FALSE; /* HH3 */ + if (q->LL3 < val) return FALSE; /* LL3 */ + return TRUE; } -static BOOL progressive_rfx_quant_cmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q1, - RFX_COMPONENT_CODEC_QUANT* q2) +static BOOL progressive_rfx_quant_cmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* + q1, + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 < q2->HL1) return FALSE; /* HL1 */ + if (q1->LH1 < q2->LH1) return FALSE; /* LH1 */ + if (q1->HH1 < q2->HH1) return FALSE; /* HH1 */ + if (q1->HL2 < q2->HL2) return FALSE; /* HL2 */ + if (q1->LH2 < q2->LH2) return FALSE; /* LH2 */ + if (q1->HH2 < q2->HH2) return FALSE; /* HH2 */ + if (q1->HL3 < q2->HL3) return FALSE; /* HL3 */ + if (q1->LH3 < q2->LH3) return FALSE; /* LH3 */ + if (q1->HH3 < q2->HH3) return FALSE; /* HH3 */ + if (q1->LL3 < q2->LL3) return FALSE; /* LL3 */ + return TRUE; } static BOOL progressive_rfx_quant_cmp_equal(RFX_COMPONENT_CODEC_QUANT* q1, - RFX_COMPONENT_CODEC_QUANT* q2) + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 != q2->HL1) return FALSE; /* HL1 */ + if (q1->LH1 != q2->LH1) return FALSE; /* LH1 */ + if (q1->HH1 != q2->HH1) return FALSE; /* HH1 */ + if (q1->HL2 != q2->HL2) return FALSE; /* HL2 */ + if (q1->LH2 != q2->LH2) return FALSE; /* LH2 */ + if (q1->HH2 != q2->HH2) return FALSE; /* HH2 */ + if (q1->HL3 != q2->HL3) return FALSE; /* HL3 */ + if (q1->LH3 != q2->LH3) return FALSE; /* LH3 */ + if (q1->HH3 != q2->HH3) return FALSE; /* HH3 */ + if (q1->LL3 != q2->LL3) return FALSE; /* LL3 */ + return TRUE; } static void progressive_rfx_quant_print(RFX_COMPONENT_CODEC_QUANT* q, - const char* name) + const char* name) { - fprintf(stderr, "%s: HL1: %d LH1: %d HH1: %d HL2: %d LH2: %d HH2: %d HL3: %d LH3: %d HH3: %d LL3: %d\n", - name, q->HL1, q->LH1, q->HH1, q->HL2, q->LH2, q->HH2, q->HL3, q->LH3, q->HH3, q->LL3); + fprintf(stderr, + "%s: HL1: %d LH1: %d HH1: %d HL2: %d LH2: %d HH2: %d HL3: %d LH3: %d HH3: %d LL3: %d\n", + name, q->HL1, q->LH1, q->HH1, q->HL2, q->LH2, q->HH2, q->HL3, q->LH3, q->HH3, + q->LL3); } static int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, - UINT16 surfaceId, void* pData) + UINT16 surfaceId, void* pData) { ULONG_PTR key; - key = ((ULONG_PTR) surfaceId) + 1; if (pData) @@ -258,25 +311,21 @@ static int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, } static void* progressive_get_surface_data(PROGRESSIVE_CONTEXT* progressive, - UINT16 surfaceId) + UINT16 surfaceId) { ULONG_PTR key; void* pData = NULL; - key = ((ULONG_PTR) surfaceId) + 1; - pData = HashTable_GetItemValue(progressive->SurfaceContexts, (void*) key); - return pData; } static PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new( - UINT16 surfaceId, UINT32 width, UINT32 height) + UINT16 surfaceId, UINT32 width, UINT32 height) { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) calloc( - 1, sizeof(PROGRESSIVE_SURFACE_CONTEXT)); + 1, sizeof(PROGRESSIVE_SURFACE_CONTEXT)); if (!surface) return NULL; @@ -287,9 +336,8 @@ static PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new( surface->gridWidth = (width + (64 - width % 64)) / 64; surface->gridHeight = (height + (64 - height % 64)) / 64; surface->gridSize = surface->gridWidth * surface->gridHeight; - surface->tiles = (RFX_PROGRESSIVE_TILE*) calloc( - surface->gridSize, sizeof(RFX_PROGRESSIVE_TILE)); + surface->gridSize, sizeof(RFX_PROGRESSIVE_TILE)); if (!surface->tiles) { @@ -300,7 +348,8 @@ static PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new( return surface; } -static void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* surface) +static void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* + surface) { UINT32 index; RFX_PROGRESSIVE_TILE* tile; @@ -323,13 +372,12 @@ static void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* surfac free(surface); } -int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, - UINT16 surfaceId, UINT32 width, UINT32 height) +INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, + UINT16 surfaceId, UINT32 width, UINT32 height) { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data( - progressive, surfaceId); + progressive, surfaceId); if (!surface) { @@ -344,12 +392,12 @@ int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, return 1; } -int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId) +int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, + UINT16 surfaceId) { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data( - progressive, surfaceId); + progressive, surfaceId); if (surface) { @@ -378,28 +426,26 @@ int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 * LL3 4015 9x9 81 */ -static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBand, - int nHighStep, INT16* pDstBand, int nDstStep, - int nLowCount, int nHighCount, int nDstCount) +static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, + INT16* pHighBand, + int nHighStep, INT16* pDstBand, int nDstStep, + int nLowCount, int nHighCount, int nDstCount) { int i, j; INT16 L0; INT16 H0, H1; INT16 X0, X1, X2; - INT16 *pL, *pH, *pX; + INT16* pL, *pH, *pX; for (i = 0; i < nDstCount; i++) { pL = pLowBand; pH = pHighBand; pX = pDstBand; - H0 = *pH; pH++; - L0 = *pL; pL++; - X0 = L0 - H0; X2 = L0 - H0; @@ -407,17 +453,13 @@ static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBa { H1 = *pH; pH++; - L0 = *pL; pL++; - X2 = L0 - ((H0 + H1) / 2); X1 = ((X0 + X2) / 2) + (2 * H0); - pX[0] = X0; pX[1] = X1; pX += 2; - X0 = X2; H0 = H1; } @@ -433,9 +475,7 @@ static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBa { L0 = *pL; pL++; - X0 = L0 - H0; - pX[0] = X2; pX[1] = ((X0 + X2) / 2) + (2 * H0); pX[2] = X0; @@ -445,16 +485,12 @@ static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBa { L0 = *pL; pL++; - X0 = L0 - (H0 / 2); - pX[0] = X2; pX[1] = ((X0 + X2) / 2) + (2 * H0); pX[2] = X0; - L0 = *pL; pL++; - pX[3] = (X0 + L0) / 2; } @@ -464,28 +500,26 @@ static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBa } } -static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBand, - int nHighStep, INT16* pDstBand, int nDstStep, - int nLowCount, int nHighCount, int nDstCount) +static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, + INT16* pHighBand, + int nHighStep, INT16* pDstBand, int nDstStep, + int nLowCount, int nHighCount, int nDstCount) { int i, j; INT16 L0; INT16 H0, H1; INT16 X0, X1, X2; - INT16 *pL, *pH, *pX; + INT16* pL, *pH, *pX; for (i = 0; i < nDstCount; i++) { pL = pLowBand; pH = pHighBand; pX = pDstBand; - H0 = *pH; pH += nHighStep; - L0 = *pL; pL += nLowStep; - X0 = L0 - H0; X2 = L0 - H0; @@ -493,19 +527,14 @@ static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBa { H1 = *pH; pH += nHighStep; - L0 = *pL; pL += nLowStep; - X2 = L0 - ((H0 + H1) / 2); X1 = ((X0 + X2) / 2) + (2 * H0); - *pX = X0; pX += nDstStep; - *pX = X1; pX += nDstStep; - X0 = X2; H0 = H1; } @@ -516,7 +545,6 @@ static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBa { *pX = X2; pX += nDstStep; - *pX = X2 + (2 * H0); pX += nDstStep; } @@ -524,15 +552,11 @@ static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBa { L0 = *pL; pL += nLowStep; - X0 = L0 - H0; - *pX = X2; pX += nDstStep; - *pX = ((X0 + X2) / 2) + (2 * H0); pX += nDstStep; - *pX = X0; pX += nDstStep; } @@ -541,21 +565,15 @@ static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBa { L0 = *pL; pL += nLowStep; - X0 = L0 - (H0 / 2); - *pX = X2; pX += nDstStep; - *pX = ((X0 + X2) / 2) + (2 * H0); pX += nDstStep; - *pX = X0; pX += nDstStep; - L0 = *pL; pL += nLowStep; - *pX = (X0 + L0) / 2; pX += nDstStep; } @@ -579,16 +597,17 @@ static int progressive_rfx_get_band_h_count(int level) return (64 + (1 << (level - 1))) >> level; } -static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int level) +static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, + int level) { int offset; int nBandL; int nBandH; int nDstStepX; int nDstStepY; - INT16 *HL, *LH; - INT16 *HH, *LL; - INT16 *L, *H, *LLx; + INT16* HL, *LH; + INT16* HH, *LL; + INT16* L, *H, *LLx; INT16* pLowBand[3]; INT16* pHighBand[3]; INT16* pDstBand[3]; @@ -598,39 +617,26 @@ static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int int nLowCount[3]; int nHighCount[3]; int nDstCount[3]; - nBandL = progressive_rfx_get_band_l_count(level); nBandH = progressive_rfx_get_band_h_count(level); - offset = 0; - HL = &buffer[offset]; offset += (nBandH * nBandL); - LH = &buffer[offset]; offset += (nBandL * nBandH); - HH = &buffer[offset]; offset += (nBandH * nBandH); - LL = &buffer[offset]; offset += (nBandL * nBandL); - nDstStepX = (nBandL + nBandH); nDstStepY = (nBandL + nBandH); - offset = 0; - L = &temp[offset]; offset += (nBandL * nDstStepX); - H = &temp[offset]; offset += (nBandH * nDstStepX); - LLx = &buffer[0]; - /* horizontal (LL + HL -> L) */ - pLowBand[0] = LL; nLowStep[0] = nBandL; pHighBand[0] = HL; @@ -640,11 +646,9 @@ static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int nLowCount[0] = nBandL; nHighCount[0] = nBandH; nDstCount[0] = nBandL; - - progressive_rfx_idwt_x(pLowBand[0], nLowStep[0], pHighBand[0], nHighStep[0], pDstBand[0], nDstStep[0], nLowCount[0], nHighCount[0], nDstCount[0]); - + progressive_rfx_idwt_x(pLowBand[0], nLowStep[0], pHighBand[0], nHighStep[0], + pDstBand[0], nDstStep[0], nLowCount[0], nHighCount[0], nDstCount[0]); /* horizontal (LH + HH -> H) */ - pLowBand[1] = LH; nLowStep[1] = nBandL; pHighBand[1] = HH; @@ -654,11 +658,9 @@ static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int nLowCount[1] = nBandL; nHighCount[1] = nBandH; nDstCount[1] = nBandH; - - progressive_rfx_idwt_x(pLowBand[1], nLowStep[1], pHighBand[1], nHighStep[1], pDstBand[1], nDstStep[1], nLowCount[1], nHighCount[1], nDstCount[1]); - + progressive_rfx_idwt_x(pLowBand[1], nLowStep[1], pHighBand[1], nHighStep[1], + pDstBand[1], nDstStep[1], nLowCount[1], nHighCount[1], nDstCount[1]); /* vertical (L + H -> LL) */ - pLowBand[2] = pDstBand[0]; nLowStep[2] = nDstStep[0]; pHighBand[2] = pDstBand[1]; @@ -668,12 +670,12 @@ static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int nLowCount[2] = nBandL; nHighCount[2] = nBandH; nDstCount[2] = nBandL + nBandH; - - progressive_rfx_idwt_y(pLowBand[2], nLowStep[2], pHighBand[2], nHighStep[2], pDstBand[2], nDstStep[2], nLowCount[2], nHighCount[2], nDstCount[2]); + progressive_rfx_idwt_y(pLowBand[2], nLowStep[2], pHighBand[2], nHighStep[2], + pDstBand[2], nDstStep[2], nLowCount[2], nHighCount[2], nDstCount[2]); } static void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, - INT16* current, INT16* sign, BOOL diff) + INT16* current, INT16* sign, BOOL diff) { const primitives_t* prims = primitives_get(); @@ -681,14 +683,14 @@ static void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, prims->add_16s(buffer, current, buffer, 4096); CopyMemory(current, buffer, 4096 * 2); - progressive_rfx_dwt_2d_decode_block(&buffer[3807], temp, 3); progressive_rfx_dwt_2d_decode_block(&buffer[3007], temp, 2); progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1); } -static void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffer, - int length, UINT32 shift) +static void progressive_rfx_decode_block(const primitives_t* prims, + INT16* buffer, + int length, UINT32 shift) { if (!shift) return; @@ -697,24 +699,21 @@ static void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffe } static int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, - RFX_COMPONENT_CODEC_QUANT* shift, - const BYTE* data, int length, - INT16* buffer, INT16* current, - INT16* sign, BOOL diff) + RFX_COMPONENT_CODEC_QUANT* shift, + const BYTE* data, int length, + INT16* buffer, INT16* current, + INT16* sign, BOOL diff) { int status; INT16* temp; const primitives_t* prims = primitives_get(); - status = rfx_rlgr_decode(data, length, buffer, 4096, 1); if (status < 0) return status; CopyMemory(sign, buffer, 4096 * 2); - rfx_differential_decode(&buffer[4015], 81); /* LL3 */ - progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1); /* HL1 */ progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1); /* LH1 */ progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1); /* HH1 */ @@ -725,18 +724,14 @@ static int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3); /* LH3 */ progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3); /* HH3 */ progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3); /* LL3 */ - temp = (INT16*) BufferPool_Take(progressive->bufferPool, -1); /* DWT buffer */ - progressive_rfx_dwt_2d_decode(buffer, temp, current, sign, diff); - BufferPool_Return(progressive->bufferPool, temp); - return 1; } static int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, - RFX_PROGRESSIVE_TILE* tile) + RFX_PROGRESSIVE_TILE* tile) { BOOL diff; BYTE* pBuffer; @@ -756,17 +751,14 @@ static int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_CODEC_QUANT* quantProgVal; static const prim_size_t roi_64x64 = { 64, 64 }; const primitives_t* prims = primitives_get(); - tile->pass = 1; - diff = tile->flags & RFX_TILE_DIFFERENCE; - - WLog_DBG(TAG, "ProgressiveTile%s: quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d flags: 0x%02X quality: %d yLen: %d cbLen: %d crLen: %d tailLen: %d", - (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ? "First" : "Simple", - tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, - tile->xIdx, tile->yIdx, tile->flags, tile->quality, tile->yLen, - tile->cbLen, tile->crLen, tile->tailLen); - + WLog_DBG(TAG, + "ProgressiveTile%s: quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d flags: 0x%02X quality: %d yLen: %d cbLen: %d crLen: %d tailLen: %d", + (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ? "First" : "Simple", + tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, + tile->xIdx, tile->yIdx, tile->flags, tile->quality, tile->yLen, + tile->cbLen, tile->crLen, tile->tailLen); region = &(progressive->region); if (tile->quantIdxY >= region->numQuant) @@ -799,19 +791,17 @@ static int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, quantProgY = &(quantProgVal->yQuantValues); quantProgCb = &(quantProgVal->cbQuantValues); quantProgCr = &(quantProgVal->crQuantValues); - CopyMemory(&(tile->yQuant), quantY, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->cbQuant), quantCb, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->crQuant), quantCr, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->yProgQuant), quantProgY, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->cbProgQuant), quantProgCb, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->crProgQuant), quantProgCr, sizeof(RFX_COMPONENT_CODEC_QUANT)); - + CopyMemory(&(tile->cbProgQuant), quantProgCb, + sizeof(RFX_COMPONENT_CODEC_QUANT)); + CopyMemory(&(tile->crProgQuant), quantProgCr, + sizeof(RFX_COMPONENT_CODEC_QUANT)); progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos)); progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos)); progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos)); - progressive_rfx_quant_add(quantY, quantProgY, &shiftY); progressive_rfx_quant_lsub(&shiftY, 1); /* -6 + 5 = -1 */ progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb); @@ -836,37 +826,43 @@ static int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, pBuffer = tile->sign; pSign[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pSign[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pSign[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - + pSign[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pSign[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ pBuffer = tile->current; - pCurrent[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pCurrent[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pCurrent[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - + pCurrent[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* Y/R buffer */ + pCurrent[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pCurrent[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ pBuffer = (BYTE*) BufferPool_Take(progressive->bufferPool, -1); - pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - + pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* Y/R buffer */ + pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, - pSrcDst[0], pCurrent[0], pSign[0], diff); /* Y */ - progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen, - pSrcDst[1], pCurrent[1], pSign[1], diff); /* Cb */ - progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen, - pSrcDst[2], pCurrent[2], pSign[2], diff); /* Cr */ + pSrcDst[0], pCurrent[0], pSign[0], diff); /* Y */ + progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, + tile->cbLen, + pSrcDst[1], pCurrent[1], pSign[1], diff); /* Cb */ + progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, + tile->crLen, + pSrcDst[2], pCurrent[2], pSign[2], diff); /* Cr */ if (!progressive->invert) prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, - tile->data, PIXEL_FORMAT_BGRX32, - 64 * 4, &roi_64x64); + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); else prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, - tile->data, PIXEL_FORMAT_BGRX32, - 64 * 4, &roi_64x64); + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); BufferPool_Return(progressive->bufferPool, pBuffer); - return 1; } @@ -885,7 +881,7 @@ struct _RFX_PROGRESSIVE_UPGRADE_STATE typedef struct _RFX_PROGRESSIVE_UPGRADE_STATE RFX_PROGRESSIVE_UPGRADE_STATE; static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, - UINT32 numBits) + UINT32 numBits) { int k; UINT32 bit; @@ -905,16 +901,13 @@ static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, if (!state->mode) { /* zero encoding */ - bit = (bs->accumulator & 0x80000000) ? 1 : 0; BitStream_Shift(bs, 1); if (!bit) { /* '0' bit, nz >= (1 << k), nz = (1 << k) */ - state->nz = (1 << k); - state->kp += 4; if (state->kp > 80) @@ -926,7 +919,6 @@ static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, else { /* '1' bit, nz < (1 << k), nz = next k bits */ - state->nz = 0; state->mode = 1; /* unary encoding is next */ @@ -946,14 +938,10 @@ static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, } state->mode = 0; /* zero encoding is next */ - /* unary encoding */ - /* read sign bit */ - sign = (bs->accumulator & 0x80000000) ? 1 : 0; BitStream_Shift(bs, 1); - state->kp -= 6; if (state->kp < 0) @@ -979,17 +967,15 @@ static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, return sign ? -1 * mag : mag; } -static int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* state) +static int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* + state) { int pad; wBitStream* srl; wBitStream* raw; - srl = state->srl; raw = state->raw; - /* Read trailing bits from RAW/SRL bit streams */ - pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0; if (pad) @@ -1007,8 +993,8 @@ static int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* s } static int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, - INT16* buffer, INT16* sign, UINT32 length, - UINT32 shift, UINT32 bitPos, UINT32 numBits) + INT16* buffer, INT16* sign, UINT32 length, + UINT32 shift, UINT32 bitPos, UINT32 numBits) { int index; INT16 input; @@ -1026,9 +1012,8 @@ static int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, for (index = 0; index < length; index++) { raw->mask = ((1 << numBits) - 1); - input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask); + input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask); BitStream_Shift(raw, numBits); - buffer[index] += (input << shift); } @@ -1040,27 +1025,22 @@ static int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, if (sign[index] > 0) { /* sign > 0, read from raw */ - raw->mask = ((1 << numBits) - 1); - input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask); + input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask); BitStream_Shift(raw, numBits); } else if (sign[index] < 0) { /* sign < 0, read from raw */ - raw->mask = ((1 << numBits) - 1); - input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask); + input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask); BitStream_Shift(raw, numBits); - input *= -1; } else { /* sign == 0, read from srl */ - input = progressive_rfx_srl_read(state, numBits); - sign[index] = input; } @@ -1071,14 +1051,14 @@ static int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, } static int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, - RFX_COMPONENT_CODEC_QUANT* shift, - RFX_COMPONENT_CODEC_QUANT* bitPos, - RFX_COMPONENT_CODEC_QUANT* numBits, - INT16* buffer, - INT16* current, INT16* sign, - const BYTE* srlData, - UINT32 srlLen, const BYTE* rawData, - UINT32 rawLen) + RFX_COMPONENT_CODEC_QUANT* shift, + RFX_COMPONENT_CODEC_QUANT* bitPos, + RFX_COMPONENT_CODEC_QUANT* numBits, + INT16* buffer, + INT16* current, INT16* sign, + const BYTE* srlData, + UINT32 srlLen, const BYTE* rawData, + UINT32 rawLen) { INT16* temp; UINT32 aRawLen; @@ -1086,37 +1066,40 @@ static int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, wBitStream s_srl; wBitStream s_raw; RFX_PROGRESSIVE_UPGRADE_STATE state; - ZeroMemory(&s_srl, sizeof(wBitStream)); ZeroMemory(&s_raw, sizeof(wBitStream)); ZeroMemory(&state, sizeof(RFX_PROGRESSIVE_UPGRADE_STATE)); - state.kp = 8; state.mode = 0; state.srl = &s_srl; state.raw = &s_raw; - BitStream_Attach(state.srl, srlData, srlLen); BitStream_Fetch(state.srl); - BitStream_Attach(state.raw, rawData, rawLen); BitStream_Fetch(state.raw); - state.nonLL = TRUE; - progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1, numBits->HL1); /* HL1 */ - progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1, bitPos->LH1, numBits->LH1); /* LH1 */ - progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1, bitPos->HH1, numBits->HH1); /* HH1 */ - progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2, bitPos->HL2, numBits->HL2); /* HL2 */ - progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2, bitPos->LH2, numBits->LH2); /* LH2 */ - progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2, bitPos->HH2, numBits->HH2); /* HH2 */ - progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3, bitPos->HL3, numBits->HL3); /* HL3 */ - progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3, bitPos->LH3, numBits->LH3); /* LH3 */ - progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3, bitPos->HH3, numBits->HH3); /* HH3 */ - + progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, + bitPos->HL1, numBits->HL1); /* HL1 */ + progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, + shift->LH1, bitPos->LH1, numBits->LH1); /* LH1 */ + progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, + shift->HH1, bitPos->HH1, numBits->HH1); /* HH1 */ + progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, + shift->HL2, bitPos->HL2, numBits->HL2); /* HL2 */ + progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, + shift->LH2, bitPos->LH2, numBits->LH2); /* LH2 */ + progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, + shift->HH2, bitPos->HH2, numBits->HH2); /* HH2 */ + progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, + shift->HL3, bitPos->HL3, numBits->HL3); /* HL3 */ + progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, + shift->LH3, bitPos->LH3, numBits->LH3); /* LH3 */ + progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, + shift->HH3, bitPos->HH3, numBits->HH3); /* HH3 */ state.nonLL = FALSE; - progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3, bitPos->LL3, numBits->LL3); /* LL3 */ + progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, + shift->LL3, bitPos->LL3, numBits->LL3); /* LL3 */ progressive_rfx_upgrade_state_finish(&state); - aRawLen = (state.raw->position + 7) / 8; aSrlLen = (state.srl->position + 7) / 8; @@ -1126,35 +1109,30 @@ static int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, int pSrlLen = 0; if (rawLen) - pRawLen = (int) ((((float) aRawLen) / ((float) rawLen)) * 100.0f); + pRawLen = (int)((((float) aRawLen) / ((float) rawLen)) * 100.0f); if (srlLen) - pSrlLen = (int) ((((float) aSrlLen) / ((float) srlLen)) * 100.0f); + pSrlLen = (int)((((float) aSrlLen) / ((float) srlLen)) * 100.0f); WLog_INFO(TAG, "RAW: %d/%d %d%% (%d/%d:%d)\tSRL: %d/%d %d%% (%d/%d:%d)", - aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8, - (rawLen * 8) - state.raw->position, - aSrlLen, srlLen, pSrlLen, state.srl->position, srlLen * 8, - (srlLen * 8) - state.srl->position); - + aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8, + (rawLen * 8) - state.raw->position, + aSrlLen, srlLen, pSrlLen, state.srl->position, srlLen * 8, + (srlLen * 8) - state.srl->position); return -1; } temp = (INT16*) BufferPool_Take(progressive->bufferPool, -1); /* DWT buffer */ - CopyMemory(buffer, current, 4096 * 2); - progressive_rfx_dwt_2d_decode_block(&buffer[3807], temp, 3); progressive_rfx_dwt_2d_decode_block(&buffer[3007], temp, 2); progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1); - BufferPool_Return(progressive->bufferPool, temp); - return 1; } static int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, - RFX_PROGRESSIVE_TILE* tile) + RFX_PROGRESSIVE_TILE* tile) { int status; BYTE* pBuffer; @@ -1180,12 +1158,12 @@ static int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_CODEC_QUANT* quantProg; static const prim_size_t roi_64x64 = { 64, 64 }; const primitives_t* prims = primitives_get(); - tile->pass++; - - WLog_DBG(TAG, "ProgressiveTileUpgrade: pass: %d quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d quality: %d ySrlLen: %d yRawLen: %d cbSrlLen: %d cbRawLen: %d crSrlLen: %d crRawLen: %d", - tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen, tile->cbRawLen, tile->crSrlLen, tile->crRawLen); - + WLog_DBG(TAG, + "ProgressiveTileUpgrade: pass: %d quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d quality: %d ySrlLen: %d yRawLen: %d cbSrlLen: %d cbRawLen: %d crSrlLen: %d crRawLen: %d", + tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, + tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen, + tile->cbRawLen, tile->crSrlLen, tile->crRawLen); region = &(progressive->region); if (tile->quantIdxY >= region->numQuant) @@ -1221,88 +1199,96 @@ static int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant))) WLog_WARN(TAG, "non-progressive quantY has changed!"); + if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant))) WLog_WARN(TAG, "non-progressive quantCb has changed!"); + if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant))) WLog_WARN(TAG, "non-progressive quantCr has changed!"); progressive_rfx_quant_add(quantY, quantProgY, &yBitPos); progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos); progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos); - progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits); progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits); progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits); - progressive_rfx_quant_add(quantY, quantProgY, &shiftY); progressive_rfx_quant_lsub(&shiftY, 1); /* -6 + 5 = -1 */ progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb); progressive_rfx_quant_lsub(&shiftCb, 1); /* -6 + 5 = -1 */ progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr); progressive_rfx_quant_lsub(&shiftCr, 1); /* -6 + 5 = -1 */ - CopyMemory(&(tile->yBitPos), &yBitPos, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->cbBitPos), &cbBitPos, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->crBitPos), &crBitPos, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->yQuant), quantY, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->cbQuant), quantCb, sizeof(RFX_COMPONENT_CODEC_QUANT)); CopyMemory(&(tile->crQuant), quantCr, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->yProgQuant), quantProgY, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->cbProgQuant), quantProgCb, sizeof(RFX_COMPONENT_CODEC_QUANT)); - CopyMemory(&(tile->crProgQuant), quantProgCr, sizeof(RFX_COMPONENT_CODEC_QUANT)); - + CopyMemory(&(tile->cbProgQuant), quantProgCb, + sizeof(RFX_COMPONENT_CODEC_QUANT)); + CopyMemory(&(tile->crProgQuant), quantProgCr, + sizeof(RFX_COMPONENT_CODEC_QUANT)); pBuffer = tile->sign; pSign[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pSign[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pSign[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - + pSign[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pSign[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ pBuffer = tile->current; - pCurrent[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pCurrent[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pCurrent[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - + pCurrent[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* Y/R buffer */ + pCurrent[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pCurrent[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ pBuffer = (BYTE*) BufferPool_Take(progressive->bufferPool, -1); - pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* Y/R buffer */ - pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ - pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - - status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits, - pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData, tile->ySrlLen, tile->yRawData, tile->yRawLen); /* Y */ + pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* Y/R buffer */ + pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* Cb/G buffer */ + pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* Cr/B buffer */ + status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, + &yNumBits, + pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData, tile->ySrlLen, + tile->yRawData, tile->yRawLen); /* Y */ if (status < 0) return -1; - status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits, - pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData, tile->cbSrlLen, tile->cbRawData, tile->cbRawLen); /* Cb */ + status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, + &cbNumBits, + pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData, tile->cbSrlLen, + tile->cbRawData, tile->cbRawLen); /* Cb */ if (status < 0) return -1; - status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits, - pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData, tile->crSrlLen, tile->crRawData, tile->crRawLen); /* Cr */ + status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, + &crNumBits, + pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData, tile->crSrlLen, + tile->crRawData, tile->crRawLen); /* Cr */ if (status < 0) return -1; if (!progressive->invert) prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, - tile->data, PIXEL_FORMAT_BGRX32, - 64 * 4, &roi_64x64); + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); else prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, - tile->data, PIXEL_FORMAT_BGRX32, - 64 * 4, &roi_64x64); + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); BufferPool_Return(progressive->bufferPool, pBuffer); - return 1; } static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, - const BYTE* blocks, UINT32 blocksLen, - const PROGRESSIVE_SURFACE_CONTEXT* surface) + const BYTE* blocks, UINT32 blocksLen, + const PROGRESSIVE_SURFACE_CONTEXT* surface) { int status = -1; const BYTE* block; @@ -1318,16 +1304,13 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_TILE* tile; RFX_PROGRESSIVE_TILE** tiles; PROGRESSIVE_BLOCK_REGION* region; - region = &(progressive->region); - tiles = region->tiles; while ((blocksLen - offset) >= 6) { boffset = 0; block = &blocks[offset]; - blockType = *((UINT16*) &block[boffset + 0]); /* blockType (2 bytes) */ blockLen = *((UINT32*) &block[boffset + 2]); /* blockLen (4 bytes) */ boffset += 6; @@ -1340,25 +1323,20 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, switch (blockType) { case PROGRESSIVE_WBT_TILE_SIMPLE: - if ((blockLen - boffset) < 16) return -1022; xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */ yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */ - zIdx = (yIdx * surface->gridWidth) + xIdx; if (zIdx >= surface->gridSize) return -1; tiles[count] = tile = &(surface->tiles[zIdx]); - tile->blockType = blockType; tile->blockLen = blockLen; - tile->quality = 0xFF; /* simple tiles use no progressive techniques */ - tile->quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */ tile->quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */ tile->quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */ @@ -1394,34 +1372,27 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, tile->tailData = &block[boffset]; boffset += tile->tailLen; - tile->width = 64; tile->height = 64; tile->x = tile->xIdx * 64; tile->y = tile->yIdx * 64; - tile->flags &= 1; - break; case PROGRESSIVE_WBT_TILE_FIRST: - if ((blockLen - boffset) < 17) return -1027; xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */ yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */ - zIdx = (yIdx * surface->gridWidth) + xIdx; if (zIdx >= surface->gridSize) return -1; tiles[count] = tile = &(surface->tiles[zIdx]); - tile->blockType = blockType; tile->blockLen = blockLen; - tile->quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */ tile->quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */ tile->quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */ @@ -1458,34 +1429,27 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, tile->tailData = &block[boffset]; boffset += tile->tailLen; - tile->width = 64; tile->height = 64; tile->x = tile->xIdx * 64; tile->y = tile->yIdx * 64; - break; case PROGRESSIVE_WBT_TILE_UPGRADE: - if ((blockLen - boffset) < 20) return -1032; xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */ yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */ - zIdx = (yIdx * surface->gridWidth) + xIdx; if (zIdx >= surface->gridSize) return -1; tiles[count] = tile = &(surface->tiles[zIdx]); - tile->blockType = blockType; tile->blockLen = blockLen; - tile->flags = 0; - tile->quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */ tile->quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */ tile->quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */ @@ -1535,12 +1499,10 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, tile->crRawData = &block[boffset]; boffset += tile->crRawLen; - tile->width = 64; tile->height = 64; tile->x = tile->xIdx * 64; tile->y = tile->yIdx * 64; - break; default: @@ -1560,7 +1522,8 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, if (count != region->numTiles) { - WLog_WARN(TAG, "numTiles inconsistency: actual: %d, expected: %d\n", count, region->numTiles); + WLog_WARN(TAG, "numTiles inconsistency: actual: %d, expected: %d\n", count, + region->numTiles); } for (index = 0; index < region->numTiles; index++) @@ -1586,11 +1549,11 @@ static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, return (int) offset; } -UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, - const BYTE* pSrcData, UINT32 SrcSize, - BYTE* pDstData, UINT32 DstFormat, - UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId) +INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId) { UINT status; const BYTE* block; @@ -1621,24 +1584,21 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, PROGRESSIVE_SURFACE_CONTEXT* surface; RFX_COMPONENT_CODEC_QUANT* quantVal; RFX_PROGRESSIVE_CODEC_QUANT* quantProgVal; - progressive->invert = FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat) ? TRUE : FALSE; - - surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data(progressive, surfaceId); + surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data( + progressive, surfaceId); if (!surface) return -1001; blocks = pSrcData; blocksLen = SrcSize; - region = &(progressive->region); while ((blocksLen - offset) >= 6) { boffset = 0; block = &blocks[offset]; - blockType = *((UINT16*) &block[boffset + 0]); /* blockType (2 bytes) */ blockLen = *((UINT32*) &block[boffset + 2]); /* blockLen (4 bytes) */ boffset += 6; @@ -1649,17 +1609,16 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, switch (blockType) { case PROGRESSIVE_WBT_SYNC: - WLog_DBG(TAG, "ProgressiveSync"); - sync.blockType = blockType; sync.blockLen = blockLen; if ((blockLen - boffset) != 6) return -1004; - sync.magic = (UINT32) *((UINT32*) &block[boffset + 0]); /* magic (4 bytes) */ - sync.version = (UINT32) *((UINT16*) &block[boffset + 4]); /* version (2 bytes) */ + sync.magic = (UINT32) * ((UINT32*) &block[boffset + 0]); /* magic (4 bytes) */ + sync.version = (UINT32) * ((UINT16*) &block[boffset + + 4]); /* version (2 bytes) */ boffset += 6; if (sync.magic != 0xCACCACCA) @@ -1671,32 +1630,28 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, break; case PROGRESSIVE_WBT_FRAME_BEGIN: - frameBegin.blockType = blockType; frameBegin.blockLen = blockLen; if ((blockLen - boffset) < 6) return -1007; - frameBegin.frameIndex = (UINT32) *((UINT32*) &block[boffset + 0]); /* frameIndex (4 bytes) */ - frameBegin.regionCount = (UINT32) *((UINT16*) &block[boffset + 4]); /* regionCount (2 bytes) */ + frameBegin.frameIndex = (UINT32) * ((UINT32*) &block[boffset + + 0]); /* frameIndex (4 bytes) */ + frameBegin.regionCount = (UINT32) * ((UINT16*) &block[boffset + + 4]); /* regionCount (2 bytes) */ boffset += 6; - WLog_DBG(TAG, "ProgressiveFrameBegin: frameIndex: %d regionCount: %d", - frameBegin.frameIndex, frameBegin.regionCount); - + frameBegin.frameIndex, frameBegin.regionCount); /** * If the number of elements specified by the regionCount field is * larger than the actual number of elements in the regions field, * the decoder SHOULD ignore this inconsistency. */ - break; case PROGRESSIVE_WBT_FRAME_END: - WLog_DBG(TAG, "ProgressiveFrameEnd"); - frameEnd.blockType = blockType; frameEnd.blockLen = blockLen; @@ -1706,7 +1661,6 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, break; case PROGRESSIVE_WBT_CONTEXT: - context.blockType = blockType; context.blockLen = blockLen; @@ -1731,7 +1685,6 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, break; case PROGRESSIVE_WBT_REGION: - region->blockType = blockType; region->blockLen = blockLen; @@ -1744,7 +1697,8 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, region->numProgQuant = block[boffset + 4]; /* numProgQuant (1 byte) */ region->flags = block[boffset + 5]; /* flags (1 byte) */ region->numTiles = *((UINT16*) &block[boffset + 6]); /* numTiles (2 bytes) */ - region->tileDataSize = *((UINT32*) &block[boffset + 8]); /* tileDataSize (4 bytes) */ + region->tileDataSize = *((UINT32*) &block[boffset + + 8]); /* tileDataSize (4 bytes) */ boffset += 12; if (region->tileSize != 64) @@ -1761,7 +1715,8 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, if (region->numRects > progressive->cRects) { - progressive->rects = (RFX_RECT*) realloc(progressive->rects, region->numRects * sizeof(RFX_RECT)); + progressive->rects = (RFX_RECT*) realloc(progressive->rects, + region->numRects * sizeof(RFX_RECT)); progressive->cRects = region->numRects; } @@ -1785,8 +1740,9 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, if (region->numQuant > progressive->cQuant) { - progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) realloc(progressive->quantVals, - region->numQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); + progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) realloc( + progressive->quantVals, + region->numQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); progressive->cQuant = region->numQuant; } @@ -1813,8 +1769,9 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, if (region->numProgQuant > progressive->cProgQuant) { - progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) realloc(progressive->quantProgVals, - region->numProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); + progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) realloc( + progressive->quantProgVals, + region->numProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); progressive->cProgQuant = region->numProgQuant; } @@ -1827,10 +1784,12 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, { quantProgVal = &(region->quantProgVals[index]); quantProgVal->quality = block[boffset + 0]; - - progressive_component_codec_quant_read(&block[boffset + 1], &(quantProgVal->yQuantValues)); - progressive_component_codec_quant_read(&block[boffset + 6], &(quantProgVal->cbQuantValues)); - progressive_component_codec_quant_read(&block[boffset + 11], &(quantProgVal->crQuantValues)); + progressive_component_codec_quant_read(&block[boffset + 1], + &(quantProgVal->yQuantValues)); + progressive_component_codec_quant_read(&block[boffset + 6], + &(quantProgVal->cbQuantValues)); + progressive_component_codec_quant_read(&block[boffset + 11], + &(quantProgVal->crQuantValues)); boffset += 16; } @@ -1840,7 +1799,7 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, if (progressive->cTiles < surface->gridSize) { progressive->tiles = (RFX_PROGRESSIVE_TILE**) realloc(progressive->tiles, - surface->gridSize * sizeof(RFX_PROGRESSIVE_TILE*)); + surface->gridSize * sizeof(RFX_PROGRESSIVE_TILE*)); progressive->cTiles = surface->gridSize; } @@ -1849,8 +1808,10 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, if (!region->tiles) return -1; - WLog_DBG(TAG, "ProgressiveRegion: numRects: %d numTiles: %d tileDataSize: %d flags: 0x%02X numQuant: %d numProgQuant: %d", - region->numRects, region->numTiles, region->tileDataSize, region->flags, region->numQuant, region->numProgQuant); + WLog_DBG(TAG, + "ProgressiveRegion: numRects: %d numTiles: %d tileDataSize: %d flags: 0x%02X numQuant: %d numProgQuant: %d", + region->numRects, region->numTiles, region->tileDataSize, region->flags, + region->numQuant, region->numProgQuant); if (!(region->flags & RFX_DWT_REDUCE_EXTRAPOLATE)) { @@ -1865,7 +1826,6 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, for (index = 0; index < region->numRects; index++) { rect = &(region->rects[index]); - idxLeft = rect->x / 64; idxTop = rect->y / 64; idxRight = (rect->x + rect->width + 63) / 64; @@ -1884,10 +1844,11 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, boxBottom = idxBottom; WLog_DBG(TAG, "rect[%d]: x: %d y: %d w: %d h: %d", - index, rect->x, rect->y, rect->width, rect->height); + index, rect->x, rect->y, rect->width, rect->height); } - status = progressive_process_tiles(progressive, &block[boffset], region->tileDataSize, surface); + status = progressive_process_tiles(progressive, &block[boffset], + region->tileDataSize, surface); if (status < 0) return status; @@ -1911,7 +1872,6 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, } boffset += (UINT32) status; - break; default: @@ -1930,19 +1890,16 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, return -1041; region = &(progressive->region); - region16_init(&clippingRects); for (i = 0; i < region->numRects; i++) { RECTANGLE_16 clippingRect; RFX_RECT* rect = &(region->rects[i]); - clippingRect.left = nXDst + rect->x; clippingRect.top = nYDst + rect->y; clippingRect.right = clippingRect.left + rect->width; clippingRect.bottom = clippingRect.top + rect->height; - region16_union_rect(&clippingRects, &clippingRects, &clippingRect); } @@ -1952,12 +1909,10 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, const RECTANGLE_16* updateRects; RECTANGLE_16 updateRect; RFX_PROGRESSIVE_TILE* tile = region->tiles[i]; - updateRect.left = nXDst + tile->x; updateRect.top = nYDst + tile->y; updateRect.right = updateRect.left + 64; updateRect.bottom = updateRect.top + 64; - region16_init(&updateRegion); region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); updateRects = region16_rects(&updateRegion, &nbUpdateRects); @@ -1968,25 +1923,22 @@ UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, UINT32 nYSrc; nWidth = updateRects[j].right - updateRects[j].left; nHeight = updateRects[j].bottom - updateRects[j].top; - nXSrc = updateRects[j].left - (nXDst + tile->x); nYSrc = updateRects[j].top - (nYDst + tile->y); - freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, tile->data, PIXEL_FORMAT_XRGB32, - 64 * 4, nXSrc, nYSrc, NULL); + nWidth, nHeight, tile->data, PIXEL_FORMAT_XRGB32, + 64 * 4, nXSrc, nYSrc, NULL); } region16_uninit(&updateRegion); } region16_uninit(&clippingRects); - return 1; } int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, - UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize) + UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize) { return 1; } @@ -2002,15 +1954,12 @@ BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* progressive) PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor) { PROGRESSIVE_CONTEXT* progressive; - progressive = (PROGRESSIVE_CONTEXT*) calloc(1, sizeof(PROGRESSIVE_CONTEXT)); if (progressive) { progressive->Compressor = Compressor; - progressive->bufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16); - progressive->cRects = 64; progressive->rects = (RFX_RECT*) malloc(progressive->cRects * sizeof(RFX_RECT)); @@ -2018,33 +1967,34 @@ PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor) goto cleanup; progressive->cTiles = 64; - progressive->tiles = (RFX_PROGRESSIVE_TILE**) malloc(progressive->cTiles * sizeof(RFX_PROGRESSIVE_TILE*)); + progressive->tiles = (RFX_PROGRESSIVE_TILE**) malloc(progressive->cTiles * + sizeof(RFX_PROGRESSIVE_TILE*)); if (!progressive->tiles) goto cleanup; progressive->cQuant = 8; - progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) malloc(progressive->cQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); + progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) malloc( + progressive->cQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); if (!progressive->quantVals) goto cleanup; progressive->cProgQuant = 8; - progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) malloc(progressive->cProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); + progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) malloc( + progressive->cProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); if (!progressive->quantProgVals) goto cleanup; - ZeroMemory(&(progressive->quantProgValFull), sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); + ZeroMemory(&(progressive->quantProgValFull), + sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); progressive->quantProgValFull.quality = 100; - progressive->SurfaceContexts = HashTable_New(TRUE); - progressive_context_reset(progressive); } return progressive; - cleanup: free(progressive->rects); free(progressive->tiles); @@ -2065,24 +2015,21 @@ void progressive_context_free(PROGRESSIVE_CONTEXT* progressive) return; BufferPool_Free(progressive->bufferPool); - free(progressive->rects); free(progressive->tiles); free(progressive->quantVals); free(progressive->quantProgVals); - count = HashTable_GetKeys(progressive->SurfaceContexts, &pKeys); for (index = 0; index < count; index++) { - surface = (PROGRESSIVE_SURFACE_CONTEXT*) HashTable_GetItemValue(progressive->SurfaceContexts, (void*) pKeys[index]); + surface = (PROGRESSIVE_SURFACE_CONTEXT*) HashTable_GetItemValue( + progressive->SurfaceContexts, (void*) pKeys[index]); progressive_surface_context_free(surface); } free(pKeys); - HashTable_Free(progressive->SurfaceContexts); - free(progressive); } diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index c411be8f7..5793a1664 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -149,7 +149,7 @@ static void rfx_profiler_print(RFX_CONTEXT* context) PROFILER_PRINT_FOOTER; } -void rfx_tile_init(RFX_TILE* tile) +static void rfx_tile_init(RFX_TILE* tile) { if (tile) { @@ -164,7 +164,7 @@ void rfx_tile_init(RFX_TILE* tile) } } -RFX_TILE* rfx_decoder_tile_new() +static RFX_TILE* rfx_decoder_tile_new(void) { RFX_TILE* tile = NULL; @@ -181,7 +181,7 @@ RFX_TILE* rfx_decoder_tile_new() return tile; } -void rfx_decoder_tile_free(RFX_TILE* tile) +static void rfx_decoder_tile_free(RFX_TILE* tile) { if (tile) { @@ -192,12 +192,12 @@ void rfx_decoder_tile_free(RFX_TILE* tile) } } -RFX_TILE* rfx_encoder_tile_new() +static RFX_TILE* rfx_encoder_tile_new() { return (RFX_TILE*)calloc(1, sizeof(RFX_TILE)); } -void rfx_encoder_tile_free(RFX_TILE* tile) +static void rfx_encoder_tile_free(RFX_TILE* tile) { free(tile); } @@ -733,8 +733,9 @@ struct _RFX_TILE_PROCESS_WORK_PARAM }; typedef struct _RFX_TILE_PROCESS_WORK_PARAM RFX_TILE_PROCESS_WORK_PARAM; -void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE - instance, void* context, PTP_WORK work) +static void CALLBACK rfx_process_message_tile_work_callback( + PTP_CALLBACK_INSTANCE + instance, void* context, PTP_WORK work) { RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*) context; rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4); diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index e8568fad9..e02540915 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -1094,7 +1094,7 @@ static BOOL gdi_surface_bits(rdpContext* context, cmd->bitmapDataLength, cmd->destLeft, cmd->destTop, pDstData, gdi->dstFormat, - gdi->width, gdi->height, NULL)) + cmd->width, cmd->height, NULL)) { WLog_ERR(TAG, "Failed to process RemoteFX message"); return FALSE; @@ -1106,14 +1106,14 @@ static BOOL gdi_surface_bits(rdpContext* context, gdi->width, gdi->height)) return FALSE; - nsc_process_message(gdi->codecs->nsc, cmd->bpp, cmd->width, - cmd->height, cmd->bitmapData, - cmd->bitmapDataLength); + if (!nsc_process_message(gdi->codecs->nsc, cmd->bpp, cmd->width, + cmd->height, cmd->bitmapData, + cmd->bitmapDataLength, gdi->bitmap_buffer, + gdi->dstFormat, + 0, 0, 0, cmd->width, cmd->height)) + return FALSE; + pDstData = gdi->bitmap_buffer; - pSrcData = gdi->codecs->nsc->BitmapData; - freerdp_image_copy(pDstData, gdi->dstFormat, -1, 0, 0, - cmd->width, cmd->height, pSrcData, - PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); gdi_DeleteObject((HGDIOBJECT)gdi->image->bitmap); gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, gdi->dstFormat, 0, diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index f0f46b06b..bffc8e5ad 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -3,6 +3,8 @@ * GDI Graphics Pipeline * * Copyright 2014 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +34,10 @@ * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* resetGraphics) +static UINT gdi_ResetGraphics(RdpgfxClientContext* context, + const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics) { - int index; + UINT32 index; UINT16 count; UINT32 DesktopWidth; UINT32 DesktopHeight; @@ -43,11 +46,11 @@ UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* rdpGdi* gdi = (rdpGdi*) context->custom; rdpUpdate* update = gdi->context->update; rdpSettings* settings = gdi->context->settings; - DesktopWidth = resetGraphics->width; DesktopHeight = resetGraphics->height; - if ((DesktopWidth != settings->DesktopWidth) || (DesktopHeight != settings->DesktopHeight)) + if ((DesktopWidth != settings->DesktopWidth) + || (DesktopHeight != settings->DesktopHeight)) { settings->DesktopWidth = DesktopWidth; settings->DesktopHeight = DesktopHeight; @@ -66,9 +69,9 @@ UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* continue; if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL, - surface->width, surface->height)) + surface->width, surface->height)) { - free (pSurfaceIds); + free(pSurfaceIds); return ERROR_INTERNAL_ERROR; } @@ -82,75 +85,60 @@ UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* return ERROR_INTERNAL_ERROR; gdi->graphicsReset = TRUE; - return CHANNEL_RC_OK; } -int gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface) +static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface) { - int nDstStep; - BYTE* pDstData; - int nXDst, nYDst; - int nXSrc, nYSrc; + UINT32 nXDst, nYDst; + UINT32 nXSrc, nYSrc; UINT16 width, height; UINT32 surfaceX, surfaceY; RECTANGLE_16 surfaceRect; const RECTANGLE_16* extents; rdpUpdate* update = gdi->context->update; - - pDstData = gdi->primary_buffer; - nDstStep = gdi->bytesPerPixel * gdi->width; - surfaceX = surface->outputOriginX; surfaceY = surface->outputOriginY; - surfaceRect.left = 0; surfaceRect.top = 0; surfaceRect.right = surface->width; surfaceRect.bottom = surface->height; - - region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect); + region16_intersect_rect(&(surface->invalidRegion), + &(surface->invalidRegion), &surfaceRect); if (!region16_is_empty(&(surface->invalidRegion))) { extents = region16_extents(&(surface->invalidRegion)); - nXSrc = extents->left; nYSrc = extents->top; - nXDst = surfaceX + extents->left; nYDst = surfaceY + extents->top; - width = extents->right - extents->left; height = extents->bottom - extents->top; - update->BeginPaint(gdi->context); - - freerdp_image_copy(pDstData, gdi->format, nDstStep, nXDst, nYDst, - width, height, surface->data, surface->format, - surface->scanline, nXSrc, nYSrc, NULL); - + freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride, + nXDst, nYDst, width, height, + surface->data, surface->format, + surface->scanline, nXSrc, nYSrc, NULL); gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst, width, height); - update->EndPaint(gdi->context); } region16_clear(&(surface->invalidRegion)); - - return 1; + return CHANNEL_RC_OK; } -int gdi_UpdateSurfaces(rdpGdi* gdi) +static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context) { UINT16 count; - int index; - int status = 1; + UINT16 index; + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; UINT16* pSurfaceIds = NULL; - RdpgfxClientContext* context = gdi->gfx; + rdpGdi* gdi = (rdpGdi*)context->custom; if (!gdi->graphicsReset) - return 1; + return status; context->GetSurfaceIds(context, &pSurfaceIds, &count); @@ -163,63 +151,11 @@ int gdi_UpdateSurfaces(rdpGdi* gdi) status = gdi_OutputUpdate(gdi, surface); - if (status < 0) + if (status != CHANNEL_RC_OK) break; } free(pSurfaceIds); - - return status; -} - -int gdi_OutputExpose(rdpGdi* gdi, int x, int y, int width, int height) -{ - int index; - int status = 1; - UINT16 count; - gdiGfxSurface* surface; - RECTANGLE_16 invalidRect; - RECTANGLE_16 surfaceRect; - RECTANGLE_16 intersection; - UINT16* pSurfaceIds = NULL; - RdpgfxClientContext* context = gdi->gfx; - - invalidRect.left = x; - invalidRect.top = y; - invalidRect.right = x + width; - invalidRect.bottom = y + height; - - context->GetSurfaceIds(context, &pSurfaceIds, &count); - - for (index = 0; index < count; index++) - { - surface = (gdiGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]); - - if (!surface || !surface->outputMapped) - continue; - - surfaceRect.left = surface->outputOriginX; - surfaceRect.top = surface->outputOriginY; - surfaceRect.right = surface->outputOriginX + surface->width; - surfaceRect.bottom = surface->outputOriginY + surface->height; - - if (rectangles_intersection(&invalidRect, &surfaceRect, &intersection)) - { - /* Invalid rects are specified relative to surface origin */ - intersection.left -= surfaceRect.left; - intersection.top -= surfaceRect.top; - intersection.right -= surfaceRect.left; - intersection.bottom -= surfaceRect.top; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &intersection); - } - } - - free(pSurfaceIds); - - if (gdi_UpdateSurfaces(gdi) < 0) - status = -1; - return status; } @@ -228,12 +164,11 @@ int gdi_OutputExpose(rdpGdi* gdi, int x, int y, int width, int height) * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_StartFrame(RdpgfxClientContext* context, RDPGFX_START_FRAME_PDU* startFrame) +static UINT gdi_StartFrame(RdpgfxClientContext* context, + const RDPGFX_START_FRAME_PDU* startFrame) { rdpGdi* gdi = (rdpGdi*) context->custom; - gdi->inGfxFrame = TRUE; - return CHANNEL_RC_OK; } @@ -242,15 +177,14 @@ UINT gdi_StartFrame(RdpgfxClientContext* context, RDPGFX_START_FRAME_PDU* startF * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_EndFrame(RdpgfxClientContext* context, RDPGFX_END_FRAME_PDU* endFrame) +static UINT gdi_EndFrame(RdpgfxClientContext* context, + const RDPGFX_END_FRAME_PDU* endFrame) { + UINT status = CHANNEL_RC_NOT_INITIALIZED; rdpGdi* gdi = (rdpGdi*) context->custom; - - gdi_UpdateSurfaces(gdi); - + IFCALLRET(context->UpdateSurfaces, status, context); gdi->inGfxFrame = FALSE; - - return CHANNEL_RC_OK; + return status; } /** @@ -258,30 +192,37 @@ UINT gdi_EndFrame(RdpgfxClientContext* context, RDPGFX_END_FRAME_PDU* endFrame) * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, + RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) return ERROR_INTERNAL_ERROR; - freerdp_image_copy(surface->data, surface->format, surface->scanline, cmd->left, cmd->top, - cmd->width, cmd->height, cmd->data, PIXEL_FORMAT_XRGB32, cmd->width * 4, 0, 0, NULL); + if (!freerdp_image_copy(surface->data, surface->format, surface->scanline, + cmd->left, cmd->top, cmd->width, cmd->height, + cmd->data, cmd->format, -1, 0, 0, NULL)) + return ERROR_INTERNAL_ERROR; invalidRect.left = cmd->left; invalidRect.top = cmd->top; invalidRect.right = cmd->right; invalidRect.bottom = cmd->bottom; - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -289,23 +230,12 @@ UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context, * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, + RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int j; - UINT16 i; - RFX_RECT* rect; - RFX_TILE* tile; - int nXDst, nYDst; - int nWidth, nHeight; - int nbUpdateRects; - RFX_MESSAGE* message; + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; - REGION16 updateRegion; - RECTANGLE_16 updateRect; - RECTANGLE_16* updateRects; - REGION16 clippingRects; - RECTANGLE_16 clippingRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -314,64 +244,23 @@ UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context, RDPG if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_REMOTEFX)) return ERROR_INTERNAL_ERROR; - if (!(message = rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length))) + if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->format, + cmd->length, + cmd->left, cmd->top, + surface->data, surface->format, surface->scanline, + surface->height, &surface->invalidRegion)) { WLog_ERR(TAG, "Failed to process RemoteFX message"); return ERROR_INTERNAL_ERROR; } - region16_init(&clippingRects); - - for (i = 0; i < message->numRects; i++) - { - rect = &(message->rects[i]); - - clippingRect.left = cmd->left + rect->x; - clippingRect.top = cmd->top + rect->y; - clippingRect.right = clippingRect.left + rect->width; - clippingRect.bottom = clippingRect.top + rect->height; - - region16_union_rect(&clippingRects, &clippingRects, &clippingRect); - } - - for (i = 0; i < message->numTiles; i++) - { - tile = message->tiles[i]; - - updateRect.left = cmd->left + tile->x; - updateRect.top = cmd->top + tile->y; - updateRect.right = updateRect.left + 64; - updateRect.bottom = updateRect.top + 64; - - region16_init(&updateRegion); - region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); - updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects); - - for (j = 0; j < nbUpdateRects; j++) - { - nXDst = updateRects[j].left; - nYDst = updateRects[j].top; - nWidth = updateRects[j].right - updateRects[j].left; - nHeight = updateRects[j].bottom - updateRects[j].top; - - freerdp_image_copy(surface->data, surface->format, surface->scanline, - nXDst, nYDst, nWidth, nHeight, - tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, 0, 0, NULL); - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &updateRects[j]); - } - - region16_uninit(&updateRegion); - } - - region16_uninit(&clippingRects); - - rfx_message_free(surface->codecs->rfx, message); - if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -379,13 +268,14 @@ UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context, RDPG * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, + RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int status; - BYTE* DstData = NULL; + INT32 rc; + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -394,12 +284,12 @@ UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RD if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_CLEARCODEC)) return ERROR_INTERNAL_ERROR; - DstData = surface->data; + rc = clear_decompress(gdi->codecs->clear, cmd->data, cmd->length, + surface->data, surface->format, + surface->scanline, cmd->left, cmd->top, + cmd->width, cmd->height); - status = clear_decompress(gdi->codecs->clear, cmd->data, cmd->length, &DstData, - surface->format, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height); - - if (status < 0) + if (rc < 0) { WLog_ERR(TAG, "clear_decompress failure: %d", status); return ERROR_INTERNAL_ERROR; @@ -409,13 +299,16 @@ UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RD invalidRect.top = cmd->top; invalidRect.right = cmd->right; invalidRect.bottom = cmd->bottom; - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -423,13 +316,14 @@ UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RD * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int status; + INT32 rc; + UINT status = CHANNEL_RC_OK; BYTE* DstData = NULL; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -439,21 +333,28 @@ UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX return ERROR_INTERNAL_ERROR; DstData = surface->data; + rc = planar_decompress(surface->codecs->planar, cmd->data, cmd->length, + &DstData, surface->format, + surface->scanline, cmd->left, cmd->top, + cmd->width, cmd->height, FALSE); - status = planar_decompress(surface->codecs->planar, cmd->data, cmd->length, &DstData, - PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, FALSE); + if (rc < 0) + return ERROR_INTERNAL_ERROR; invalidRect.left = cmd->left; invalidRect.top = cmd->top; invalidRect.right = cmd->right; invalidRect.bottom = cmd->bottom; - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -461,14 +362,16 @@ UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX * * @return 0 on success, otherwise a Win32 error code */ -static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, + RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int status; + INT32 rc; + UINT status = CHANNEL_RC_OK; UINT32 i; gdiGfxSurface* surface; RDPGFX_H264_METABLOCK* meta; RDPGFX_AVC420_BITMAP_STREAM* bs; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -483,14 +386,13 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context, return ERROR_INTERNAL_ERROR; meta = &(bs->meta); + rc = avc420_decompress(surface->codecs->h264, bs->data, bs->length, + surface->data, surface->format, + surface->scanline, surface->width, + surface->height, meta->regionRects, + meta->numRegionRects); - status = avc420_decompress(surface->codecs->h264, bs->data, bs->length, - surface->data, PIXEL_FORMAT_XRGB32, - surface->scanline, surface->width, - surface->height, meta->regionRects, - meta->numRegionRects); - - if (status < 0) + if (rc < 0) { WLog_WARN(TAG, "avc420_decompress failure: %d, ignoring update.", status); return CHANNEL_RC_OK; @@ -498,13 +400,17 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context, for (i = 0; i < meta->numRegionRects; i++) { - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), (RECTANGLE_16*) &(meta->regionRects[i])); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + (RECTANGLE_16*) & (meta->regionRects[i])); } if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -512,9 +418,11 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context, * * @return 0 on success, otherwise a Win32 error code */ -static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int status; + INT32 rc; + UINT status = CHANNEL_RC_OK; UINT32 i; gdiGfxSurface* surface; RDPGFX_AVC444_BITMAP_STREAM* bs; @@ -523,7 +431,6 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_AVC420_BITMAP_STREAM* avc2; RDPGFX_H264_METABLOCK* meta2; RECTANGLE_16* regionRects = NULL; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -541,14 +448,14 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, avc2 = &bs->bitstream[1]; meta1 = &avc1->meta; meta2 = &avc2->meta; - status = avc444_decompress(surface->codecs->h264, bs->LC, - meta1->regionRects, meta1->numRegionRects, - avc1->data, avc1->length, - meta2->regionRects, meta2->numRegionRects, - avc2->data, avc2->length, - surface->data, PIXEL_FORMAT_XRGB32, - surface->scanline, surface->width, - surface->height); + rc = avc444_decompress(surface->codecs->h264, bs->LC, + meta1->regionRects, meta1->numRegionRects, + avc1->data, avc1->length, + meta2->regionRects, meta2->numRegionRects, + avc2->data, avc2->length, + surface->data, surface->format, + surface->scanline, surface->width, + surface->height); if (status < 0) { @@ -559,23 +466,25 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, for (i = 0; i < meta1->numRegionRects; i++) { region16_union_rect(&(surface->invalidRegion), - &(surface->invalidRegion), - &(meta1->regionRects[i])); + &(surface->invalidRegion), + &(meta1->regionRects[i])); } for (i = 0; i < meta2->numRegionRects; i++) { region16_union_rect(&(surface->invalidRegion), - &(surface->invalidRegion), - &(meta2->regionRects[i])); + &(surface->invalidRegion), + &(meta2->regionRects[i])); } if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } free(regionRects); - - return CHANNEL_RC_OK; + return status; } /** @@ -583,12 +492,12 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int status = 0; + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -598,23 +507,25 @@ UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_ return ERROR_INTERNAL_ERROR; WLog_DBG(TAG, "gdi_SurfaceCommand_Alpha: status: %d", status); - /* fill with green for now to distinguish from the rest */ - - freerdp_image_fill(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline, - cmd->left, cmd->top, cmd->width, cmd->height, 0x00FF00); + if (!freerdp_image_fill(surface->data, surface->format, surface->scanline, + cmd->left, cmd->top, cmd->width, cmd->height, 0x00FF00)) + return ERROR_INTERNAL_ERROR; invalidRect.left = cmd->left; invalidRect.top = cmd->top; invalidRect.right = cmd->right; invalidRect.bottom = cmd->bottom; - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -622,25 +533,14 @@ UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_ * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, + RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { - int i, j; - int status; - BYTE* DstData; - RFX_RECT* rect; - int nXDst, nYDst; - int nXSrc, nYSrc; - int nWidth, nHeight; - int nbUpdateRects; + INT32 rc; + UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; - REGION16 updateRegion; - RECTANGLE_16 updateRect; - RECTANGLE_16* updateRects; - REGION16 clippingRects; - RECTANGLE_16 clippingRect; - RFX_PROGRESSIVE_TILE* tile; - PROGRESSIVE_BLOCK_REGION* region; - + RECTANGLE_16 invalidRect; surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -649,12 +549,9 @@ UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, R if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PROGRESSIVE)) return ERROR_INTERNAL_ERROR; - progressive_create_surface_context(surface->codecs->progressive, cmd->surfaceId, surface->width, surface->height); - - DstData = surface->data; - - status = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, &DstData, - PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, cmd->surfaceId); + rc = progressive_create_surface_context(surface->codecs->progressive, + cmd->surfaceId, + surface->width, surface->height); if (status < 0) { @@ -662,61 +559,20 @@ UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, R return ERROR_INTERNAL_ERROR; } - region = &(surface->codecs->progressive->region); - - region16_init(&clippingRects); - - for (i = 0; i < region->numRects; i++) - { - rect = &(region->rects[i]); - - clippingRect.left = cmd->left + rect->x; - clippingRect.top = cmd->top + rect->y; - clippingRect.right = clippingRect.left + rect->width; - clippingRect.bottom = clippingRect.top + rect->height; - - region16_union_rect(&clippingRects, &clippingRects, &clippingRect); - } - - for (i = 0; i < region->numTiles; i++) - { - tile = region->tiles[i]; - - updateRect.left = cmd->left + tile->x; - updateRect.top = cmd->top + tile->y; - updateRect.right = updateRect.left + 64; - updateRect.bottom = updateRect.top + 64; - - region16_init(&updateRegion); - region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); - updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects); - - for (j = 0; j < nbUpdateRects; j++) - { - nXDst = updateRects[j].left; - nYDst = updateRects[j].top; - nWidth = updateRects[j].right - updateRects[j].left; - nHeight = updateRects[j].bottom - updateRects[j].top; - - nXSrc = nXDst - (cmd->left + tile->x); - nYSrc = nYDst - (cmd->top + tile->y); - - freerdp_image_copy(surface->data, surface->format, - surface->scanline, nXDst, nYDst, nWidth, nHeight, - tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, nXSrc, nYSrc, NULL); - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &updateRects[j]); - } - - region16_uninit(&updateRegion); - } - - region16_uninit(&clippingRects); + invalidRect.left = cmd->left; + invalidRect.top = cmd->top; + invalidRect.right = cmd->right; + invalidRect.bottom = cmd->bottom; + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -724,7 +580,8 @@ UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, R * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceCommand(RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) +static UINT gdi_SurfaceCommand(RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) { UINT status = CHANNEL_RC_OK; rdpGdi* gdi = (rdpGdi*) context->custom; @@ -780,7 +637,8 @@ UINT gdi_SurfaceCommand(RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cm * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_DeleteEncodingContext(RdpgfxClientContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext) +static UINT gdi_DeleteEncodingContext(RdpgfxClientContext* context, + const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext) { return CHANNEL_RC_OK; } @@ -790,11 +648,11 @@ UINT gdi_DeleteEncodingContext(RdpgfxClientContext* context, RDPGFX_DELETE_ENCOD * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* createSurface) +static UINT gdi_CreateSurface(RdpgfxClientContext* context, + const RDPGFX_CREATE_SURFACE_PDU* createSurface) { gdiGfxSurface* surface; rdpGdi* gdi = (rdpGdi*) context->custom; - surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface)); if (!surface) @@ -804,23 +662,35 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* if (!surface->codecs) { - free (surface); + free(surface); return CHANNEL_RC_NO_MEMORY; } if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL, - createSurface->width, createSurface->height)) + createSurface->width, createSurface->height)) { - free (surface); + free(surface); return ERROR_INTERNAL_ERROR; } surface->surfaceId = createSurface->surfaceId; surface->width = (UINT32) createSurface->width; surface->height = (UINT32) createSurface->height; - surface->alpha = (createSurface->pixelFormat == PIXEL_FORMAT_ARGB_8888) ? TRUE : FALSE; - surface->format = (!gdi->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32; + switch (createSurface->pixelFormat) + { + case PIXEL_FORMAT_ARGB_8888: + surface->format = PIXEL_FORMAT_BGRA32; + break; + + case PIXEL_FORMAT_XRGB_8888: + surface->format = PIXEL_FORMAT_BGRX32; + break; + + default: + free(surface); + return ERROR_INTERNAL_ERROR; + } surface->scanline = (surface->width + (surface->width % 4)) * 4; surface->data = (BYTE*) calloc(1, surface->scanline * surface->height); @@ -832,11 +702,8 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* } surface->outputMapped = FALSE; - region16_init(&surface->invalidRegion); - context->SetSurfaceData(context, surface->surfaceId, (void*) surface); - return CHANNEL_RC_OK; } @@ -845,12 +712,13 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* deleteSurface) +static UINT gdi_DeleteSurface(RdpgfxClientContext* context, + const RDPGFX_DELETE_SURFACE_PDU* deleteSurface) { rdpCodecs* codecs = NULL; gdiGfxSurface* surface = NULL; - - surface = (gdiGfxSurface*) context->GetSurfaceData(context, deleteSurface->surfaceId); + surface = (gdiGfxSurface*) context->GetSurfaceData(context, + deleteSurface->surfaceId); if (surface) { @@ -863,10 +731,10 @@ UINT gdi_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* context->SetSurfaceData(context, deleteSurface->surfaceId, NULL); if (codecs && codecs->progressive) - progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId); + progressive_delete_surface_context(codecs->progressive, + deleteSurface->surfaceId); codecs_free(codecs); - return CHANNEL_RC_OK; } @@ -875,18 +743,20 @@ UINT gdi_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SolidFill(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFill) +static UINT gdi_SolidFill(RdpgfxClientContext* context, + const RDPGFX_SOLID_FILL_PDU* solidFill) { + UINT status = CHANNEL_RC_OK; UINT16 index; UINT32 color; BYTE a, r, g, b; - int nWidth, nHeight; + UINT32 nWidth, nHeight; RECTANGLE_16* rect; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; rdpGdi* gdi = (rdpGdi*) context->custom; - - surface = (gdiGfxSurface*) context->GetSurfaceData(context, solidFill->surfaceId); + surface = (gdiGfxSurface*) context->GetSurfaceData(context, + solidFill->surfaceId); if (!surface) return ERROR_INTERNAL_ERROR; @@ -895,34 +765,31 @@ UINT gdi_SolidFill(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFil g = solidFill->fillPixel.G; r = solidFill->fillPixel.R; a = solidFill->fillPixel.XA; - - if (!gdi->invert) - color = ARGB32(a, r, g, b); - else - color = ABGR32(a, r, g, b); + color = GetColor(PIXEL_FORMAT_ARGB32, r, g, b, a); + color = ConvertColor(color, PIXEL_FORMAT_ARGB32, surface->format, NULL); for (index = 0; index < solidFill->fillRectCount; index++) { rect = &(solidFill->fillRects[index]); - nWidth = rect->right - rect->left; nHeight = rect->bottom - rect->top; - invalidRect.left = rect->left; invalidRect.top = rect->top; invalidRect.right = rect->right; invalidRect.bottom = rect->bottom; - freerdp_image_fill(surface->data, surface->format, surface->scanline, - rect->left, rect->top, nWidth, nHeight, color); - - region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + rect->left, rect->top, nWidth, nHeight, color); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), + &invalidRect); } if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -930,26 +797,28 @@ UINT gdi_SolidFill(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFil * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceToSurface(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface) +static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface) { + UINT status = CHANNEL_RC_OK; UINT16 index; BOOL sameSurface; - int nWidth, nHeight; - RECTANGLE_16* rectSrc; + UINT32 nWidth, nHeight; + const RECTANGLE_16* rectSrc; RDPGFX_POINT16* destPt; RECTANGLE_16 invalidRect; gdiGfxSurface* surfaceSrc; gdiGfxSurface* surfaceDst; rdpGdi* gdi = (rdpGdi*) context->custom; - rectSrc = &(surfaceToSurface->rectSrc); - - surfaceSrc = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc); - - sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest) ? TRUE : FALSE; + surfaceSrc = (gdiGfxSurface*) context->GetSurfaceData(context, + surfaceToSurface->surfaceIdSrc); + sameSurface = (surfaceToSurface->surfaceIdSrc == + surfaceToSurface->surfaceIdDest) ? TRUE : FALSE; if (!sameSurface) - surfaceDst = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest); + surfaceDst = (gdiGfxSurface*) context->GetSurfaceData(context, + surfaceToSurface->surfaceIdDest); else surfaceDst = surfaceSrc; @@ -962,31 +831,27 @@ UINT gdi_SurfaceToSurface(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFAC for (index = 0; index < surfaceToSurface->destPtsCount; index++) { destPt = &surfaceToSurface->destPts[index]; - - if (sameSurface) - { - freerdp_image_move(surfaceDst->data, surfaceDst->format, surfaceDst->scanline, - destPt->x, destPt->y, nWidth, nHeight, rectSrc->left, rectSrc->top); - } - else - { - freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline, - destPt->x, destPt->y, nWidth, nHeight, surfaceSrc->data, surfaceSrc->format, - surfaceSrc->scanline, rectSrc->left, rectSrc->top, NULL); - } - + freerdp_image_copy(surfaceDst->data, surfaceDst->format, + surfaceDst->scanline, + destPt->x, destPt->y, nWidth, nHeight, + surfaceSrc->data, surfaceSrc->format, + surfaceSrc->scanline, + rectSrc->left, rectSrc->top, NULL); invalidRect.left = destPt->x; invalidRect.top = destPt->y; invalidRect.right = destPt->x + rectSrc->right; invalidRect.bottom = destPt->y + rectSrc->bottom; - - region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion, &invalidRect); + region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion, + &invalidRect); } if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -994,16 +859,15 @@ UINT gdi_SurfaceToSurface(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFAC * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache) +static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache) { - RECTANGLE_16* rect; + const RECTANGLE_16* rect; gdiGfxSurface* surface; gdiGfxCacheEntry* cacheEntry; - rdpGdi* gdi = (rdpGdi*) context->custom; - rect = &(surfaceToCache->rectSrc); - - surface = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToCache->surfaceId); + surface = (gdiGfxSurface*) context->GetSurfaceData(context, + surfaceToCache->surfaceId); if (!surface) return ERROR_INTERNAL_ERROR; @@ -1013,12 +877,9 @@ UINT gdi_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PD if (!cacheEntry) return ERROR_INTERNAL_ERROR; - cacheEntry->width = (UINT32) (rect->right - rect->left); - cacheEntry->height = (UINT32) (rect->bottom - rect->top); - cacheEntry->alpha = surface->alpha; - - cacheEntry->format = (!gdi->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32; - + cacheEntry->width = (UINT32)(rect->right - rect->left); + cacheEntry->height = (UINT32)(rect->bottom - rect->top); + cacheEntry->format = surface->format; cacheEntry->scanline = (cacheEntry->width + (cacheEntry->width % 4)) * 4; cacheEntry->data = (BYTE*) calloc(1, cacheEntry->scanline * cacheEntry->height); @@ -1029,11 +890,10 @@ UINT gdi_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PD } freerdp_image_copy(cacheEntry->data, cacheEntry->format, cacheEntry->scanline, - 0, 0, cacheEntry->width, cacheEntry->height, surface->data, - surface->format, surface->scanline, rect->left, rect->top, NULL); - - context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (void*) cacheEntry); - + 0, 0, cacheEntry->width, cacheEntry->height, surface->data, + surface->format, surface->scanline, rect->left, rect->top, NULL); + context->SetCacheSlotData(context, surfaceToCache->cacheSlot, + (void*) cacheEntry); return CHANNEL_RC_OK; } @@ -1042,17 +902,20 @@ UINT gdi_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PD * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_CacheToSurface(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface) +static UINT gdi_CacheToSurface(RdpgfxClientContext* context, + const RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface) { + UINT status = CHANNEL_RC_OK; UINT16 index; RDPGFX_POINT16* destPt; gdiGfxSurface* surface; gdiGfxCacheEntry* cacheEntry; RECTANGLE_16 invalidRect; rdpGdi* gdi = (rdpGdi*) context->custom; - - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cacheToSurface->surfaceId); - cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, cacheToSurface->cacheSlot); + surface = (gdiGfxSurface*) context->GetSurfaceData(context, + cacheToSurface->surfaceId); + cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, + cacheToSurface->cacheSlot); if (!surface || !cacheEntry) return ERROR_INTERNAL_ERROR; @@ -1060,23 +923,24 @@ UINT gdi_CacheToSurface(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PD for (index = 0; index < cacheToSurface->destPtsCount; index++) { destPt = &cacheToSurface->destPts[index]; - freerdp_image_copy(surface->data, surface->format, surface->scanline, - destPt->x, destPt->y, cacheEntry->width, cacheEntry->height, - cacheEntry->data, cacheEntry->format, cacheEntry->scanline, 0, 0, NULL); - + destPt->x, destPt->y, cacheEntry->width, cacheEntry->height, + cacheEntry->data, cacheEntry->format, cacheEntry->scanline, 0, 0, NULL); invalidRect.left = destPt->x; invalidRect.top = destPt->y; invalidRect.right = destPt->x + cacheEntry->width - 1; invalidRect.bottom = destPt->y + cacheEntry->height - 1; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); + region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, + &invalidRect); } if (!gdi->inGfxFrame) - gdi_UpdateSurfaces(gdi); + { + status = CHANNEL_RC_NOT_INITIALIZED; + IFCALLRET(context->UpdateSurfaces, status, context); + } - return CHANNEL_RC_OK; + return status; } /** @@ -1084,7 +948,8 @@ UINT gdi_CacheToSurface(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PD * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_CacheImportReply(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply) +static UINT gdi_CacheImportReply(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply) { return CHANNEL_RC_OK; } @@ -1094,11 +959,12 @@ UINT gdi_CacheImportReply(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_REPL * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_EvictCacheEntry(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry) +static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context, + const RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry) { gdiGfxCacheEntry* cacheEntry; - - cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, evictCacheEntry->cacheSlot); + cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, + evictCacheEntry->cacheSlot); if (cacheEntry) { @@ -1107,7 +973,6 @@ UINT gdi_EvictCacheEntry(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_ } context->SetCacheSlotData(context, evictCacheEntry->cacheSlot, NULL); - return CHANNEL_RC_OK; } @@ -1116,11 +981,12 @@ UINT gdi_EvictCacheEntry(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_ * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput) +static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput) { gdiGfxSurface* surface; - - surface = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToOutput->surfaceId); + surface = (gdiGfxSurface*) context->GetSurfaceData(context, + surfaceToOutput->surfaceId); if (!surface) return ERROR_INTERNAL_ERROR; @@ -1128,9 +994,7 @@ UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_ surface->outputMapped = TRUE; surface->outputOriginX = surfaceToOutput->outputOriginX; surface->outputOriginY = surfaceToOutput->outputOriginY; - region16_clear(&surface->invalidRegion); - return CHANNEL_RC_OK; } @@ -1139,7 +1003,8 @@ UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_ * * @return 0 on success, otherwise a Win32 error code */ -UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow) +static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow) { return CHANNEL_RC_OK; } @@ -1148,7 +1013,6 @@ void gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx) { gdi->gfx = gfx; gfx->custom = (void*) gdi; - gfx->ResetGraphics = gdi_ResetGraphics; gfx->StartFrame = gdi_StartFrame; gfx->EndFrame = gdi_EndFrame; @@ -1164,12 +1028,12 @@ void gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx) gfx->EvictCacheEntry = gdi_EvictCacheEntry; gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput; gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow; + gfx->UpdateSurfaces = gdi_UpdateSurfaces; } void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx) { region16_uninit(&(gdi->invalidRegion)); - gdi->gfx = NULL; gfx->custom = NULL; }