小工具知识网

当前位置: 首页 > 行业知识 > 缩放算法优化步骤详解

行业知识

缩放算法优化步骤详解

2026-11-12 18:13:43 来源:互联网转载

���加链接描述

背景

假设数据存放在在unsigned char* m_pData 里面,宽和高分别是:m_nDataWidth m_nDataHeight

给定缩放比例:fXZoom fYZoom,返回缩放后的unsigned char* dataZoom

这里采用最简单的缩放算法即:

根据比例计算原图和缩放后图坐标的对应关系:缩放后图坐标*缩放比例 = 原图坐标

原始代码 未优化

#pragma onceclass zoomBlock{public:zoomBlock() {};~zoomBlock();void zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom);void zoomData(unsigned char* dataZoom, float  fXZoom, float fYZoom);void test(float  fXZoom =0.5, float fYZoom=0.5);void init(int DataWidth, int DataHeight);private:void computeSrcValues(int* srcValues, size_t size, float zoom, int dataSize);private:unsigned char* m_pData = nullptr;float m_fXZoom = 1 ;//x轴缩放比例  m_nXZoom=1时 不缩放float m_fYZoom = 1 ;//y轴缩放比例int m_nDataWidth = 0;int m_nDataHeight = 0;};#include "zoomBlock.h"#include #include #include#define SAFE_DELETE_ARRAY(p) { if( (p) != NULL ) delete[] (p); (p) = NULL; }zoomBlock::~zoomBlock(){SAFE_DELETE_ARRAY(m_pData);}void zoomBlock::init(int DataWidth, int DataHeight){m_nDataWidth = DataWidth;m_nDataHeight = DataHeight;m_pData = new unsigned char[m_nDataWidth* m_nDataHeight];for (int i = 0; i 

上一篇:响应式网站自适应布局制作宝典,轻松上手响应式主题!

下一篇:揭秘微赞分享榜单观看秘籍!