title: What is the most efficient way to handle a layer/image type?
body: <p><a href="https://github.com/Cave-Dweller/CaveArt/tree/dev" rel="nofollow">Code can be found under src/ from here.</a></p>
  
  <p>The way I have the pixel types set up is to have the bit depth-specific formats be used for loading images and serialization, and the float-based pixel type would be used to actually be modified and for conversion between the depth-specific types.</p>
  
  <p>Conceptually, <code>Layer</code> should hold the data relevant to the application (to be modified), but my issue is with efficiency with different areas- should I have <code>Layer</code> hold a two-dimensional pointer to the <code>PixelBase</code> type for easy loading and serialization, but ugly and seemingly inefficient conversion and modification (and also manual memory management), or should I hold a <code>std::vector&lt;std::vector&lt;PixelRGBAF&gt;&gt;</code> for simple conversion and modification, but seemingly ugly and inefficient loading and serialization?</p>
  
  <p>Examples of what I mean:</p>
  
  <pre><code>class Layer {
      PixelBase** data;
      int width, height;
      //...
  public:
      Layer(QImage&amp; qi) {
          width = qi.width();
          height = qi.height();
          if(qi.format() == QImage::Format_RGBA8888) {
              data = new PixelRGBA32[height];
              for(int i = 0; i &lt; width; ++i) {
                  data[i] = new PixelRGBA32[width];
              }
              //...
              for(int y = 0; y &lt; height; ++y) {
                  for(int x = 0; x &lt; 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
                  }
              }
          }
          //...
      }
  };
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>class Layer {
      std::vector&lt;std::vector&lt;PixelRGBAF&gt;&gt; data;
      int width, height;
      //...
  public:
      Layer(QImage&amp; qi) {
          width = qi.width();
          height = qi.height();
          if(qi.format() == QImage::Format_RGBA8888) {
              for(int y = 0; y &lt; height; ++y) {
                  for(int x = 0; x &lt; 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)
                  }
              }
          }
          //...
      }
  };
  </code></pre>
  
  <p>I do want a scripting language I'm building to interact with layers directly in the future, so in my thinking, using the <code>vector&lt;vector&lt;PixelRGBAF&gt;&gt;</code> option would be better in terms of efficiency for most use, but I have a feeling I'm skipping over some important detail and it's actually less efficient.</p>