zoukankan      html  css  js  c++  java
  • RGB格式等比例缩放

    原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置。

     1 /*
     2  lrgb:   input 24bits rgb buffer
     3  srgb:   output 24bits rgb buffer
     4    input width
     5  height: input height
     6  xscale: changed vector
     7  yscale: changed vector
     8  */
     9 int lrgbtosrgb(unsigned char *lrgb, unsigned char *srgb, int width, int height, float xscale, float yscale)
    10 {
    11     int in = 0, out = 0;
    12     int ox, oy;     //the pixel site is after changed
    13     int rx, ry;     //the pixel site is before changed
    14     int temp = 0;   //turn site(x,y) to memory storage
    15     int outwidth = width * xscale;      //after changed width
    16     int outheight = height * yscale;    //after changed height
    17 
    18     //rx = ox/xscale + 0.5;// out--to--input
    19     //ry = oy/yscale + 0.5;// out--to--input
    20 
    21     for (oy = 0; oy < outheight; oy++)
    22     {
    23         ry = (int)(oy/0.5 + 0.5);
    24         if(ry >= height)
    25         ry--;
    26         temp = ry * width *3;//origion pixel site of which width
    27 
    28         for (ox = 0; ox < outwidth; ox++)
    29         {
    30             rx = (int)(ox/0.5 + 0.5);
    31             if (rx >= width)
    32                 rx--;
    33             in = temp + rx * 3;//change site(x,y) to storage
    34 
    35             srgb[out+0] = lrgb[in+0];
    36             srgb[out+1] = lrgb[in+1];
    37             srgb[out+2] = lrgb[in+2];
    38 
    39             out += 3;
    40         }
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    浏览器的渲染与小优化
    css3 贝塞尔曲线理解
    mac下配置汇编环境
    报错 net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
    vue中使用iframe,加载完成的onload事件偶尔不触发
    nrm的使用
    js原生实现元素跟随鼠标拖动
    webpack多页面打包笔记
    关于React的组件优化笔记
    React生成器
  • 原文地址:https://www.cnblogs.com/eustoma/p/6664446.html
Copyright © 2011-2022 走看看