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>
|
|
|
|
|
|
|
|
#include <freerdp/codec/color.h>
|
|
|
|
#include <freerdp/codec/progressive.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-07-30 01:37:46 +04:00
|
|
|
int progressive_process_blocks(PROGRESSIVE_CONTEXT* progressive, BYTE* blocks, UINT32 blocksLen, UINT32 blockCount, UINT32 flags)
|
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-07-29 20:38:29 +04:00
|
|
|
UINT16 index;
|
2014-07-29 07:41:16 +04:00
|
|
|
UINT32 boffset;
|
|
|
|
UINT16 blockType;
|
|
|
|
UINT32 blockLen;
|
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;
|
|
|
|
PROGRESSIVE_BLOCK_REGION region;
|
|
|
|
PROGRESSIVE_BLOCK_CONTEXT context;
|
|
|
|
PROGRESSIVE_BLOCK_FRAME_BEGIN frameBegin;
|
|
|
|
PROGRESSIVE_BLOCK_FRAME_END frameEnd;
|
|
|
|
PROGRESSIVE_BLOCK_TILE_SIMPLE simple;
|
|
|
|
PROGRESSIVE_BLOCK_TILE_FIRST first;
|
|
|
|
PROGRESSIVE_BLOCK_TILE_UPGRADE upgrade;
|
|
|
|
RFX_COMPONENT_CODEC_QUANT* quantVal;
|
|
|
|
RFX_PROGRESSIVE_CODEC_QUANT* quantProgVal;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
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-07-30 01:37:46 +04:00
|
|
|
if (flags & PROGRESSIVE_BLOCKS_REGION)
|
|
|
|
{
|
|
|
|
if ((count + 1) > blockCount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (blockType != PROGRESSIVE_WBT_REGION)
|
|
|
|
return -1001;
|
|
|
|
}
|
|
|
|
else if (flags & PROGRESSIVE_BLOCKS_TILE)
|
|
|
|
{
|
|
|
|
if ((count + 1) > blockCount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((blockType != PROGRESSIVE_WBT_TILE_SIMPLE) &&
|
|
|
|
(blockType != PROGRESSIVE_WBT_TILE_FIRST) &&
|
|
|
|
(blockType != PROGRESSIVE_WBT_TILE_UPGRADE))
|
|
|
|
{
|
|
|
|
return -1002;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\n", progressive_get_block_type_string(blockType));
|
|
|
|
|
|
|
|
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-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) > 0)
|
2014-07-29 20:38:29 +04:00
|
|
|
{
|
2014-07-30 01:37:46 +04:00
|
|
|
status = progressive_process_blocks(progressive, &block[boffset],
|
|
|
|
blockLen - boffset, frameBegin.regionCount, PROGRESSIVE_BLOCKS_REGION);
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
boffset += status;
|
|
|
|
}
|
2014-07-29 20:38:29 +04:00
|
|
|
|
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-29 20:38:29 +04:00
|
|
|
region.blockType = blockType;
|
|
|
|
region.blockLen = blockLen;
|
|
|
|
|
|
|
|
if ((blockLen - boffset) < 12)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1011;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
region.tileSize = block[boffset + 0]; /* tileSize (1 byte) */
|
2014-07-29 07:41:16 +04:00
|
|
|
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) */
|
|
|
|
boffset += 12;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if (region.tileSize != 64)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1012;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
if (region.numRects < 1)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1013;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
if (region.numQuant > 7)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1014;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
if ((blockLen - boffset) < (region.numRects * 8))
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1015;
|
|
|
|
|
|
|
|
if (region.numRects > progressive->cRects)
|
|
|
|
{
|
|
|
|
progressive->rects = (RFX_RECT*) realloc(progressive->rects, region.numRects * sizeof(RFX_RECT));
|
|
|
|
progressive->cRects = region.numRects;
|
|
|
|
}
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
region.rects = progressive->rects;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
if (!region.rects)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1016;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
for (index = 0; index < region.numRects; index++)
|
|
|
|
{
|
|
|
|
rect = &(region.rects[index]);
|
|
|
|
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-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < (region.numQuant * 5))
|
|
|
|
return -1017;
|
|
|
|
|
|
|
|
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,
|
|
|
|
region.numQuant * sizeof(RFX_COMPONENT_CODEC_QUANT));
|
|
|
|
progressive->cQuant = region.numQuant;
|
2014-07-29 20:38:29 +04:00
|
|
|
}
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
region.quantVals = progressive->quantVals;
|
|
|
|
|
|
|
|
if (!region.quantVals)
|
|
|
|
return -1018;
|
|
|
|
|
|
|
|
for (index = 0; index < region.numQuant; index++)
|
2014-07-29 20:38:29 +04:00
|
|
|
{
|
2014-07-30 01:37:46 +04:00
|
|
|
quantVal = &(region.quantVals[index]);
|
|
|
|
quantVal->LL3 = block[boffset + 0] & 0x0F;
|
|
|
|
quantVal->HL3 = block[boffset + 0] >> 4;
|
|
|
|
quantVal->LH3 = block[boffset + 1] & 0x0F;
|
|
|
|
quantVal->HH3 = block[boffset + 1] >> 4;
|
|
|
|
quantVal->HL2 = block[boffset + 2] & 0x0F;
|
|
|
|
quantVal->LH2 = block[boffset + 2] >> 4;
|
|
|
|
quantVal->HH2 = block[boffset + 3] & 0x0F;
|
|
|
|
quantVal->HL1 = block[boffset + 3] >> 4;
|
|
|
|
quantVal->LH1 = block[boffset + 4] & 0x0F;
|
|
|
|
quantVal->HH1 = block[boffset + 4] >> 4;
|
|
|
|
boffset += 5;
|
2014-07-29 20:38:29 +04:00
|
|
|
}
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < (region.numProgQuant * 16))
|
|
|
|
return -1019;
|
|
|
|
|
|
|
|
if (region.numProgQuant > progressive->cProgQuant)
|
|
|
|
{
|
|
|
|
progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) realloc(progressive->quantProgVals,
|
|
|
|
region.numProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT));
|
|
|
|
progressive->cProgQuant = region.numProgQuant;
|
|
|
|
}
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
region.quantProgVals = progressive->quantProgVals;
|
|
|
|
|
|
|
|
if (!region.quantProgVals)
|
|
|
|
return -1020;
|
|
|
|
|
|
|
|
for (index = 0; index < region.numProgQuant; index++)
|
|
|
|
{
|
|
|
|
quantProgVal = &(region.quantProgVals[index]);
|
|
|
|
quantProgVal->quality = block[boffset + 0];
|
|
|
|
CopyMemory(quantProgVal->yQuantValues, &block[boffset + 1], 5);
|
|
|
|
CopyMemory(quantProgVal->cbQuantValues, &block[boffset + 6], 5);
|
|
|
|
CopyMemory(quantProgVal->crQuantValues, &block[boffset + 11], 5);
|
|
|
|
boffset += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((blockLen - boffset) < region.tileDataSize)
|
|
|
|
return -1021;
|
|
|
|
|
|
|
|
printf("numRects: %d numTiles: %d numQuant: %d numProgQuant: %d\n",
|
|
|
|
region.numRects, region.numTiles, region.numQuant, region.numProgQuant);
|
|
|
|
|
|
|
|
status = progressive_process_blocks(progressive, &block[boffset],
|
|
|
|
region.tileDataSize, region.numTiles, PROGRESSIVE_BLOCKS_TILE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_SIMPLE:
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
simple.blockType = blockType;
|
|
|
|
simple.blockLen = blockLen;
|
|
|
|
|
|
|
|
if ((blockLen - boffset) < 16)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1022;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
simple.quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */
|
2014-07-29 07:41:16 +04:00
|
|
|
simple.quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */
|
|
|
|
simple.quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */
|
|
|
|
simple.xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
simple.yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
|
|
|
simple.flags = block[boffset + 7]; /* flags (1 byte) */
|
|
|
|
simple.yLen = *((UINT16*) &block[boffset + 8]); /* yLen (2 bytes) */
|
|
|
|
simple.cbLen = *((UINT16*) &block[boffset + 10]); /* cbLen (2 bytes) */
|
|
|
|
simple.crLen = *((UINT16*) &block[boffset + 12]); /* crLen (2 bytes) */
|
|
|
|
simple.tailLen = *((UINT16*) &block[boffset + 14]); /* tailLen (2 bytes) */
|
|
|
|
boffset += 16;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < simple.yLen)
|
|
|
|
return -1023;
|
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
simple.yData = &block[boffset];
|
|
|
|
boffset += simple.yLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < simple.cbLen)
|
|
|
|
return -1024;
|
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
simple.cbData = &block[boffset];
|
|
|
|
boffset += simple.cbLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < simple.crLen)
|
|
|
|
return -1025;
|
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
simple.crData = &block[boffset];
|
|
|
|
boffset += simple.crLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < simple.tailLen)
|
|
|
|
return -1026;
|
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
simple.tailData = &block[boffset];
|
|
|
|
boffset += simple.tailLen;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
case PROGRESSIVE_WBT_TILE_FIRST:
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
first.blockType = blockType;
|
|
|
|
first.blockLen = blockLen;
|
|
|
|
|
|
|
|
if ((blockLen - boffset) < 17)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1027;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
|
|
|
first.quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */
|
2014-07-29 07:41:16 +04:00
|
|
|
first.quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */
|
|
|
|
first.quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */
|
|
|
|
first.xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
first.yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
|
|
|
first.flags = block[boffset + 7]; /* flags (1 byte) */
|
|
|
|
first.quality = block[boffset + 8]; /* quality (1 byte) */
|
|
|
|
first.yLen = *((UINT16*) &block[boffset + 9]); /* yLen (2 bytes) */
|
|
|
|
first.cbLen = *((UINT16*) &block[boffset + 11]); /* cbLen (2 bytes) */
|
|
|
|
first.crLen = *((UINT16*) &block[boffset + 13]); /* crLen (2 bytes) */
|
|
|
|
first.tailLen = *((UINT16*) &block[boffset + 15]); /* tailLen (2 bytes) */
|
|
|
|
boffset += 17;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < first.yLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1028;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
first.yData = &block[boffset];
|
|
|
|
boffset += first.yLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < first.cbLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1029;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
first.cbData = &block[boffset];
|
|
|
|
boffset += first.cbLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < first.crLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1030;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
first.crData = &block[boffset];
|
|
|
|
boffset += first.crLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < first.tailLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1031;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
first.tailData = &block[boffset];
|
|
|
|
boffset += first.tailLen;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
case PROGRESSIVE_WBT_TILE_UPGRADE:
|
|
|
|
|
|
|
|
upgrade.blockType = blockType;
|
|
|
|
upgrade.blockLen = blockLen;
|
|
|
|
|
2014-07-30 01:37:46 +04:00
|
|
|
if ((blockLen - boffset) < 20)
|
|
|
|
return -1032;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
upgrade.quantIdxY = block[boffset + 0]; /* quantIdxY (1 byte) */
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.quantIdxCb = block[boffset + 1]; /* quantIdxCb (1 byte) */
|
|
|
|
upgrade.quantIdxCr = block[boffset + 2]; /* quantIdxCr (1 byte) */
|
|
|
|
upgrade.xIdx = *((UINT16*) &block[boffset + 3]); /* xIdx (2 bytes) */
|
|
|
|
upgrade.yIdx = *((UINT16*) &block[boffset + 5]); /* yIdx (2 bytes) */
|
|
|
|
upgrade.quality = block[boffset + 7]; /* quality (1 byte) */
|
|
|
|
upgrade.ySrlLen = *((UINT16*) &block[boffset + 8]); /* ySrlLen (2 bytes) */
|
|
|
|
upgrade.yRawLen = *((UINT16*) &block[boffset + 10]); /* yRawLen (2 bytes) */
|
|
|
|
upgrade.cbSrlLen = *((UINT16*) &block[boffset + 12]); /* cbSrlLen (2 bytes) */
|
|
|
|
upgrade.cbRawLen = *((UINT16*) &block[boffset + 14]); /* cbRawLen (2 bytes) */
|
|
|
|
upgrade.crSrlLen = *((UINT16*) &block[boffset + 16]); /* crSrlLen (2 bytes) */
|
|
|
|
upgrade.crRawLen = *((UINT16*) &block[boffset + 18]); /* crRawLen (2 bytes) */
|
2014-07-30 01:37:46 +04:00
|
|
|
boffset += 20;
|
2014-07-29 07:41:16 +04:00
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.ySrlLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1033;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.ySrlData = &block[boffset];
|
|
|
|
boffset += upgrade.ySrlLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.yRawLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1034;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.yRawData = &block[boffset];
|
|
|
|
boffset += upgrade.yRawLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.cbSrlLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1035;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.cbSrlData = &block[boffset];
|
|
|
|
boffset += upgrade.cbSrlLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.cbRawLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1036;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.cbRawData = &block[boffset];
|
|
|
|
boffset += upgrade.cbRawLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.crSrlLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1037;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.crSrlData = &block[boffset];
|
|
|
|
boffset += upgrade.crSrlLen;
|
|
|
|
|
2014-07-29 20:38:29 +04:00
|
|
|
if ((blockLen - boffset) < upgrade.crRawLen)
|
2014-07-30 01:37:46 +04:00
|
|
|
return -1038;
|
2014-07-29 20:38:29 +04:00
|
|
|
|
2014-07-29 07:41:16 +04:00
|
|
|
upgrade.crRawData = &block[boffset];
|
|
|
|
boffset += upgrade.crRawLen;
|
|
|
|
|
|
|
|
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-07-30 01:37:46 +04:00
|
|
|
return (int) offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize,
|
|
|
|
BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = progressive_process_blocks(progressive, pSrcData, SrcSize, 0, PROGRESSIVE_BLOCKS_ALL);
|
|
|
|
|
|
|
|
if (status >= 0)
|
|
|
|
status = 1;
|
|
|
|
|
|
|
|
return status;
|
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
|
|
|
|
|
|
|
progressive->cRects = 64;
|
|
|
|
progressive->rects = (RFX_RECT*) malloc(progressive->cRects * sizeof(RFX_RECT));
|
|
|
|
|
|
|
|
if (!progressive->rects)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-07-30 01:37:46 +04:00
|
|
|
free(progressive->rects);
|
|
|
|
free(progressive->quantVals);
|
|
|
|
free(progressive->quantProgVals);
|
|
|
|
|
2014-07-29 01:42:23 +04:00
|
|
|
free(progressive);
|
|
|
|
}
|
|
|
|
|