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

📄 img_msg_handler.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (max_file_buffer < MAX_IMG_ENC_FILE_BUFFER_LEN)
        max_file_buffer = MAX_IMG_ENC_FILE_BUFFER_LEN;

    /* open the file */
    img_context_p->file_handle = FS_Open((kal_wchar*) file_name, FS_CREATE | FS_READ_WRITE);

    kal_prompt_trace(MOD_MED, "img_open_image_file handle :%d \n", img_context_p->file_handle );

    if (img_context_p->file_handle >= 0)
    {
        img_context_p->file_buffer_address = NULL;
        while(1)
        {
            img_context_p->file_buffer_address=(kal_uint32)med_alloc_ext_mem(max_file_buffer);
            if(img_context_p->file_buffer_address==NULL)
            {
                max_file_buffer -= 25*1024;
                if (max_file_buffer < 0)
                {
                    max_file_buffer = 0;
                    break;
                }
            }
            else
            {
                break;
            }
        }

        img_context_p->file_buffer_size=max_file_buffer;
        if (img_context_p->file_buffer_address == NULL)
        {
            FS_Close(img_context_p->file_handle);
            FS_Delete((kal_wchar*) file_name);
            return MED_RES_MEM_INSUFFICIENT;
        }
        else
        {
            img_context_p->file_name_p = (kal_wchar*) file_name;
            return MED_RES_OK;
        }
    }
    else if (img_context_p->file_handle == FS_WRITE_PROTECTION)
    {
        return MED_RES_WRITE_PROTECTION;
    }
    else if (img_context_p->file_handle == FS_DISK_FULL)
    {
        return MED_RES_DISC_FULL;
    }
    else if (img_context_p->file_handle == FS_DRIVE_NOT_FOUND)
    {
        return MED_RES_NO_DISC;
    }
    else if (img_context_p->file_handle == FS_ROOT_DIR_FULL)
    {
        return MED_RES_ROOT_DIR_FULL;
    }
    else
    {
        return MED_RES_OPEN_FILE_FAIL;
    }

}


/*****************************************************************************
 * FUNCTION
 *  img_close_image_file
 * DESCRIPTION
 *  This function is to close image file for encode.
 * PARAMETERS
 *  size        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
kal_int32 img_close_image_file(kal_uint32 size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result;
    kal_uint32 len;
    kal_int32 res = MED_RES_OK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (size > 0)
    {
        result = FS_Write(img_context_p->file_handle, (void*)img_context_p->file_buffer_address, size, &len);
        FS_Close(img_context_p->file_handle);

        kal_prompt_trace(MOD_MED, "img_close_image_file error:%d \n", result);

        if (result != FS_NO_ERROR)
        {
            FS_Delete(img_context_p->file_name_p);
            if (result == FS_DRIVE_NOT_FOUND)
            {
                res = MED_RES_NO_DISC;
            }
            else if (result == FS_DISK_FULL)
            {
                res = MED_RES_DISC_FULL;
            }
            else if (img_context_p->file_handle == FS_ROOT_DIR_FULL)
            {
                res = MED_RES_ROOT_DIR_FULL;
            }
            else
            {
                res = MED_RES_OPEN_FILE_FAIL;
            }
        }
        else if (size != len)
        {
            FS_Delete(img_context_p->file_name_p);
            res = MED_RES_DISC_FULL;
        }
    }
    else
    {
        /* Close and delete the file */
        FS_Close(img_context_p->file_handle);
        FS_Delete((kal_wchar*) img_context_p->file_name_p);
        res = MED_RES_FAIL;
    }

    img_release_memory();
    return res;
}


/*****************************************************************************
 * FUNCTION
 *  img_release_memory
 * DESCRIPTION
 *  This function is to release memory for image decoding/encoding.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void img_release_memory(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (img_context_p->file_buffer_address)
    {
        med_free_ext_mem((void **)&img_context_p->file_buffer_address);
    }
    if (img_context_p->intmem_start_address)
    {
        med_free_int_mem((void **)&img_context_p->intmem_start_address);
    }
    if (img_context_p->extmem_start_address)
    {
        med_free_ext_mem((void **)&img_context_p->extmem_start_address);
    }
    #ifdef BEREMOVED
    if (img_context_p->image_buffer_address1)
    {
        med_free_ext_mem((void **)&img_context_p->image_buffer_address1);
    }
    #endif
}


/*****************************************************************************
 * FUNCTION
 *  img_get_decode_res
 * DESCRIPTION
 *  This function is to get the decode result.
 * PARAMETERS
 *  cause       [IN]        
 * RETURNS
 *  kal_int16
 *****************************************************************************/
