Esempio n. 1
0
char* Stream::decompress(int tableId, int recordNumber)
{
	char *data;
	short *q, *limit;
	int run = 0;
	decompressedLength = 0;

	for (Segment *segment = segments; segment; segment = segment->next)
	{
		if (segment->length == 0)
			continue;
		const short* p = (short*) segment->address;
		const short* end = (short*) (segment->address + segment->length);
		if (decompressedLength == 0)
		{
			decompressedLength = *p++;
			if (decompressedLength <= 0)
			{
				Log::log ("corrupted record, table %d, record %d, decompressed length %d\n",
						  tableId, recordNumber, decompressedLength);
				throw SQLEXCEPTION (RUNTIME_ERROR, "corrupted record, table %d, record %d, decompressed length %d",
									tableId, recordNumber, decompressedLength);
			}
			int len = ((decompressedLength + 1) / 2) * 2;
			//data = new char [len];
			data = ALLOCATE_RECORD (len);
			limit = (short*) (data + decompressedLength);
			if (decompressedLength & 1)
				++limit;
			q = (short*) data;
		}
		while (p < end)
		{
			const short n = *p++;
//#ifdef ENGINE
			if (n == 0 && run == 0)
			{
				Log::log ("corrupted record (zero run), table %d, record %d\n", tableId, recordNumber);
				printShorts ("Zero run", (segment->length + 1) / 2, (short*) segment->address);
				printChars ("Zero run", segment->length, segment->address);
			}
//#endif
			if (run > 0)
			{
				for (; run; --run)
					*q++ = n;
			}
			else if (run < 0)
			{
				*q++ = n;
				++run;
			}
			else
			{
				run = n;
				if (q + run > limit)
				{
//#ifdef ENGINE
					Log::log ("corrupted record (overrun), table %d, record %d\n", tableId, recordNumber);
					printShorts ("Compressed", (segment->length + 1)/2, (short*) segment->address);
					printChars ("Compressed", segment->length, segment->address);
//#endif
					if (q == limit)
						return data;
					throw SQLEXCEPTION (RUNTIME_ERROR, "corrupted record, table %d, record %d", tableId, recordNumber);
				}
			}
		}
	}

	//printShorts ("Decompressed", (decompressedLength + 1) / 2, (short*) data);
	return data;
}
/* ************************************************************************* 

   NAME:  test_float2char

   USAGE: 

   test_float2char();

   returns: void

   DESCRIPTION:
                 convert floats to ints to shorts to chars to test
                 rounding/truncating

   REFERENCES:

   Ian Ollmann's Altivec Tutorial
   
   LIMITATIONS:

   GLOBAL VARIABLES:

      accessed: none

      modified: none

   FUNCTIONS CALLED:
   
   fprintf
   vec_st - store a vector to memory
   vec_cts - convert to fixed point
   vec_pack - narrow 2 vectors and pack them into one vector
   vec_packsu - saturating pack, unsigned result

   
   REVISION HISTORY:
        STR        Description of Revision                   Author
     07-Feb-2011    Based off of gpk's condense_float_rgbas   kaj

 ************************************************************************* */
void test_float2char(void)
{
  vector float floatVec1 = {0.0, -50.14455,  21.7790, 100.0 };
  vector float floatVec2 = {-100.4567, 250.14455,  -210.7790, 170.0 };
  vector float floatVec3 = {0.09876, -150.55,  1.7790, -120.0 };
  vector float floatVec4 = {-90.234, -30.9455,  -205.90, 199.9 };
  vector signed int intVec1, intVec2, intVec3, intVec4;
  vector signed short shortVec1, shortVec2;
  vector unsigned char charVec;
  unsigned char printchar[CHAR_ARRAYSIZE] __attribute__ ((aligned (16)));
  float printfloat[FLOAT_ARRAYSIZE] __attribute__ ((aligned (16)));
  signed short printshort[SHORT_ARRAYSIZE] __attribute__ ((aligned (16)));
  signed int printint[INT_ARRAYSIZE] __attribute__ ((aligned (16)));
  int i;

  fprintf(stderr, "--- function %s ------\n", __FUNCTION__);

  /* print out floats */
  vec_st(floatVec1,0,printfloat);
  printFloats(printfloat);

  vec_st(floatVec2,0,printfloat);
  printFloats(printfloat);

  vec_st(floatVec3,0,printfloat);
  printFloats(printfloat);

  vec_st(floatVec4,0,printfloat);
  printFloats(printfloat);

  //floatVec1 = vec_trunc(floatVec1);
  vec_trunc(floatVec1);

  /* convert from float to signed int and print */
  intVec1 = vec_cts(floatVec1,0);
  vec_st(intVec1,0,printint);
  printInts(printint);

  intVec2 = vec_cts(floatVec2,0);
  vec_st(intVec2,0,printint);
  printInts(printint);

  intVec3 = vec_cts(floatVec3,0);
  vec_st(intVec3,0,printint);
  printInts(printint);

  intVec4 = vec_cts(floatVec4,0);
  vec_st(intVec4,0,printint);
  printInts(printint);

  /* convert from signed int to signed short and print */
  shortVec1 = vec_pack(intVec1,intVec2);
  vec_st(shortVec1,0,printshort);
  printShorts(printshort);

  shortVec2 = vec_pack(intVec3,intVec4);
  vec_st(shortVec2,0,printshort);
  printShorts(printshort);

  /* convert from signed short to unsigned char and print */
  charVec  = vec_packsu(shortVec1, shortVec2);
  vec_st(charVec,0,printchar);
  printChars(printchar);

} /* test_float2char */