CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, bool hasAlpha, unsigned int flags) { CXBTFFrame frame; #ifdef USE_LZO_PACKING lzo_uint packedSize = size; if ((flags & FLAGS_USE_LZO) == FLAGS_USE_LZO) { // grab a temporary buffer for unpacking into packedSize = size + size / 16 + 64 + 3; // see simple.c in lzo unsigned char *packed = new unsigned char[packedSize]; unsigned char *working = new unsigned char[LZO1X_999_MEM_COMPRESS]; if (packed && working) { if (lzo1x_999_compress(data, size, packed, &packedSize, working) != LZO_E_OK || packedSize > size) { // compression failed, or compressed size is bigger than uncompressed, so store as uncompressed packedSize = size; writer.AppendContent(data, size); } else { // success lzo_uint optimSize = size; if (lzo1x_optimize(packed, packedSize, data, &optimSize, NULL) != LZO_E_OK || optimSize != size) { //optimisation failed packedSize = size; writer.AppendContent(data, size); } else { // success writer.AppendContent(packed, packedSize); } } delete[] working; delete[] packed; } } else #else unsigned int packedSize = size; #endif { writer.AppendContent(data, size); } frame.SetPackedSize(packedSize); frame.SetUnpackedSize(size); frame.SetWidth(width); frame.SetHeight(height); frame.SetFormat(hasAlpha ? format : format | XB_FMT_OPAQUE); frame.SetDuration(0); return frame; }
CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, unsigned int flags) { CXBTFFrame frame; lzo_uint compressedSize = size; if ((flags & FLAGS_USE_LZO) == FLAGS_USE_LZO) { // grab a temporary buffer for unpacking into squish::u8 *compressed = new squish::u8[size + size / 16 + 64 + 3]; // see simple.c in lzo squish::u8 *working = new squish::u8[LZO1X_999_MEM_COMPRESS]; if (compressed && working) { if (lzo1x_999_compress(data, size, compressed, (lzo_uint*)&compressedSize, working) != LZO_E_OK || compressedSize > size) { // compression failed, or compressed size is bigger than uncompressed, so store as uncompressed compressedSize = size; writer.AppendContent(data, size); } else { // success lzo_uint optimSize = size; lzo1x_optimize(compressed, compressedSize, data, &optimSize, NULL); writer.AppendContent(compressed, compressedSize); } delete[] working; delete[] compressed; } } else { writer.AppendContent(data, size); } frame.SetPackedSize(compressedSize); frame.SetUnpackedSize(size); frame.SetWidth(width); frame.SetHeight(height); frame.SetFormat(format); frame.SetDuration(0); return frame; }