kal_int16 img_get_decode_res(kal_uint8 cause)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_prompt_trace(MOD_MED, "img_get_decode_res :%d \n", cause);

    switch (cause)
    {
    #ifdef JPG_DECODE
        case JPEG_DECODE_SUCCESS:
        case JPEG_DECODE_DECODER_OVERFLOW_FAIL:
        case JPEG_DECODE_DECODER_BREAK_FAIL:
            return MED_RES_OK;
        case JPEG_DECODE_INT_BUFFER_NOT_ENOUGH:
        case JPEG_DECODE_EXT_BUFFER_NOT_ENOUGH:
            return MED_RES_MEM_INSUFFICIENT;
        case JPEG_DECODE_TARGET_BUFFER_NOT_ENOUGH:
        case JPEG_DECODE_SRC_WIDHT_TOO_LARGE_FAIL:
        case JPEG_DECODE_SRC_HEIGHT_TOO_LARGE_FAIL:
        case JPEG_DECODE_TARGET_WIDTH_TOO_LARGE_FAIL:
        case JPEG_DECODE_TARGET_HEIGHT_TOO_LARGE_FAIL:
        case JPEG_DECODE_BUFFER_SIZE_FAIL:
            return MED_RES_BUFFER_INSUFFICIENT;
    #endif /* JPG_DECODE */ 
        default:
            return MED_RES_FAIL;
    }
}


/*****************************************************************************
 * FUNCTION
 *  img_get_encode_res
 * DESCRIPTION
 *  This function is to get the encode result.
 * PARAMETERS
 *  cause       [IN]        
 * RETURNS
 *  kal_int16
 *****************************************************************************/
kal_int16 img_get_encode_res(kal_uint8 cause)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_prompt_trace(MOD_MED, "img_get_encode_res :%d \n", cause);

    switch (cause)
    {
    #ifdef JPG_ENCODE
        case JPEG_ENCODE_DONE:
            return MED_RES_OK;
        case JPEG_ENCODE_STALL:
            return MED_RES_FAIL;
    #endif /* JPG_ENCODE */ 
        default:
            return MED_RES_FAIL;
    }
}


/*****************************************************************************
 * FUNCTION
 *  img_decode_callback
 * DESCRIPTION
 *  This function is the callback function of decoding.
 * PARAMETERS
 *  cause       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void img_decode_callback(kal_uint8 cause)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    img_context_p->processing = KAL_FALSE;
    img_send_decode_event_ind(cause, 0, 0);
}


/*****************************************************************************
 * FUNCTION
 *  img_decode_restart
 * DESCRIPTION
 *  This function is to restart decode process for retrying.
 * PARAMETERS
 *  void
 *  kal_uint8 cause(?)
 * RETURNS
 *  void
 *****************************************************************************/
void img_decode_restart(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 waiting_time;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    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);
    }

    if (img_context_p->media_mode == MED_MODE_FILE)
    {
    #ifdef JPG_DECODE
        if (img_context_p->media_type == MED_TYPE_JPG)
        {
            /* init jpeg */
            kal_int16 result;
            kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;

        #ifdef __MTK_TARGET__
            dec_ret = jpeg_decode_process(&jpg_decode);
        #endif 
            if (dec_ret == JPEG_DECODE_DECODING)
            {
                img_context_p->processing = KAL_TRUE;
                med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
            }
            else
            {
                img_release_memory();
                result = img_get_decode_res(dec_ret);
                if (!img_context_p->blocking)
                {
                    img_send_decode_finish_ind(result, img_context_p->seq_num);
                }
                else
                {
                    img_set_result(result);
                    IMG_SET_EVENT(IMG_EVT_DECODE);
                }
                IMG_ENTER_STATE(IMG_IDLE);
            }
        }
        else
    #endif /* JPG_DECODE */ 
        {
            img_release_memory();
            if (!img_context_p->blocking)
            {
                img_send_decode_finish_ind(MED_RES_INVALID_FORMAT, img_context_p->seq_num);
            }
            else
            {
                img_set_result(MED_RES_INVALID_FORMAT);
                IMG_SET_EVENT(IMG_EVT_DECODE);
            }
            IMG_ENTER_STATE(IMG_IDLE);
        }
    }
    else if (img_context_p->media_mode == MED_MODE_ARRAY)
    {
    #ifdef JPG_DECODE
        if (img_context_p->media_type == MED_TYPE_JPG)
        {
            /* init jpeg */
            kal_int16 result;
            kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;

        #ifdef __MTK_TARGET__
            dec_ret = jpeg_decode_process(&jpg_decode);
        #endif 

⌨️ 快捷键说明

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