2011-08-10 11:13:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-10 11:13:39 +04:00
|
|
|
* RemoteFX Codec Library - Quantization
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
#include "rfx_quantization.h"
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static void rfx_quantization_decode_block(INT16* buffer, int buffer_size, UINT32 factor)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
INT16* dst;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2011-09-03 22:34:49 +04:00
|
|
|
if (factor == 0)
|
2011-08-10 11:13:39 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (dst = buffer; buffer_size > 0; dst++, buffer_size--)
|
|
|
|
{
|
|
|
|
*dst <<= factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void rfx_quantization_decode(INT16* buffer, const UINT32* quantization_values)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2011-09-03 22:34:49 +04:00
|
|
|
/* Scale the values so that they are represented as 11.5 fixed-point number */
|
|
|
|
rfx_quantization_decode_block(buffer, 4096, 5);
|
|
|
|
|
|
|
|
rfx_quantization_decode_block(buffer, 1024, quantization_values[8] - 6); /* HL1 */
|
|
|
|
rfx_quantization_decode_block(buffer + 1024, 1024, quantization_values[7] - 6); /* LH1 */
|
|
|
|
rfx_quantization_decode_block(buffer + 2048, 1024, quantization_values[9] - 6); /* HH1 */
|
|
|
|
rfx_quantization_decode_block(buffer + 3072, 256, quantization_values[5] - 6); /* HL2 */
|
|
|
|
rfx_quantization_decode_block(buffer + 3328, 256, quantization_values[4] - 6); /* LH2 */
|
|
|
|
rfx_quantization_decode_block(buffer + 3584, 256, quantization_values[6] - 6); /* HH2 */
|
|
|
|
rfx_quantization_decode_block(buffer + 3840, 64, quantization_values[2] - 6); /* HL3 */
|
|
|
|
rfx_quantization_decode_block(buffer + 3904, 64, quantization_values[1] - 6); /* LH3 */
|
2011-10-24 02:40:58 +04:00
|
|
|
rfx_quantization_decode_block(buffer + 3968, 64, quantization_values[3] - 6); /* HH3 */
|
2011-09-03 22:34:49 +04:00
|
|
|
rfx_quantization_decode_block(buffer + 4032, 64, quantization_values[0] - 6); /* LL3 */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static void rfx_quantization_encode_block(INT16* buffer, int buffer_size, UINT32 factor)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
INT16* dst;
|
|
|
|
INT16 half;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2011-09-03 22:34:49 +04:00
|
|
|
if (factor == 0)
|
2011-08-10 11:13:39 +04:00
|
|
|
return;
|
|
|
|
|
2011-09-05 05:26:20 +04:00
|
|
|
half = (1 << (factor - 1));
|
2011-08-10 11:13:39 +04:00
|
|
|
for (dst = buffer; buffer_size > 0; dst++, buffer_size--)
|
|
|
|
{
|
2011-09-05 05:26:20 +04:00
|
|
|
*dst = (*dst + half) >> factor;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void rfx_quantization_encode(INT16* buffer, const UINT32* quantization_values)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2011-09-03 22:34:49 +04:00
|
|
|
rfx_quantization_encode_block(buffer, 1024, quantization_values[8] - 6); /* HL1 */
|
|
|
|
rfx_quantization_encode_block(buffer + 1024, 1024, quantization_values[7] - 6); /* LH1 */
|
|
|
|
rfx_quantization_encode_block(buffer + 2048, 1024, quantization_values[9] - 6); /* HH1 */
|
|
|
|
rfx_quantization_encode_block(buffer + 3072, 256, quantization_values[5] - 6); /* HL2 */
|
|
|
|
rfx_quantization_encode_block(buffer + 3328, 256, quantization_values[4] - 6); /* LH2 */
|
|
|
|
rfx_quantization_encode_block(buffer + 3584, 256, quantization_values[6] - 6); /* HH2 */
|
|
|
|
rfx_quantization_encode_block(buffer + 3840, 64, quantization_values[2] - 6); /* HL3 */
|
|
|
|
rfx_quantization_encode_block(buffer + 3904, 64, quantization_values[1] - 6); /* LH3 */
|
2011-10-29 20:24:30 +04:00
|
|
|
rfx_quantization_encode_block(buffer + 3968, 64, quantization_values[3] - 6); /* HH3 */
|
2011-09-03 22:34:49 +04:00
|
|
|
rfx_quantization_encode_block(buffer + 4032, 64, quantization_values[0] - 6); /* LL3 */
|
|
|
|
|
|
|
|
/* The coefficients are scaled by << 5 at RGB->YCbCr phase, so we round it back here */
|
|
|
|
rfx_quantization_encode_block(buffer, 4096, 5);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|