处理图层/图像类型的最有效方法是什么?

时间:2014-02-09 04:24:49

标签: c++ qt memory-management vector

Code can be found under src/ from here.

我设置像素类型的方法是使用特定于位深度的格式来加载图像和序列化,并且基于浮点的像素类型将用于实际修改并用于深度之间的转换 - 特定类型。

从概念上讲,Layer应该保存与应用程序相关的数据(待修改),但我的问题是效率与不同的区域 - 我应该Layer持有二维指针指向PixelBase类型用于轻松加载和序列化,但是丑陋且看似效率低下的转换和修改(以及手动内存管理),或者我应该持有std::vector<std::vector<PixelRGBAF>>进行简单的转换和修改,但看似丑陋且低效的加载和序列化?

我的意思是:

class Layer {
    PixelBase** data;
    int width, height;
    //...
public:
    Layer(QImage& qi) {
        width = qi.width();
        height = qi.height();
        if(qi.format() == QImage::Format_RGBA8888) {
            data = new PixelRGBA32[height];
            for(int i = 0; i < width; ++i) {
                data[i] = new PixelRGBA32[width];
            }
            //...
            for(int y = 0; y < height; ++y) {
                for(int x = 0; x < width; ++x) {
                    QRgb temp = qi.pixel(x, y);
                    data[y][x] = PixelRGBA32{ temp.red(), temp.green(), temp.blue(), temp.alpha()};    //data is used once in initialization
                }
            }
        }
        //...
    }
};

class Layer {
    std::vector<std::vector<PixelRGBAF>> data;
    int width, height;
    //...
public:
    Layer(QImage& qi) {
        width = qi.width();
        height = qi.height();
        if(qi.format() == QImage::Format_RGBA8888) {
            for(int y = 0; y < height; ++y) {
                for(int x = 0; x < width; ++x) {
                    QRgb temp = qi.pixel(x, y);
                    PixelRGBA32 prgba= PixelRGBA32{ temp.red(), temp.green(), temp.blue(), temp.alpha()};    //this data is used once and thrown away, is an extra step in initialization
                    data[y][x] = prgba.getAsDepthAgnostic();    //data is copied into a larger chunk of data (32 * 4 instead of 8 * 4)
                }
            }
        }
        //...
    }
};

我确实想要一种脚本语言,我正在构建以便将来直接与图层进行交互,因此在我的想法中,使用vector<vector<PixelRGBAF>>选项在大多数用途的效率方面会更好,但我有一个感觉我正在跳过一些重要的细节,实际上效率不高。

0 个答案:

没有答案
相关问题