18e9a21e730449c10cac6e6f69d255611c93f63c2hding/* 2430ce5c32361119ed81a62c918be6afbdd053eddhding * Copyright (c) 2011 Intel Corporation. All Rights Reserved. 3430ce5c32361119ed81a62c918be6afbdd053eddhding * Copyright (c) Imagination Technologies Limited, UK 48e9a21e730449c10cac6e6f69d255611c93f63c2hding * 5430ce5c32361119ed81a62c918be6afbdd053eddhding * Permission is hereby granted, free of charge, to any person obtaining a 6430ce5c32361119ed81a62c918be6afbdd053eddhding * copy of this software and associated documentation files (the 7430ce5c32361119ed81a62c918be6afbdd053eddhding * "Software"), to deal in the Software without restriction, including 8430ce5c32361119ed81a62c918be6afbdd053eddhding * without limitation the rights to use, copy, modify, merge, publish, 9430ce5c32361119ed81a62c918be6afbdd053eddhding * distribute, sub license, and/or sell copies of the Software, and to 10430ce5c32361119ed81a62c918be6afbdd053eddhding * permit persons to whom the Software is furnished to do so, subject to 11430ce5c32361119ed81a62c918be6afbdd053eddhding * the following conditions: 12430ce5c32361119ed81a62c918be6afbdd053eddhding * 13430ce5c32361119ed81a62c918be6afbdd053eddhding * The above copyright notice and this permission notice (including the 14430ce5c32361119ed81a62c918be6afbdd053eddhding * next paragraph) shall be included in all copies or substantial portions 15430ce5c32361119ed81a62c918be6afbdd053eddhding * of the Software. 16430ce5c32361119ed81a62c918be6afbdd053eddhding * 17430ce5c32361119ed81a62c918be6afbdd053eddhding * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18430ce5c32361119ed81a62c918be6afbdd053eddhding * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19430ce5c32361119ed81a62c918be6afbdd053eddhding * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20430ce5c32361119ed81a62c918be6afbdd053eddhding * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21430ce5c32361119ed81a62c918be6afbdd053eddhding * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22430ce5c32361119ed81a62c918be6afbdd053eddhding * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23430ce5c32361119ed81a62c918be6afbdd053eddhding * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 248e9a21e730449c10cac6e6f69d255611c93f63c2hding * 258e9a21e730449c10cac6e6f69d255611c93f63c2hding * Authors: 268e9a21e730449c10cac6e6f69d255611c93f63c2hding * Elaine Wang <elaine.wang@intel.com> 278e9a21e730449c10cac6e6f69d255611c93f63c2hding * 288e9a21e730449c10cac6e6f69d255611c93f63c2hding */ 298e9a21e730449c10cac6e6f69d255611c93f63c2hding 308e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <stdlib.h> 318e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <stdint.h> 328e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <string.h> 338e9a21e730449c10cac6e6f69d255611c93f63c2hding 348e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_def.h" 358e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_drv_debug.h" 368e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_surface.h" 378e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_cmdbuf.h" 38430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_hostcode.h" 39430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_hostheader.h" 40430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_jpegES.h" 418e9a21e730449c10cac6e6f69d255611c93f63c2hding#ifdef _TOPAZHP_PDUMP_ 42430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_trace.h" 438e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif 448e9a21e730449c10cac6e6f69d255611c93f63c2hding 45430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic void tng__trace_cmdbuf(tng_cmdbuf_p cmdbuf) 468e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 478e9a21e730449c10cac6e6f69d255611c93f63c2hding int i; 488e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 ui32CmdTmp[4]; 498e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 *ptmp = (IMG_UINT32 *)(cmdbuf->cmd_start); 508e9a21e730449c10cac6e6f69d255611c93f63c2hding 518e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: start\n", __FUNCTION__); 528e9a21e730449c10cac6e6f69d255611c93f63c2hding 538e9a21e730449c10cac6e6f69d255611c93f63c2hding //skip the newcodec 548e9a21e730449c10cac6e6f69d255611c93f63c2hding if (*ptmp != MTX_CMDID_SW_NEW_CODEC) { 558e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: error new coded\n", __FUNCTION__); 568e9a21e730449c10cac6e6f69d255611c93f63c2hding return ; 578e9a21e730449c10cac6e6f69d255611c93f63c2hding } 58e26d82700f9514cc175d2b54733ebdeb8824922ehding ptmp += 6; 598e9a21e730449c10cac6e6f69d255611c93f63c2hding 608e9a21e730449c10cac6e6f69d255611c93f63c2hding if ((*ptmp & 0xf) != MTX_CMDID_SETUP_INTERFACE) { 618e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: error setup interface\n", __FUNCTION__); 628e9a21e730449c10cac6e6f69d255611c93f63c2hding return ; 638e9a21e730449c10cac6e6f69d255611c93f63c2hding } 648e9a21e730449c10cac6e6f69d255611c93f63c2hding 658e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[0] = *ptmp++; 668e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[1] = *ptmp++; 678e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[2] = *ptmp++; 688e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[3] = 0; 698e9a21e730449c10cac6e6f69d255611c93f63c2hding#ifdef _TOPAZHP_PDUMP_ 708e9a21e730449c10cac6e6f69d255611c93f63c2hding topazhp_dump_command((unsigned int*)ui32CmdTmp); 718e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif 728e9a21e730449c10cac6e6f69d255611c93f63c2hding for (i = 0; i < 3; i++) { 738e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[0] = *ptmp++; 748e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[1] = *ptmp++; 758e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[2] = 0; 768e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32CmdTmp[3] = 0; 778e9a21e730449c10cac6e6f69d255611c93f63c2hding#ifdef _TOPAZHP_PDUMP_ 788e9a21e730449c10cac6e6f69d255611c93f63c2hding topazhp_dump_command((unsigned int*)ui32CmdTmp); 798e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif 808e9a21e730449c10cac6e6f69d255611c93f63c2hding } 818e9a21e730449c10cac6e6f69d255611c93f63c2hding 828e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: end\n", __FUNCTION__); 838e9a21e730449c10cac6e6f69d255611c93f63c2hding 84578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing return; 858e9a21e730449c10cac6e6f69d255611c93f63c2hding} 868e9a21e730449c10cac6e6f69d255611c93f63c2hding 878e9a21e730449c10cac6e6f69d255611c93f63c2hding#define SURFACE(id) ((object_surface_p) object_heap_lookup( &ctx->obj_context->driver_data->surface_heap, id )) 888e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BUFFER(id) ((object_buffer_p) object_heap_lookup( &ctx->obj_context->driver_data->buffer_heap, id )) 898e9a21e730449c10cac6e6f69d255611c93f63c2hding 908153ccc65f30ec7cecee4c6a4f0e72f7c402edbdSUN,Jing#define PTG_JPEG_MAX_MCU_PER_SCAN (0x4000) 918e9a21e730449c10cac6e6f69d255611c93f63c2hding#define PTG_JPEG_HEADER_MAX_SIZE (1024) 928e9a21e730449c10cac6e6f69d255611c93f63c2hding 938e9a21e730449c10cac6e6f69d255611c93f63c2hding 948e9a21e730449c10cac6e6f69d255611c93f63c2hding#define C_INTERLEAVE 1 958e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LC_YUYVINTERLEAVE 2 968e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LC_YVYUINTERLEAVE 3 978e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LC_UYVYINTERLEAVE 4 988e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LC_VYUYINTERLEAVE 5 998e9a21e730449c10cac6e6f69d255611c93f63c2hding 1008e9a21e730449c10cac6e6f69d255611c93f63c2hding#define ISCHROMAINTERLEAVED(eSurfaceFormat) ((IMG_UINT)(eSurfaceFormat==IMG_CODEC_PL12) * C_INTERLEAVE) 1018e9a21e730449c10cac6e6f69d255611c93f63c2hding 1028e9a21e730449c10cac6e6f69d255611c93f63c2hding 1038e9a21e730449c10cac6e6f69d255611c93f63c2hding/****************************************************************************** 1048e9a21e730449c10cac6e6f69d255611c93f63c2hdingGeneral definitions 1058e9a21e730449c10cac6e6f69d255611c93f63c2hding******************************************************************************/ 1068e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BYTE 8 1078e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BYTES_IN_INT 4 1088e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BITS_IN_INT 32 1098e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BLOCK_SIZE 8 1108e9a21e730449c10cac6e6f69d255611c93f63c2hding#define PELS_IN_BLOCK 64 1118e9a21e730449c10cac6e6f69d255611c93f63c2hding 1128e9a21e730449c10cac6e6f69d255611c93f63c2hding/****************************************************************************** 1138e9a21e730449c10cac6e6f69d255611c93f63c2hdingJPEG marker definitions 1148e9a21e730449c10cac6e6f69d255611c93f63c2hding******************************************************************************/ 1158e9a21e730449c10cac6e6f69d255611c93f63c2hding#define START_OF_IMAGE 0xFFD8 1168e9a21e730449c10cac6e6f69d255611c93f63c2hding#define SOF_BASELINE_DCT 0xFFC0 1178e9a21e730449c10cac6e6f69d255611c93f63c2hding#define END_OF_IMAGE 0xFFD9 1188e9a21e730449c10cac6e6f69d255611c93f63c2hding#define START_OF_SCAN 0xFFDA 1198e9a21e730449c10cac6e6f69d255611c93f63c2hding 1208e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Definitions for the huffman table specification in the Marker segment */ 1218e9a21e730449c10cac6e6f69d255611c93f63c2hding#define DHT_MARKER 0xFFC4 1228e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LH_DC 0x001F 1238e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LH_AC 0x00B5 1248e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LEVEL_SHIFT 128 1258e9a21e730449c10cac6e6f69d255611c93f63c2hding 1268e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Definitions for the quantization table specification in the Marker segment */ 1278e9a21e730449c10cac6e6f69d255611c93f63c2hding#define DQT_MARKER 0xFFDB 1288e9a21e730449c10cac6e6f69d255611c93f63c2hding#define ACMAX 0x03FF 1298e9a21e730449c10cac6e6f69d255611c93f63c2hding#define DCMAX 0x07FF 1308e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Length and precision of the quantization table parameters */ 1318e9a21e730449c10cac6e6f69d255611c93f63c2hding#define LQPQ 0x00430 1328e9a21e730449c10cac6e6f69d255611c93f63c2hding#define QMAX 255 1338e9a21e730449c10cac6e6f69d255611c93f63c2hding#define CLIP(Number,Max,Min) if((Number) > (Max)) (Number) = (Max); \ 1348e9a21e730449c10cac6e6f69d255611c93f63c2hding else if((Number) < (Min)) (Number) = (Min) 1358e9a21e730449c10cac6e6f69d255611c93f63c2hding 1368e9a21e730449c10cac6e6f69d255611c93f63c2hding///////////////////////////////////////////////////////////////////////////////////// 1378e9a21e730449c10cac6e6f69d255611c93f63c2hding// BMP Reading Header Stuff 1388e9a21e730449c10cac6e6f69d255611c93f63c2hding///////////////////////////////////////////////////////////////////////////////////// 1398e9a21e730449c10cac6e6f69d255611c93f63c2hding 1408e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gQuantLuma[QUANT_TABLE_SIZE_BYTES] = { 1418e9a21e730449c10cac6e6f69d255611c93f63c2hding 16, 11, 10, 16, 24, 40, 51, 61, 1428e9a21e730449c10cac6e6f69d255611c93f63c2hding 12, 12, 14, 19, 26, 58, 60, 55, 1438e9a21e730449c10cac6e6f69d255611c93f63c2hding 14, 13, 16, 24, 40, 57, 69, 56, 1448e9a21e730449c10cac6e6f69d255611c93f63c2hding 14, 17, 22, 29, 51, 87, 80, 62, 1458e9a21e730449c10cac6e6f69d255611c93f63c2hding 18, 22, 37, 56, 68, 109, 103, 77, 1468e9a21e730449c10cac6e6f69d255611c93f63c2hding 24, 35, 55, 64, 81, 104, 113, 92, 1478e9a21e730449c10cac6e6f69d255611c93f63c2hding 49, 64, 78, 87, 103, 121, 120, 101, 1488e9a21e730449c10cac6e6f69d255611c93f63c2hding 72, 92, 95, 98, 112, 100, 103, 99 1498e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 1508e9a21e730449c10cac6e6f69d255611c93f63c2hding 1518e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1528e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gQuantChroma */ 1538e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 1548e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Contains the data that needs to be sent in the marker segment of an */ 1558e9a21e730449c10cac6e6f69d255611c93f63c2hding/* interchange format JPEG stream or an abbreviated format table */ 1568e9a21e730449c10cac6e6f69d255611c93f63c2hding/* specification data stream. */ 1578e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Quantizer table for the chrominance component */ 1588e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1598e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gQuantChroma[QUANT_TABLE_SIZE_BYTES] = { 1608e9a21e730449c10cac6e6f69d255611c93f63c2hding 17, 18, 24, 47, 99, 99, 99, 99, 1618e9a21e730449c10cac6e6f69d255611c93f63c2hding 18, 21, 26, 66, 99, 99, 99, 99, 1628e9a21e730449c10cac6e6f69d255611c93f63c2hding 24, 26, 56, 99, 99, 99, 99, 99, 1638e9a21e730449c10cac6e6f69d255611c93f63c2hding 47, 66, 99, 99, 99, 99, 99, 99, 1648e9a21e730449c10cac6e6f69d255611c93f63c2hding 99, 99, 99, 99, 99, 99, 99, 99, 1658e9a21e730449c10cac6e6f69d255611c93f63c2hding 99, 99, 99, 99, 99, 99, 99, 99, 1668e9a21e730449c10cac6e6f69d255611c93f63c2hding 99, 99, 99, 99, 99, 99, 99, 99, 1678e9a21e730449c10cac6e6f69d255611c93f63c2hding 99, 99, 99, 99, 99, 99, 99, 99 1688e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 1698e9a21e730449c10cac6e6f69d255611c93f63c2hding 1708e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1718e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gZigZag */ 1728e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 1738e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Zigzag scan pattern */ 1748e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1758e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gZigZag[] = { 1768e9a21e730449c10cac6e6f69d255611c93f63c2hding 0, 1, 8, 16, 9, 2, 3, 10, 1778e9a21e730449c10cac6e6f69d255611c93f63c2hding 17, 24, 32, 25, 18, 11, 4, 5, 1788e9a21e730449c10cac6e6f69d255611c93f63c2hding 12, 19, 26, 33, 40, 48, 41, 34, 1798e9a21e730449c10cac6e6f69d255611c93f63c2hding 27, 20, 13, 6, 7, 14, 21, 28, 1808e9a21e730449c10cac6e6f69d255611c93f63c2hding 35, 42, 49, 56, 57, 50, 43, 36, 1818e9a21e730449c10cac6e6f69d255611c93f63c2hding 29, 22, 15, 23, 30, 37, 44, 51, 1828e9a21e730449c10cac6e6f69d255611c93f63c2hding 58, 59, 52, 45, 38, 31, 39, 46, 1838e9a21e730449c10cac6e6f69d255611c93f63c2hding 53, 60, 61, 54, 47, 55, 62, 63 1848e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 1858e9a21e730449c10cac6e6f69d255611c93f63c2hding 1868e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1878e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gMarkerDataLumaDc */ 1888e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 1898e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Contains the data that needs to be sent in the marker segment of an */ 1908e9a21e730449c10cac6e6f69d255611c93f63c2hding/* interchange format JPEG stream or an abbreviated format table */ 1918e9a21e730449c10cac6e6f69d255611c93f63c2hding/* specification data stream. */ 1928e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Specifies the huffman table used for encoding the luminance DC */ 1938e9a21e730449c10cac6e6f69d255611c93f63c2hding/* coefficient differences. The table represents Table K.3 of */ 1948e9a21e730449c10cac6e6f69d255611c93f63c2hding/* IS0/IEC 10918-1:1994(E) */ 1958e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 1968e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gMarkerDataLumaDc[] = { 1978e9a21e730449c10cac6e6f69d255611c93f63c2hding //TcTh Li 1988e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 1998e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x00, 0x00, 0x00, 0x00, 2008e9a21e730449c10cac6e6f69d255611c93f63c2hding // Vi 2018e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B 2028e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 2038e9a21e730449c10cac6e6f69d255611c93f63c2hding 2048e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2058e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gMarkerDataLumaAc */ 2068e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 2078e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Contains the data that needs to be sent in the marker segment of an */ 2088e9a21e730449c10cac6e6f69d255611c93f63c2hding/* interchange format JPEG stream or an abbreviated format table */ 2098e9a21e730449c10cac6e6f69d255611c93f63c2hding/* specification data stream. */ 2108e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Specifies the huffman table used for encoding the luminance AC */ 2118e9a21e730449c10cac6e6f69d255611c93f63c2hding/* coefficients. The table represents Table K.5 of IS0/IEC 10918-1:1994(E) */ 2128e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2138e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gMarkerDataLumaAc[] = { 2148e9a21e730449c10cac6e6f69d255611c93f63c2hding // TcTh Li 2158e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 2168e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x04, 0x00, 0x00, 0x01, 0x7D, 2178e9a21e730449c10cac6e6f69d255611c93f63c2hding // Vi 2188e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 2198e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 2208e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 2218e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 2228e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 2238e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 2248e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 2258e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 2268e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 2278e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 2288e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 2298e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 2308e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 2318e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA 2328e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 2338e9a21e730449c10cac6e6f69d255611c93f63c2hding 2348e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2358e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gMarkerDataChromaDc */ 2368e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 2378e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Contains the data that needs to be sent in the marker segment of an */ 2388e9a21e730449c10cac6e6f69d255611c93f63c2hding/* interchange format JPEG stream or an abbreviated format table */ 2398e9a21e730449c10cac6e6f69d255611c93f63c2hding/* specification data stream. */ 2408e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Specifies the huffman table used for encoding the chrominance DC */ 2418e9a21e730449c10cac6e6f69d255611c93f63c2hding/* coefficient differences. The table represents Table K.4 of */ 2428e9a21e730449c10cac6e6f69d255611c93f63c2hding/* IS0/IEC 10918-1:1994(E) */ 2438e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2448e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gMarkerDataChromaDc[] = { 2458e9a21e730449c10cac6e6f69d255611c93f63c2hding // TcTh Li 2468e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 2478e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x00, 0x00, 0x00, 0x00, 2488e9a21e730449c10cac6e6f69d255611c93f63c2hding 2498e9a21e730449c10cac6e6f69d255611c93f63c2hding // Vi 2508e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B 2518e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 2528e9a21e730449c10cac6e6f69d255611c93f63c2hding 2538e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2548e9a21e730449c10cac6e6f69d255611c93f63c2hding/* \brief gMarkerDataChromaAc */ 2558e9a21e730449c10cac6e6f69d255611c93f63c2hding/* */ 2568e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Contains the data that needs to be sent in the marker segment of an */ 2578e9a21e730449c10cac6e6f69d255611c93f63c2hding/* interchange format JPEG stream or an abbreviated format table */ 2588e9a21e730449c10cac6e6f69d255611c93f63c2hding/* specification data stream. */ 2598e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Specifies the huffman table used for encoding the chrominance AC */ 2608e9a21e730449c10cac6e6f69d255611c93f63c2hding/* coefficients. The table represents Table K.6 of IS0/IEC 10918-1:1994(E) */ 2618e9a21e730449c10cac6e6f69d255611c93f63c2hding/*****************************************************************************/ 2628e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic const IMG_UINT8 gMarkerDataChromaAc[] = { 2638e9a21e730449c10cac6e6f69d255611c93f63c2hding // TcTh 2648e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 2658e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x04, 0x00, 0x01, 0x02, 0x77, 2668e9a21e730449c10cac6e6f69d255611c93f63c2hding 2678e9a21e730449c10cac6e6f69d255611c93f63c2hding // Vi 2688e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 2698e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 2708e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 2718e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 2728e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 2738e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 2748e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 2758e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 2768e9a21e730449c10cac6e6f69d255611c93f63c2hding 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 2778e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 2788e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 2798e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 2808e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 2818e9a21e730449c10cac6e6f69d255611c93f63c2hding 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA 2828e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 2838e9a21e730449c10cac6e6f69d255611c93f63c2hding 284578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jingstatic int CustomizeQuantizationTables(unsigned char *luma_matrix, 285578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing unsigned char *chroma_matrix, 286578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing unsigned int ui32Quality) 287578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing{ 288578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing unsigned int uc_qVal; 289578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing unsigned int uc_j; 290578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 291578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing if((NULL == luma_matrix) || (NULL == chroma_matrix) || 292578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ui32Quality < 1) || (ui32Quality > 100)) 293578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing return 1; 294578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 295578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Compute luma quantization table */ 296578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing ui32Quality = (ui32Quality<50) ? (5000/ui32Quality) : (200-ui32Quality*2); 297578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing for(uc_j=0; uc_j<QUANT_TABLE_SIZE_BYTES; ++uc_j) { 298578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (gQuantLuma[uc_j] * ui32Quality + 50) / 100; 299578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (uc_qVal>0xFF)? 0xFF:uc_qVal; 300578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (uc_qVal<1)? 1:uc_qVal; 301578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing luma_matrix[uc_j] = (unsigned char)uc_qVal; 302578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing } 303578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 304578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Compute chroma quantization table */ 305578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing for(uc_j=0; uc_j<QUANT_TABLE_SIZE_BYTES; ++uc_j) { 306578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (gQuantChroma[uc_j] * ui32Quality + 50) / 100; 307578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (uc_qVal>0xFF)? 0xFF:uc_qVal; 308578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing uc_qVal = (uc_qVal<1)? 1:uc_qVal; 309578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing chroma_matrix[uc_j] = (unsigned char)uc_qVal; 310578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing } 311578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 312578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing return 0; 313578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing} 3148e9a21e730449c10cac6e6f69d255611c93f63c2hding 3158e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void SetDefaultQmatix(void *pMemInfoTableBlock) 3168e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 3178e9a21e730449c10cac6e6f69d255611c93f63c2hding JPEG_MTX_QUANT_TABLE *pQTable = pMemInfoTableBlock; 3188e9a21e730449c10cac6e6f69d255611c93f63c2hding memcpy(pQTable->aui8LumaQuantParams, gQuantLuma, QUANT_TABLE_SIZE_BYTES); 3198e9a21e730449c10cac6e6f69d255611c93f63c2hding memcpy(pQTable->aui8ChromaQuantParams, gQuantChroma, QUANT_TABLE_SIZE_BYTES); 3208e9a21e730449c10cac6e6f69d255611c93f63c2hding return; 3218e9a21e730449c10cac6e6f69d255611c93f63c2hding} 3228e9a21e730449c10cac6e6f69d255611c93f63c2hding 3238e9a21e730449c10cac6e6f69d255611c93f63c2hding 3248e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void IssueQmatix(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 3258e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 3268e9a21e730449c10cac6e6f69d255611c93f63c2hding int i; 3278e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 3288e9a21e730449c10cac6e6f69d255611c93f63c2hding 3298e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Dump MTX setup data for debug */ 3308e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(NULL != pJPEGContext->pMemInfoTableBlock); 3318e9a21e730449c10cac6e6f69d255611c93f63c2hding 3328e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Issue Quantization Table data\n"); 333c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing for (i=0; i<128; i+=8) { 334c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing if (0 == i) { 335c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing drv_debug_msg(VIDEO_DEBUG_GENERAL, "Table 0:\n"); 336c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing } 337c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing else if (64 == i) { 338c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing drv_debug_msg(VIDEO_DEBUG_GENERAL, "Table 1:\n"); 339c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing } 340c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing drv_debug_msg(VIDEO_DEBUG_GENERAL, "%d %d %d %d %d %d %d %d\n", 341c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i), 342c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+1), 343c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+2), 344c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+3), 345c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+4), 346c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+5), 347c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+6), 348c79caccb602f74ef23c5b82d194bf005a7009551SUN,Jing *((unsigned char *)ctx->obj_context->tng_cmdbuf->jpeg_pic_params_p+i+7)); 3498e9a21e730449c10cac6e6f69d255611c93f63c2hding } 3508e9a21e730449c10cac6e6f69d255611c93f63c2hding 351381e313cd06b652a08bef36b3e9d44ae096e72b2pingshix tng_cmdbuf_insert_command(ctx->obj_context, 3528e9a21e730449c10cac6e6f69d255611c93f63c2hding 0, 3538e9a21e730449c10cac6e6f69d255611c93f63c2hding MTX_CMDID_SETQUANT, 35488d0460822f8807666406c14662591167eed73a0hding 0, 355430ce5c32361119ed81a62c918be6afbdd053eddhding &(ctx->obj_context->tng_cmdbuf->jpeg_pic_params), 3568e9a21e730449c10cac6e6f69d255611c93f63c2hding 0); 3578e9a21e730449c10cac6e6f69d255611c93f63c2hding} 3588e9a21e730449c10cac6e6f69d255611c93f63c2hding 3598e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void InitializeJpegEncode(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 3608e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 3618e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 3628e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT16 ui16_width; 3638e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT16 ui16_height; 3648e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 ui32UpperLimit; 3658e9a21e730449c10cac6e6f69d255611c93f63c2hding 3668e9a21e730449c10cac6e6f69d255611c93f63c2hding /*********************************************************************/ 3678e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Determine the horizonal and the vertical sampling frequency of */ 3688e9a21e730449c10cac6e6f69d255611c93f63c2hding /* each of components in the image */ 3698e9a21e730449c10cac6e6f69d255611c93f63c2hding /*********************************************************************/ 3708e9a21e730449c10cac6e6f69d255611c93f63c2hding 3718e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16_width = ctx->ui16Width; 3728e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16_height = ctx->ui16FrameHeight; //pTFrame->height isn't the real height of image, because vaCreateSurface has made it aligned with 32 3738e9a21e730449c10cac6e6f69d255611c93f63c2hding 3748e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (pJPEGContext->eFormat) { 3758e9a21e730449c10cac6e6f69d255611c93f63c2hding case IMG_CODEC_PL12: 3768e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 3778e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32WidthBlocks = 16; 3788e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32HeightBlocks = 16; 3798e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32XLimit = ui16_width; 3808e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32YLimit = ui16_height; 3818e9a21e730449c10cac6e6f69d255611c93f63c2hding 3828e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32WidthBlocks = 8; 3838e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32HeightBlocks = 8; 3848e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32XLimit = ui16_width >> 1; 3858e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32YLimit = ui16_height >> 1; 3868e9a21e730449c10cac6e6f69d255611c93f63c2hding 3878e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32WidthBlocks = 8; 3888e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32HeightBlocks = 8; 3898e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32XLimit = ui16_width >> 1; 3908e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32YLimit = ui16_height >> 1; 3918e9a21e730449c10cac6e6f69d255611c93f63c2hding 3928e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 3938e9a21e730449c10cac6e6f69d255611c93f63c2hding } 3948e9a21e730449c10cac6e6f69d255611c93f63c2hding 3958e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (ISCHROMAINTERLEAVED(pJPEGContext->eFormat)) { 3968e9a21e730449c10cac6e6f69d255611c93f63c2hding case C_INTERLEAVE: 3978e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 3988e9a21e730449c10cac6e6f69d255611c93f63c2hding // Chroma format is byte interleaved, as the engine runs using planar colour surfaces we need 3998e9a21e730449c10cac6e6f69d255611c93f63c2hding // to fool the engine into offsetting by 16 instead of 8 4008e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32WidthBlocks += 4018e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32WidthBlocks; 4028e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[1].ui32XLimit += 4038e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32XLimit; 4048e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32XLimit = 4058e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32YLimit = 4068e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32WidthBlocks = 4078e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[2].ui32HeightBlocks = 0; 4088e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 4098e9a21e730449c10cac6e6f69d255611c93f63c2hding } 4108e9a21e730449c10cac6e6f69d255611c93f63c2hding 4118e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX = 4128e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->MCUComponent[0].ui32XLimit + 4138e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->MCUComponent[0].ui32WidthBlocks - 1)) / 4148e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32WidthBlocks; 4158e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsY = 4168e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->MCUComponent[0].ui32YLimit + 4178e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->MCUComponent[0].ui32HeightBlocks - 1)) / 4188e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->MCUComponent[0].ui32HeightBlocks; 4198e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncode = 4208e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX * 4218e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsY; 4228e9a21e730449c10cac6e6f69d255611c93f63c2hding 4238e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of X MCUs: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX); 4248e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of Y MCUs: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsY); 4258e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of total MCUs: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncode); 4268e9a21e730449c10cac6e6f69d255611c93f63c2hding 4278e9a21e730449c10cac6e6f69d255611c93f63c2hding 4288e9a21e730449c10cac6e6f69d255611c93f63c2hding // Number of MCUs sent for a scan _must_ lie at the beginning of a line so that the chroma component can't violate the 16 byte DMA start alignment constraint 4298e9a21e730449c10cac6e6f69d255611c93f63c2hding // (Actual memory alignment for final DMA will have width aligned to 64, so start of line will automatically meet the 16 byte alignment required by the DMA engine) 4308e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan = 4318e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->sScan_Encode_Info.ui32NumberMCUsY + (pJPEGContext->NumCores - 1)) / pJPEGContext->NumCores; 4328e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan *= 4338e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX; 4348e9a21e730449c10cac6e6f69d255611c93f63c2hding 4358e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of MCUs per core: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan); 4368e9a21e730449c10cac6e6f69d255611c93f63c2hding 4378e9a21e730449c10cac6e6f69d255611c93f63c2hding 4388e9a21e730449c10cac6e6f69d255611c93f63c2hding // Limit the scan size to maximum useable (due to it being used as the 16 bit field for Restart Intervals) = 0xFFFF MCUs 4398e9a21e730449c10cac6e6f69d255611c93f63c2hding // In reality, worst case allocatable bytes is less than this, something around 0x159739C == 0x4b96 MCUs = 139 x 139 MCUS = 2224 * 2224 pixels, approx. 4408e9a21e730449c10cac6e6f69d255611c93f63c2hding // We'll give this upper limit some margin for error, and limit our MCUsPerScan to 2000 * 2000 pixels = 125 * 125 MCUS = 0x3D09 MCUS = 0x116F322 bytes (1170 worst case per MCU) 4418e9a21e730449c10cac6e6f69d255611c93f63c2hding // If more MCUs are required, then the image will be automatically encoded with multiple scans on the same pipes 4428e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32UpperLimit = PTG_JPEG_MAX_MCU_PER_SCAN / pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX; 4438e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32UpperLimit *= pJPEGContext->sScan_Encode_Info.ui32NumberMCUsX; 4448e9a21e730449c10cac6e6f69d255611c93f63c2hding 4458e9a21e730449c10cac6e6f69d255611c93f63c2hding if (pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan > ui32UpperLimit) { 4468e9a21e730449c10cac6e6f69d255611c93f63c2hding // Set MCUs to encode per scan to equal maximum limit and then truncate to ensure it lies at the first MCU of a line (to satisfy the 64 byte requirement) 4478e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan = ui32UpperLimit; 4488e9a21e730449c10cac6e6f69d255611c93f63c2hding } 4498e9a21e730449c10cac6e6f69d255611c93f63c2hding 4508e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of MCUs per scan: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan); 4518e9a21e730449c10cac6e6f69d255611c93f63c2hding 4528e9a21e730449c10cac6e6f69d255611c93f63c2hding //Need to set up CB Output slicenumber to equal number of slices required to encode image 4538e9a21e730449c10cac6e6f69d255611c93f63c2hding // Set current CB scan to maximum scan number (will count down as scans are output) 4548e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui16ScansInImage = 4558e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncode + 4568e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan - 1)) / 4578e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan; 4588e9a21e730449c10cac6e6f69d255611c93f63c2hding 4598e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui8NumberOfCodedBuffers = 4608e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui16ScansInImage; 4618e9a21e730449c10cac6e6f69d255611c93f63c2hding 4628e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Scans in image: %d\n", pJPEGContext->sScan_Encode_Info.ui16ScansInImage); 4638e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of coded buffers: %d\n", pJPEGContext->sScan_Encode_Info.ui8NumberOfCodedBuffers); 4648e9a21e730449c10cac6e6f69d255611c93f63c2hding 4658e9a21e730449c10cac6e6f69d255611c93f63c2hding return; 4668e9a21e730449c10cac6e6f69d255611c93f63c2hding} 4678e9a21e730449c10cac6e6f69d255611c93f63c2hding 4688e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void AssignCodedDataBuffers(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 4698e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 4708e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 ui8Loop; 4718e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->ui32SizePerCodedBuffer = 4728e9a21e730449c10cac6e6f69d255611c93f63c2hding (pJPEGContext->jpeg_coded_buf.ui32Size - PTG_JPEG_HEADER_MAX_SIZE) / 4738e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui8NumberOfCodedBuffers; 474e26d82700f9514cc175d2b54733ebdeb8824922ehding pJPEGContext->ui32SizePerCodedBuffer &= ~0xf; 4758e9a21e730449c10cac6e6f69d255611c93f63c2hding 4768e9a21e730449c10cac6e6f69d255611c93f63c2hding memset((void *)pJPEGContext->sScan_Encode_Info.aBufferTable, 0x0, 4778e9a21e730449c10cac6e6f69d255611c93f63c2hding sizeof(TOPAZHP_JPEG_BUFFER_INFO)*pJPEGContext->sScan_Encode_Info.ui8NumberOfCodedBuffers); 4788e9a21e730449c10cac6e6f69d255611c93f63c2hding 4798e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "jpeg_coded_buf.pMemInfo: 0x%x\n", (unsigned int)(pJPEGContext->jpeg_coded_buf.pMemInfo)); 4808e9a21e730449c10cac6e6f69d255611c93f63c2hding 4818e9a21e730449c10cac6e6f69d255611c93f63c2hding for (ui8Loop = 0 ; ui8Loop < pJPEGContext->sScan_Encode_Info.ui8NumberOfCodedBuffers; ui8Loop++) { 4828e9a21e730449c10cac6e6f69d255611c93f63c2hding //pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].ui32DataBufferSizeBytes = DATA_BUFFER_SIZE(pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan); 4838e9a21e730449c10cac6e6f69d255611c93f63c2hding //pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].ui32DataBufferSizeBytes = (pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].ui32DataBufferSizeBytes+sizeof(BUFFER_HEADER)) + 3 & ~3; 4848e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].ui32DataBufferUsedBytes = 0; 4858e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].i8PipeNumber = 0; // Indicates buffer is idle 4868e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].ui16ScanNumber = 0; // Indicates buffer is idle 4878e9a21e730449c10cac6e6f69d255611c93f63c2hding 4888e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].pMemInfo = (void *) 489cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan ((IMG_UINT32)pJPEGContext->jpeg_coded_buf.pMemInfo + PTG_JPEG_HEADER_MAX_SIZE + 4908e9a21e730449c10cac6e6f69d255611c93f63c2hding ui8Loop * pJPEGContext->ui32SizePerCodedBuffer); 4918e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "aBufferTable[%d].pMemInfo: 0x%x\n", ui8Loop, 4928e9a21e730449c10cac6e6f69d255611c93f63c2hding (unsigned int)(pJPEGContext->sScan_Encode_Info.aBufferTable[ui8Loop].pMemInfo)); 4938e9a21e730449c10cac6e6f69d255611c93f63c2hding } 4948e9a21e730449c10cac6e6f69d255611c93f63c2hding 4958e9a21e730449c10cac6e6f69d255611c93f63c2hding return; 4968e9a21e730449c10cac6e6f69d255611c93f63c2hding} 4978e9a21e730449c10cac6e6f69d255611c93f63c2hding 4988e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void SetSetupInterface(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 4998e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 5008e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 5018e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]); 5028e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_mem_size *ps_mem_size = &(ctx->ctx_mem_size); 5038e9a21e730449c10cac6e6f69d255611c93f63c2hding 50488d0460822f8807666406c14662591167eed73a0hding tng_cmdbuf_set_phys(pJPEGContext->pMTXWritebackMemory->apWritebackRegions, WB_FIFO_SIZE, 5058e9a21e730449c10cac6e6f69d255611c93f63c2hding &(ctx->bufs_writeback), 0, ps_mem_size->writeback); 5068e9a21e730449c10cac6e6f69d255611c93f63c2hding} 5078e9a21e730449c10cac6e6f69d255611c93f63c2hding 5088e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void IssueSetupInterface(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 5098e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 51088d0460822f8807666406c14662591167eed73a0hding int i; 5118e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 5128e9a21e730449c10cac6e6f69d255611c93f63c2hding 5138e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(NULL != pJPEGContext->pMTXSetup); 5148e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Issue SetupInterface\n"); 5158e9a21e730449c10cac6e6f69d255611c93f63c2hding 51688d0460822f8807666406c14662591167eed73a0hding for (i = 0; i < WB_FIFO_SIZE; i++) { 51788d0460822f8807666406c14662591167eed73a0hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "apWritebackRegions[%d]: 0x%x\n", i, 51888d0460822f8807666406c14662591167eed73a0hding pJPEGContext->pMTXWritebackMemory->apWritebackRegions[i]); 51988d0460822f8807666406c14662591167eed73a0hding } 52088d0460822f8807666406c14662591167eed73a0hding 521381e313cd06b652a08bef36b3e9d44ae096e72b2pingshix tng_cmdbuf_insert_command(ctx->obj_context, 5228e9a21e730449c10cac6e6f69d255611c93f63c2hding 0, 5238e9a21e730449c10cac6e6f69d255611c93f63c2hding MTX_CMDID_SETUP_INTERFACE, 52488d0460822f8807666406c14662591167eed73a0hding 0, 525430ce5c32361119ed81a62c918be6afbdd053eddhding &(ctx->obj_context->tng_cmdbuf->jpeg_header_interface_mem), 5268e9a21e730449c10cac6e6f69d255611c93f63c2hding 0); 5278e9a21e730449c10cac6e6f69d255611c93f63c2hding} 5288e9a21e730449c10cac6e6f69d255611c93f63c2hding 5298e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_ERRORCODE SetMTXSetup( 5308e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 5318e9a21e730449c10cac6e6f69d255611c93f63c2hding object_surface_p pTFrame) 5328e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 5338e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 srf_buf_offset; 5348e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 535430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_p cmdbuf = ctx->obj_context->tng_cmdbuf; 5368e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]); 5378e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_mem_size *ps_mem_size = &(ctx->ctx_mem_size); 5388e9a21e730449c10cac6e6f69d255611c93f63c2hding 5398e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ui32ComponentsInScan = MTX_MAX_COMPONENTS; 5408e9a21e730449c10cac6e6f69d255611c93f63c2hding 5418e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (pJPEGContext->eFormat) { 5428e9a21e730449c10cac6e6f69d255611c93f63c2hding case IMG_CODEC_PL12: 543bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing if (pTFrame->psb_surface->stride % 64) { 544bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing drv_debug_msg(VIDEO_DEBUG_ERROR, "Surface stride isn't aligned to 64 bytes as HW requires: %u!\n", 545bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing pTFrame->psb_surface->stride); 546bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing return IMG_ERR_INVALID_CONTEXT; 547bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing } 5488e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[0].ui32Stride = pTFrame->psb_surface->stride; 5498e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[1].ui32Stride = pTFrame->psb_surface->stride; 5508e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[2].ui32Stride = pTFrame->psb_surface->stride; 5518e9a21e730449c10cac6e6f69d255611c93f63c2hding 552e26d82700f9514cc175d2b54733ebdeb8824922ehding pJPEGContext->pMTXSetup->ComponentPlane[0].ui32Height = pJPEGContext->MCUComponent[0].ui32YLimit; 553e26d82700f9514cc175d2b54733ebdeb8824922ehding pJPEGContext->pMTXSetup->ComponentPlane[1].ui32Height = pJPEGContext->MCUComponent[0].ui32YLimit / 2; 554e26d82700f9514cc175d2b54733ebdeb8824922ehding pJPEGContext->pMTXSetup->ComponentPlane[2].ui32Height = pJPEGContext->MCUComponent[0].ui32YLimit / 2; 5558e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 556bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing default: 557bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing drv_debug_msg(VIDEO_DEBUG_ERROR, "Not supported FOURCC: %x!\n", pJPEGContext->eFormat); 558bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing return IMG_ERR_INVALID_CONTEXT; 5598e9a21e730449c10cac6e6f69d255611c93f63c2hding } 5608e9a21e730449c10cac6e6f69d255611c93f63c2hding 5618e9a21e730449c10cac6e6f69d255611c93f63c2hding srf_buf_offset = pTFrame->psb_surface->buf.buffer_ofs; 562bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing RELOC_JPEG_PIC_PARAMS_PTG(&pJPEGContext->pMTXSetup->ComponentPlane[0].ui32PhysAddr, srf_buf_offset, 563bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing &pTFrame->psb_surface->buf); 5648e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (pJPEGContext->eFormat) { 5658e9a21e730449c10cac6e6f69d255611c93f63c2hding case IMG_CODEC_PL12: 5668e9a21e730449c10cac6e6f69d255611c93f63c2hding RELOC_JPEG_PIC_PARAMS_PTG(&pJPEGContext->pMTXSetup->ComponentPlane[1].ui32PhysAddr, 5678e9a21e730449c10cac6e6f69d255611c93f63c2hding srf_buf_offset + pTFrame->psb_surface->stride * pTFrame->height, 5688e9a21e730449c10cac6e6f69d255611c93f63c2hding &pTFrame->psb_surface->buf); 5698e9a21e730449c10cac6e6f69d255611c93f63c2hding //Byte interleaved surface, so need to force chroma to use single surface by fooling it into 5708e9a21e730449c10cac6e6f69d255611c93f63c2hding //thinking it's dealing with standard 8x8 planaerblocks 5718e9a21e730449c10cac6e6f69d255611c93f63c2hding RELOC_JPEG_PIC_PARAMS_PTG(&pJPEGContext->pMTXSetup->ComponentPlane[2].ui32PhysAddr, 5728e9a21e730449c10cac6e6f69d255611c93f63c2hding srf_buf_offset + pTFrame->psb_surface->stride * pTFrame->height + 8, 5738e9a21e730449c10cac6e6f69d255611c93f63c2hding &pTFrame->psb_surface->buf); 5748e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 5758e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 576bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing drv_debug_msg(VIDEO_DEBUG_ERROR, "Not supported FOURCC: %x!\n", pJPEGContext->eFormat); 5778e9a21e730449c10cac6e6f69d255611c93f63c2hding return IMG_ERR_INVALID_CONTEXT; 5788e9a21e730449c10cac6e6f69d255611c93f63c2hding } 5798e9a21e730449c10cac6e6f69d255611c93f63c2hding 5808e9a21e730449c10cac6e6f69d255611c93f63c2hding memcpy((void *)pJPEGContext->pMTXSetup->MCUComponent, 5818e9a21e730449c10cac6e6f69d255611c93f63c2hding (void *)pJPEGContext->MCUComponent, 5828e9a21e730449c10cac6e6f69d255611c93f63c2hding sizeof(pJPEGContext->MCUComponent)); 5838e9a21e730449c10cac6e6f69d255611c93f63c2hding 5848e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ui32TableA = 0; 5858e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ui16DataInterleaveStatus = ISCHROMAINTERLEAVED(pJPEGContext->eFormat); 58688d0460822f8807666406c14662591167eed73a0hding pJPEGContext->pMTXSetup->ui16MaxPipes = (IMG_UINT16)pJPEGContext->NumCores; 5878e9a21e730449c10cac6e6f69d255611c93f63c2hding 5888e9a21e730449c10cac6e6f69d255611c93f63c2hding return IMG_ERR_OK; 5898e9a21e730449c10cac6e6f69d255611c93f63c2hding} 5908e9a21e730449c10cac6e6f69d255611c93f63c2hding 5918e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void IssueMTXSetup(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 5928e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 593cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan uint32_t i; 5948e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)pJPEGContext->ctx; 5958e9a21e730449c10cac6e6f69d255611c93f63c2hding 5968e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Dump MTX setup data for debug */ 5978e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(NULL != pJPEGContext->pMTXSetup); 5988e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Issue MTX setup data\n"); 5998e9a21e730449c10cac6e6f69d255611c93f63c2hding 6008e9a21e730449c10cac6e6f69d255611c93f63c2hding for (i = 0; i < pJPEGContext->pMTXSetup->ui32ComponentsInScan; i++) { 6018e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ComponentPlane[%d]: 0x%x, %d, %d\n", i, 6028e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[i].ui32PhysAddr, 6038e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[i].ui32Stride, 6048e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->ComponentPlane[i].ui32Height); 6058e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "MCUComponent[%d]: %d, %d, %d, %d\n", i, 6068e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->MCUComponent[i].ui32WidthBlocks, 6078e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->MCUComponent[i].ui32HeightBlocks, 6088e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->MCUComponent[i].ui32XLimit, 6098e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->pMTXSetup->MCUComponent[i].ui32YLimit); 6108e9a21e730449c10cac6e6f69d255611c93f63c2hding } 6118e9a21e730449c10cac6e6f69d255611c93f63c2hding 6128e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32ComponentsInScan: %d\n", pJPEGContext->pMTXSetup->ui32ComponentsInScan); 6138e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32TableA: %d\n", pJPEGContext->pMTXSetup->ui32TableA); 6148e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui16DataInterleaveStatus: %d\n", pJPEGContext->pMTXSetup->ui16DataInterleaveStatus); 6158e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui16MaxPipes: %d\n", pJPEGContext->pMTXSetup->ui16MaxPipes); 6168e9a21e730449c10cac6e6f69d255611c93f63c2hding 617381e313cd06b652a08bef36b3e9d44ae096e72b2pingshix tng_cmdbuf_insert_command(ctx->obj_context, 6188e9a21e730449c10cac6e6f69d255611c93f63c2hding 0, 6198e9a21e730449c10cac6e6f69d255611c93f63c2hding MTX_CMDID_SETUP, 62088d0460822f8807666406c14662591167eed73a0hding 0, 621430ce5c32361119ed81a62c918be6afbdd053eddhding &(ctx->obj_context->tng_cmdbuf->jpeg_header_mem), 6228e9a21e730449c10cac6e6f69d255611c93f63c2hding 0); 6238e9a21e730449c10cac6e6f69d255611c93f63c2hding 6248e9a21e730449c10cac6e6f69d255611c93f63c2hding return; 6258e9a21e730449c10cac6e6f69d255611c93f63c2hding} 6268e9a21e730449c10cac6e6f69d255611c93f63c2hding 6278e9a21e730449c10cac6e6f69d255611c93f63c2hding 6288e9a21e730449c10cac6e6f69d255611c93f63c2hding 6298e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void fPutBitsToBuffer(STREAMTYPEW *BitStream, IMG_UINT8 NoOfBytes, IMG_UINT32 ActualBits) 6308e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 6318e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 ui8Lp; 6328e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 *pui8S; 6338e9a21e730449c10cac6e6f69d255611c93f63c2hding 6348e9a21e730449c10cac6e6f69d255611c93f63c2hding pui8S = (IMG_UINT8 *)BitStream->Buffer; 6358e9a21e730449c10cac6e6f69d255611c93f63c2hding pui8S += BitStream->Offset; 6368e9a21e730449c10cac6e6f69d255611c93f63c2hding 6378e9a21e730449c10cac6e6f69d255611c93f63c2hding for (ui8Lp = NoOfBytes; ui8Lp > 0; ui8Lp--) 6388e9a21e730449c10cac6e6f69d255611c93f63c2hding *(pui8S++) = ((IMG_UINT8 *) &ActualBits)[ui8Lp-1]; 6398e9a21e730449c10cac6e6f69d255611c93f63c2hding 6408e9a21e730449c10cac6e6f69d255611c93f63c2hding BitStream->Offset += NoOfBytes; 6418e9a21e730449c10cac6e6f69d255611c93f63c2hding} 6428e9a21e730449c10cac6e6f69d255611c93f63c2hding 6438e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_UINT32 EncodeMarkerSegment(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 6448e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 *puc_stream_buff, IMG_BOOL bIncludeHuffmanTables) 6458e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 6468e9a21e730449c10cac6e6f69d255611c93f63c2hding STREAMTYPEW s_streamW; 6478e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 uc_i; 6488e9a21e730449c10cac6e6f69d255611c93f63c2hding 6498e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Offset = 0; 6508e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Buffer = puc_stream_buff; 6518e9a21e730449c10cac6e6f69d255611c93f63c2hding 6528e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the start of image marker */ 6538e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, START_OF_IMAGE); 6548e9a21e730449c10cac6e6f69d255611c93f63c2hding 6558e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the quantization table for luminance into the stream */ 6568e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DQT_MARKER); 6578e9a21e730449c10cac6e6f69d255611c93f63c2hding 6588e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 3, LQPQ << 4); // 20 bits = LQPQ, 4 bits = 0 (Destination identifier for the luminance quantizer tables) 6598e9a21e730449c10cac6e6f69d255611c93f63c2hding 6608e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_ASSERT(PELS_IN_BLOCK <= QUANT_TABLE_SIZE_BYTES); 6618e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < PELS_IN_BLOCK; uc_i++) { 6628e9a21e730449c10cac6e6f69d255611c93f63c2hding // Write zigzag ordered luma quantization values to our JPEG header 6638e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, pJPEGContext->psTablesBlock->aui8LumaQuantParams[gZigZag[uc_i]]); 6648e9a21e730449c10cac6e6f69d255611c93f63c2hding } 6658e9a21e730449c10cac6e6f69d255611c93f63c2hding 6668e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the quantization table for chrominance into the stream */ 6678e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DQT_MARKER); 6688e9a21e730449c10cac6e6f69d255611c93f63c2hding 6698e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 3, (LQPQ << 4) | 1); // 20 bits = LQPQ, 4 bits = 1 (Destination identifier for the chrominance quantizer tables) 6708e9a21e730449c10cac6e6f69d255611c93f63c2hding 6718e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < PELS_IN_BLOCK; uc_i++) { 6728e9a21e730449c10cac6e6f69d255611c93f63c2hding // Write zigzag ordered chroma quantization values to our JPEG header 6738e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, pJPEGContext->psTablesBlock->aui8ChromaQuantParams[gZigZag[uc_i]]); 6748e9a21e730449c10cac6e6f69d255611c93f63c2hding } 6758e9a21e730449c10cac6e6f69d255611c93f63c2hding 6768e9a21e730449c10cac6e6f69d255611c93f63c2hding 6778e9a21e730449c10cac6e6f69d255611c93f63c2hding 6788e9a21e730449c10cac6e6f69d255611c93f63c2hding 6798e9a21e730449c10cac6e6f69d255611c93f63c2hding if (bIncludeHuffmanTables) { 6808e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the huffman tables for luminance dc coeffs */ 6818e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Write the DHT Marker */ 6828e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DHT_MARKER); 6838e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, LH_DC); 6848e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < LH_DC - 2; uc_i++) { 6858e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, gMarkerDataLumaDc[uc_i]); 6868e9a21e730449c10cac6e6f69d255611c93f63c2hding } 6878e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the huffman tables for luminance ac coeffs */ 6888e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Write the DHT Marker */ 6898e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DHT_MARKER); 6908e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, LH_AC); 6918e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < LH_AC - 2; uc_i++) { 6928e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, gMarkerDataLumaAc[uc_i]); 6938e9a21e730449c10cac6e6f69d255611c93f63c2hding } 6948e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the huffman tables for chrominance dc coeffs */ 6958e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DHT_MARKER); 6968e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, LH_DC); 6978e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < LH_DC - 2; uc_i++) { 6988e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, gMarkerDataChromaDc[uc_i]); 6998e9a21e730449c10cac6e6f69d255611c93f63c2hding } 7008e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the huffman tables for luminance ac coeffs */ 7018e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Write the DHT Marker */ 7028e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, DHT_MARKER); 7038e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, LH_AC); 7048e9a21e730449c10cac6e6f69d255611c93f63c2hding for (uc_i = 0; uc_i < LH_AC - 2; uc_i++) { 7058e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, gMarkerDataChromaAc[uc_i]); 7068e9a21e730449c10cac6e6f69d255611c93f63c2hding } 7078e9a21e730449c10cac6e6f69d255611c93f63c2hding } 7088e9a21e730449c10cac6e6f69d255611c93f63c2hding 7098e9a21e730449c10cac6e6f69d255611c93f63c2hding // Activate Restart markers 7108e9a21e730449c10cac6e6f69d255611c93f63c2hding if (pJPEGContext->sScan_Encode_Info.ui16CScan > 1) { 7118e9a21e730449c10cac6e6f69d255611c93f63c2hding // Only use restart intervals if we need them (ie. multiple Scan encode and/or parallel CB encode) 7128e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, 0xFFDD); //Marker header 7138e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, 4); // Byte size of marker (header not included) 7148e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan); // Restart Interval (same as MCUs per buffer) 7158e9a21e730449c10cac6e6f69d255611c93f63c2hding } 7168e9a21e730449c10cac6e6f69d255611c93f63c2hding 7178e9a21e730449c10cac6e6f69d255611c93f63c2hding return s_streamW.Offset; 7188e9a21e730449c10cac6e6f69d255611c93f63c2hding} 7198e9a21e730449c10cac6e6f69d255611c93f63c2hding 7208e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_UINT32 EncodeFrameHeader(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 7218e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 *puc_stream_buff) 7228e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 7238e9a21e730449c10cac6e6f69d255611c93f63c2hding STREAMTYPEW ps_streamW; 7248e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 uc_num_comp_in_img; 7258e9a21e730449c10cac6e6f69d255611c93f63c2hding 7268e9a21e730449c10cac6e6f69d255611c93f63c2hding uc_num_comp_in_img = pJPEGContext->pMTXSetup->ui32ComponentsInScan; 7278e9a21e730449c10cac6e6f69d255611c93f63c2hding 7288e9a21e730449c10cac6e6f69d255611c93f63c2hding ps_streamW.Offset = 0; 7298e9a21e730449c10cac6e6f69d255611c93f63c2hding ps_streamW.Buffer = puc_stream_buff; 7308e9a21e730449c10cac6e6f69d255611c93f63c2hding 7318e9a21e730449c10cac6e6f69d255611c93f63c2hding 7328e9a21e730449c10cac6e6f69d255611c93f63c2hding //if(ps_jpeg_params->uc_isAbbreviated != 0) 7338e9a21e730449c10cac6e6f69d255611c93f63c2hding // fPutBitsToBuffer(&ps_streamW, 2, START_OF_IMAGE); 7348e9a21e730449c10cac6e6f69d255611c93f63c2hding 7358e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Writing the frame header */ 7368e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 2, SOF_BASELINE_DCT); 7378e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Frame header length */ 7388e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 2, 8 + 3 * uc_num_comp_in_img); 7398e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Precision */ 7408e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 8); 7418e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Height : sample lines */ 7428e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 2, pJPEGContext->ui32OutputHeight); 7438e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Width : samples per line */ 7448e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 2, pJPEGContext->ui32OutputWidth); 7458e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Number of image components */ 7468e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, uc_num_comp_in_img); 7478e9a21e730449c10cac6e6f69d255611c93f63c2hding 7488e9a21e730449c10cac6e6f69d255611c93f63c2hding 7498e9a21e730449c10cac6e6f69d255611c93f63c2hding //Chroma Details 7508e9a21e730449c10cac6e6f69d255611c93f63c2hding if (pJPEGContext->pMTXSetup->ui16DataInterleaveStatus < C_INTERLEAVE) { 7518e9a21e730449c10cac6e6f69d255611c93f63c2hding //Luma Details 7528e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Component identifier */ 7538e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); //CompId 0 = 1, 1 = 2, 2 = 3 7548e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[0].ui32WidthBlocks >> 3) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[0].ui32HeightBlocks >> 3)); 7558e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 0); // 0 = Luma(0), 1,2 = Chroma(1) 7568e9a21e730449c10cac6e6f69d255611c93f63c2hding 7578e9a21e730449c10cac6e6f69d255611c93f63c2hding //Chroma planar 7588e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 2); //CompId 0 = 1, 1 = 2, 2 = 3 7598e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7608e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[1].ui32WidthBlocks >> 3) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[1].ui32HeightBlocks >> 3)); 7618e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7628e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 3); //CompId 0 = 1, 1 = 2, 2 = 3 7638e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7648e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[2].ui32WidthBlocks >> 3) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[2].ui32HeightBlocks >> 3)); 7658e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7668e9a21e730449c10cac6e6f69d255611c93f63c2hding } else if (pJPEGContext->pMTXSetup->ui16DataInterleaveStatus == C_INTERLEAVE) { 7678e9a21e730449c10cac6e6f69d255611c93f63c2hding //Luma Details 7688e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Component identifier */ 7698e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); //CompId 0 = 1, 1 = 2, 2 = 3 7708e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[0].ui32WidthBlocks >> 3) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[0].ui32HeightBlocks >> 3)); 7718e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 0); // 0 = Luma(0), 1,2 = Chroma(1) 7728e9a21e730449c10cac6e6f69d255611c93f63c2hding 7738e9a21e730449c10cac6e6f69d255611c93f63c2hding // Chroma Interleaved 7748e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 2); //CompId 0 = 1, 1 = 2, 2 = 3 7758e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7768e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[1].ui32WidthBlocks >> 4) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[1].ui32HeightBlocks >> 3)); 7778e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7788e9a21e730449c10cac6e6f69d255611c93f63c2hding 7798e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 3); //CompId 0 = 1, 1 = 2, 2 = 3 7808e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7818e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[1].ui32WidthBlocks >> 4) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[1].ui32HeightBlocks >> 3)); 7828e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7838e9a21e730449c10cac6e6f69d255611c93f63c2hding } else { 7848e9a21e730449c10cac6e6f69d255611c93f63c2hding //Luma Details 7858e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Component identifier */ 7868e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); //CompId 0 = 1, 1 = 2, 2 = 3 7878e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[0].ui32WidthBlocks >> 4) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[0].ui32HeightBlocks >> 3)); 7888e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 0); // 0 = Luma(0), 1,2 = Chroma(1) 7898e9a21e730449c10cac6e6f69d255611c93f63c2hding 7908e9a21e730449c10cac6e6f69d255611c93f63c2hding //Chroma YUYV - Special case 7918e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 2); //CompId 0 = 1, 1 = 2, 2 = 3 7928e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7938e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[0].ui32WidthBlocks >> 5) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[0].ui32HeightBlocks >> 3)); 7948e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7958e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 3); //CompId 0 = 1, 1 = 2, 2 = 3 7968e9a21e730449c10cac6e6f69d255611c93f63c2hding /* 4 bit Horizontal and 4 bit vertical sampling factors */ 7978e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, ((pJPEGContext->pMTXSetup->MCUComponent[0].ui32WidthBlocks >> 5) << 4) | (pJPEGContext->pMTXSetup->MCUComponent[0].ui32HeightBlocks >> 3)); 7988e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&ps_streamW, 1, 1); // 0 = Luma(0), 1,2 = Chroma(1) 7998e9a21e730449c10cac6e6f69d255611c93f63c2hding } 8008e9a21e730449c10cac6e6f69d255611c93f63c2hding 8018e9a21e730449c10cac6e6f69d255611c93f63c2hding 8028e9a21e730449c10cac6e6f69d255611c93f63c2hding //Use if you want start of scan (image data) to align to 32 803234896afa7fd6fda7e36cb3e60dc3012d207e915hding //fPutBitsToBuffer(&ps_streamW, 1, 0xFF); 8048e9a21e730449c10cac6e6f69d255611c93f63c2hding 8058e9a21e730449c10cac6e6f69d255611c93f63c2hding return ps_streamW.Offset; 8068e9a21e730449c10cac6e6f69d255611c93f63c2hding} 8078e9a21e730449c10cac6e6f69d255611c93f63c2hding 8088e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_UINT32 JPGEncodeMarker(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext , 8098e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8* pui8BitStreamBuffer , 8108e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 *pui32BytesWritten, IMG_BOOL bIncludeHuffmanTables) 8118e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 8128e9a21e730449c10cac6e6f69d255611c93f63c2hding#ifdef JPEG_VERBOSE 8138e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "PVRJPGEncodeMarker"); 8148e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif 8158e9a21e730449c10cac6e6f69d255611c93f63c2hding 8168e9a21e730449c10cac6e6f69d255611c93f63c2hding 8178e9a21e730449c10cac6e6f69d255611c93f63c2hding *pui32BytesWritten += EncodeMarkerSegment(pJPEGContext, pui8BitStreamBuffer + *pui32BytesWritten, bIncludeHuffmanTables); 8188e9a21e730449c10cac6e6f69d255611c93f63c2hding 8198e9a21e730449c10cac6e6f69d255611c93f63c2hding return 0; 8208e9a21e730449c10cac6e6f69d255611c93f63c2hding} 8218e9a21e730449c10cac6e6f69d255611c93f63c2hding 8228e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_UINT32 JPGEncodeHeader(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 8238e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8* pui8BitStreamBuffer , 8248e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32* pui32BytesWritten) 8258e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 8268e9a21e730449c10cac6e6f69d255611c93f63c2hding#ifdef JPEG_VERBOSE 8278e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "JPGEncodeHeader"); 8288e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif 8298e9a21e730449c10cac6e6f69d255611c93f63c2hding 8308e9a21e730449c10cac6e6f69d255611c93f63c2hding *pui32BytesWritten += EncodeFrameHeader(pJPEGContext, pui8BitStreamBuffer + *pui32BytesWritten); 8318e9a21e730449c10cac6e6f69d255611c93f63c2hding 8328e9a21e730449c10cac6e6f69d255611c93f63c2hding return 0; 8338e9a21e730449c10cac6e6f69d255611c93f63c2hding} 8348e9a21e730449c10cac6e6f69d255611c93f63c2hding 8358e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_UINT32 JPGEncodeSOSHeader(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 8368e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8* pui8BitStreamBuffer , 8378e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32* pui32BytesWritten) 8388e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 8398e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 uc_comp_id, ui8Comp; 8408e9a21e730449c10cac6e6f69d255611c93f63c2hding STREAMTYPEW s_streamW; 8418e9a21e730449c10cac6e6f69d255611c93f63c2hding 8428e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Offset = 0; 8438e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Buffer = pui8BitStreamBuffer + *pui32BytesWritten; 8448e9a21e730449c10cac6e6f69d255611c93f63c2hding 8458e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Start of scan */ 8468e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, START_OF_SCAN); 8478e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Scan header length */ 8488e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, 6 + (pJPEGContext->pMTXSetup->ui32ComponentsInScan << 1)); 8498e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Number of image components in scan */ 8508e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, pJPEGContext->pMTXSetup->ui32ComponentsInScan); 8518e9a21e730449c10cac6e6f69d255611c93f63c2hding for (ui8Comp = 0; ui8Comp < pJPEGContext->pMTXSetup->ui32ComponentsInScan; ui8Comp++) { 8528e9a21e730449c10cac6e6f69d255611c93f63c2hding uc_comp_id = ui8Comp + 1; 8538e9a21e730449c10cac6e6f69d255611c93f63c2hding 8548e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Scan component selector */ 8558e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, uc_comp_id); 8568e9a21e730449c10cac6e6f69d255611c93f63c2hding 8578e9a21e730449c10cac6e6f69d255611c93f63c2hding /*4 Bits Dc entropy coding table destination selector */ 8588e9a21e730449c10cac6e6f69d255611c93f63c2hding /*4 Bits Ac entropy coding table destination selector */ 8598e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, ((ui8Comp != 0 ? 1 : 0) << 4) | (ui8Comp != 0 ? 1 : 0)); // Huffman table refs = 0 Luma 1 Chroma 8608e9a21e730449c10cac6e6f69d255611c93f63c2hding } 8618e9a21e730449c10cac6e6f69d255611c93f63c2hding 8628e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Start of spectral or predictor selection */ 8638e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, 0); 8648e9a21e730449c10cac6e6f69d255611c93f63c2hding /* End of spectral selection */ 8658e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, 63); 8668e9a21e730449c10cac6e6f69d255611c93f63c2hding /*4 Bits Successive approximation bit position high (0)*/ 8678e9a21e730449c10cac6e6f69d255611c93f63c2hding /*4 Bits Successive approximation bit position low or point transform (0)*/ 8688e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 1, 0); 8698e9a21e730449c10cac6e6f69d255611c93f63c2hding 8708e9a21e730449c10cac6e6f69d255611c93f63c2hding *pui32BytesWritten += s_streamW.Offset; 8718e9a21e730449c10cac6e6f69d255611c93f63c2hding 8728e9a21e730449c10cac6e6f69d255611c93f63c2hding return 0; 8738e9a21e730449c10cac6e6f69d255611c93f63c2hding} 8748e9a21e730449c10cac6e6f69d255611c93f63c2hding 8758e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic void InitializeScanCounter(TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext) 8768e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 8778e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui16SScan = 8788e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui16CScan = 8798e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.ui16ScansInImage; 8808e9a21e730449c10cac6e6f69d255611c93f63c2hding} 8818e9a21e730449c10cac6e6f69d255611c93f63c2hding 8828e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_ERRORCODE PrepareHeader(TOPAZHP_JPEG_ENCODER_CONTEXT * pJPEGContext, IMG_CODED_BUFFER *pCBuffer, IMG_UINT32 ui32StartOffset, IMG_BOOL bIncludeHuffmanTables) 8838e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 8848e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_ERRORCODE rc; 8858e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT8 *ui8OutputBuffer; 8868e9a21e730449c10cac6e6f69d255611c93f63c2hding 8878e9a21e730449c10cac6e6f69d255611c93f63c2hding //Locate our JPEG Coded buffer 8888e9a21e730449c10cac6e6f69d255611c93f63c2hding ui8OutputBuffer = (IMG_UINT8 *)pCBuffer->pMemInfo; 8898e9a21e730449c10cac6e6f69d255611c93f63c2hding 8908e9a21e730449c10cac6e6f69d255611c93f63c2hding pCBuffer->ui32BytesWritten = ui32StartOffset; 8918e9a21e730449c10cac6e6f69d255611c93f63c2hding *((IMG_UINT32*)ui8OutputBuffer + pCBuffer->ui32BytesWritten) = 0; 8928e9a21e730449c10cac6e6f69d255611c93f63c2hding 8938e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Before writing headers, ui32BytesWritten: %d\n", pCBuffer->ui32BytesWritten); 8948e9a21e730449c10cac6e6f69d255611c93f63c2hding 8958e9a21e730449c10cac6e6f69d255611c93f63c2hding // JPGEncodeMarker - Currently misses out the APP0 header 8968e9a21e730449c10cac6e6f69d255611c93f63c2hding rc = JPGEncodeMarker(pJPEGContext, (IMG_UINT8 *) ui8OutputBuffer, &pCBuffer->ui32BytesWritten, bIncludeHuffmanTables); 8978e9a21e730449c10cac6e6f69d255611c93f63c2hding if (rc) return rc; 8988e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "After JPGEncodeMarker, ui32BytesWritten: %d\n", pCBuffer->ui32BytesWritten); 8998e9a21e730449c10cac6e6f69d255611c93f63c2hding 9008e9a21e730449c10cac6e6f69d255611c93f63c2hding rc = JPGEncodeHeader(pJPEGContext , (IMG_UINT8 *) ui8OutputBuffer , &pCBuffer->ui32BytesWritten); 9018e9a21e730449c10cac6e6f69d255611c93f63c2hding if (rc) return rc; 9028e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "After JPGEncodeHeader, ui32BytesWritten: %d\n", pCBuffer->ui32BytesWritten); 9038e9a21e730449c10cac6e6f69d255611c93f63c2hding 9048e9a21e730449c10cac6e6f69d255611c93f63c2hding rc = JPGEncodeSOSHeader(pJPEGContext, (IMG_UINT8 *) ui8OutputBuffer, &pCBuffer->ui32BytesWritten); 9058e9a21e730449c10cac6e6f69d255611c93f63c2hding if (rc) return rc; 9068e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "After JPGEncodeSOSHeader, ui32BytesWritten: %d\n", pCBuffer->ui32BytesWritten); 9078e9a21e730449c10cac6e6f69d255611c93f63c2hding 9088e9a21e730449c10cac6e6f69d255611c93f63c2hding return IMG_ERR_OK; 9098e9a21e730449c10cac6e6f69d255611c93f63c2hding} 9108e9a21e730449c10cac6e6f69d255611c93f63c2hding 9118e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic IMG_ERRORCODE IssueBufferToHW( 9128e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *pJPEGContext, 9138e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT16 ui16BCnt, 9148e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_INT8 i8PipeNumber, 9158e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 ui32NoMCUsToEncode) 9168e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 9178e9a21e730449c10cac6e6f69d255611c93f63c2hding MTX_ISSUE_BUFFERS *psBufferCmd; 9188e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p)(pJPEGContext->ctx); 9198e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_frame_buf *ps_buf = &(ctx->ctx_frame_buf); 9208e9a21e730449c10cac6e6f69d255611c93f63c2hding 9218e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].ui32DataBufferUsedBytes = ((BUFFER_HEADER*)(pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].pMemInfo))->ui32BytesUsed = -1; // Won't be necessary with SC Peek commands enabled 9228e9a21e730449c10cac6e6f69d255611c93f63c2hding 9238e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Submit Scan %d which contains %d MCU in Buffer %d to MTX %d\n", 9248e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].ui16ScanNumber, 9258e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32NoMCUsToEncode, ui16BCnt, i8PipeNumber); 9268e9a21e730449c10cac6e6f69d255611c93f63c2hding 9278e9a21e730449c10cac6e6f69d255611c93f63c2hding // Issue to MTX //////////////////////////// 9288e9a21e730449c10cac6e6f69d255611c93f63c2hding 9298e9a21e730449c10cac6e6f69d255611c93f63c2hding psBufferCmd = (MTX_ISSUE_BUFFERS *)(pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].pMemInfo); 9308e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(psBufferCmd); 9318e9a21e730449c10cac6e6f69d255611c93f63c2hding 9328e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui16ScansInImage: %d\n", pJPEGContext->sScan_Encode_Info.ui16ScansInImage); 9338e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui16ScanNumber: %d\n", pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].ui16ScanNumber); 9348e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32NumberMCUsToEncodePerScan: %d\n", pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan); 93588d0460822f8807666406c14662591167eed73a0hding 9368e9a21e730449c10cac6e6f69d255611c93f63c2hding psBufferCmd->ui32MCUCntAndResetFlag = (ui32NoMCUsToEncode << 1) | 0x1; 93788d0460822f8807666406c14662591167eed73a0hding 9388e9a21e730449c10cac6e6f69d255611c93f63c2hding psBufferCmd->ui32MCUPositionOfScanAndPipeNo = 93988d0460822f8807666406c14662591167eed73a0hding (((pJPEGContext->sScan_Encode_Info.ui16ScansInImage - 9408e9a21e730449c10cac6e6f69d255611c93f63c2hding pJPEGContext->sScan_Encode_Info.aBufferTable[ui16BCnt].ui16ScanNumber) * 94188d0460822f8807666406c14662591167eed73a0hding pJPEGContext->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan)<<2)&(~2); 9428e9a21e730449c10cac6e6f69d255611c93f63c2hding 9438e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(0 == i8PipeNumber); 94488d0460822f8807666406c14662591167eed73a0hding if (i8PipeNumber <= 3) 94588d0460822f8807666406c14662591167eed73a0hding psBufferCmd->ui32MCUPositionOfScanAndPipeNo |= i8PipeNumber; 9468e9a21e730449c10cac6e6f69d255611c93f63c2hding 9478e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32MCUPositionOfScanAndPipeNo: 0x%x\n", psBufferCmd->ui32MCUPositionOfScanAndPipeNo); 9488e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32MCUCntAndResetFlag: 0x%x\n", psBufferCmd->ui32MCUCntAndResetFlag); 9498e9a21e730449c10cac6e6f69d255611c93f63c2hding 9508e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "psBufferCmd: 0x%x\n", (unsigned int)(psBufferCmd)); 9518e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Command Data: 0x%x\n", (unsigned int)(PTG_JPEG_HEADER_MAX_SIZE + ui16BCnt * pJPEGContext->ui32SizePerCodedBuffer)); 9528e9a21e730449c10cac6e6f69d255611c93f63c2hding 9538e9a21e730449c10cac6e6f69d255611c93f63c2hding // Issue buffers 954381e313cd06b652a08bef36b3e9d44ae096e72b2pingshix tng_cmdbuf_insert_command(ctx->obj_context, 9558e9a21e730449c10cac6e6f69d255611c93f63c2hding 0, 9568e9a21e730449c10cac6e6f69d255611c93f63c2hding MTX_CMDID_ISSUEBUFF, 95788d0460822f8807666406c14662591167eed73a0hding 0, 9588e9a21e730449c10cac6e6f69d255611c93f63c2hding ps_buf->coded_buf->psb_buffer, 9598e9a21e730449c10cac6e6f69d255611c93f63c2hding PTG_JPEG_HEADER_MAX_SIZE + ui16BCnt * pJPEGContext->ui32SizePerCodedBuffer); 9608e9a21e730449c10cac6e6f69d255611c93f63c2hding 9618e9a21e730449c10cac6e6f69d255611c93f63c2hding return IMG_ERR_OK; 9628e9a21e730449c10cac6e6f69d255611c93f63c2hding} 9638e9a21e730449c10cac6e6f69d255611c93f63c2hding 964430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic void tng_jpeg_QueryConfigAttributes( 965cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan VAProfile __maybe_unused profile, 966cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan VAEntrypoint __maybe_unused entrypoint, 9678e9a21e730449c10cac6e6f69d255611c93f63c2hding VAConfigAttrib *attrib_list, 9688e9a21e730449c10cac6e6f69d255611c93f63c2hding int num_attribs) 9698e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 9708e9a21e730449c10cac6e6f69d255611c93f63c2hding int i; 9718e9a21e730449c10cac6e6f69d255611c93f63c2hding 972430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_QueryConfigAttributes\n"); 9738e9a21e730449c10cac6e6f69d255611c93f63c2hding 974578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Return supported attributes */ 9758e9a21e730449c10cac6e6f69d255611c93f63c2hding for (i = 0; i < num_attribs; i++) { 9768e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (attrib_list[i].type) { 9778e9a21e730449c10cac6e6f69d255611c93f63c2hding case VAConfigAttribRTFormat: 978578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Already handled in psb_GetConfigAttributes */ 979578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing break; 980578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing case VAConfigAttribEncJPEG: 981578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* The below JPEG ENC capabilities are fixed by TopazHP and not changable. */ 982578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing { 983578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing VAConfigAttribValEncJPEG* ptr = (VAConfigAttribValEncJPEG *)&(attrib_list[i].value); 984578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).arithmatic_coding_mode = 0; /* Unsupported */ 985578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).progressive_dct_mode = 0; /* Unsupported */ 986578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).non_interleaved_mode = 1; /* Supported */ 987578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).differential_mode = 0; /* Unsupported */ 988578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).max_num_components = MTX_MAX_COMPONENTS; /* Only 3 is supported */ 989578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).max_num_scans = PTG_JPEG_MAX_SCAN_NUM; 990578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).max_num_huffman_tables = 4; /* Only 4 is supported */ 991578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ptr->bits).max_num_huffman_tables = 2; /* Only 2 is supported */ 992578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing } 993578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing break; 994578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing case VAConfigAttribMaxPictureWidth: 995578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing case VAConfigAttribMaxPictureHeight: 996578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* No pure limitation on an image's width or height seperately, 997578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing as long as the image's MCUs need less than max_num_scans rounds of encoding 998578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing and a surface of that source size is allocatable. */ 999578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing attrib_list[i].value = 0; /* No pure limitation */ 10008e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 10018e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 10028e9a21e730449c10cac6e6f69d255611c93f63c2hding attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED; 10038e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 10048e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10058e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10068e9a21e730449c10cac6e6f69d255611c93f63c2hding 10078e9a21e730449c10cac6e6f69d255611c93f63c2hding return; 10088e9a21e730449c10cac6e6f69d255611c93f63c2hding} 10098e9a21e730449c10cac6e6f69d255611c93f63c2hding 10108e9a21e730449c10cac6e6f69d255611c93f63c2hding 1011430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_jpeg_ValidateConfig( 10128e9a21e730449c10cac6e6f69d255611c93f63c2hding object_config_p obj_config) 10138e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 1014430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_ValidateConfig\n"); 1015d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun int i; 1016d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun /* Check all attributes */ 1017d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun for (i = 0; i < obj_config->attrib_count; i++) { 1018d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun switch (obj_config->attrib_list[i].type) { 1019d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun case VAConfigAttribRTFormat: 1020d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun /* Ignore */ 1021d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun break; 1022d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun case VAConfigAttribRateControl: 1023d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun break; 1024d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun default: 1025d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED; 1026d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun } 1027d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun } 10288e9a21e730449c10cac6e6f69d255611c93f63c2hding 1029d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun return VA_STATUS_SUCCESS; 10308e9a21e730449c10cac6e6f69d255611c93f63c2hding} 10318e9a21e730449c10cac6e6f69d255611c93f63c2hding 1032430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_jpeg_CreateContext( 10338e9a21e730449c10cac6e6f69d255611c93f63c2hding object_context_p obj_context, 10348e9a21e730449c10cac6e6f69d255611c93f63c2hding object_config_p obj_config) 10358e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 10368e9a21e730449c10cac6e6f69d255611c93f63c2hding int i; 10378e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 10388e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx; 10398e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx_p; 10408e9a21e730449c10cac6e6f69d255611c93f63c2hding 1041430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_CreateContext\n"); 10428e9a21e730449c10cac6e6f69d255611c93f63c2hding 1043430ce5c32361119ed81a62c918be6afbdd053eddhding vaStatus = tng_CreateContext(obj_context, obj_config, 1); 10448e9a21e730449c10cac6e6f69d255611c93f63c2hding if (VA_STATUS_SUCCESS != vaStatus) 10458e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_ALLOCATION_FAILED; 10468e9a21e730449c10cac6e6f69d255611c93f63c2hding 10478e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx = (context_ENC_p) obj_context->format_data; 10488e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->eCodec = IMG_CODEC_JPEG; 10498e9a21e730449c10cac6e6f69d255611c93f63c2hding 10508e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(0 == (ctx->ui16Width % 2)); 10518e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(0 == (ctx->ui16FrameHeight % 2)); 10528e9a21e730449c10cac6e6f69d255611c93f63c2hding 10538e9a21e730449c10cac6e6f69d255611c93f63c2hding for (i = 0; i < obj_config->attrib_count; i++) { 10548e9a21e730449c10cac6e6f69d255611c93f63c2hding if (VAConfigAttribRTFormat == obj_config->attrib_list[i].type) { 10558e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (obj_config->attrib_list[i].value) { 10568e9a21e730449c10cac6e6f69d255611c93f63c2hding case VA_RT_FORMAT_YUV420: 10578e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->eFormat = IMG_CODEC_PL12; 10588e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "JPEG encoding: NV12 format chose.\n"); 10598e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 10608e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 10618e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "JPEG encoding: unsupported YUV format and force it to be NV12!\n"); 10628e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->eFormat = IMG_CODEC_PL12; 10638e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 10648e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10658e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 10668e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10678e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10688e9a21e730449c10cac6e6f69d255611c93f63c2hding 10698e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->jpeg_ctx = (TOPAZHP_JPEG_ENCODER_CONTEXT *)calloc(1, sizeof(TOPAZHP_JPEG_ENCODER_CONTEXT)); 10708e9a21e730449c10cac6e6f69d255611c93f63c2hding if (NULL == ctx->jpeg_ctx) 10718e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_ALLOCATION_FAILED; 10728e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p = ctx->jpeg_ctx; 10738e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->ctx = ctx; 10748e9a21e730449c10cac6e6f69d255611c93f63c2hding 10758e9a21e730449c10cac6e6f69d255611c93f63c2hding memset((void *)jpeg_ctx_p, 0x0, sizeof(jpeg_ctx_p)); 10768e9a21e730449c10cac6e6f69d255611c93f63c2hding 1077c4a7c43f761ec6b9b4777aa0ccf3ab6045562242SUN,Jing jpeg_ctx_p->NumCores = TOPAZHP_PIPE_NUM; 10788e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->eFormat = ctx->eFormat; 10798e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->ui32OutputWidth = ctx->ui16Width; 10808e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->ui32OutputHeight = ctx->ui16FrameHeight; 10818e9a21e730449c10cac6e6f69d255611c93f63c2hding 10828e9a21e730449c10cac6e6f69d255611c93f63c2hding InitializeJpegEncode(jpeg_ctx_p); 10838e9a21e730449c10cac6e6f69d255611c93f63c2hding 10848e9a21e730449c10cac6e6f69d255611c93f63c2hding if ((jpeg_ctx_p->sScan_Encode_Info.ui16ScansInImage < 1) || 10858e9a21e730449c10cac6e6f69d255611c93f63c2hding (jpeg_ctx_p->sScan_Encode_Info.ui16ScansInImage > PTG_JPEG_MAX_SCAN_NUM)) { 10868e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "JPEG MCU scanning number(%d) is wrong!\n", jpeg_ctx_p->sScan_Encode_Info.ui16ScansInImage); 10878e9a21e730449c10cac6e6f69d255611c93f63c2hding free(ctx->jpeg_ctx); 10888e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->jpeg_ctx = NULL; 10898e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_UNKNOWN; 10908e9a21e730449c10cac6e6f69d255611c93f63c2hding } 10918e9a21e730449c10cac6e6f69d255611c93f63c2hding 10928e9a21e730449c10cac6e6f69d255611c93f63c2hding /*Allocate coded buffers' descripters */ 10938e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.aBufferTable = (TOPAZHP_JPEG_BUFFER_INFO *)calloc(1, (jpeg_ctx_p->sScan_Encode_Info.ui8NumberOfCodedBuffers) * (sizeof(TOPAZHP_JPEG_BUFFER_INFO))); 10948e9a21e730449c10cac6e6f69d255611c93f63c2hding if (NULL == jpeg_ctx_p->sScan_Encode_Info.aBufferTable) 10958e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_ALLOCATION_FAILED; 10968e9a21e730449c10cac6e6f69d255611c93f63c2hding 10978e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 10988e9a21e730449c10cac6e6f69d255611c93f63c2hding} 10998e9a21e730449c10cac6e6f69d255611c93f63c2hding 11008e9a21e730449c10cac6e6f69d255611c93f63c2hding 1101430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic void tng_jpeg_DestroyContext( 11028e9a21e730449c10cac6e6f69d255611c93f63c2hding object_context_p obj_context) 11038e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 11048e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx; 11058e9a21e730449c10cac6e6f69d255611c93f63c2hding 1106430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_DestroyPicture\n"); 11078e9a21e730449c10cac6e6f69d255611c93f63c2hding 11088e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx = (context_ENC_p)(obj_context->format_data); 11098e9a21e730449c10cac6e6f69d255611c93f63c2hding 11108e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ctx->jpeg_ctx) { 11118e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ctx->jpeg_ctx->sScan_Encode_Info.aBufferTable) { 11128e9a21e730449c10cac6e6f69d255611c93f63c2hding free(ctx->jpeg_ctx->sScan_Encode_Info.aBufferTable); 11138e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->jpeg_ctx->sScan_Encode_Info.aBufferTable = NULL; 11148e9a21e730449c10cac6e6f69d255611c93f63c2hding } 11158e9a21e730449c10cac6e6f69d255611c93f63c2hding 11168e9a21e730449c10cac6e6f69d255611c93f63c2hding free(ctx->jpeg_ctx); 11178e9a21e730449c10cac6e6f69d255611c93f63c2hding } 11188e9a21e730449c10cac6e6f69d255611c93f63c2hding 1119430ce5c32361119ed81a62c918be6afbdd053eddhding tng_DestroyContext(obj_context, 1); 11208e9a21e730449c10cac6e6f69d255611c93f63c2hding} 11218e9a21e730449c10cac6e6f69d255611c93f63c2hding 1122430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng__cmdbuf_lowpower(context_ENC_p ctx) 1123430ce5c32361119ed81a62c918be6afbdd053eddhding{ 1124430ce5c32361119ed81a62c918be6afbdd053eddhding VAStatus vaStatus = VA_STATUS_SUCCESS; 1125430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_p cmdbuf = ctx->obj_context->tng_cmdbuf; 1126430ce5c32361119ed81a62c918be6afbdd053eddhding psb_driver_data_p driver_data = ctx->obj_context->driver_data; 1127430ce5c32361119ed81a62c918be6afbdd053eddhding 1128430ce5c32361119ed81a62c918be6afbdd053eddhding *cmdbuf->cmd_idx++ = 1129430ce5c32361119ed81a62c918be6afbdd053eddhding ((MTX_CMDID_SW_LEAVE_LOWPOWER & MTX_CMDWORD_ID_MASK) << MTX_CMDWORD_ID_SHIFT) | 1130430ce5c32361119ed81a62c918be6afbdd053eddhding ((ctx->ui32RawFrameCount & MTX_CMDWORD_CORE_MASK) << MTX_CMDWORD_CORE_SHIFT) | 1131430ce5c32361119ed81a62c918be6afbdd053eddhding (((driver_data->context_id & MTX_CMDWORD_COUNT_MASK) << MTX_CMDWORD_COUNT_SHIFT)); 1132430ce5c32361119ed81a62c918be6afbdd053eddhding 1133430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_insert_command_param(ctx->eCodec); 1134430ce5c32361119ed81a62c918be6afbdd053eddhding 1135430ce5c32361119ed81a62c918be6afbdd053eddhding return vaStatus; 1136430ce5c32361119ed81a62c918be6afbdd053eddhding} 1137430ce5c32361119ed81a62c918be6afbdd053eddhding 1138430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_jpeg_BeginPicture( 11398e9a21e730449c10cac6e6f69d255611c93f63c2hding object_context_p obj_context) 11408e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 11418e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 11428e9a21e730449c10cac6e6f69d255611c93f63c2hding int ret; 1143430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_p cmdbuf; 11448e9a21e730449c10cac6e6f69d255611c93f63c2hding 11458e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p) obj_context->format_data; 11468e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx_p = ctx->jpeg_ctx; 11478e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_frame_buf *ps_buf = &(ctx->ctx_frame_buf); 1148430ce5c32361119ed81a62c918be6afbdd053eddhding psb_driver_data_p driver_data = ctx->obj_context->driver_data; 11498e9a21e730449c10cac6e6f69d255611c93f63c2hding 1150430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_BeginPicture: Frame %d\n", ctx->obj_context->frame_count); 11518e9a21e730449c10cac6e6f69d255611c93f63c2hding 11528e9a21e730449c10cac6e6f69d255611c93f63c2hding 11538e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Get the current surface */ 11548e9a21e730449c10cac6e6f69d255611c93f63c2hding ps_buf->src_surface = ctx->obj_context->current_render_target; 11558e9a21e730449c10cac6e6f69d255611c93f63c2hding 11568e9a21e730449c10cac6e6f69d255611c93f63c2hding 11578e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Initialize the command buffer */ 1158430ce5c32361119ed81a62c918be6afbdd053eddhding ret = tng_context_get_next_cmdbuf(ctx->obj_context); 11598e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ret) { 11608e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "get next cmdbuf fail\n"); 11618e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = VA_STATUS_ERROR_UNKNOWN; 11628e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 11638e9a21e730449c10cac6e6f69d255611c93f63c2hding } 1164430ce5c32361119ed81a62c918be6afbdd053eddhding cmdbuf = ctx->obj_context->tng_cmdbuf; 11658e9a21e730449c10cac6e6f69d255611c93f63c2hding 11668e9a21e730449c10cac6e6f69d255611c93f63c2hding 11678e9a21e730449c10cac6e6f69d255611c93f63c2hding //For the first picture of a set to be encoded, need to ask kernel to perpare JPEG encoding 11688e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ctx->obj_context->frame_count == 0) { /* first picture */ 11698e9a21e730449c10cac6e6f69d255611c93f63c2hding 11708e9a21e730449c10cac6e6f69d255611c93f63c2hding *cmdbuf->cmd_idx++ = ((MTX_CMDID_SW_NEW_CODEC & MTX_CMDWORD_ID_MASK) << MTX_CMDWORD_ID_SHIFT) | 1171430ce5c32361119ed81a62c918be6afbdd053eddhding ((ctx->eCodec) << MTX_CMDWORD_CORE_SHIFT) | 11728e9a21e730449c10cac6e6f69d255611c93f63c2hding (((driver_data->drm_context & MTX_CMDWORD_COUNT_MASK) << MTX_CMDWORD_COUNT_SHIFT)); 1173430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_insert_command_param((ctx->ui16Width << 16) | ctx->ui16FrameHeight); 11748e9a21e730449c10cac6e6f69d255611c93f63c2hding } 11758e9a21e730449c10cac6e6f69d255611c93f63c2hding 11768e9a21e730449c10cac6e6f69d255611c93f63c2hding 11778e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Map MTX setup buffer */ 1178cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan vaStatus = psb_buffer_map(&cmdbuf->jpeg_header_mem, (unsigned char **)&cmdbuf->jpeg_header_mem_p); 11798e9a21e730449c10cac6e6f69d255611c93f63c2hding if (vaStatus) { 11808e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "Fail to map MTX setup buffer\n"); 11818e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 11828e9a21e730449c10cac6e6f69d255611c93f63c2hding } 11838e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->pMemInfoMTXSetup = cmdbuf->jpeg_header_mem_p; 11848e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->pMTXSetup = (JPEG_MTX_DMA_SETUP*)jpeg_ctx_p->pMemInfoMTXSetup; 11858e9a21e730449c10cac6e6f69d255611c93f63c2hding memset(jpeg_ctx_p->pMemInfoMTXSetup, 0x0, ctx->jpeg_header_mem_size); 11868e9a21e730449c10cac6e6f69d255611c93f63c2hding 11878e9a21e730449c10cac6e6f69d255611c93f63c2hding 11888e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Map MTX setup interface buffer */ 1189cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan vaStatus = psb_buffer_map(&cmdbuf->jpeg_header_interface_mem, (unsigned char **)&cmdbuf->jpeg_header_interface_mem_p); 11908e9a21e730449c10cac6e6f69d255611c93f63c2hding if (vaStatus) { 11918e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "Fail to map MTX setup interface buffer\n"); 11928e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&cmdbuf->jpeg_header_mem); 11938e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 11948e9a21e730449c10cac6e6f69d255611c93f63c2hding } 119588d0460822f8807666406c14662591167eed73a0hding jpeg_ctx_p->pMemInfoWritebackMemory = cmdbuf->jpeg_header_interface_mem_p; 119688d0460822f8807666406c14662591167eed73a0hding jpeg_ctx_p->pMTXWritebackMemory = (JPEG_MTX_WRITEBACK_MEMORY*)jpeg_ctx_p->pMemInfoWritebackMemory; 119788d0460822f8807666406c14662591167eed73a0hding memset(jpeg_ctx_p->pMemInfoWritebackMemory, 0x0, ctx->jpeg_header_interface_mem_size); 11988e9a21e730449c10cac6e6f69d255611c93f63c2hding 11998e9a21e730449c10cac6e6f69d255611c93f63c2hding 12008e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Map quantization table buffer */ 1201cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan vaStatus = psb_buffer_map(&cmdbuf->jpeg_pic_params, (unsigned char **)&cmdbuf->jpeg_pic_params_p); 12028e9a21e730449c10cac6e6f69d255611c93f63c2hding if (vaStatus) { 12038e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "Fail to map quantization table buffer\n"); 12048e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&cmdbuf->jpeg_header_mem); 12058e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&cmdbuf->jpeg_header_interface_mem); 12068e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 12078e9a21e730449c10cac6e6f69d255611c93f63c2hding } 12088e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->pMemInfoTableBlock = cmdbuf->jpeg_pic_params_p; 12098e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->psTablesBlock = (JPEG_MTX_QUANT_TABLE *)jpeg_ctx_p->pMemInfoTableBlock; 12108e9a21e730449c10cac6e6f69d255611c93f63c2hding memset(jpeg_ctx_p->pMemInfoTableBlock, 0x0, ctx->jpeg_pic_params_size); 12118e9a21e730449c10cac6e6f69d255611c93f63c2hding 1212430ce5c32361119ed81a62c918be6afbdd053eddhding vaStatus = tng__cmdbuf_lowpower(ctx); 1213430ce5c32361119ed81a62c918be6afbdd053eddhding if (vaStatus != VA_STATUS_SUCCESS) { 1214430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_ERROR, "cmdbuf lowpower\n"); 1215430ce5c32361119ed81a62c918be6afbdd053eddhding } 12168e9a21e730449c10cac6e6f69d255611c93f63c2hding 12178e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Set SetupInterface*/ 12188e9a21e730449c10cac6e6f69d255611c93f63c2hding SetSetupInterface(jpeg_ctx_p); 12198e9a21e730449c10cac6e6f69d255611c93f63c2hding IssueSetupInterface(jpeg_ctx_p); 12208e9a21e730449c10cac6e6f69d255611c93f63c2hding 12218e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Set MTX setup struture */ 12228e9a21e730449c10cac6e6f69d255611c93f63c2hding ret = SetMTXSetup(jpeg_ctx_p, ps_buf->src_surface); 12238e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ret != IMG_ERR_OK) 1224bc6509a80b5f32358354063af4dc786294fa76c3SUN,Jing return ret; 12258e9a21e730449c10cac6e6f69d255611c93f63c2hding IssueMTXSetup(jpeg_ctx_p); 12268e9a21e730449c10cac6e6f69d255611c93f63c2hding 12278e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Initialize the default quantization tables */ 12288e9a21e730449c10cac6e6f69d255611c93f63c2hding SetDefaultQmatix(jpeg_ctx_p->pMemInfoTableBlock); 12298e9a21e730449c10cac6e6f69d255611c93f63c2hding 12308e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Initialize scan counters */ 12318e9a21e730449c10cac6e6f69d255611c93f63c2hding InitializeScanCounter(jpeg_ctx_p); 12328e9a21e730449c10cac6e6f69d255611c93f63c2hding 1233430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_buffer_ref(cmdbuf, &(ctx->obj_context->current_render_target->psb_surface->buf)); 12348e9a21e730449c10cac6e6f69d255611c93f63c2hding 12358e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 12368e9a21e730449c10cac6e6f69d255611c93f63c2hding} 12378e9a21e730449c10cac6e6f69d255611c93f63c2hding 12388e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic VAStatus ProcessQmatrixParam(context_ENC_p ctx, object_buffer_p obj_buffer) 12398e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 12408e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 12418e9a21e730449c10cac6e6f69d255611c93f63c2hding VAQMatrixBufferJPEG *pBuffer; 12428e9a21e730449c10cac6e6f69d255611c93f63c2hding JPEG_MTX_QUANT_TABLE* pQMatrix = (JPEG_MTX_QUANT_TABLE *)(ctx->jpeg_ctx->psTablesBlock); 12438e9a21e730449c10cac6e6f69d255611c93f63c2hding 12448e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(obj_buffer->type == VAQMatrixBufferType); 12458e9a21e730449c10cac6e6f69d255611c93f63c2hding 12468e9a21e730449c10cac6e6f69d255611c93f63c2hding pBuffer = (VAQMatrixBufferJPEG *)obj_buffer->buffer_data; 12478e9a21e730449c10cac6e6f69d255611c93f63c2hding 12488e9a21e730449c10cac6e6f69d255611c93f63c2hding if (0 != pBuffer->load_lum_quantiser_matrix) { 12498e9a21e730449c10cac6e6f69d255611c93f63c2hding memcpy(pQMatrix->aui8LumaQuantParams, 12508e9a21e730449c10cac6e6f69d255611c93f63c2hding pBuffer->lum_quantiser_matrix, 12518e9a21e730449c10cac6e6f69d255611c93f63c2hding QUANT_TABLE_SIZE_BYTES); 12528e9a21e730449c10cac6e6f69d255611c93f63c2hding } 12538e9a21e730449c10cac6e6f69d255611c93f63c2hding 12548e9a21e730449c10cac6e6f69d255611c93f63c2hding if (0 != pBuffer->load_chroma_quantiser_matrix) { 12558e9a21e730449c10cac6e6f69d255611c93f63c2hding memcpy(pQMatrix->aui8ChromaQuantParams, 12568e9a21e730449c10cac6e6f69d255611c93f63c2hding pBuffer->chroma_quantiser_matrix, 12578e9a21e730449c10cac6e6f69d255611c93f63c2hding QUANT_TABLE_SIZE_BYTES); 12588e9a21e730449c10cac6e6f69d255611c93f63c2hding } 12598e9a21e730449c10cac6e6f69d255611c93f63c2hding 12608e9a21e730449c10cac6e6f69d255611c93f63c2hding free(obj_buffer->buffer_data); 12618e9a21e730449c10cac6e6f69d255611c93f63c2hding obj_buffer->buffer_data = NULL; 12628e9a21e730449c10cac6e6f69d255611c93f63c2hding 12638e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 12648e9a21e730449c10cac6e6f69d255611c93f63c2hding} 12658e9a21e730449c10cac6e6f69d255611c93f63c2hding 12668e9a21e730449c10cac6e6f69d255611c93f63c2hdingstatic VAStatus ProcessPictureParam(context_ENC_p ctx, object_buffer_p obj_buffer) 12678e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 12688e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 12698e9a21e730449c10cac6e6f69d255611c93f63c2hding VAEncPictureParameterBufferJPEG *pBuffer = NULL; 12708e9a21e730449c10cac6e6f69d255611c93f63c2hding BUFFER_HEADER *pBufHeader = NULL; 12718e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx = ctx->jpeg_ctx; 1272578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing JPEG_MTX_QUANT_TABLE* pQMatrix = (JPEG_MTX_QUANT_TABLE *) 1273578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (ctx->jpeg_ctx->pMemInfoTableBlock); 12748e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_frame_buf *ps_buf = &(ctx->ctx_frame_buf); 12758e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_ERRORCODE rc; 127688d0460822f8807666406c14662591167eed73a0hding 12778e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Check the input buffer */ 12788e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(obj_buffer->type == VAEncPictureParameterBufferType); 12798e9a21e730449c10cac6e6f69d255611c93f63c2hding if ((obj_buffer->num_elements != 1) || 12808e9a21e730449c10cac6e6f69d255611c93f63c2hding (obj_buffer->size != sizeof(VAEncPictureParameterBufferJPEG))) { 12818e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_UNKNOWN; 12828e9a21e730449c10cac6e6f69d255611c93f63c2hding } 12838e9a21e730449c10cac6e6f69d255611c93f63c2hding 12848e9a21e730449c10cac6e6f69d255611c93f63c2hding 12858e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Lookup and get coded buffer */ 12868e9a21e730449c10cac6e6f69d255611c93f63c2hding pBuffer = (VAEncPictureParameterBufferJPEG *)obj_buffer->buffer_data; 12878e9a21e730449c10cac6e6f69d255611c93f63c2hding 1288578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Parameters checking */ 1289578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing if (((pBuffer->pic_flags).bits.profile != 0) || /* Only "0 - Baseline" is supported */ 1290578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing ((pBuffer->pic_flags).bits.progressive != 0) || /* Only "0 - sequential" is supported */ 1291578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing ((pBuffer->pic_flags).bits.huffman != 1) || /* Only "1 - huffman" is supported */ 1292578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing ((pBuffer->pic_flags).bits.interleaved != 0) || /* Only "0 - non interleaved" is supported */ 1293578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing ((pBuffer->pic_flags).bits.differential != 0)) /* Only "0 - non differential" is supported */ 1294578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing return VA_STATUS_ERROR_INVALID_PARAMETER; 1295578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 1296578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing if ((pBuffer->sample_bit_depth != 8) || /* Only 8-bits sample depth is supported */ 1297578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (pBuffer->num_components != MTX_MAX_COMPONENTS) || /* Only 3 components setting is supported */ 1298578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing (pBuffer->quality > 100)) 1299578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing return VA_STATUS_ERROR_INVALID_PARAMETER; 1300578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 1301578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing /* Set quality */ 1302578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing if (pBuffer->quality != 0) { /* Quality value is set */ 1303578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing CustomizeQuantizationTables(pQMatrix->aui8LumaQuantParams, 1304578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing pQMatrix->aui8ChromaQuantParams, 1305578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing pBuffer->quality); 1306578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing } 1307578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing 13088e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(ctx->ui16Width == pBuffer->picture_width); 13098e9a21e730449c10cac6e6f69d255611c93f63c2hding ASSERT(ctx->ui16FrameHeight == pBuffer->picture_height); 13108e9a21e730449c10cac6e6f69d255611c93f63c2hding 13118e9a21e730449c10cac6e6f69d255611c93f63c2hding ps_buf->coded_buf = BUFFER(pBuffer->coded_buf); 13128e9a21e730449c10cac6e6f69d255611c93f63c2hding 13138e9a21e730449c10cac6e6f69d255611c93f63c2hding free(pBuffer); 13148e9a21e730449c10cac6e6f69d255611c93f63c2hding obj_buffer->buffer_data = NULL; 13158e9a21e730449c10cac6e6f69d255611c93f63c2hding obj_buffer->size = 0; 13168e9a21e730449c10cac6e6f69d255611c93f63c2hding 13178e9a21e730449c10cac6e6f69d255611c93f63c2hding if (NULL == ps_buf->coded_buf) { 13188e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "%s L%d Invalid coded buffer handle\n", __FUNCTION__, __LINE__); 13198e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_INVALID_BUFFER; 13208e9a21e730449c10cac6e6f69d255611c93f63c2hding } 13218e9a21e730449c10cac6e6f69d255611c93f63c2hding 13228e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Map coded buffer */ 1323cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan vaStatus = psb_buffer_map(ps_buf->coded_buf->psb_buffer, (unsigned char **)&jpeg_ctx->jpeg_coded_buf.pMemInfo); 13248e9a21e730449c10cac6e6f69d255611c93f63c2hding if (vaStatus) { 13258e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_ERROR, "ERROR: Map coded_buf failed!"); 13268e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 13278e9a21e730449c10cac6e6f69d255611c93f63c2hding } 13288e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx->jpeg_coded_buf.ui32Size = ps_buf->coded_buf->size; 13298e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx->jpeg_coded_buf.sLock = BUFFER_FREE; 13308e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx->jpeg_coded_buf.ui32BytesWritten = 0; 13318e9a21e730449c10cac6e6f69d255611c93f63c2hding 13328e9a21e730449c10cac6e6f69d255611c93f63c2hding if ((jpeg_ctx->jpeg_coded_buf.ui32Size) < (9 + 6 + (4 * 3))) { 13338e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_INVALID_BUFFER; 13348e9a21e730449c10cac6e6f69d255611c93f63c2hding } 13358e9a21e730449c10cac6e6f69d255611c93f63c2hding 13368e9a21e730449c10cac6e6f69d255611c93f63c2hding 13378e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Assign coded buffer to each scan */ 13388e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Assign coded buffer to each scan\n"); 13398e9a21e730449c10cac6e6f69d255611c93f63c2hding AssignCodedDataBuffers(jpeg_ctx); 13408e9a21e730449c10cac6e6f69d255611c93f63c2hding 13418e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Coded buffer total size is %d," 13428e9a21e730449c10cac6e6f69d255611c93f63c2hding "coded segment size per scan is %d\n", 134388d0460822f8807666406c14662591167eed73a0hding jpeg_ctx->jpeg_coded_buf.ui32Size, jpeg_ctx->ui32SizePerCodedBuffer); 13448e9a21e730449c10cac6e6f69d255611c93f63c2hding 13458e9a21e730449c10cac6e6f69d255611c93f63c2hding 13468e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Write JPEG headers to coded buffer */ 13478e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Write JPEG Headers to coded buf\n"); 13488e9a21e730449c10cac6e6f69d255611c93f63c2hding 13498e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader = (BUFFER_HEADER *)jpeg_ctx->jpeg_coded_buf.pMemInfo; 13508e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32BytesUsed = 0; /* Not include BUFFER_HEADER*/ 13518e9a21e730449c10cac6e6f69d255611c93f63c2hding 13528e9a21e730449c10cac6e6f69d255611c93f63c2hding rc = PrepareHeader(jpeg_ctx, &jpeg_ctx->jpeg_coded_buf, sizeof(BUFFER_HEADER), IMG_TRUE); 13538e9a21e730449c10cac6e6f69d255611c93f63c2hding if (rc != IMG_ERR_OK) 13548e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_UNKNOWN; 13558e9a21e730449c10cac6e6f69d255611c93f63c2hding 13568e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32Reserved3 = PTG_JPEG_HEADER_MAX_SIZE;//Next coded buffer offset 13578e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32BytesUsed = jpeg_ctx->jpeg_coded_buf.ui32BytesWritten - sizeof(BUFFER_HEADER); 13588e9a21e730449c10cac6e6f69d255611c93f63c2hding 13598e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "sizeof(BUFFER_HEADER): %d, ui32BytesUsed :%d, ui32Reserved3: %d, ui32BytesWritten: %d\n", 13608e9a21e730449c10cac6e6f69d255611c93f63c2hding sizeof(BUFFER_HEADER), pBufHeader->ui32BytesUsed, pBufHeader->ui32Reserved3, jpeg_ctx->jpeg_coded_buf.ui32BytesWritten); 13618e9a21e730449c10cac6e6f69d255611c93f63c2hding 13628e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 13638e9a21e730449c10cac6e6f69d255611c93f63c2hding} 1364430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_jpeg_RenderPicture( 13658e9a21e730449c10cac6e6f69d255611c93f63c2hding object_context_p obj_context, 13668e9a21e730449c10cac6e6f69d255611c93f63c2hding object_buffer_p *buffers, 13678e9a21e730449c10cac6e6f69d255611c93f63c2hding int num_buffers) 13688e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 13698e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p) obj_context->format_data; 13708e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 13718e9a21e730449c10cac6e6f69d255611c93f63c2hding int i; 13728e9a21e730449c10cac6e6f69d255611c93f63c2hding 1373430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_RenderPicture\n"); 13748e9a21e730449c10cac6e6f69d255611c93f63c2hding 13758e9a21e730449c10cac6e6f69d255611c93f63c2hding for (i = 0; i < num_buffers; i++) { 13768e9a21e730449c10cac6e6f69d255611c93f63c2hding object_buffer_p obj_buffer = buffers[i]; 13778e9a21e730449c10cac6e6f69d255611c93f63c2hding 13788e9a21e730449c10cac6e6f69d255611c93f63c2hding switch (obj_buffer->type) { 13798e9a21e730449c10cac6e6f69d255611c93f63c2hding case VAQMatrixBufferType: 1380430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_RenderPicture got VAEncSliceParameterBufferType\n"); 13818e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = ProcessQmatrixParam(ctx, obj_buffer); 13828e9a21e730449c10cac6e6f69d255611c93f63c2hding DEBUG_FAILURE; 13838e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 13848e9a21e730449c10cac6e6f69d255611c93f63c2hding case VAEncPictureParameterBufferType: 1385430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_RenderPicture got VAEncPictureParameterBufferType\n"); 13868e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = ProcessPictureParam(ctx, obj_buffer); 13878e9a21e730449c10cac6e6f69d255611c93f63c2hding DEBUG_FAILURE; 13888e9a21e730449c10cac6e6f69d255611c93f63c2hding break; 1389578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing case VAEncSliceParameterBufferType: 1390578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_RenderPicture got VAEncSliceParameterBufferType\n"); 1391578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing drv_debug_msg(VIDEO_DEBUG_WARNING, "VAEncSliceParameterBufferType is ignored on TopazHP\n"); 1392578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing vaStatus = VA_STATUS_SUCCESS; 1393578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing DEBUG_FAILURE; 1394578d2ad7e1ef903d817be99a1aac92bd68b5ee53SUN,Jing break; 13958e9a21e730449c10cac6e6f69d255611c93f63c2hding default: 13968e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = VA_STATUS_ERROR_UNKNOWN; 13978e9a21e730449c10cac6e6f69d255611c93f63c2hding DEBUG_FAILURE; 13988e9a21e730449c10cac6e6f69d255611c93f63c2hding } 13998e9a21e730449c10cac6e6f69d255611c93f63c2hding } 14008e9a21e730449c10cac6e6f69d255611c93f63c2hding 14018e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 14028e9a21e730449c10cac6e6f69d255611c93f63c2hding} 14038e9a21e730449c10cac6e6f69d255611c93f63c2hding 1404430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_jpeg_EndPicture( 14058e9a21e730449c10cac6e6f69d255611c93f63c2hding object_context_p obj_context) 14068e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 14078e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT16 ui16BCnt; 14088e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 rc = 0; 14098e9a21e730449c10cac6e6f69d255611c93f63c2hding VAStatus vaStatus = VA_STATUS_SUCCESS; 14108e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 ui32NoMCUsToEncode = 0; 14118e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT32 ui32RemainMCUs = 0; 14128e9a21e730449c10cac6e6f69d255611c93f63c2hding 14138e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p) obj_context->format_data; 14148e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx_p = ctx->jpeg_ctx; 1415430ce5c32361119ed81a62c918be6afbdd053eddhding tng_cmdbuf_p cmdbuf = (tng_cmdbuf_p)ctx->obj_context->tng_cmdbuf; 14168e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]); 14178e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_frame_buf *ps_buf = &(ctx->ctx_frame_buf); 14188e9a21e730449c10cac6e6f69d255611c93f63c2hding 1419430ce5c32361119ed81a62c918be6afbdd053eddhding drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_jpeg_EndPicture\n"); 14208e9a21e730449c10cac6e6f69d255611c93f63c2hding 14218e9a21e730449c10cac6e6f69d255611c93f63c2hding IssueQmatix(jpeg_ctx_p); 14228e9a21e730449c10cac6e6f69d255611c93f63c2hding 14238e9a21e730449c10cac6e6f69d255611c93f63c2hding /* Compute the next scan to be sent */ 14248e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32RemainMCUs = jpeg_ctx_p->sScan_Encode_Info.ui32NumberMCUsToEncode; 14258e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32RemainMCUs: %d\n", ui32RemainMCUs); 14268e9a21e730449c10cac6e6f69d255611c93f63c2hding 14278e9a21e730449c10cac6e6f69d255611c93f63c2hding for (ui16BCnt = 0; (ui16BCnt < jpeg_ctx_p->sScan_Encode_Info.ui8NumberOfCodedBuffers) 14288e9a21e730449c10cac6e6f69d255611c93f63c2hding && (jpeg_ctx_p->sScan_Encode_Info.ui16SScan > 0); ui16BCnt++) { 14298e9a21e730449c10cac6e6f69d255611c93f63c2hding 14308e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.aBufferTable[ui16BCnt].ui16ScanNumber = jpeg_ctx_p->sScan_Encode_Info.ui16SScan--; 14318e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.aBufferTable[ui16BCnt].i8PipeNumber = 14328153ccc65f30ec7cecee4c6a4f0e72f7c402edbdSUN,Jing (1 == jpeg_ctx_p->NumCores) ? 0 : ((ui16BCnt+1) % jpeg_ctx_p->NumCores); 14338e9a21e730449c10cac6e6f69d255611c93f63c2hding 14348e9a21e730449c10cac6e6f69d255611c93f63c2hding if (jpeg_ctx_p->sScan_Encode_Info.ui16SScan > 0) { 14358e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32NoMCUsToEncode = jpeg_ctx_p->sScan_Encode_Info.ui32NumberMCUsToEncodePerScan; 14368e9a21e730449c10cac6e6f69d255611c93f63c2hding } else { 14378e9a21e730449c10cac6e6f69d255611c93f63c2hding // Final scan, may need fewer MCUs than buffer size, calculate the remainder 14388e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32NoMCUsToEncode = ui32RemainMCUs; 14398e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.aBufferTable[ui16BCnt].i8PipeNumber = 0; 14408e9a21e730449c10cac6e6f69d255611c93f63c2hding } 14418e9a21e730449c10cac6e6f69d255611c93f63c2hding 14428e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "ui32NoMCUsToEncode: %d\n", ui32NoMCUsToEncode); 14438e9a21e730449c10cac6e6f69d255611c93f63c2hding //Send scan to MTX 14448e9a21e730449c10cac6e6f69d255611c93f63c2hding rc = IssueBufferToHW(jpeg_ctx_p, ui16BCnt, 14458e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.aBufferTable[ui16BCnt].i8PipeNumber, 14468e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32NoMCUsToEncode); 14478e9a21e730449c10cac6e6f69d255611c93f63c2hding if (rc != IMG_ERR_OK) { 14488e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = VA_STATUS_ERROR_UNKNOWN; 14498e9a21e730449c10cac6e6f69d255611c93f63c2hding DEBUG_FAILURE; 14508e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 14518e9a21e730449c10cac6e6f69d255611c93f63c2hding } 14528e9a21e730449c10cac6e6f69d255611c93f63c2hding 14538e9a21e730449c10cac6e6f69d255611c93f63c2hding ui32RemainMCUs -= ui32NoMCUsToEncode; 14548e9a21e730449c10cac6e6f69d255611c93f63c2hding } 14558e9a21e730449c10cac6e6f69d255611c93f63c2hding 14568e9a21e730449c10cac6e6f69d255611c93f63c2hding 14578e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&cmdbuf->jpeg_pic_params); 14588e9a21e730449c10cac6e6f69d255611c93f63c2hding cmdbuf->jpeg_pic_params_p = NULL; 14598e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&cmdbuf->jpeg_header_mem); 14608e9a21e730449c10cac6e6f69d255611c93f63c2hding cmdbuf->jpeg_header_mem_p = NULL; 14618e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(ps_buf->coded_buf->psb_buffer); 14628e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->jpeg_coded_buf.pMemInfo = NULL; 14638e9a21e730449c10cac6e6f69d255611c93f63c2hding 14648e9a21e730449c10cac6e6f69d255611c93f63c2hding psb_buffer_unmap(&(ctx->bufs_writeback)); 14658e9a21e730449c10cac6e6f69d255611c93f63c2hding 14668e9a21e730449c10cac6e6f69d255611c93f63c2hding 1467430ce5c32361119ed81a62c918be6afbdd053eddhding //tng__trace_cmdbuf(cmdbuf); 14688e9a21e730449c10cac6e6f69d255611c93f63c2hding 1469430ce5c32361119ed81a62c918be6afbdd053eddhding if (tng_context_flush_cmdbuf(ctx->obj_context)) { 14708e9a21e730449c10cac6e6f69d255611c93f63c2hding vaStatus = VA_STATUS_ERROR_UNKNOWN; 14718e9a21e730449c10cac6e6f69d255611c93f63c2hding return vaStatus; 14728e9a21e730449c10cac6e6f69d255611c93f63c2hding } 14738e9a21e730449c10cac6e6f69d255611c93f63c2hding 14748e9a21e730449c10cac6e6f69d255611c93f63c2hding ctx->obj_context->frame_count++; 14758e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_SUCCESS; 14768e9a21e730449c10cac6e6f69d255611c93f63c2hding} 14778e9a21e730449c10cac6e6f69d255611c93f63c2hding 14788e9a21e730449c10cac6e6f69d255611c93f63c2hding/* Add Restart interval termination (RSTm)to coded buf 1 ~ NumCores-1*/ 1479430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic inline VAStatus tng_OutputResetIntervalToCB(IMG_UINT8 *pui8Buf, IMG_UINT8 ui8_marker) 14808e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 14818e9a21e730449c10cac6e6f69d255611c93f63c2hding if (NULL == pui8Buf) 14828e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_UNKNOWN; 14838e9a21e730449c10cac6e6f69d255611c93f63c2hding /*Refer to CCITT Rec. T.81 (1992 E), B.2.1*/ 14848e9a21e730449c10cac6e6f69d255611c93f63c2hding /*RSTm: Restart marker conditional marker which is placed between 14858e9a21e730449c10cac6e6f69d255611c93f63c2hding * entropy-coded segments only if restartis enabled. There are 8 unique 14868e9a21e730449c10cac6e6f69d255611c93f63c2hding * restart markers (m = 0 - 7) which repeat in sequence from 0 to 7, starting with 14878e9a21e730449c10cac6e6f69d255611c93f63c2hding * zero for each scan, to provide a modulo 8 restart interval count*/ 14888e9a21e730449c10cac6e6f69d255611c93f63c2hding 14898e9a21e730449c10cac6e6f69d255611c93f63c2hding *pui8Buf++ = 0xff; 14908e9a21e730449c10cac6e6f69d255611c93f63c2hding *pui8Buf = (ui8_marker & 0x7) | 0xD0; 14918e9a21e730449c10cac6e6f69d255611c93f63c2hding 14928e9a21e730449c10cac6e6f69d255611c93f63c2hding return 0; 14938e9a21e730449c10cac6e6f69d255611c93f63c2hding} 14948e9a21e730449c10cac6e6f69d255611c93f63c2hding 1495430ce5c32361119ed81a62c918be6afbdd053eddhdingVAStatus tng_jpeg_AppendMarkers(object_context_p obj_context, void *raw_coded_buf) 14968e9a21e730449c10cac6e6f69d255611c93f63c2hding{ 14978e9a21e730449c10cac6e6f69d255611c93f63c2hding context_ENC_p ctx = (context_ENC_p) obj_context->format_data; 14988e9a21e730449c10cac6e6f69d255611c93f63c2hding TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx_p = ctx->jpeg_ctx; 14998e9a21e730449c10cac6e6f69d255611c93f63c2hding 15008e9a21e730449c10cac6e6f69d255611c93f63c2hding IMG_UINT16 ui16BCnt; 15018e9a21e730449c10cac6e6f69d255611c93f63c2hding BUFFER_HEADER* pBufHeader; 15028e9a21e730449c10cac6e6f69d255611c93f63c2hding STREAMTYPEW s_streamW; 15038e9a21e730449c10cac6e6f69d255611c93f63c2hding void *pSegStart = raw_coded_buf; 15048e9a21e730449c10cac6e6f69d255611c93f63c2hding 15058e9a21e730449c10cac6e6f69d255611c93f63c2hding if (pSegStart == NULL) { 15068e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_ERROR_UNKNOWN; 15078e9a21e730449c10cac6e6f69d255611c93f63c2hding } 15088e9a21e730449c10cac6e6f69d255611c93f63c2hding 15098e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader = (BUFFER_HEADER *)pSegStart; 15108e9a21e730449c10cac6e6f69d255611c93f63c2hding 15118e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Number of Coded buffers %d, Per Coded Buffer size : %d\n", 15128e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->sScan_Encode_Info.ui8NumberOfCodedBuffers, 15138e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->ui32SizePerCodedBuffer); 15148e9a21e730449c10cac6e6f69d255611c93f63c2hding 15158e9a21e730449c10cac6e6f69d255611c93f63c2hding /*The first part of coded buffer contains JPEG headers*/ 15168e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32Reserved3 = PTG_JPEG_HEADER_MAX_SIZE; 15178e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->jpeg_coded_buf.ui32BytesWritten = 0; 15188e9a21e730449c10cac6e6f69d255611c93f63c2hding 15198e9a21e730449c10cac6e6f69d255611c93f63c2hding for (ui16BCnt = 0; 15208e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16BCnt < jpeg_ctx_p->sScan_Encode_Info.ui8NumberOfCodedBuffers; 15218e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16BCnt++) { 15228e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader = (BUFFER_HEADER *)pSegStart; 15238e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32Reserved3 = 15248e9a21e730449c10cac6e6f69d255611c93f63c2hding PTG_JPEG_HEADER_MAX_SIZE + jpeg_ctx_p->ui32SizePerCodedBuffer * ui16BCnt ; 15258e9a21e730449c10cac6e6f69d255611c93f63c2hding 15268e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Coded Buffer Part %d, size %d, next part offset: %d\n", 15278e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16BCnt, pBufHeader->ui32BytesUsed, pBufHeader->ui32Reserved3); 15288e9a21e730449c10cac6e6f69d255611c93f63c2hding 15298e9a21e730449c10cac6e6f69d255611c93f63c2hding if (ui16BCnt > 0) { 15308e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Append 2 bytes Reset Interval %d " 15318e9a21e730449c10cac6e6f69d255611c93f63c2hding "to Coded Buffer Part %d\n", ui16BCnt - 1, ui16BCnt); 15328e9a21e730449c10cac6e6f69d255611c93f63c2hding 15338e9a21e730449c10cac6e6f69d255611c93f63c2hding // OUTPUT RESTART INTERVAL TO CODED BUFFER 1534430ce5c32361119ed81a62c918be6afbdd053eddhding tng_OutputResetIntervalToCB( 1535cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan (IMG_UINT8 *)((IMG_UINT32)pSegStart + sizeof(BUFFER_HEADER) + pBufHeader->ui32BytesUsed), 15368e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16BCnt - 1); 15378e9a21e730449c10cac6e6f69d255611c93f63c2hding 15388e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32BytesUsed += 2; 15398e9a21e730449c10cac6e6f69d255611c93f63c2hding } 15408e9a21e730449c10cac6e6f69d255611c93f63c2hding 15418e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->jpeg_coded_buf.ui32BytesWritten += pBufHeader->ui32BytesUsed; 1542cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan pSegStart = (void *)((IMG_UINT32)raw_coded_buf + pBufHeader->ui32Reserved3); 15438e9a21e730449c10cac6e6f69d255611c93f63c2hding } 15448e9a21e730449c10cac6e6f69d255611c93f63c2hding 15458e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader = (BUFFER_HEADER *)pSegStart; 15468e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32Reserved3 = 0; /*Last Part of Coded Buffer*/ 15478e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->jpeg_coded_buf.ui32BytesWritten += pBufHeader->ui32BytesUsed; 15488e9a21e730449c10cac6e6f69d255611c93f63c2hding 15498e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Coded Buffer Part %d, size %d, next part offset: %d\n", 15508e9a21e730449c10cac6e6f69d255611c93f63c2hding ui16BCnt, pBufHeader->ui32BytesUsed, pBufHeader->ui32Reserved3); 15518e9a21e730449c10cac6e6f69d255611c93f63c2hding 15528e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Buffer = pSegStart; 15538e9a21e730449c10cac6e6f69d255611c93f63c2hding s_streamW.Offset = (sizeof(BUFFER_HEADER) + pBufHeader->ui32BytesUsed); 15548e9a21e730449c10cac6e6f69d255611c93f63c2hding 15558e9a21e730449c10cac6e6f69d255611c93f63c2hding fPutBitsToBuffer(&s_streamW, 2, END_OF_IMAGE); 15568e9a21e730449c10cac6e6f69d255611c93f63c2hding 15578e9a21e730449c10cac6e6f69d255611c93f63c2hding pBufHeader->ui32BytesUsed += 2; 15588e9a21e730449c10cac6e6f69d255611c93f63c2hding jpeg_ctx_p->jpeg_coded_buf.ui32BytesWritten += 2; 15598e9a21e730449c10cac6e6f69d255611c93f63c2hding 15608e9a21e730449c10cac6e6f69d255611c93f63c2hding drv_debug_msg(VIDEO_DEBUG_GENERAL, "Add two bytes to last part of coded buffer," 15618e9a21e730449c10cac6e6f69d255611c93f63c2hding " total: %d\n", jpeg_ctx_p->jpeg_coded_buf.ui32BytesWritten); 15628e9a21e730449c10cac6e6f69d255611c93f63c2hding return VA_STATUS_SUCCESS; 15638e9a21e730449c10cac6e6f69d255611c93f63c2hding} 15648e9a21e730449c10cac6e6f69d255611c93f63c2hding 1565430ce5c32361119ed81a62c918be6afbdd053eddhdingstruct format_vtable_s tng_JPEGES_vtable = { 15668e9a21e730449c10cac6e6f69d255611c93f63c2hdingqueryConfigAttributes: 1567430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_QueryConfigAttributes, 15688e9a21e730449c10cac6e6f69d255611c93f63c2hdingvalidateConfig: 1569430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_ValidateConfig, 15708e9a21e730449c10cac6e6f69d255611c93f63c2hdingcreateContext: 1571430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_CreateContext, 15728e9a21e730449c10cac6e6f69d255611c93f63c2hdingdestroyContext: 1573430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_DestroyContext, 15748e9a21e730449c10cac6e6f69d255611c93f63c2hdingbeginPicture: 1575430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_BeginPicture, 15768e9a21e730449c10cac6e6f69d255611c93f63c2hdingrenderPicture: 1577430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_RenderPicture, 15788e9a21e730449c10cac6e6f69d255611c93f63c2hdingendPicture: 1579430ce5c32361119ed81a62c918be6afbdd053eddhding tng_jpeg_EndPicture 15808e9a21e730449c10cac6e6f69d255611c93f63c2hding}; 1581