imagecommon.cpp

来自「在MTK平台上开放的一个皮肤工具,可以支持jpg、bmp、png图片」· C++ 代码 · 共 485 行 · 第 1/2 页

CPP
485
字号
#include "stdafx.h"
#include "mmi.h"

/*****************************************************************************
 * FUNCTION
 *  bytestream_initialize
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]         
 *  data        [?]         
 *  size        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void bytestream_initialize(bytestream *file, U8 *data, long int size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    file->data = data;
    file->size = size;
    file->current_offset = 0;
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fclose
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void bytestream_fclose(bytestream *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    file->data = NULL;
    file->size = 0;
    file->current_offset = 0;
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fseek
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]         
 *  offset      [IN]        
 *  mode        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
U8 bytestream_fseek(bytestream *file, long int offset, int mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    int start_offset, final_offset;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (mode)
    {
        case SEEK_END:
            start_offset = file->size - 1;
            break;
        case SEEK_SET:
            start_offset = 0;
            break;
        case SEEK_CUR:
        default:
            start_offset = file->current_offset;
            break;
    }
    final_offset = start_offset + offset;
    if (final_offset < 0 || final_offset >= file->size)
    {
        return (1);
    }
    else
    {
        file->current_offset = final_offset;
        return (0);
    }
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_feof
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]     
 * RETURNS
 *  
 *****************************************************************************/
U8 bytestream_feof(bytestream *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (file->current_offset >= file->size)
    {
        return (1);
    }
    else
    {
        return (0);
    }
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fgetbyte
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]     
 * RETURNS
 *  
 *****************************************************************************/
U8 bytestream_fgetbyte(bytestream *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 c;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (bytestream_feof(file))
    {
        return (0);
    }
    c = file->data[file->current_offset];
    file->current_offset++;
    return (c);
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fputbyte
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]         
 *  c           [IN]        
 * RETURNS
 *  
 *****************************************************************************/
U8 bytestream_fputbyte(bytestream *file, U8 c)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (bytestream_feof(file))
    {
        return (0);
    }
    file->data[file->current_offset] = c;
    file->current_offset++;
    return (1);
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fread
 * DESCRIPTION
 *  
 * PARAMETERS
 *  buffer      [?]         
 *  size        [IN]        
 *  number      [IN]        
 *  file        [?]         
 * RETURNS
 *  
 *****************************************************************************/
int bytestream_fread(U8 *buffer, int size, int number, bytestream *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    int count = 0, i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < (long)size * number; i++)
    {
        if (bytestream_feof(file))
        {
            break;
        }
        buffer[count++] = bytestream_fgetbyte(file);
    }
    return (count);
}


/*****************************************************************************
 * FUNCTION
 *  bytestream_fgetword
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file        [?]     
 * RETURNS
 *  
 *****************************************************************************/
U16 bytestream_fgetword(bytestream *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

⌨️ 快捷键说明

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