0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF
};
-static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat,
+static BOOL convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat,
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat,
UINT32 nDstWidth, UINT32 nDstHeight, const gdiPalette* palette)
UINT32 color = ReadColor(pSrcPixel, SrcFormat);
color = ConvertColor(color, SrcFormat,
DstFormat, palette);
- WriteColor(pDstPixel, DstFormat, color);
+
+ if (!WriteColor(pDstPixel, DstFormat, color))
+ return FALSE;
}
}
+
+ return TRUE;
}
static BOOL clear_decompress_nscodec(NSC_CONTEXT* nsc, UINT32 width,
BOOL rc;
if (Stream_GetRemainingLength(s) < bitmapDataByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ bitmapDataByteCount);
return FALSE;
+ }
rc = nsc_process_message(nsc, 32, width, height, Stream_Pointer(s),
bitmapDataByteCount, pDstData, DstFormat,
UINT32 palette[128] = { 0 };
if (Stream_GetRemainingLength(s) < bitmapDataByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ bitmapDataByteCount);
return FALSE;
+ }
Stream_Read_UINT8(s, paletteCount);
bitmapDataOffset = 1 + (paletteCount * 3);
if (paletteCount > 127)
+ {
+ WLog_ERR(TAG, "paletteCount %lu", paletteCount);
return FALSE;
+ }
for (i = 0; i < paletteCount; i++)
{
BYTE r, g, b;
- UINT32 color;
Stream_Read_UINT8(s, b);
Stream_Read_UINT8(s, g);
Stream_Read_UINT8(s, r);
- color = GetColor(SrcFormat, r, g, b, 0xFF);
+ UINT32 color = GetColor(SrcFormat, r, g, b, 0xFF);
palette[i] = ConvertColor(color, SrcFormat, DstFormat, NULL);
}
UINT32 runLengthFactor;
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 2);
return FALSE;
+ }
Stream_Read_UINT8(s, tmp);
Stream_Read_UINT8(s, runLengthFactor);
if (runLengthFactor >= 0xFF)
{
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 2);
return FALSE;
+ }
Stream_Read_UINT16(s, runLengthFactor);
bitmapDataOffset += 2;
if (runLengthFactor >= 0xFFFF)
{
if (Stream_GetRemainingLength(s) < 4)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 4);
return FALSE;
+ }
Stream_Read_UINT32(s, runLengthFactor);
bitmapDataOffset += 4;
}
if (startIndex >= paletteCount)
+ {
+ WLog_ERR(TAG, "startIndex %lu > paletteCount %lu]", startIndex, paletteCount);
return FALSE;
+ }
if (stopIndex >= paletteCount)
+ {
+ WLog_ERR(TAG, "stopIndex %lu > paletteCount %lu]", stopIndex, paletteCount);
return FALSE;
+ }
suiteIndex = startIndex;
if (suiteIndex > 127)
+ {
+ WLog_ERR(TAG, "suiteIndex %lu > %lu]", suiteIndex, 127);
return FALSE;
+ }
color = palette[suiteIndex];
if ((pixelIndex + runLengthFactor) > pixelCount)
+ {
+ WLog_ERR(TAG, "pixelIndex %lu + runLengthFactor %lu > pixelCount %lu",
+ pixelIndex, runLengthFactor,
+ pixelCount);
return FALSE;
+ }
for (i = 0; i < runLengthFactor; i++)
{
pixelIndex += runLengthFactor;
if ((pixelIndex + (suiteDepth + 1)) > pixelCount)
+ {
+ WLog_ERR(TAG, "pixelIndex %lu + suiteDepth %lu + 1 > pixelCount %lu",
+ pixelIndex, suiteDepth,
+ pixelCount);
return FALSE;
+ }
for (i = 0; i <= suiteDepth; i++)
{
UINT32 color = palette[suiteIndex];
if (suiteIndex > 127)
+ {
+ WLog_ERR(TAG, "suiteIndex %lu > %lu", suiteIndex, 127);
return FALSE;
+ }
suiteIndex++;
nSrcStep = width * GetBytesPerPixel(DstFormat);
if (pixelIndex != pixelCount)
+ {
+ WLog_ERR(TAG, "pixelIndex %lu != pixelCount %lu", pixelIndex, pixelCount);
return FALSE;
+ }
return TRUE;
}
UINT32 pixelCount;
if (Stream_GetRemainingLength(s) < residualByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ residualByteCount);
return FALSE;
+ }
suboffset = 0;
pixelIndex = 0;
UINT32 color;
if (Stream_GetRemainingLength(s) < 4)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 4);
return FALSE;
+ }
Stream_Read_UINT8(s, b);
Stream_Read_UINT8(s, g);
if (runLengthFactor >= 0xFF)
{
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 2);
return FALSE;
+ }
Stream_Read_UINT16(s, runLengthFactor);
suboffset += 2;
if (runLengthFactor >= 0xFFFF)
{
if (Stream_GetRemainingLength(s) < 4)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 4);
return FALSE;
+ }
Stream_Read_UINT32(s, runLengthFactor);
suboffset += 4;
}
if ((pixelIndex + runLengthFactor) > pixelCount)
+ {
+ WLog_ERR(TAG, "pixelIndex %lu + runLengthFactor %lu > pixelCount %lu",
+ pixelIndex, runLengthFactor,
+ pixelCount);
return FALSE;
+ }
for (i = 0; i < runLengthFactor; i++)
{
nSrcStep = nWidth * GetBytesPerPixel(clear->format);
if (pixelIndex != pixelCount)
- return -1019;
+ {
+ WLog_ERR(TAG, "pixelIndex %lu != pixelCount %lu", pixelIndex, pixelCount);
+ return FALSE;
+ }
- convert_color(pDstData, nDstStep, DstFormat,
- nXDst, nYDst, nWidth, nHeight,
- clear->TempBuffer, nSrcStep, clear->format,
- nDstWidth, nDstHeight, palette);
- return TRUE;
+ return convert_color(pDstData, nDstStep, DstFormat,
+ nXDst, nYDst, nWidth, nHeight,
+ clear->TempBuffer, nSrcStep, clear->format,
+ nDstWidth, nDstHeight, palette);
}
static BOOL clear_decompress_subcodecs_data(CLEAR_CONTEXT* clear, wStream* s,
UINT32 suboffset;
if (Stream_GetRemainingLength(s) < subcodecByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ subcodecByteCount);
return FALSE;
+ }
suboffset = 0;
UINT32 nYDstRel;
if (Stream_GetRemainingLength(s) < 13)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 13);
return FALSE;
+ }
Stream_Read_UINT16(s, xStart);
Stream_Read_UINT16(s, yStart);
suboffset += 13;
if (Stream_GetRemainingLength(s) < bitmapDataByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ bitmapDataByteCount);
return FALSE;
+ }
nXDstRel = nXDst + xStart;
nYDstRel = nYDst + yStart;
if (width > nWidth)
+ {
+ WLog_ERR(TAG, "width %lu > nWidth %lu", width, nWidth);
return FALSE;
+ }
if (height > nHeight)
+ {
+ WLog_ERR(TAG, "height %lu > nHeight %lu", height, nHeight);
return FALSE;
+ }
if ((width * height * GetBytesPerPixel(clear->format)) >
clear->TempSize)
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
if (!clear->TempBuffer)
+ {
+ WLog_ERR(TAG, "clear->TempBuffer realloc failed for %lu bytes",
+ clear->TempSize);
return FALSE;
+ }
}
switch (subcodecId)
{
case 0: /* Uncompressed */
{
- UINT32 nSrcStep = width * GetBytesPerPixel(PIXEL_FORMAT_BGR24);
+ UINT32 nSrcStep = width * GetBytesPerPixel(PIXEL_FORMAT_BGR24);;
UINT32 nSrcSize = nSrcStep * height;
if (bitmapDataByteCount != nSrcSize)
+ {
+ WLog_ERR(TAG, "bitmapDataByteCount %lu != nSrcSize %lu", bitmapDataByteCount,
+ nSrcSize);
+ return FALSE;
+ }
+
+ if (!convert_color(pDstData, nDstStep, DstFormat,
+ nXDstRel, nYDstRel, width, height,
+ Stream_Pointer(s), nSrcStep,
+ PIXEL_FORMAT_BGR24,
+ nDstWidth, nDstHeight, palette))
return FALSE;
- convert_color(pDstData, nDstStep, DstFormat,
- nXDstRel, nYDstRel, width, height,
- Stream_Pointer(s), nSrcStep,
- PIXEL_FORMAT_BGR24,
- nDstWidth, nDstHeight, palette);
Stream_Seek(s, bitmapDataByteCount);
}
break;
break;
default:
+ WLog_ERR(TAG, "Unknown subcodec ID %lu", subcodecId);
return FALSE;
}
vBarEntry->count * bpp);
if (!tmp)
+ {
+ WLog_ERR(TAG, "vBarEntry->pixels realloc %lu failed", vBarEntry->count * bpp);
return FALSE;
+ }
memset(&tmp[oldPos], 0, diffSize);
vBarEntry->pixels = tmp;
}
if (!vBarEntry->pixels && vBarEntry->size)
+ {
+ WLog_ERR(TAG, "!vBarEntry->pixels %lu && vBarEntry->size %lu",
+ vBarEntry->pixels, vBarEntry->size);
return FALSE;
+ }
return TRUE;
}
UINT32 nYDstRel;
if (Stream_GetRemainingLength(s) < bandsByteCount)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 11);
return FALSE;
+ }
suboffset = 0;
UINT32 vBarShortPixelCount;
if (Stream_GetRemainingLength(s) < 11)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 11);
return FALSE;
+ }
Stream_Read_UINT16(s, xStart);
Stream_Read_UINT16(s, xEnd);
colorBkg = GetColor(clear->format, r, g, b, 0xFF);
if (xEnd < xStart)
+ {
+ WLog_ERR(TAG, "xEnd %lu < xStart %lu", xEnd, xStart);
return FALSE;
+ }
if (yEnd < yStart)
+ {
+ WLog_ERR(TAG, "yEnd %lu < yStart %lu", yEnd, yStart);
return FALSE;
+ }
vBarCount = (xEnd - xStart) + 1;
const BYTE* pSrcPixel;
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 2);
return FALSE;
+ }
Stream_Read_UINT16(s, vBarHeader);;
suboffset += 2;
vBarHeight = (yEnd - yStart + 1);
if (vBarHeight > 52)
+ {
+ WLog_ERR(TAG, "vBarHeight > 52", vBarHeight);
return FALSE;
+ }
if ((vBarHeader & 0xC000) == 0x4000) /* SHORT_VBAR_CACHE_HIT */
{
vBarShortEntry = &(clear->ShortVBarStorage[vBarIndex]);
if (!vBarShortEntry)
+ {
+ WLog_ERR(TAG, "missing vBarShortEntry %lu", vBarIndex);
return FALSE;
+ }
if (Stream_GetRemainingLength(s) < 1)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 1);
return FALSE;
+ }
Stream_Read_UINT8(s, vBarYOn);
suboffset += 1;
vBarYOff = ((vBarHeader >> 8) & 0x3F);
if (vBarYOff < vBarYOn)
+ {
+ WLog_ERR(TAG, "vBarYOff %lu < vBarYOn %lu", vBarYOff, vBarYOn);
return FALSE;
+ }
vBarShortPixelCount = (vBarYOff - vBarYOn);
if (vBarShortPixelCount > 52)
+ {
+ WLog_ERR(TAG, "vBarShortPixelCount %lu > 52", vBarShortPixelCount);
return FALSE;
+ }
if (Stream_GetRemainingLength(s) < (vBarShortPixelCount * 3))
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ (vBarShortPixelCount * 3));
return FALSE;
+ }
if (clear->ShortVBarStorageCursor >= CLEARCODEC_VBAR_SHORT_SIZE)
+ {
+ WLog_ERR(TAG,
+ "clear->ShortVBarStorageCursor %lu >= CLEARCODEC_VBAR_SHORT_SIZE %lu",
+ clear->ShortVBarStorageCursor, CLEARCODEC_VBAR_SHORT_SIZE);
return FALSE;
+ }
vBarShortEntry = &(clear->ShortVBarStorage[clear->ShortVBarStorageCursor]);
vBarShortEntry->count = vBarShortPixelCount;
Stream_Read_UINT8(s, g);
Stream_Read_UINT8(s, r);
color = GetColor(clear->format, r, g, b, 0xFF);
- WriteColor(dstBuffer, clear->format, color);
+
+ if (!WriteColor(dstBuffer, clear->format, color))
+ return FALSE;
}
suboffset += (vBarShortPixelCount * 3);
}
else
{
+ WLog_ERR(TAG, "invalid vBarHeader %08lX", vBarHeader);
return FALSE; /* invalid vBarHeader */
}
BYTE* dstBuffer;
if (clear->VBarStorageCursor >= CLEARCODEC_VBAR_SIZE)
+ {
+ WLog_ERR(TAG, "clear->VBarStorageCursor %lu >= CLEARCODEC_VBAR_SIZE %lu",
+ clear->VBarStorageCursor,
+ CLEARCODEC_VBAR_SIZE);
return FALSE;
+ }
vBarEntry = &(clear->VBarStorage[clear->VBarStorageCursor]);
vBarPixelCount = vBarHeight;
UINT32 color;
color = ReadColor(&vBarShortEntry->pixels[x * GetBytesPerPixel(clear->format)],
clear->format);
- WriteColor(dstBuffer, clear->format, color);
+
+ if (!WriteColor(dstBuffer, clear->format, color))
+ return FALSE;
+
dstBuffer += GetBytesPerPixel(clear->format);
}
while (count--)
{
- WriteColor(dstBuffer, clear->format, colorBkg);
+ if (!WriteColor(dstBuffer, clear->format, colorBkg))
+ return FALSE;
+
dstBuffer += GetBytesPerPixel(clear->format);
}
}
if (vBarEntry->count != vBarHeight)
+ {
+ WLog_ERR(TAG, "vBarEntry->count %lu != vBarHeight %lu", vBarEntry->count,
+ vBarHeight);
return FALSE;
+ }
nXDstRel = nXDst + xStart;
nYDstRel = nYDst + yStart;
UINT32 color = ReadColor(pSrcPixel, clear->format);
color = ConvertColor(color, clear->format,
DstFormat, NULL);
- WriteColor(pDstPixel8, DstFormat, color);
+
+ if (!WriteColor(pDstPixel8, DstFormat, color))
+ return FALSE;
+
pSrcPixel += GetBytesPerPixel(clear->format);
}
}
}
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s),
+ 2);
return FALSE;
+ }
Stream_Read_UINT16(s, glyphIndex);
{
UINT32 nSrcStep;
CLEAR_GLYPH_ENTRY* glyphEntry = &(clear->GlyphCache[glyphIndex]);
- BYTE* glyphData = (BYTE*) glyphEntry->pixels;
+ BYTE* glyphData;
+
+ if (!glyphEntry)
+ {
+ WLog_ERR(TAG, "clear->GlyphCache[%lu]=NULL", glyphIndex);
+ return FALSE;
+ }
+
+ glyphData = (BYTE*) glyphEntry->pixels;
if (!glyphData)
+ {
+ WLog_ERR(TAG, "clear->GlyphCache[%lu]->pixels=NULL", glyphIndex);
return FALSE;
+ }
- if ((nWidth * nHeight) > (int) glyphEntry->count)
+ if ((nWidth * nHeight) > glyphEntry->count)
+ {
+ WLog_ERR(TAG, "(nWidth %lu * nHeight %lu) > glyphEntry->count %lu", nWidth, nHeight,
+ glyphEntry->count);
return FALSE;
+ }
nSrcStep = nWidth * GetBytesPerPixel(clear->format);
- convert_color(pDstData, nDstStep, DstFormat,
- nXDst, nYDst, nWidth, nHeight,
- glyphData, nSrcStep, clear->format,
- nDstWidth, nDstHeight, palette);
- return TRUE;
+ return convert_color(pDstData, nDstStep, DstFormat,
+ nXDst, nYDst, nWidth, nHeight,
+ glyphData, nSrcStep, clear->format,
+ nDstWidth, nDstHeight, palette);
}
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)
tmp = (UINT32*) realloc(glyphEntry->pixels, glyphEntry->size * 4);
if (!tmp)
+ {
+ WLog_ERR(TAG, "glyphEntry->pixels realloc %lu failed!", glyphEntry->size * 4);
return FALSE;
+ }
glyphEntry->pixels = tmp;
}
if (!glyphEntry->pixels)
+ {
+ WLog_ERR(TAG, "glyphEntry->pixels=NULL");
return FALSE;
+ }
glyphData = (BYTE*) glyphEntry->pixels;
nSrcStep = nWidth * GetBytesPerPixel(clear->format);
- convert_color(pDstData, nDstStep, DstFormat,
- nXDst, nYDst, nWidth, nHeight,
- glyphData, nSrcStep, clear->format,
- nDstWidth, nDstHeight, palette);
+
+ if (!convert_color(pDstData, nDstStep, DstFormat,
+ nXDst, nYDst, nWidth, nHeight,
+ glyphData, nSrcStep, clear->format,
+ nDstWidth, nDstHeight, palette))
+ return FALSE;
}
return TRUE;
Stream_SetLength(s, SrcSize);
if (Stream_GetRemainingLength(s) < 2)
+ {
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s), 2);
goto fail;
+ }
Stream_Read_UINT8(s, glyphFlags);
Stream_Read_UINT8(s, seqNumber);
{
WLog_ERR(TAG, "Sequence number unexpected %u - %u",
seqNumber, clear->seqNumber);
+ WLog_ERR(TAG, "seqNumber %lu != clear->seqNumber %lu", seqNumber, clear->seqNumber);
goto fail;
}
nHeight, pDstData, DstFormat,
nDstStep, nXDst, nYDst,
nDstWidth, nDstHeight, palette))
+ {
+ WLog_ERR(TAG, "clear_decompress_glyph_data failed!");
goto fail;
+ }
/* Read composition payload header parameters */
if (Stream_GetRemainingLength(s) < 12)
if ((glyphFlags & mask) == mask)
goto finish;
+ WLog_ERR(TAG, "stream short %lu [%lu expected]", Stream_GetRemainingLength(s), 12);
goto fail;
}
if (!clear_decompress_residual_data(clear, s, residualByteCount, nWidth,
nHeight, pDstData, DstFormat, nDstStep, nXDst, nYDst,
nDstWidth, nDstHeight, palette))
+ {
+ WLog_ERR(TAG, "clear_decompress_residual_data failed!");
goto fail;
+ }
}
if (bandsByteCount > 0)
{
if (!clear_decompress_bands_data(clear, s, bandsByteCount, nWidth, nHeight,
pDstData, DstFormat, nDstStep, nXDst, nYDst))
+ {
+ WLog_ERR(TAG, "clear_decompress_bands_data failed!");
goto fail;
+ }
}
if (subcodecByteCount > 0)
nHeight, pDstData, DstFormat,
nDstStep, nXDst, nYDst,
nDstWidth, nDstHeight, palette))
+ {
+ WLog_ERR(TAG, "clear_decompress_subcodecs_data failed!");
goto fail;
+ }
}
finish:
int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
BYTE** ppDstData, UINT32* pDstSize)
{
+ WLog_ERR(TAG, "TODO: %s not implemented!");
return 1;
}
BOOL clear_context_reset(CLEAR_CONTEXT* clear)
nsc_context_set_pixel_format(clear->nsc, PIXEL_FORMAT_RGB24);
clear->TempSize = 512 * 512 * 4;
clear->TempBuffer = (BYTE*) malloc(clear->TempSize);
- clear_context_reset(clear);
+
+ if (!clear->TempBuffer)
+ goto error_nsc;
+
+ if (!clear_context_reset(clear))
+ goto error_nsc;
+
return clear;
error_nsc:
- free(clear);
+ clear_context_free(clear);
return NULL;
}
void clear_context_free(CLEAR_CONTEXT* clear)