2014-07-29 01:42:23 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Progressive Codec Bitmap Compression
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/bitstream.h>
|
|
|
|
|
2014-08-19 03:12:08 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2014-07-29 01:42:23 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
|
|
|
#include <freerdp/codec/progressive.h>
|
|
|
|
|
2014-08-19 03:12:08 +04:00
|
|
|
#include "rfx_differential.h"
|
|
|
|
#include "rfx_quantization.h"
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
const char* progressive_get_block_type_string(UINT16 blockType)
|
|
|
|
{
|
|
|
|
switch (blockType)
|
|
|
|
{
|
|
|
|
case PROGRESSIVE_WBT_SYNC:
|
|
|
|
return "PROGRESSIVE_WBT_SYNC";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_BEGIN:
|
|
|
|
return "PROGRESSIVE_WBT_FRAME_BEGIN";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_END:
|
|
|
|
return "PROGRESSIVE_WBT_FRAME_END";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_CONTEXT:
|
|
|
|
return "PROGRESSIVE_WBT_CONTEXT";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_REGION:
|
|
|
|
return "PROGRESSIVE_WBT_REGION";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_SIMPLE:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_SIMPLE";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_FIRST:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_FIRST";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_UPGRADE:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_UPGRADE";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "PROGRESSIVE_WBT_UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "PROGRESSIVE_WBT_UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
void progressive_component_codec_quant_read(BYTE* block, RFX_COMPONENT_CODEC_QUANT* quantVal)
|
|
|
|
{
|
|
|
|
quantVal->LL3 = block[0] & 0x0F;
|
|
|
|
quantVal->HL3 = block[0] >> 4;
|
|
|
|
quantVal->LH3 = block[1] & 0x0F;
|
|
|
|
quantVal->HH3 = block[1] >> 4;
|
|
|
|
quantVal->HL2 = block[2] & 0x0F;
|
|
|
|
quantVal->LH2 = block[2] >> 4;
|
|
|
|
quantVal->HH2 = block[3] & 0x0F;
|
|
|
|
quantVal->HL1 = block[3] >> 4;
|
|
|
|
quantVal->LH1 = block[4] & 0x0F;
|
|
|
|
quantVal->HH1 = block[4] >> 4;
|
|
|
|
}
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
void progressive_rfx_quant_ladd(RFX_COMPONENT_CODEC_QUANT* q, int val)
|
|
|
|
{
|
|
|
|
q->HL1 += val; /* HL1 */
|
|
|
|
q->LH1 += val; /* LH1 */
|
|
|
|
q->HH1 += val; /* HH1 */
|
|
|
|
q->HL2 += val; /* HL2 */
|
|
|
|
q->LH2 += val; /* LH2 */
|
|
|
|
q->HH2 += val; /* HH2 */
|
|
|
|
q->HL3 += val; /* HL3 */
|
|
|
|
q->LH3 += val; /* LH3 */
|
|
|
|
q->HH3 += val; /* HH3 */
|
|
|
|
q->LL3 += val; /* LL3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
void progressive_rfx_quant_add(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2, RFX_COMPONENT_CODEC_QUANT* dst)
|
|
|
|
{
|
|
|
|
dst->HL1 = q1->HL1 + q2->HL1; /* HL1 */
|
|
|
|
dst->LH1 = q1->LH1 + q2->LH1; /* LH1 */
|
|
|
|
dst->HH1 = q1->HH1 + q2->HH1; /* HH1 */
|
|
|
|
dst->HL2 = q1->HL2 + q2->HL2; /* HL2 */
|
|
|
|
dst->LH2 = q1->LH2 + q2->LH2; /* LH2 */
|
|
|
|
dst->HH2 = q1->HH2 + q2->HH2; /* HH2 */
|
|
|
|
dst->HL3 = q1->HL3 + q2->HL3; /* HL3 */
|
|
|
|
dst->LH3 = q1->LH3 + q2->LH3; /* LH3 */
|
|
|
|
dst->HH3 = q1->HH3 + q2->HH3; /* HH3 */
|
|
|
|
dst->LL3 = q1->LL3 + q2->LL3; /* LL3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
void progressive_rfx_quant_lsub(RFX_COMPONENT_CODEC_QUANT* q, int val)
|
|
|
|
{
|
|
|
|
q->HL1 -= val; /* HL1 */
|
|
|
|
q->LH1 -= val; /* LH1 */
|
|
|
|
q->HH1 -= val; /* HH1 */
|
|
|
|
q->HL2 -= val; /* HL2 */
|
|
|
|
q->LH2 -= val; /* LH2 */
|
|
|
|
q->HH2 -= val; /* HH2 */
|
|
|
|
q->HL3 -= val; /* HL3 */
|
|
|
|
q->LH3 -= val; /* LH3 */
|
|
|
|
q->HH3 -= val; /* HH3 */
|
|
|
|
q->LL3 -= val; /* LL3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2, RFX_COMPONENT_CODEC_QUANT* dst)
|
|
|
|
{
|
|
|
|
dst->HL1 = q1->HL1 - q2->HL1; /* HL1 */
|
|
|
|
dst->LH1 = q1->LH1 - q2->LH1; /* LH1 */
|
|
|
|
dst->HH1 = q1->HH1 - q2->HH1; /* HH1 */
|
|
|
|
dst->HL2 = q1->HL2 - q2->HL2; /* HL2 */
|
|
|
|
dst->LH2 = q1->LH2 - q2->LH2; /* LH2 */
|
|
|
|
dst->HH2 = q1->HH2 - q2->HH2; /* HH2 */
|
|
|
|
dst->HL3 = q1->HL3 - q2->HL3; /* HL3 */
|
|
|
|
dst->LH3 = q1->LH3 - q2->LH3; /* LH3 */
|
|
|
|
dst->HH3 = q1->HH3 - q2->HH3; /* HH3 */
|
|
|
|
dst->LL3 = q1->LL3 - q2->LL3; /* LL3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL progressive_rfx_quant_lcmp_less_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL progressive_rfx_quant_cmp_less_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
BOOL progressive_rfx_quant_cmp_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;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, void* pData)
|
|
|
|
{
|
|
|
|
ULONG_PTR key;
|
|
|
|
|
|
|
|
key = ((ULONG_PTR) surfaceId) + 1;
|
|
|
|
|
|
|
|
if (pData)
|
|
|
|
HashTable_Add(progressive->SurfaceContexts, (void*) key, pData);
|
|
|
|
else
|
|
|
|
HashTable_Remove(progressive->SurfaceContexts, (void*) key);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* progressive_get_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId)
|
|
|
|
{
|
|
|
|
ULONG_PTR key;
|
|
|
|
void* pData = NULL;
|
|
|
|
|
|
|
|
key = ((ULONG_PTR) surfaceId) + 1;
|
|
|
|
|
|
|
|
pData = HashTable_GetItemValue(progressive->SurfaceContexts, (void*) key);
|
|
|
|
|
|
|
|
return pData;
|
|
|
|
}
|
|
|
|
|
|
|
|
int 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);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
{
|
|
|
|
surface = (PROGRESSIVE_SURFACE_CONTEXT*) malloc(sizeof(PROGRESSIVE_SURFACE_CONTEXT));
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
surface->id = surfaceId;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
surface->gridWidth = (width + (width % 64)) / 64;
|
|
|
|
surface->gridHeight = (height + (height % 64)) / 64;
|
|
|
|
surface->gridSize = surface->gridWidth * surface->gridHeight;
|
|
|
|
|
|
|
|
surface->tiles = (RFX_PROGRESSIVE_TILE*) calloc(surface->gridSize, sizeof(RFX_PROGRESSIVE_TILE));
|
|
|
|
|
|
|
|
if (!surface->tiles)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
progressive_set_surface_data(progressive, surfaceId, (void*) surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId)
|
|
|
|
{
|
|
|
|
PROGRESSIVE_SURFACE_CONTEXT* surface;
|
|
|
|
|
|
|
|
surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data(progressive, surfaceId);
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
|
|
|
progressive_set_surface_data(progressive, surfaceId, NULL);
|
|
|
|
|
|
|
|
free(surface->tiles);
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-19 03:12:08 +04:00
|
|
|
/*
|
|
|
|
* Band Offset Dimensions Size
|
|
|
|
*
|
|
|
|
* HL1 0 31x33 1023
|
|
|
|
* LH1 1023 33x31 1023
|
|
|
|
* HH1 2046 31x31 961
|
|
|
|
*
|
|
|
|
* HL2 3007 16x17 272
|
|
|
|
* LH2 3279 17x16 272
|
|
|
|
* HH2 3551 16x16 256
|
|
|
|
*
|
|
|
|
* HL3 3807 8x9 72
|
|
|
|
* LH3 3879 9x8 72
|
|
|
|
* HH3 3951 8x8 64
|
|
|
|
*
|
|
|
|
* LL3 4015 9x9 81
|
|
|
|
*/
|
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBand, int nHighStep,
|
|
|
|
INT16* pDstBand, int nDstStep, int nLowCount, int nHighCount, int nDstCount)
|
2014-08-19 22:48:09 +04:00
|
|
|
{
|
2014-08-21 03:12:08 +04:00
|
|
|
int i, j;
|
|
|
|
INT16 L0;
|
|
|
|
INT16 H0, H1;
|
|
|
|
INT16 X0, X1, X2;
|
|
|
|
INT16 *pL, *pH, *pX;
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
for (i = 0; i < nDstCount; i++)
|
|
|
|
{
|
|
|
|
pL = pLowBand;
|
|
|
|
pH = pHighBand;
|
|
|
|
pX = pDstBand;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
H0 = *pH;
|
|
|
|
pH++;
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
L0 = *pL;
|
|
|
|
pL++;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
X0 = L0 - H0;
|
|
|
|
X2 = L0 - H0;
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
for (j = 0; j < (nHighCount - 1); j++)
|
|
|
|
{
|
|
|
|
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;
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
X0 = X2;
|
|
|
|
H0 = H1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nLowCount <= (nHighCount + 1))
|
2014-08-19 22:48:09 +04:00
|
|
|
{
|
2014-08-21 03:12:08 +04:00
|
|
|
if (nLowCount <= nHighCount)
|
|
|
|
{
|
|
|
|
pX[0] = X2;
|
|
|
|
pX[1] = X2 + (2 * H0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
L0 = *pL;
|
|
|
|
pL++;
|
|
|
|
|
|
|
|
X0 = L0 - H0;
|
|
|
|
|
|
|
|
pX[0] = X2;
|
|
|
|
pX[1] = ((X0 + X2) / 2) + (2 * H0);
|
|
|
|
pX[2] = X0;
|
|
|
|
}
|
2014-08-19 22:48:09 +04:00
|
|
|
}
|
2014-08-21 03:12:08 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
L0 = *pL;
|
|
|
|
pL++;
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
X0 = L0 - (H0 / 2);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
pX[0] = X2;
|
|
|
|
pX[1] = ((X0 + X2) / 2) + (2 * H0);
|
|
|
|
pX[2] = X0;
|
|
|
|
|
|
|
|
L0 = *pL;
|
|
|
|
pL++;
|
|
|
|
|
|
|
|
pX[3] = (X0 + L0) / 2;
|
2014-08-19 22:48:09 +04:00
|
|
|
}
|
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
pLowBand += nLowStep;
|
|
|
|
pHighBand += nHighStep;
|
|
|
|
pDstBand += nDstStep;
|
2014-08-21 01:16:34 +04:00
|
|
|
}
|
2014-08-21 03:12:08 +04:00
|
|
|
}
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
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;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
for (i = 0; i < nDstCount; i++)
|
2014-08-21 01:16:34 +04:00
|
|
|
{
|
2014-08-21 03:12:08 +04:00
|
|
|
pL = pLowBand;
|
|
|
|
pH = pHighBand;
|
|
|
|
pX = pDstBand;
|
|
|
|
|
|
|
|
H0 = *pH;
|
|
|
|
pH += nHighStep;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
L0 = *pL;
|
|
|
|
pL += nLowStep;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
X0 = L0 - H0;
|
|
|
|
X2 = L0 - H0;
|
|
|
|
|
|
|
|
for (j = 0; j < (nHighCount - 1); j++)
|
2014-08-21 01:16:34 +04:00
|
|
|
{
|
2014-08-21 03:12:08 +04:00
|
|
|
H1 = *pH;
|
|
|
|
pH += nHighStep;
|
|
|
|
|
|
|
|
L0 = *pL;
|
|
|
|
pL += nLowStep;
|
|
|
|
|
|
|
|
X2 = L0 - ((H0 + H1) / 2);
|
|
|
|
X1 = ((X0 + X2) / 2) + (2 * H0);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
*pX = X0;
|
|
|
|
pX += nDstStep;
|
|
|
|
|
|
|
|
*pX = X1;
|
|
|
|
pX += nDstStep;
|
|
|
|
|
|
|
|
X0 = X2;
|
|
|
|
H0 = H1;
|
|
|
|
}
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
if (nLowCount <= (nHighCount + 1))
|
2014-08-21 01:16:34 +04:00
|
|
|
{
|
2014-08-21 03:12:08 +04:00
|
|
|
if (nLowCount <= nHighCount)
|
|
|
|
{
|
|
|
|
*pX = X2;
|
|
|
|
pX += nDstStep;
|
|
|
|
|
|
|
|
*pX = X2 + (2 * H0);
|
|
|
|
pX += nDstStep;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
L0 = *pL;
|
|
|
|
pL += nLowStep;
|
|
|
|
|
|
|
|
X0 = L0 - H0;
|
|
|
|
|
|
|
|
*pX = X2;
|
|
|
|
pX += nDstStep;
|
|
|
|
|
|
|
|
*pX = ((X0 + X2) / 2) + (2 * H0);
|
|
|
|
pX += nDstStep;
|
|
|
|
|
|
|
|
*pX = X0;
|
|
|
|
pX += nDstStep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
2014-08-21 01:16:34 +04:00
|
|
|
}
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-22 03:02:26 +04:00
|
|
|
pLowBand++;
|
|
|
|
pHighBand++;
|
|
|
|
pDstBand++;
|
2014-08-19 22:48:09 +04:00
|
|
|
}
|
2014-08-21 03:12:08 +04:00
|
|
|
}
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
static int progressive_rfx_get_band_l_count(int level)
|
2014-08-21 03:12:08 +04:00
|
|
|
{
|
2014-08-22 00:05:39 +04:00
|
|
|
return (64 >> level) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int progressive_rfx_get_band_h_count(int level)
|
|
|
|
{
|
|
|
|
if (level == 1)
|
|
|
|
return (64 >> 1) - 1;
|
|
|
|
else
|
|
|
|
return (64 + (1 << (level - 1))) >> level;
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:36:33 +04:00
|
|
|
static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int level)
|
2014-08-22 00:05:39 +04:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int nBandL;
|
|
|
|
int nBandH;
|
|
|
|
int nDstStepX;
|
|
|
|
int nDstStepY;
|
|
|
|
INT16 *HL, *LH;
|
|
|
|
INT16 *HH, *LL;
|
2014-08-26 22:36:33 +04:00
|
|
|
INT16 *L, *H, *LLx;
|
2014-08-22 00:05:39 +04:00
|
|
|
INT16* pLowBand[3];
|
|
|
|
INT16* pHighBand[3];
|
|
|
|
INT16* pDstBand[3];
|
|
|
|
int nLowStep[3];
|
|
|
|
int nHighStep[3];
|
|
|
|
int nDstStep[3];
|
|
|
|
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);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
HH = &buffer[offset];
|
|
|
|
offset += (nBandH * nBandH);
|
|
|
|
|
|
|
|
LL = &buffer[offset];
|
|
|
|
offset += (nBandL * nBandL);
|
|
|
|
|
2014-08-22 01:14:10 +04:00
|
|
|
nDstStepX = (nBandL + nBandH);
|
|
|
|
nDstStepY = (nBandL + nBandH);
|
2014-08-22 00:05:39 +04:00
|
|
|
|
2014-08-26 22:36:33 +04:00
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
L = &temp[offset];
|
|
|
|
offset += (nBandL * nDstStepX);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-26 22:36:33 +04:00
|
|
|
H = &temp[offset];
|
|
|
|
offset += (nBandH * nDstStepX);
|
|
|
|
|
|
|
|
LLx = &buffer[0];
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
/* horizontal (LL + HL -> L) */
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
pLowBand[0] = LL;
|
2014-08-22 03:02:26 +04:00
|
|
|
nLowStep[0] = nBandL;
|
2014-08-22 00:05:39 +04:00
|
|
|
pHighBand[0] = HL;
|
2014-08-22 03:02:26 +04:00
|
|
|
nHighStep[0] = nBandH;
|
2014-08-22 00:05:39 +04:00
|
|
|
pDstBand[0] = L;
|
|
|
|
nDstStep[0] = nDstStepX;
|
|
|
|
nLowCount[0] = nBandL;
|
|
|
|
nHighCount[0] = nBandH;
|
|
|
|
nDstCount[0] = nBandL;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
progressive_rfx_idwt_x(pLowBand[0], nLowStep[0], pHighBand[0], nHighStep[0], pDstBand[0], nDstStep[0], nLowCount[0], nHighCount[0], nDstCount[0]);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
/* horizontal (LH + HH -> H) */
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
pLowBand[1] = LH;
|
2014-08-22 03:02:26 +04:00
|
|
|
nLowStep[1] = nBandL;
|
2014-08-22 00:05:39 +04:00
|
|
|
pHighBand[1] = HH;
|
2014-08-22 03:02:26 +04:00
|
|
|
nHighStep[1] = nBandH;
|
2014-08-22 00:05:39 +04:00
|
|
|
pDstBand[1] = H;
|
|
|
|
nDstStep[1] = nDstStepX;
|
|
|
|
nLowCount[1] = nBandL;
|
|
|
|
nHighCount[1] = nBandH;
|
|
|
|
nDstCount[1] = nBandH;
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
progressive_rfx_idwt_x(pLowBand[1], nLowStep[1], pHighBand[1], nHighStep[1], pDstBand[1], nDstStep[1], nLowCount[1], nHighCount[1], nDstCount[1]);
|
2014-08-21 01:16:34 +04:00
|
|
|
|
2014-08-21 03:12:08 +04:00
|
|
|
/* vertical (L + H -> LL) */
|
|
|
|
|
2014-08-22 00:05:39 +04:00
|
|
|
pLowBand[2] = pDstBand[0];
|
|
|
|
nLowStep[2] = nDstStep[0];
|
|
|
|
pHighBand[2] = pDstBand[1];
|
|
|
|
nHighStep[2] = nDstStep[1];
|
2014-08-26 22:36:33 +04:00
|
|
|
pDstBand[2] = LLx;
|
2014-08-22 00:05:39 +04:00
|
|
|
nDstStep[2] = nDstStepY;
|
|
|
|
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]);
|
2014-08-19 22:48:09 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, INT16* current, INT16* sign, BOOL diff)
|
2014-08-19 22:48:09 +04:00
|
|
|
{
|
2014-08-26 22:36:33 +04:00
|
|
|
const primitives_t* prims = primitives_get();
|
|
|
|
|
|
|
|
if (diff)
|
|
|
|
prims->add_16s(buffer, current, buffer, 4096);
|
|
|
|
|
|
|
|
CopyMemory(current, buffer, 4096 * 2);
|
2014-08-27 23:15:37 +04:00
|
|
|
|
|
|
|
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);
|
2014-08-19 22:48:09 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffer, int length, UINT32 shift)
|
|
|
|
{
|
|
|
|
if (!shift)
|
|
|
|
return;
|
|
|
|
|
|
|
|
prims->lShiftC_16s(buffer, shift, buffer, length);
|
|
|
|
}
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, RFX_COMPONENT_CODEC_QUANT* shift,
|
2014-08-28 23:14:01 +04:00
|
|
|
const BYTE* data, int length, INT16* buffer, INT16* current, INT16* sign, BOOL diff)
|
2014-08-06 18:23:14 +04:00
|
|
|
{
|
|
|
|
int status;
|
2014-08-26 22:36:33 +04:00
|
|
|
INT16* temp;
|
2014-08-19 03:12:08 +04:00
|
|
|
const primitives_t* prims = primitives_get();
|
2014-08-06 18:23:14 +04:00
|
|
|
|
|
|
|
status = rfx_rlgr_decode(data, length, buffer, 4096, 1);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
CopyMemory(sign, buffer, 4096 * 2);
|
|
|
|
|
2014-08-19 03:12:08 +04:00
|
|
|
rfx_differential_decode(&buffer[4015], 81); /* LL3 */
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
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 */
|
|
|
|
progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2); /* HL2 */
|
|
|
|
progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2); /* LH2 */
|
|
|
|
progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2); /* HH2 */
|
|
|
|
progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3); /* HL3 */
|
|
|
|
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 */
|
2014-08-19 03:12:08 +04:00
|
|
|
|
2014-08-26 22:36:33 +04:00
|
|
|
temp = (INT16*) BufferPool_Take(progressive->bufferPool, -1); /* DWT buffer */
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
progressive_rfx_dwt_2d_decode(buffer, temp, current, sign, diff);
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-26 22:36:33 +04:00
|
|
|
BufferPool_Return(progressive->bufferPool, temp);
|
2014-08-19 22:48:09 +04:00
|
|
|
|
2014-08-06 18:23:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_TILE* tile)
|
|
|
|
{
|
|
|
|
BOOL diff;
|
|
|
|
BYTE* pBuffer;
|
2014-08-28 23:14:01 +04:00
|
|
|
INT16* pSign[3];
|
2014-08-28 20:14:28 +04:00
|
|
|
INT16* pSrcDst[3];
|
|
|
|
INT16* pCurrent[3];
|
|
|
|
PROGRESSIVE_BLOCK_REGION* region;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftCr;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantCr;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgCr;
|
|
|
|
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;
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
#if 0
|
2014-08-28 20:14:28 +04:00
|
|
|
printf("ProgressiveTileFirst: quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d flags: 0x%02X quality: %d yLen: %d cbLen: %d crLen: %d tailLen: %d\n",
|
|
|
|
tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx, tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
|
2014-09-03 02:15:36 +04:00
|
|
|
#endif
|
2014-08-28 20:14:28 +04:00
|
|
|
|
|
|
|
region = &(progressive->region);
|
|
|
|
|
|
|
|
if (tile->quantIdxY >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantY = &(region->quantVals[tile->quantIdxY]);
|
|
|
|
|
|
|
|
if (tile->quantIdxCb >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantCb = &(region->quantVals[tile->quantIdxCb]);
|
|
|
|
|
|
|
|
if (tile->quantIdxCr >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantCr = &(region->quantVals[tile->quantIdxCr]);
|
|
|
|
|
|
|
|
if (tile->quality == 0xFF)
|
|
|
|
{
|
|
|
|
quantProgVal = &(progressive->quantProgValFull);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tile->quality >= region->numProgQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantProgVal = &(region->quantProgVals[tile->quality]);
|
|
|
|
}
|
|
|
|
|
|
|
|
quantProgY = &(quantProgVal->yQuantValues);
|
|
|
|
quantProgCb = &(quantProgVal->cbQuantValues);
|
|
|
|
quantProgCr = &(quantProgVal->crQuantValues);
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
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));
|
|
|
|
|
|
|
|
progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
|
|
|
|
progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
|
|
|
|
progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
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 */
|
|
|
|
|
|
|
|
if (!tile->data)
|
|
|
|
{
|
|
|
|
tile->data = (BYTE*) _aligned_malloc(64 * 64 * 4, 16);
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
if (!tile->sign)
|
|
|
|
{
|
|
|
|
tile->sign = (BYTE*) _aligned_malloc((8192 + 32) * 3, 16);
|
|
|
|
}
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
if (!tile->current)
|
|
|
|
{
|
|
|
|
tile->current = (BYTE*) _aligned_malloc((8192 + 32) * 3, 16);
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
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 */
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
pBuffer = tile->current;
|
2014-08-28 20:14:28 +04:00
|
|
|
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 */
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
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 */
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-09-04 21:09:46 +04:00
|
|
|
prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2,
|
2014-08-28 20:14:28 +04:00
|
|
|
tile->data, 64 * 4, &roi_64x64);
|
|
|
|
|
|
|
|
BufferPool_Return(progressive->bufferPool, pBuffer);
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
//WLog_Image(progressive->log, WLOG_TRACE, tile->data, 64, 64, 32);
|
2014-08-28 20:14:28 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-28 02:34:37 +04:00
|
|
|
struct _RFX_PROGRESSIVE_UPGRADE_STATE
|
|
|
|
{
|
|
|
|
BOOL nonLL;
|
|
|
|
wBitStream* srl;
|
|
|
|
wBitStream* raw;
|
|
|
|
|
|
|
|
/* SRL state */
|
|
|
|
|
|
|
|
int kp;
|
|
|
|
int nz;
|
|
|
|
BOOL mode;
|
|
|
|
};
|
|
|
|
typedef struct _RFX_PROGRESSIVE_UPGRADE_STATE RFX_PROGRESSIVE_UPGRADE_STATE;
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, UINT32 numBits)
|
|
|
|
{
|
2014-09-03 02:15:36 +04:00
|
|
|
int k;
|
2014-08-28 20:14:28 +04:00
|
|
|
UINT32 bit;
|
|
|
|
UINT32 max;
|
|
|
|
UINT32 mag;
|
|
|
|
UINT32 sign;
|
|
|
|
wBitStream* bs = state->srl;
|
|
|
|
|
|
|
|
if (state->nz)
|
|
|
|
{
|
|
|
|
state->nz--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
k = state->kp / 8;
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
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) */
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
state->nz = (1 << k);
|
2014-08-28 20:14:28 +04:00
|
|
|
|
|
|
|
state->kp += 4;
|
|
|
|
|
|
|
|
if (state->kp > 80)
|
|
|
|
state->kp = 80;
|
|
|
|
|
|
|
|
state->nz--;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-03 02:15:36 +04:00
|
|
|
else
|
2014-08-28 23:14:01 +04:00
|
|
|
{
|
2014-09-03 02:15:36 +04:00
|
|
|
/* '1' bit, nz < (1 << k), nz = next k bits */
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
state->nz = 0;
|
2014-08-28 23:14:01 +04:00
|
|
|
state->mode = 1; /* unary encoding is next */
|
2014-09-03 02:15:36 +04:00
|
|
|
|
|
|
|
if (k)
|
|
|
|
{
|
|
|
|
bs->mask = ((1 << k) - 1);
|
|
|
|
state->nz = ((bs->accumulator >> (32 - k)) & bs->mask);
|
|
|
|
BitStream_Shift(bs, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->nz)
|
|
|
|
{
|
|
|
|
state->nz--;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-08-28 20:14:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state->mode = 0; /* zero encoding is next */
|
|
|
|
|
|
|
|
/* unary encoding */
|
|
|
|
|
|
|
|
/* read sign bit */
|
|
|
|
|
|
|
|
sign = (bs->accumulator & 0x80000000) ? 1 : 0;
|
|
|
|
BitStream_Shift(bs, 1);
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
state->kp -= 6;
|
|
|
|
|
|
|
|
if (state->kp < 0)
|
|
|
|
state->kp = 0;
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
if (numBits == 1)
|
|
|
|
return sign ? -1 : 1;
|
|
|
|
|
|
|
|
mag = 1;
|
2014-08-28 20:14:28 +04:00
|
|
|
max = (1 << numBits) - 1;
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
while (mag < max)
|
2014-08-28 20:14:28 +04:00
|
|
|
{
|
2014-09-02 21:31:40 +04:00
|
|
|
bit = (bs->accumulator & 0x80000000) ? 1 : 0;
|
|
|
|
BitStream_Shift(bs, 1);
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
if (bit)
|
|
|
|
break;
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
mag++;
|
2014-08-28 20:14:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return sign ? -mag : mag;
|
|
|
|
}
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, INT16* buffer,
|
|
|
|
INT16* sign, int length, UINT32 shift, UINT32 bitPos, UINT32 numBits)
|
2014-08-28 02:34:37 +04:00
|
|
|
{
|
2014-09-03 02:15:36 +04:00
|
|
|
int pad;
|
2014-08-28 02:34:37 +04:00
|
|
|
int index;
|
|
|
|
INT16 input;
|
|
|
|
wBitStream* srl;
|
|
|
|
wBitStream* raw;
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
if (!numBits)
|
2014-08-28 20:14:28 +04:00
|
|
|
return 1;
|
|
|
|
|
2014-08-28 02:34:37 +04:00
|
|
|
srl = state->srl;
|
|
|
|
raw = state->raw;
|
|
|
|
|
|
|
|
if (!state->nonLL)
|
|
|
|
{
|
|
|
|
for (index = 0; index < length; index++)
|
|
|
|
{
|
|
|
|
raw->mask = ((1 << numBits) - 1);
|
|
|
|
input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask);
|
|
|
|
BitStream_Shift(raw, numBits);
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
buffer[index] += (input << shift);
|
2014-08-28 02:34:37 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
/* This is the last band, read padding bits from RAW and SRL bit streams */
|
|
|
|
|
|
|
|
pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
|
|
|
|
|
|
|
|
if (pad)
|
|
|
|
BitStream_Shift(raw, pad);
|
|
|
|
|
|
|
|
pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
|
|
|
|
|
|
|
|
if (pad)
|
|
|
|
BitStream_Shift(srl, pad);
|
|
|
|
|
|
|
|
if (BitStream_GetRemainingLength(srl) == 8)
|
|
|
|
BitStream_Shift(srl, 8);
|
|
|
|
|
2014-08-28 02:34:37 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < length; index++)
|
|
|
|
{
|
2014-08-28 23:14:01 +04:00
|
|
|
if (sign[index] > 0)
|
2014-08-28 02:34:37 +04:00
|
|
|
{
|
|
|
|
/* sign > 0, read from raw */
|
|
|
|
|
|
|
|
raw->mask = ((1 << numBits) - 1);
|
|
|
|
input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask);
|
|
|
|
BitStream_Shift(raw, numBits);
|
|
|
|
}
|
2014-08-28 23:14:01 +04:00
|
|
|
else if (sign[index] < 0)
|
2014-08-28 02:34:37 +04:00
|
|
|
{
|
|
|
|
/* sign < 0, read from raw */
|
|
|
|
|
|
|
|
raw->mask = ((1 << numBits) - 1);
|
|
|
|
input = (INT16) ((raw->accumulator >> (32 - numBits)) & raw->mask);
|
|
|
|
BitStream_Shift(raw, numBits);
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
input *= -1;
|
2014-08-28 02:34:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* sign == 0, read from srl */
|
2014-08-28 20:14:28 +04:00
|
|
|
|
|
|
|
input = progressive_rfx_srl_read(state, numBits);
|
2014-08-28 02:34:37 +04:00
|
|
|
}
|
2014-08-28 23:14:01 +04:00
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
buffer[index] += (input << shift);
|
2014-08-28 23:14:01 +04:00
|
|
|
sign[index] = input;
|
2014-08-28 02:34:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
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, int srlLen, const BYTE* rawData, int rawLen)
|
2014-08-28 02:34:37 +04:00
|
|
|
{
|
2014-09-03 03:25:01 +04:00
|
|
|
INT16* temp;
|
2014-08-28 20:14:28 +04:00
|
|
|
int aRawLen;
|
|
|
|
int aSrlLen;
|
2014-08-28 02:34:37 +04:00
|
|
|
wBitStream s_srl;
|
|
|
|
wBitStream s_raw;
|
|
|
|
RFX_PROGRESSIVE_UPGRADE_STATE state;
|
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
ZeroMemory(&s_srl, sizeof(wBitStream));
|
|
|
|
ZeroMemory(&s_raw, sizeof(wBitStream));
|
|
|
|
ZeroMemory(&state, sizeof(RFX_PROGRESSIVE_UPGRADE_STATE));
|
|
|
|
|
|
|
|
state.kp = 8;
|
2014-09-03 02:15:36 +04:00
|
|
|
state.mode = 0;
|
2014-08-28 02:34:37 +04:00
|
|
|
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;
|
2014-09-03 03:25:01 +04:00
|
|
|
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 */
|
2014-08-28 02:34:37 +04:00
|
|
|
|
|
|
|
state.nonLL = FALSE;
|
2014-09-03 03:25:01 +04:00
|
|
|
progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3, bitPos->LL3, numBits->LL3); /* LL3 */
|
2014-08-28 02:34:37 +04:00
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
aRawLen = (state.raw->position + 7) / 8;
|
|
|
|
aSrlLen = (state.srl->position + 7) / 8;
|
2014-08-28 01:02:15 +04:00
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
if ((aRawLen != rawLen) || (aSrlLen != srlLen))
|
2014-08-01 17:44:00 +04:00
|
|
|
{
|
2014-08-28 20:14:28 +04:00
|
|
|
int pRawLen = 0;
|
|
|
|
int pSrlLen = 0;
|
2014-08-01 17:44:00 +04:00
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
if (rawLen)
|
|
|
|
pRawLen = (int) ((((float) aRawLen) / ((float) rawLen)) * 100.0f);
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
if (srlLen)
|
|
|
|
pSrlLen = (int) ((((float) aSrlLen) / ((float) srlLen)) * 100.0f);
|
2014-08-26 22:36:33 +04:00
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
printf("RAW: %d/%d %d%% (%d/%d:%d)\tSRL: %d/%d %d%% (%d/%d:%d)\n",
|
|
|
|
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);
|
2014-08-28 23:14:01 +04:00
|
|
|
|
|
|
|
return -1;
|
2014-08-26 22:36:33 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
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);
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_TILE* tile)
|
2014-07-31 23:08:54 +04:00
|
|
|
{
|
2014-08-28 23:14:01 +04:00
|
|
|
int status;
|
2014-08-28 02:34:37 +04:00
|
|
|
BYTE* pBuffer;
|
2014-08-28 23:14:01 +04:00
|
|
|
INT16* pSign[3];
|
|
|
|
INT16* pSrcDst[3];
|
2014-08-28 02:34:37 +04:00
|
|
|
INT16* pCurrent[3];
|
2014-07-31 23:08:54 +04:00
|
|
|
PROGRESSIVE_BLOCK_REGION* region;
|
2014-09-03 03:25:01 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT shiftCr;
|
2014-09-02 21:31:40 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT yBitPos;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT cbBitPos;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT crBitPos;
|
2014-08-28 01:02:15 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT yNumBits;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT cbNumBits;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT crNumBits;
|
2014-07-31 23:08:54 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantCr;
|
2014-08-27 23:15:37 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgY;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgCb;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantProgCr;
|
2014-08-28 01:02:15 +04:00
|
|
|
RFX_PROGRESSIVE_CODEC_QUANT* quantProg;
|
2014-08-28 23:14:01 +04:00
|
|
|
static const prim_size_t roi_64x64 = { 64, 64 };
|
|
|
|
const primitives_t* prims = primitives_get();
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-28 20:14:28 +04:00
|
|
|
tile->pass++;
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
#if 0
|
2014-08-28 20:14:28 +04:00
|
|
|
printf("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\n",
|
|
|
|
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);
|
2014-09-03 02:15:36 +04:00
|
|
|
#endif
|
2014-07-31 23:08:54 +04:00
|
|
|
|
|
|
|
region = &(progressive->region);
|
|
|
|
|
|
|
|
if (tile->quantIdxY >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantY = &(region->quantVals[tile->quantIdxY]);
|
|
|
|
|
|
|
|
if (tile->quantIdxCb >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantCb = &(region->quantVals[tile->quantIdxCb]);
|
|
|
|
|
|
|
|
if (tile->quantIdxCr >= region->numQuant)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
quantCr = &(region->quantVals[tile->quantIdxCr]);
|
|
|
|
|
|
|
|
if (tile->quality == 0xFF)
|
|
|
|
{
|
2014-08-28 01:02:15 +04:00
|
|
|
quantProg = &(progressive->quantProgValFull);
|
2014-07-31 23:08:54 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tile->quality >= region->numProgQuant)
|
|
|
|
return -1;
|
|
|
|
|
2014-08-28 01:02:15 +04:00
|
|
|
quantProg = &(region->quantProgVals[tile->quality]);
|
2014-07-31 23:08:54 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 01:02:15 +04:00
|
|
|
quantProgY = &(quantProg->yQuantValues);
|
|
|
|
quantProgCb = &(quantProg->cbQuantValues);
|
|
|
|
quantProgCr = &(quantProg->crQuantValues);
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
|
|
|
|
printf("warning: non-progressive quantY has changed!\n");
|
|
|
|
if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
|
|
|
|
printf("warning: non-progressive quantCb has changed!\n");
|
|
|
|
if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
|
|
|
|
printf("warning: non-progressive quantCr has changed!\n");
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
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 */
|
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
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));
|
2014-08-28 01:02:15 +04:00
|
|
|
|
2014-09-02 21:31:40 +04:00
|
|
|
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));
|
2014-08-28 02:34:37 +04:00
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
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 */
|
|
|
|
|
2014-08-28 02:34:37 +04:00
|
|
|
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 */
|
|
|
|
|
2014-08-28 23:14:01 +04:00
|
|
|
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 */
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
|
2014-08-28 23:14:01 +04:00
|
|
|
pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData, tile->ySrlLen, tile->yRawData, tile->yRawLen); /* Y */
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
|
2014-08-28 23:14:01 +04:00
|
|
|
pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData, tile->cbSrlLen, tile->cbRawData, tile->cbRawLen); /* Cb */
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
|
|
|
|
2014-09-03 03:25:01 +04:00
|
|
|
status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
|
2014-08-28 23:14:01 +04:00
|
|
|
pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData, tile->crSrlLen, tile->crRawData, tile->crRawLen); /* Cr */
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
|
|
|
|
2014-09-04 21:09:46 +04:00
|
|
|
prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2,
|
2014-08-28 23:14:01 +04:00
|
|
|
tile->data, 64 * 4, &roi_64x64);
|
|
|
|
|
|
|
|
BufferPool_Return(progressive->bufferPool, pBuffer);
|
2014-08-27 23:15:37 +04:00
|
|
|
|
2014-09-04 02:46:57 +04:00
|
|
|
//WLog_Image(progressive->log, WLOG_TRACE, tile->data, 64, 64, 32);
|
2014-09-03 03:25:01 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, BYTE* blocks, UINT32 blocksLen, PROGRESSIVE_SURFACE_CONTEXT* surface)
|
2014-07-31 23:08:54 +04:00
|
|
|
{
|
2014-08-28 23:14:01 +04:00
|
|
|
int status;
|
2014-08-01 17:44:00 +04:00
|
|
|
BYTE* block;
|
2014-08-27 00:15:22 +04:00
|
|
|
UINT16 xIdx;
|
|
|
|
UINT16 yIdx;
|
|
|
|
UINT16 zIdx;
|
2014-08-01 17:44:00 +04:00
|
|
|
UINT16 index;
|
|
|
|
UINT32 boffset;
|
2014-08-27 00:15:22 +04:00
|
|
|
UINT16 blockType;
|
|
|
|
UINT32 blockLen;
|
2014-08-01 17:44:00 +04:00
|
|
|
UINT32 count = 0;
|
|
|
|
UINT32 offset = 0;
|
|
|
|
RFX_PROGRESSIVE_TILE* tile;
|
2014-08-27 00:15:22 +04:00
|
|
|
RFX_PROGRESSIVE_TILE** tiles;
|
2014-07-31 23:08:54 +04:00
|
|
|
PROGRESSIVE_BLOCK_REGION* region;
|
|
|
|
|
|
|
|
region = &(progressive->region);
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
tiles = region->tiles;
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
while ((blocksLen - offset) >= 6)
|
|
|
|
{
|
|
|
|
boffset = 0;
|
|
|
|
block = &blocks[offset];
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
blockType = *((UINT16*) &block[boffset + 0]); /* blockType (2 bytes) */
|
|
|
|
blockLen = *((UINT32*) &block[boffset + 2]); /* blockLen (4 bytes) */
|
2014-08-01 17:44:00 +04:00
|
|
|
boffset += 6;
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-27 23:15:37 +04:00
|
|
|
//printf("%s\n", progressive_get_block_type_string(blockType));
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
if ((blocksLen - offset) < blockLen)
|
2014-08-01 17:44:00 +04:00
|
|
|
return -1003;
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
switch (blockType)
|
2014-08-01 17:44:00 +04:00
|
|
|
{
|
|
|
|
case PROGRESSIVE_WBT_TILE_SIMPLE:
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
if ((blockLen - boffset) < 16)
|
2014-08-01 17:44:00 +04:00
|
|
|
return -1022;
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
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;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
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) */
|
|
|
|
tile->xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
tile->yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
2014-08-26 03:50:42 +04:00
|
|
|
tile->flags = block[boffset + 7] & 1; /* flags (1 byte) */
|
2014-08-01 17:44:00 +04:00
|
|
|
tile->yLen = *((UINT16*) &block[boffset + 8]); /* yLen (2 bytes) */
|
|
|
|
tile->cbLen = *((UINT16*) &block[boffset + 10]); /* cbLen (2 bytes) */
|
|
|
|
tile->crLen = *((UINT16*) &block[boffset + 12]); /* crLen (2 bytes) */
|
|
|
|
tile->tailLen = *((UINT16*) &block[boffset + 14]); /* tailLen (2 bytes) */
|
|
|
|
boffset += 16;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->yLen)
|
|
|
|
return -1023;
|
|
|
|
|
|
|
|
tile->yData = &block[boffset];
|
|
|
|
boffset += tile->yLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->cbLen)
|
|
|
|
return -1024;
|
|
|
|
|
|
|
|
tile->cbData = &block[boffset];
|
|
|
|
boffset += tile->cbLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->crLen)
|
|
|
|
return -1025;
|
|
|
|
|
|
|
|
tile->crData = &block[boffset];
|
|
|
|
boffset += tile->crLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->tailLen)
|
|
|
|
return -1026;
|
|
|
|
|
|
|
|
tile->tailData = &block[boffset];
|
|
|
|
boffset += tile->tailLen;
|
|
|
|
|
2014-08-19 22:48:09 +04:00
|
|
|
tile->width = 64;
|
|
|
|
tile->height = 64;
|
|
|
|
tile->x = tile->xIdx * 64;
|
|
|
|
tile->y = tile->yIdx * 64;
|
|
|
|
|
2014-08-26 03:50:42 +04:00
|
|
|
tile->flags &= 1;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_FIRST:
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
if ((blockLen - boffset) < 17)
|
2014-08-01 17:44:00 +04:00
|
|
|
return -1027;
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
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;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
tile->quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */
|
|
|
|
tile->quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */
|
|
|
|
tile->quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */
|
|
|
|
tile->xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
tile->yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
2014-08-26 03:50:42 +04:00
|
|
|
tile->flags = block[boffset + 7] & 1; /* flags (1 byte) */
|
2014-08-01 17:44:00 +04:00
|
|
|
tile->quality = block[boffset + 8]; /* quality (1 byte) */
|
|
|
|
tile->yLen = *((UINT16*) &block[boffset + 9]); /* yLen (2 bytes) */
|
|
|
|
tile->cbLen = *((UINT16*) &block[boffset + 11]); /* cbLen (2 bytes) */
|
|
|
|
tile->crLen = *((UINT16*) &block[boffset + 13]); /* crLen (2 bytes) */
|
|
|
|
tile->tailLen = *((UINT16*) &block[boffset + 15]); /* tailLen (2 bytes) */
|
|
|
|
boffset += 17;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->yLen)
|
|
|
|
return -1028;
|
|
|
|
|
|
|
|
tile->yData = &block[boffset];
|
|
|
|
boffset += tile->yLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->cbLen)
|
|
|
|
return -1029;
|
|
|
|
|
|
|
|
tile->cbData = &block[boffset];
|
|
|
|
boffset += tile->cbLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->crLen)
|
|
|
|
return -1030;
|
|
|
|
|
|
|
|
tile->crData = &block[boffset];
|
|
|
|
boffset += tile->crLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->tailLen)
|
|
|
|
return -1031;
|
|
|
|
|
|
|
|
tile->tailData = &block[boffset];
|
|
|
|
boffset += tile->tailLen;
|
|
|
|
|
2014-08-19 22:48:09 +04:00
|
|
|
tile->width = 64;
|
|
|
|
tile->height = 64;
|
|
|
|
tile->x = tile->xIdx * 64;
|
|
|
|
tile->y = tile->yIdx * 64;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_UPGRADE:
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
if ((blockLen - boffset) < 20)
|
2014-08-01 17:44:00 +04:00
|
|
|
return -1032;
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
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;
|
|
|
|
|
2014-08-26 03:50:42 +04:00
|
|
|
tile->flags = 0;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
tile->quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */
|
|
|
|
tile->quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */
|
|
|
|
tile->quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */
|
|
|
|
tile->xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
tile->yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
|
|
|
tile->quality = block[boffset + 7]; /* quality (1 byte) */
|
|
|
|
tile->ySrlLen = *((UINT16*) &block[boffset + 8]); /* ySrlLen (2 bytes) */
|
|
|
|
tile->yRawLen = *((UINT16*) &block[boffset + 10]); /* yRawLen (2 bytes) */
|
|
|
|
tile->cbSrlLen = *((UINT16*) &block[boffset + 12]); /* cbSrlLen (2 bytes) */
|
|
|
|
tile->cbRawLen = *((UINT16*) &block[boffset + 14]); /* cbRawLen (2 bytes) */
|
|
|
|
tile->crSrlLen = *((UINT16*) &block[boffset + 16]); /* crSrlLen (2 bytes) */
|
|
|
|
tile->crRawLen = *((UINT16*) &block[boffset + 18]); /* crRawLen (2 bytes) */
|
|
|
|
boffset += 20;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->ySrlLen)
|
|
|
|
return -1033;
|
|
|
|
|
|
|
|
tile->ySrlData = &block[boffset];
|
|
|
|
boffset += tile->ySrlLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->yRawLen)
|
|
|
|
return -1034;
|
|
|
|
|
|
|
|
tile->yRawData = &block[boffset];
|
|
|
|
boffset += tile->yRawLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->cbSrlLen)
|
|
|
|
return -1035;
|
|
|
|
|
|
|
|
tile->cbSrlData = &block[boffset];
|
|
|
|
boffset += tile->cbSrlLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->cbRawLen)
|
|
|
|
return -1036;
|
|
|
|
|
|
|
|
tile->cbRawData = &block[boffset];
|
|
|
|
boffset += tile->cbRawLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->crSrlLen)
|
|
|
|
return -1037;
|
|
|
|
|
|
|
|
tile->crSrlData = &block[boffset];
|
|
|
|
boffset += tile->crSrlLen;
|
|
|
|
|
|
|
|
if ((tile->blockLen - boffset) < tile->crRawLen)
|
|
|
|
return -1038;
|
|
|
|
|
|
|
|
tile->crRawData = &block[boffset];
|
|
|
|
boffset += tile->crRawLen;
|
|
|
|
|
2014-08-19 22:48:09 +04:00
|
|
|
tile->width = 64;
|
|
|
|
tile->height = 64;
|
|
|
|
tile->x = tile->xIdx * 64;
|
|
|
|
tile->y = tile->yIdx * 64;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1039;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
if (boffset != blockLen)
|
2014-08-01 17:44:00 +04:00
|
|
|
return -1040;
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
offset += blockLen;
|
2014-08-01 17:44:00 +04:00
|
|
|
count++;
|
2014-07-31 23:08:54 +04:00
|
|
|
}
|
2014-08-01 17:44:00 +04:00
|
|
|
|
|
|
|
if (offset != blocksLen)
|
|
|
|
return -1041;
|
|
|
|
|
|
|
|
for (index = 0; index < region->numTiles; index++)
|
2014-07-31 23:08:54 +04:00
|
|
|
{
|
2014-08-27 00:15:22 +04:00
|
|
|
tile = tiles[index];
|
2014-07-31 23:08:54 +04:00
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
switch (tile->blockType)
|
|
|
|
{
|
|
|
|
case PROGRESSIVE_WBT_TILE_SIMPLE:
|
|
|
|
case PROGRESSIVE_WBT_TILE_FIRST:
|
2014-08-28 23:14:01 +04:00
|
|
|
status = progressive_decompress_tile_first(progressive, tile);
|
2014-08-01 17:44:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_UPGRADE:
|
2014-08-28 23:14:01 +04:00
|
|
|
status = progressive_decompress_tile_upgrade(progressive, tile);
|
2014-08-01 17:44:00 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-08-28 23:14:01 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
2014-07-31 23:08:54 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
return (int) offset;
|
2014-07-31 23:08:54 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize,
|
2014-08-27 00:15:22 +04:00
|
|
|
BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, UINT16 surfaceId)
|
2014-07-29 01:42:23 +04:00
|
|
|
{
|
2014-07-30 01:37:46 +04:00
|
|
|
int status;
|
2014-07-29 07:41:16 +04:00
|
|
|
BYTE* block;
|
2014-08-01 17:44:00 +04:00
|
|
|
BYTE* blocks;
|
2014-07-29 20:38:29 +04:00
|
|
|
UINT16 index;
|
2014-07-29 07:41:16 +04:00
|
|
|
UINT32 boffset;
|
|
|
|
UINT16 blockType;
|
|
|
|
UINT32 blockLen;
|
2014-08-01 17:44:00 +04:00
|
|
|
UINT32 blocksLen;
|
2014-07-30 01:37:46 +04:00
|
|
|
UINT32 count = 0;
|
2014-07-29 07:41:16 +04:00
|
|
|
UINT32 offset = 0;
|
2014-07-30 01:37:46 +04:00
|
|
|
RFX_RECT* rect = NULL;
|
2014-07-29 20:38:29 +04:00
|
|
|
PROGRESSIVE_BLOCK_SYNC sync;
|
2014-07-31 23:08:54 +04:00
|
|
|
PROGRESSIVE_BLOCK_REGION* region;
|
2014-07-29 20:38:29 +04:00
|
|
|
PROGRESSIVE_BLOCK_CONTEXT context;
|
|
|
|
PROGRESSIVE_BLOCK_FRAME_BEGIN frameBegin;
|
|
|
|
PROGRESSIVE_BLOCK_FRAME_END frameEnd;
|
2014-08-27 00:15:22 +04:00
|
|
|
PROGRESSIVE_SURFACE_CONTEXT* surface;
|
2014-07-29 20:38:29 +04:00
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantVal;
|
|
|
|
RFX_PROGRESSIVE_CODEC_QUANT* quantProgVal;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data(progressive, surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return -1001;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
blocks = pSrcData;
|
|
|
|
blocksLen = SrcSize;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region = &(progressive->region);
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
while ((blocksLen - offset) >= 6)
|
2014-07-29 07:41:16 +04:00
|
|
|
{
|
|
|
|
boffset = 0;
|
2014-07-30 01:37:46 +04:00
|
|
|
block = &blocks[offset];
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
blockType = *((UINT16*) &block[boffset + 0]); /* blockType (2 bytes) */
|
2014-07-29 07:41:16 +04:00
|
|
|
blockLen = *((UINT32*) &block[boffset + 2]); /* blockLen (4 bytes) */
|
|
|
|
boffset += 6;
|
|
|
|
|
2014-09-03 02:15:36 +04:00
|
|
|
//printf("%s\n", progressive_get_block_type_string(blockType));
|
2014-07-30 01:37:46 +04:00
|
|
|
|
|
|
|
if ((blocksLen - offset) < blockLen)
|
|
|
|
return -1003;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
switch (blockType)
|
|
|
|
{
|
|
|
|
case PROGRESSIVE_WBT_SYNC:
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
sync.blockType = blockType;
|
|
|
|
sync.blockLen = blockLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) != 6)
|
|
|
|
return -1004;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
sync.magic = (UINT32) *((UINT32*) &block[boffset + 0]); /* magic (4 bytes) */
|
|
|
|
sync.version = (UINT32) *((UINT16*) &block[boffset + 4]); /* version (2 bytes) */
|
2014-07-29 07:41:16 +04:00
|
|
|
boffset += 6;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if (sync.magic != 0xCACCACCA)
|
|
|
|
return -1005;
|
|
|
|
|
|
|
|
if (sync.version != 0x0100)
|
|
|
|
return -1006;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_BEGIN:
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
frameBegin.blockType = blockType;
|
|
|
|
frameBegin.blockLen = blockLen;
|
|
|
|
|
|
|
|
if ((blockLen - boffset) < 6)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1007;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
frameBegin.frameIndex = (UINT32) *((UINT32*) &block[boffset + 0]); /* frameIndex (4 bytes) */
|
|
|
|
frameBegin.regionCount = (UINT32) *((UINT16*) &block[boffset + 4]); /* regionCount (2 bytes) */
|
2014-07-29 07:41:16 +04:00
|
|
|
boffset += 6;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_END:
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
frameEnd.blockType = blockType;
|
|
|
|
frameEnd.blockLen = blockLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) != 0)
|
|
|
|
return -1008;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_CONTEXT:
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
context.blockType = blockType;
|
|
|
|
context.blockLen = blockLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) != 4)
|
|
|
|
return -1009;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
context.ctxId = block[boffset + 0]; /* ctxId (1 byte) */
|
|
|
|
context.tileSize = *((UINT16*) &block[boffset + 1]); /* tileSize (2 bytes) */
|
|
|
|
context.flags = block[boffset + 3]; /* flags (1 byte) */
|
2014-07-29 07:41:16 +04:00
|
|
|
boffset += 4;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if (context.tileSize != 64)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1010;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_REGION:
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region->blockType = blockType;
|
|
|
|
region->blockLen = blockLen;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
if ((blockLen - boffset) < 12)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1011;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region->tileSize = block[boffset + 0]; /* tileSize (1 byte) */
|
|
|
|
region->numRects = *((UINT16*) &block[boffset + 1]); /* numRects (2 bytes) */
|
|
|
|
region->numQuant = block[boffset + 3]; /* numQuant (1 byte) */
|
|
|
|
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) */
|
2014-07-29 07:41:16 +04:00
|
|
|
boffset += 12;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->tileSize != 64)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1012;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->numRects < 1)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1013;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->numQuant > 7)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1014;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if ((blockLen - boffset) < (region->numRects * 8))
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1015;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->numRects > progressive->cRects)
|
2014-07-30 01:37:46 +04:00
|
|
|
{
|
2014-07-31 23:08:54 +04:00
|
|
|
progressive->rects = (RFX_RECT*) realloc(progressive->rects, region->numRects * sizeof(RFX_RECT));
|
|
|
|
progressive->cRects = region->numRects;
|
2014-07-30 01:37:46 +04:00
|
|
|
}
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region->rects = progressive->rects;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (!region->rects)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1016;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
for (index = 0; index < region->numRects; index++)
|
2014-07-29 20:38:29 +04:00
|
|
|
{
|
2014-07-31 23:08:54 +04:00
|
|
|
rect = &(region->rects[index]);
|
2014-07-29 20:38:29 +04:00
|
|
|
rect->x = *((UINT16*) &block[boffset + 0]);
|
|
|
|
rect->y = *((UINT16*) &block[boffset + 2]);
|
|
|
|
rect->width = *((UINT16*) &block[boffset + 4]);
|
|
|
|
rect->height = *((UINT16*) &block[boffset + 6]);
|
|
|
|
boffset += 8;
|
|
|
|
}
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if ((blockLen - boffset) < (region->numQuant * 5))
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1017;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->numQuant > progressive->cQuant)
|
2014-07-29 20:38:29 +04:00
|
|
|
{
|
2014-07-30 01:37:46 +04:00
|
|
|
progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) realloc(progressive->quantVals,
|
2014-07-31 23:08:54 +04:00
|
|
|
region->numQuant * sizeof(RFX_COMPONENT_CODEC_QUANT));
|
|
|
|
progressive->cQuant = region->numQuant;
|
2014-07-29 20:38:29 +04:00
|
|
|
}
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region->quantVals = progressive->quantVals;
|
2014-07-30 01:37:46 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (!region->quantVals)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1018;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
for (index = 0; index < region->numQuant; index++)
|
2014-07-29 20:38:29 +04:00
|
|
|
{
|
2014-07-31 23:08:54 +04:00
|
|
|
quantVal = &(region->quantVals[index]);
|
2014-08-26 01:58:38 +04:00
|
|
|
progressive_component_codec_quant_read(&block[boffset], quantVal);
|
2014-07-30 01:37:46 +04:00
|
|
|
boffset += 5;
|
2014-08-28 20:14:28 +04:00
|
|
|
|
|
|
|
if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
|
|
|
|
return -1;
|
2014-07-29 20:38:29 +04:00
|
|
|
}
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if ((blockLen - boffset) < (region->numProgQuant * 16))
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1019;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (region->numProgQuant > progressive->cProgQuant)
|
2014-07-30 01:37:46 +04:00
|
|
|
{
|
|
|
|
progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) realloc(progressive->quantProgVals,
|
2014-07-31 23:08:54 +04:00
|
|
|
region->numProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT));
|
|
|
|
progressive->cProgQuant = region->numProgQuant;
|
2014-07-30 01:37:46 +04:00
|
|
|
}
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
region->quantProgVals = progressive->quantProgVals;
|
2014-07-30 01:37:46 +04:00
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if (!region->quantProgVals)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1020;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
for (index = 0; index < region->numProgQuant; index++)
|
2014-07-30 01:37:46 +04:00
|
|
|
{
|
2014-07-31 23:08:54 +04:00
|
|
|
quantProgVal = &(region->quantProgVals[index]);
|
2014-07-30 01:37:46 +04:00
|
|
|
quantProgVal->quality = block[boffset + 0];
|
2014-08-28 20:14:28 +04:00
|
|
|
|
2014-08-26 01:58:38 +04:00
|
|
|
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));
|
2014-07-30 01:37:46 +04:00
|
|
|
boffset += 16;
|
|
|
|
}
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
if ((blockLen - boffset) < region->tileDataSize)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1021;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
if (region->numTiles > progressive->cTiles)
|
|
|
|
{
|
2014-08-27 00:15:22 +04:00
|
|
|
progressive->tiles = (RFX_PROGRESSIVE_TILE**) realloc(progressive->tiles,
|
|
|
|
region->numTiles * sizeof(RFX_PROGRESSIVE_TILE*));
|
2014-08-01 17:44:00 +04:00
|
|
|
progressive->cTiles = region->numTiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
region->tiles = progressive->tiles;
|
|
|
|
|
|
|
|
if (!region->tiles)
|
|
|
|
return -1;
|
|
|
|
|
2014-09-06 03:11:03 +04:00
|
|
|
//printf("numRects: %d numTiles: %d numQuant: %d numProgQuant: %d\n",
|
|
|
|
// region->numRects, region->numTiles, region->numQuant, region->numProgQuant);
|
2014-07-30 01:37:46 +04:00
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
status = progressive_process_tiles(progressive, &block[boffset], region->tileDataSize, surface);
|
2014-07-30 01:37:46 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
boffset += (UINT32) status;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
break;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
default:
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1039;
|
2014-07-29 20:38:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boffset != blockLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1040;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
|
|
|
offset += blockLen;
|
2014-07-30 01:37:46 +04:00
|
|
|
count++;
|
2014-07-29 07:41:16 +04:00
|
|
|
}
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if (offset != blocksLen)
|
|
|
|
return -1041;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
return 1;
|
2014-07-29 01:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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;
|
2014-07-30 01:37:46 +04:00
|
|
|
|
2014-08-22 03:43:37 +04:00
|
|
|
progressive->log = WLog_Get("com.freerdp.codec.progressive");
|
|
|
|
|
2014-08-06 18:23:14 +04:00
|
|
|
progressive->bufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16);
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
progressive->cRects = 64;
|
|
|
|
progressive->rects = (RFX_RECT*) malloc(progressive->cRects * sizeof(RFX_RECT));
|
|
|
|
|
|
|
|
if (!progressive->rects)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-01 17:44:00 +04:00
|
|
|
progressive->cTiles = 64;
|
2014-08-27 00:15:22 +04:00
|
|
|
progressive->tiles = (RFX_PROGRESSIVE_TILE**) malloc(progressive->cTiles * sizeof(RFX_PROGRESSIVE_TILE*));
|
2014-08-01 17:44:00 +04:00
|
|
|
|
|
|
|
if (!progressive->tiles)
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
progressive->cQuant = 8;
|
|
|
|
progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) malloc(progressive->cQuant * sizeof(RFX_COMPONENT_CODEC_QUANT));
|
|
|
|
|
|
|
|
if (!progressive->quantVals)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
progressive->cProgQuant = 8;
|
|
|
|
progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) malloc(progressive->cProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT));
|
|
|
|
|
|
|
|
if (!progressive->quantProgVals)
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-31 23:08:54 +04:00
|
|
|
ZeroMemory(&(progressive->quantProgValFull), sizeof(RFX_PROGRESSIVE_CODEC_QUANT));
|
|
|
|
progressive->quantProgValFull.quality = 100;
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
progressive->SurfaceContexts = HashTable_New(TRUE);
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
progressive_context_reset(progressive);
|
2014-07-29 01:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return progressive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
|
|
|
|
{
|
|
|
|
if (!progressive)
|
|
|
|
return;
|
|
|
|
|
2014-08-06 18:23:14 +04:00
|
|
|
BufferPool_Free(progressive->bufferPool);
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
free(progressive->rects);
|
2014-08-01 17:44:00 +04:00
|
|
|
free(progressive->tiles);
|
2014-07-30 01:37:46 +04:00
|
|
|
free(progressive->quantVals);
|
|
|
|
free(progressive->quantProgVals);
|
|
|
|
|
2014-08-27 00:15:22 +04:00
|
|
|
HashTable_Free(progressive->SurfaceContexts);
|
|
|
|
|
2014-07-29 01:42:23 +04:00
|
|
|
free(progressive);
|
|
|
|
}
|
|
|
|
|