zoukankan      html  css  js  c++  java
  • alphaRGB 转 RGB、16位

    struct xColor
    {
    BYTE b, g, r, a;
    };
    struct RGBColor
    {
    BYTE b, g, r;
    };
    //void operator <<(RGBColor& rgb, xColor& color)
    //{
    // rgb.r = color.a * 1.0 / 0xFF * color.r;
    // rgb.g = color.a * 1.0 / 0xFF * color.g;
    // rgb.b = color.a * 1.0 / 0xFF * color.b;
    //}

    void operator <<(RGBColor& rgb, xColor& color)
    {
    rgb.r = 0xFF;
    rgb.g = 0x0;
    rgb.b = 0x0;
    }


    void alphaRGB2RGB(unsigned char* src, unsigned char* dest, int sizePixel)
    {
    assert(src != NULL && dest != NULL);
    xColor* pColor = (xColor*)src;
    RGBColor* pRGBColor = (RGBColor*)dest;
    while (--sizePixel >= 0)
    {
    *pRGBColor << *pColor;
    //printf("pColor r[%d] g[%d] b[%d] a[%d] ", pColor->r, pColor->g, pColor->b, pColor->a);
    //printf("prgbColor r[%d] g[%d] b[%d] ", pRGBColor->r, pRGBColor->g, pRGBColor->b);
    ++pRGBColor;
    ++pColor;
    }
    }
    unsigned short
    RGB888toRGB565(xColor& color)
    {
    unsigned short B = ( (color.a / 0xFF * color.b) >> 3) & 0x001F;
    unsigned short G = (( (color.a / 0xFF * color.g) >> 2) << 5) & 0x07E0;
    unsigned short R = (( (color.a / 0xFF * color.r) >> 3) << 11) & 0xF800;

    return (unsigned short) (R | G | B);
    }

    void alphaRGB2RGB565(unsigned char* src, unsigned char* dest, int xWidth, int yHeight, int nLineWidthByte)
    {
    assert(src != NULL && dest != NULL);
    printf("xWidth[%d] xHeight[%d] nLineWidthByte[%d]", xWidth, yHeight, nLineWidthByte);
    xColor* pColor = (xColor*)src;
    BYTE* pDstLineByte = (BYTE*)dest;
    for(int y =0; y < yHeight; ++y)
    {
    unsigned short* pDstPixel = (unsigned short*)pDstLineByte;

    for(int x = 0; x < xWidth; ++x)
    {
    *pDstPixel = RGB888toRGB565(*pColor);
    ++pDstPixel;
    ++pColor;
    }
    pDstLineByte += nLineWidthByte;
    }
    }

    unsigned short
    RGB888toRGB565(unsigned char red, unsigned char green, unsigned char blue)
    {
    unsigned short B = (blue >> 3) & 0x001F;
    unsigned short G = ((green >> 2) << 5) & 0x07E0;
    unsigned short R = ((red >> 3) << 11) & 0xF800;

    return (unsigned short) (R | G | B);
    }

  • 相关阅读:
    JMeter使用正则表达式提取相应信息
    Python的configparser生成配置文件,以及相关操作
    Python函数主要的作用
    Python函数传参位置关系总结
    Python中的作用域
    Python高阶函数解析
    Python中set集合的增加,update和add的区别
    Oracle 11g服务详细介绍及哪些服务是必须开启的?
    javacc jjtree 写法 以及 jj写法 基本语法 以及应用
    Python 3.3 try catch所有的错误Error,不包括Exception。关键在于 sys.exc_info()
  • 原文地址:https://www.cnblogs.com/hqu-ye/p/5607884.html
Copyright © 2011-2022 走看看