博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ImageX分块处理和保存
阅读量:5171 次
发布时间:2019-06-13

本文共 4579 字,大约阅读时间需要 15 分钟。

COneTif* pOt = new COneTif();    pOt->m_strTifPath = m_pOt->m_strTifPath;    if (!pOt->Initilize())    {        return;    }    const int nBlock = 1024;    const int& nImgWidth = pOt->m_nImgWidth;    const int& nImgHeight = pOt->m_nImgHeight;    const int& nBandNum = pOt->m_nBandNum;    const int& nBPB = pOt->m_nBPB;    BYTE* pBlockBufferRead = new BYTE[nImgWidth * nBandNum * nBPB * nBlock];    BYTE* pBlockBufferWrite = new BYTE[nImgWidth * nBandNum * nBPB * nBlock];    memset(pBlockBufferRead, 0, sizeof(BYTE)* nImgWidth * nBandNum * nBPB * nBlock);    memset(pBlockBufferWrite, 0, sizeof(BYTE)* nImgWidth * nBandNum * nBPB * nBlock);    int nBPP = nBPB * nBandNum;    IImageX* pImage = nullptr;    HRESULT hRes = CoCreateInstance(CLSID_ImageDriverX, NULL, CLSCTX_ALL, IID_IImageX, (void**)&pImage);    if (FAILED(hRes))    {        return;    }    hRes = pImage->CreateImg(szFileName.GetBuffer(), modeCreate, nImgWidth, nImgHeight, 0, nBandNum, BIP, 0, 0, 1);    if (hRes == S_FALSE)    {        return;    }    int nRowBlockNum = (nImgHeight + nBlock - 1) / nBlock;    for (int j = 0; j < nRowBlockNum; ++j)    {        memset(pBlockBufferRead, 0, sizeof(BYTE)* nImgWidth * nBandNum * nBPB * nBlock);        memset(pBlockBufferWrite, 0, sizeof(BYTE)* nImgWidth * nBandNum * nBPB * nBlock);        pOt->m_pImage->ReadImg(0, j * nBlock, nImgWidth, j * nBlock + nBlock, pBlockBufferRead, nImgWidth, nBlock, nBandNum, 0, 0, nImgWidth, nBlock, -1, 0);        for (int m = 0; m < nBlock; m++)        {            BYTE *pBufferWriteIndex = pBlockBufferWrite + m * nImgWidth * nBPP;            BYTE *pBufferBlockIndex = pBlockBufferRead + m * nImgWidth * nBPP;            for (int n = 0; n < nImgWidth; n++)            {                BYTE *pSubBufferWriteIndex = pBufferWriteIndex + n * nBPP;                BYTE *pSubBufferBlockIndex = pBufferBlockIndex + n * nBPP;                //对每一个像素进行计算                if (nBandNum == 3)                {                    //此时rgba实际上为rgb,bmp格式存放的是bgr                    const BYTE* rgba = pSubBufferBlockIndex;                    double rgb[3];                    rgb[0] = m_arrWeight[0] * rgba[0] + m_arrWeight[1] * rgba[1] + m_arrWeight[2] * rgba[2];                    rgb[1] = m_arrWeight[4] * rgba[0] + m_arrWeight[5] * rgba[1] + m_arrWeight[6] * rgba[2];                    rgb[2] = m_arrWeight[8] * rgba[0] + m_arrWeight[9] * rgba[1] + m_arrWeight[10] * rgba[2];                    for (int k = 0; k < nBandNum; ++k)                    {                        rgb[k] = rgb[k] > 255.0 ? 255.0 : rgb[k];                        pSubBufferWriteIndex[k] = (BYTE)rgb[k];                    }                }                else if (nBandNum == 4)                {                    //加入的调色代码                    const BYTE* rgba = pSubBufferBlockIndex;                    double rgb[4];                    rgb[0] = m_arrWeight[0] * rgba[0] + m_arrWeight[1] * rgba[1] + m_arrWeight[2] * rgba[2] + m_arrWeight[3] * rgba[3];                    rgb[1] = m_arrWeight[4] * rgba[0] + m_arrWeight[5] * rgba[1] + m_arrWeight[6] * rgba[2] + m_arrWeight[7] * rgba[3];                    rgb[2] = m_arrWeight[8] * rgba[0] + m_arrWeight[9] * rgba[1] + m_arrWeight[10] * rgba[2] + m_arrWeight[11] * rgba[3];                    rgb[3] = m_arrWeight[12] * rgba[0] + m_arrWeight[13] * rgba[1] + m_arrWeight[14] * rgba[2] + m_arrWeight[15] * rgba[3];#ifdef _MATRIX_                    double ivv[3];                    RGBtoIHS(rgb[0], rgb[1], rgb[2], ivv);                    ivv[2] = ivv[2] / 4;                    IHStoRGB(ivv, rgb);                    rgb[0] = 16 * sqrt(rgb[0]);                    rgb[1] = 16 * sqrt(rgb[1]);                    rgb[2] = 16 * sqrt(rgb[2]);#endif // _MATRIX_                    for (int k = 0; k < nBandNum; ++k)                    {                        rgb[k] = rgb[k] > 255.0 ? 255.0 : rgb[k];                        pSubBufferWriteIndex[k] = (BYTE)rgb[k];                    }                }            }        }        pImage->WriteImg(0, j * nBlock, nImgWidth, j * nBlock + nBlock, pBlockBufferWrite, nImgWidth, nBlock, nBandNum, 0, 0, nImgWidth, nBlock, -1, 0);    }    if (pBlockBufferRead)    {        delete[] pBlockBufferRead;        pBlockBufferRead = nullptr;    }    if (pBlockBufferWrite)    {        delete[] pBlockBufferWrite;        pBlockBufferWrite = nullptr;    }    delete pOt;    pOt = nullptr;    if (pImage != NULL)    {        pImage->Close();        pImage->Release();        pImage = NULL;    }    AfxMessageBox(_T("OK"));

 

转载于:https://www.cnblogs.com/autumoonchina/p/8005146.html

你可能感兴趣的文章
Hero In Maze
查看>>
学习使用autotools
查看>>
166. Fraction to Recurring Decimal
查看>>
redis集群原理
查看>>
Spark基础知识
查看>>
jQuery快速入门
查看>>
《软件需求分析》读书笔记NO.4
查看>>
qt初步---Qt实现软件从Windows到Linux跨平台
查看>>
16.1 Class类与Java反射
查看>>
CentosOS 7: 创建Nginx+Https网站
查看>>
向数据源DataTable 中添加新的一列,并向其赋值
查看>>
(C/C++) Link List - C 語言版本
查看>>
Spring 各种包功能
查看>>
[leedcode 122] Best Time to Buy and Sell Stock II
查看>>
[leedcode 137] Single Number II
查看>>
[转载]如何捕获控制台消息
查看>>
myeclipse激活+Aptana安装配置
查看>>
嵊州D1T1 总统先生,一路走好!
查看>>
Python字符串图解
查看>>
[家里蹲大学数学杂志]第270期张恭庆编《泛函分析讲义》2.5节以前的习题参考解答...
查看>>