TS_SumDataEncoded
This is a Data Header variable.
Type = (encoded) array of longs
TS Technical Specification_SumDataEncoded is an array of encoded histogram counts (Cumulative History trace mapping). The array is organized in horizontal scan line groups, where the bottom scan line is the first group in the array.
The Cumulative History trace shows the number of times a trace line occupies each pixel; therefore in the decoded array, there is one count per pixel in the trace grid area.
The following code can be used to decode the "SumDataEncoded" array. First, call DecodeSize() function first to determine the size of the decoded array (which is usually much larger than encoded array. Next, using the returned count, allocate an array for the decoded values. Last, call DecodeBuffer() to decode the array.
// Return the number of longs in the decoded array
// from the passed encoded array, where:
//
// src the pointer to the beginning of the encoded array
// cnt the number of longs in the encoded array
//
static long DecodeSize(long* src, long cnt)
{
long totalCnt = 0;
while (cnt > 0)
{
long partCnt = *src++;
--cnt;
if (partCnt == 0)
return 0;
if (partCnt > 0)
{
totalCnt += partCnt;
src += partCnt;
cnt -= partCnt;
}
else
{
totalCnt -= partCnt;
src++;
--cnt;
}
}
return totalCnt;
}
// Decode the passed encoded long array, where:
//
// dst the beginning address of the destination (decoded) array
// dstCnt the number of longs in the destination (decoded) array
// src the beginning address of the source (encoded) array
// srcCnt the number of longs in the source (encoded) array
static void DecodeBuffer(long* dst, long dstCnt, long* src, long srcCnt)
{
while (srcCnt > 0 && dstCnt > 0)
{
long partCnt = *src++;
--srcCnt;
if (partCnt == 0)
return;
if (partCnt > 0)
{
if (partCnt > dstCnt)
partCnt = dstCnt;
memcpy(dst, src, partCnt * sizeof(long));
dst += partCnt;
src += partCnt;
srcCnt -= partCnt;
}
else
{
partCnt = -partCnt;
if (partCnt > dstCnt)
partCnt = dstCnt;
long value = *src++;
--srcCnt;
for (int i = 0; i < partCnt; ++i)
*dst++ = value;
}
dstCnt -= partCnt;
}
}