⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 img_msg_handler.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    sx1 = (dx1 - dx) * rw1 / rw2;
    sy1 = (dy1 - dy) * rh1 / rh2;
    sx2 = (dx2 - dx) * rw1 / rw2;
    sy2 = (dy2 - dy) * rh1 / rh2;
    sw = sx2 - sx1 + 1;
    sh = sy2 - sy1 + 1;

    /* check the ratio , how to fit into work buffer */
    for (ratio = 0; (sw >> ratio) * (sh >> ratio) > wb_pixel_size; ratio++)
    {
        ;
    }

    *ret_ratio = ratio;

    /* calculate the work buffer width/height depends on the ratio of sw,sh */
    *wb_width = sw >> ratio;
    *wb_height = sh >> ratio;

    /* calculate the dest_x,dest_y in work buffer coordinate */
    *wb_dest_x = -sx1 / (1 << ratio);
    *wb_dest_y = -sy1 / (1 << ratio);

}

#ifdef JPG_DECODE


/*****************************************************************************
 * FUNCTION
 *  image_decoder_jpeg_req_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  req_p       [?]     
 * RETURNS
 *  
 *****************************************************************************/
kal_int32 image_decoder_jpeg_req_hdlr(media_img_decode_req_struct *req_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result;
    kal_uint32 waiting_time;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* init jpeg_decode_retry_flag to DISABLE */    
    jpg_decode.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_DISABLE;

    if (req_p->media_mode == MED_MODE_FILE)
    {
        if (req_p->media_type == MED_TYPE_JPG)
        {
            /* init jpeg */
            kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;

            img_context_p->display_width = req_p->display_width;
            img_context_p->display_height = req_p->display_height;
            img_context_p->image_clip_x1 = req_p->image_clip_x1;
            img_context_p->image_clip_x2 = req_p->image_clip_x2;
            img_context_p->image_clip_y1 = req_p->image_clip_y1;
            img_context_p->image_clip_y2 = req_p->image_clip_y2;
            img_context_p->image_buffer_address = (kal_uint32) req_p->image_buffer_p;
            img_context_p->image_buffer_size = (kal_uint32) req_p->image_buffer_size;
            img_context_p->file_handle = (kal_int32) req_p->data;
            img_context_p->seq_num = req_p->seq_num;
            img_context_p->blocking = req_p->blocking;
            img_context_p->callback = req_p->callback;
            img_context_p->file_buffer_address = (kal_uint32) med_alloc_ext_mem(MAX_IMG_DEC_FILE_BUFFER_LEN);
            img_context_p->file_buffer_size = MAX_IMG_DEC_FILE_BUFFER_LEN;

            get_jpeg_resize_size(
                img_context_p->file_handle,
                img_context_p->file_buffer_address,
                img_context_p->file_buffer_size,
                &(img_context_p->display_width),
                &(img_context_p->display_height),
                &(img_context_p->image_width),
                &(img_context_p->image_height));

            jpg_decode.jpeg_file_handle = img_context_p->file_handle;
            /* DRM_REPLACE */
            /* FS_GetFileSize(img_context_p->file_handle, &img_context_p->file_size); */
            DRM_file_size(img_context_p->file_handle, &img_context_p->file_size);
            jpg_decode.jpeg_file_buffer_address = img_context_p->file_buffer_address;
            jpg_decode.jpeg_file_buffer_size = img_context_p->file_buffer_size;
            jpg_decode.intmem_start_address = img_context_p->intmem_start_address =
                (kal_uint32) med_alloc_int_mem(MAX_IMG_DEC_INT_MEM_SIZE);
            jpg_decode.intmem_size = img_context_p->intmem_size = MAX_IMG_DEC_INT_MEM_SIZE;
            img_context_p->extmem_start_address = (kal_uint32) med_alloc_ext_mem(MAX_PROG_JPG_DEC_EXT_MEM_SIZE);
            if (img_context_p->extmem_start_address)
            {
                img_context_p->extmem_size = MAX_PROG_JPG_DEC_EXT_MEM_SIZE;
            }
            else
            {
                kal_uint32 buf_size = MAX_PROG_JPG_DEC_EXT_MEM_SIZE ;
                /* this is for the case that target buffer size is allcated from MED */
                do
                {
                    buf_size = buf_size / 2;
                    img_context_p->extmem_start_address = (kal_uint32) med_alloc_ext_mem(buf_size);
                } while ((buf_size > MAX_IMG_DEC_EXT_MEM_SIZE) && img_context_p->extmem_start_address == NULL);

                if (img_context_p->extmem_start_address)
                {
                    img_context_p->extmem_size = buf_size;
                }
                else
                {
                    if ((img_context_p->extmem_start_address =
                         (kal_uint32) med_alloc_ext_mem(MAX_IMG_DEC_EXT_MEM_SIZE)) == 0)
                    {
                        ASSERT(img_context_p->extmem_start_address > 0);
                    }
                    img_context_p->extmem_size = MAX_IMG_DEC_EXT_MEM_SIZE;
                }
            }
            jpg_decode.extmem_start_address = img_context_p->extmem_start_address;
            jpg_decode.extmem_size = img_context_p->extmem_size;
            jpg_decode.image_buffer_address = img_context_p->image_buffer_address;
            jpg_decode.image_buffer_size = img_context_p->image_buffer_size;
            jpg_decode.image_width = img_context_p->display_width;
            jpg_decode.image_height = img_context_p->display_height;
            jpg_decode.image_clip_x1 = img_context_p->image_clip_x1;
            jpg_decode.image_clip_x2 = img_context_p->image_clip_x2;
            jpg_decode.image_clip_y1 = img_context_p->image_clip_y1;
            jpg_decode.image_clip_y2 = img_context_p->image_clip_y2;
            jpg_decode.jpeg_decode_cb = img_decode_callback;

            jpg_decode.jpeg_thumbnail_mode = req_p->jpeg_thumbnail_mode;
        #if MT6228_SERIES
            jpg_decode.image_pitch_mode = req_p->image_pitch_mode;
            jpg_decode.image_data_format = req_p->image_data_format;
            jpg_decode.image_pitch_bytes = req_p->image_pitch_bytes;

            jpg_decode.memory_output = req_p->memory_output;
            jpg_decode.memory_output_width = req_p->memory_output_width;
            jpg_decode.memory_output_height = req_p->memory_output_height;
            jpg_decode.memory_output_buffer_address = req_p->memory_output_buffer_address;
            jpg_decode.memory_output_buffer_size = req_p->memory_output_buffer_size;
        #endif /* MT6228_SERIES */ 

            if (img_context_p->blocking)
            {
                waiting_time = IMG_CODEC_BLOCK_WAITING_TIME;
            }
            else
            {
                waiting_time = IMG_CODEC_RETRY_TIME * ((img_context_p->file_size >> IMG_DECODE_FILE_UNIT) + 1);
            }

        #ifdef __MTK_TARGET__
            dec_ret = jpeg_decode_process(&jpg_decode);
        #endif 
            if (dec_ret == JPEG_DECODE_DECODING)
            {
                img_context_p->processing = KAL_TRUE;
                img_context_p->retry_conut = 0;
                med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
                IMG_ENTER_STATE(IMG_JPG_DECODE);
                return MED_RES_OK;
            }
            else if (dec_ret == JPEG_DECODE_BUFFER_SIZE_FAIL)
            {
                /* use different buffer size to retry again */
                med_free_ext_mem((void **)&img_context_p->file_buffer_address);
                img_context_p->file_buffer_address = (kal_uint32) med_alloc_ext_mem(MAX_IMG_DEC_FILE_BUFFER_LEN * 2);
                jpg_decode.jpeg_file_buffer_address = img_context_p->file_buffer_address;
                jpg_decode.jpeg_file_buffer_size = img_context_p->file_buffer_size = MAX_IMG_DEC_FILE_BUFFER_LEN * 2;

                //kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process: 6");
                /* stop jpeg decode process */
                //stop_jpeg_decode_process();

                dec_ret = jpeg_decode_process(&jpg_decode);
                if (dec_ret == JPEG_DECODE_DECODING)
                {
                    img_context_p->processing = KAL_TRUE;
                    img_context_p->retry_conut = 0;
                    med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
                    IMG_ENTER_STATE(IMG_JPG_DECODE);
                    return MED_RES_OK;
                }
                else if (dec_ret == JPEG_DECODE_BUFFER_SIZE_FAIL)
                {
                    /* use different buffer size to retry again */
                    med_free_ext_mem((void **)&img_context_p->file_buffer_address);
                    img_context_p->file_buffer_address =
                        (kal_uint32) med_alloc_ext_mem(MAX_IMG_DEC_FILE_BUFFER_LEN * 3);
                    jpg_decode.jpeg_file_buffer_address = img_context_p->file_buffer_address;
                    jpg_decode.jpeg_file_buffer_size = img_context_p->file_buffer_size =
                        MAX_IMG_DEC_FILE_BUFFER_LEN * 3;
                    //kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process: 7");                    /* stop jpeg decode process */
                    /* stop jpeg decode process */                    
                    //stop_jpeg_decode_process();

                    dec_ret = jpeg_decode_process(&jpg_decode);
                    if (dec_ret == JPEG_DECODE_DECODING)
                    {
                        img_context_p->processing = KAL_TRUE;
                        img_context_p->retry_conut = 0;
                        med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
                        IMG_ENTER_STATE(IMG_JPG_DECODE);
                        return MED_RES_OK;
                    }
                    else
                    {
                        //kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process: 8");
                        /* stop jpeg decode process */
                        //stop_jpeg_decode_process();

                        img_release_memory();
                        result = img_get_decode_res(dec_ret);
                        return result;
                    }
                }
                else
                {
                    //kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process: 9");
                    /* stop jpeg decode process */
                    //stop_jpeg_decode_process();
                
                    img_release_memory();
                    result = img_get_decode_res(dec_ret);
                    return result;
                }
            }
            else
            {
                //kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process: 10");
                /* stop jpeg decode process */
                //stop_jpeg_decode_process();
            
                img_release_memory();
                result = img_get_decode_res(dec_ret);
                img_set_decoded_width(img_context_p->image_width);
                if (dec_ret == JPEG_DECODE_SUCCESS)
                {
                    if (img_context_p->callback != NULL)
                    {
                        img_context_p->callback(result);
                    }
                    IMG_ENTER_STATE(IMG_IDLE);
                    if (!img_context_p->blocking)
			        {
			            img_send_decode_finish_ind((kal_int16) result, img_context_p->seq_num);
			        }
                    else
			            IMG_SET_EVENT(IMG_EVT_DECODE);
                }
                return result;
            }
        }
        else
        {
            img_release_memory();
            return MED_RES_INVALID_FORMAT;
        }
    }
    else if (req_p->media_mode == MED_MODE_ARRAY)
    {
        if (req_p->media_type == MED_TYPE_JPG)
        {
            /* init jpeg */
            kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;

            img_context_p->file_buffer_address = (kal_uint32) req_p->data;
            img_context_p->file_size = req_p->file_size;
            img_context_p->display_width = req_p->display_width;
            img_context_p->display_height = req_p->display_height;
            img_context_p->image_clip_x1 = req_p->image_clip_x1;
            img_context_p->image_clip_x2 = req_p->image_clip_x2;
            img_context_p->image_clip_y1 = req_p->image_clip_y1;
            img_context_p->image_clip_y2 = req_p->image_clip_y2;
            img_context_p->image_buffer_address = (kal_uint32) req_p->image_buffer_p;
            img_context_p->image_buffer_size = (kal_uint32) req_p->image_buffer_size;
            img_context_p->seq_num = req_p->seq_num;
            img_context_p->blocking = req_p->blocking;
            img_context_p->file_handle = 0;
            img_context_p->callback = req_p->callback;

            if (req_p->data != NULL && req_p->file_size > 0)
            {

                get_jpeg_resize_size(
                    0,
                    img_context_p->file_buffer_address,
                    img_context_p->file_size,
                    &(img_context_p->display_width),
                    &(img_context_p->display_height),
                    &(img_context_p->image_width),
                    &(img_context_p->image_height));

                jpg_decode.jpeg_file_handle = 0;
                jpg_decode.jpeg_file_buffer_address = img_context_p->file_buffer_address;
                jpg_decode.jpeg_file_size = img_context_p->file_size;
                jpg_decode.intmem_start_address = img_context_p->intmem_start_address =
                    (kal_uint32) med_alloc_int_mem(MAX_IMG_DEC_INT_MEM_SIZE);
                jpg_decode.intmem_size = img_context_p->intmem_size = MAX_IMG_DEC_INT_MEM_SIZE;
                img_context_p->extmem_start_address = (kal_uint32) med_alloc_ext_mem(MAX_PROG_JPG_DEC_EXT_MEM_SIZE);
                if (img_context_p->extmem_start_address)
                {
                    img_context_p->extmem_size = MAX_PROG_JPG_DEC_EXT_MEM_SIZE;
                }
                else
                {
                    if ((img_context_p->extmem_start_address =
                         (kal_uint32) med_alloc_ext_mem(MAX_IMG_DEC_EXT_MEM_SIZE)) == 0)
                    {
                        ASSERT(img_context_p->extmem_start_address > 0);
                    }
                    img_context_p->extmem_size = MAX_IMG_DEC_EXT_MEM_SIZE;
                }
                jpg_decode.extmem_start_address = img_context_p->extmem_start_address;
                jpg_decode.extmem_size = img_context_p->extmem_size;
                jpg_decode.image_buffer_address = img_context_p->image_buffer_address;
                jpg_decode.image_buffer_size = img_context_p->image_buffer_size;
                jpg_decode.image_width = img_context_p->display_width;
                jpg_decode.image_height = img_context_p->display_height;
                jpg_decode.image_clip_x1 = img_context_p->image_clip_x1;
                jpg_decode.image_clip_x2 = img_context_p->image_clip_x2;
                jpg_decode.image_clip_y1 = img_context_p->image_clip_y1;
                jpg_decode.image_clip_y2 = img_context_p->image_clip_y2;
                jpg_decode.jpeg_decode_cb = img_decode_callback;

                jpg_decode.jpeg_thumbnail_mode = req_p->jpeg_thumbnail_mode;
            #if MT6228_SERIES
                jpg_decode.image_pitch_mode = req_p->image_pitch_mode;
                jpg_decode.image_data_format = req_p->image_data_format;
                jpg_decode.image_pitch_bytes = req_p->image_pitch_bytes;

                jpg_decode.memory_output = req_p->memory_output;
                jpg_decode.memory_output_width = req_p->memory_output_width;
                jpg_decode.memory_output_height = req_p->memory_output_height;
                jpg_decode.memory_output_buffer_address = req_p->memory_output_buffer_address;
                jpg_decode.memory_output_buffer_size = req_p->memory_output_buffer_size;
            #endif /* MT6228_SERIES */ 
                if (img_context_p->blocking)
                {
                    waiting_time = IMG_CODEC_BLOCK_WAITING_TIME;
                }
                else
                {
                    waiting_time = IMG_CODEC_RETRY_TIME * ((img_context_p->file_size >> IMG_DECODE_FILE_UNIT) + 1);
                }

            #ifdef __MTK_TARGET__
                dec_ret = jpeg_decode_process(&jpg_decode);
            #endif 
                if (dec_ret == JPEG_DECODE_DECODING)
                {
                    img_context_p->processing = KAL_TRUE;
                    img_context_p->retry_conut = 0;
                    med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
                    IMG_ENTER_STATE(IMG_JPG_DECODE);
                    return MED_RES_OK;
                }
                else
                {
                    img_context_p->file_buffer_address = NULL;
                    img_release_memory();
                    result = img_get_decode_res(dec_ret);
                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -