void ofPixels_<PixelType>::mirrorTo(ofPixels_<PixelType> & dst, bool vertically, bool horizontal) const{ if(&dst == this){ dst.mirror(vertically,horizontal); return; } if (!vertically && !horizontal){ dst = *this; return; } int bytesPerPixel = getNumChannels(); dst.allocate(width, height, getPixelFormat()); if(vertically && !horizontal){ auto dstLines = dst.getLines(); auto lineSrc = getConstLines().begin(); auto line = --dstLines.end(); auto stride = line.getStride(); for(; line>=dstLines.begin(); --line, ++lineSrc){ memcpy(line.begin(), lineSrc.begin(), stride); } }else if (!vertically && horizontal){ int wToDo = width/2; int hToDo = height; for (int i = 0; i < wToDo; i++){ for (int j = 0; j < hToDo; j++){ int pixelb = i; int pixela = j*width + i; for (int k = 0; k < bytesPerPixel; k++){ dst[pixela*bytesPerPixel + k] = pixels[pixelb*bytesPerPixel + k]; dst[pixelb*bytesPerPixel + k] = pixels[pixela*bytesPerPixel + k]; } } } } else { // I couldn't think of a good way to do this in place. I'm sure there is. mirrorTo(dst,true, false); dst.mirror(false, true); } }
void ofPixels_<PixelType>::mirrorTo(ofPixels_<PixelType> & dst, bool vertically, bool horizontal) const{ if(&dst == this){ dst.mirror(vertically,horizontal); return; } if (!vertically && !horizontal){ dst = *this; return; } int bytesPerPixel = getNumChannels(); if (! (vertically && horizontal)){ int wToDo = horizontal ? width/2 : width; int hToDo = vertically ? height/2 : height; for (int i = 0; i < wToDo; i++){ for (int j = 0; j < hToDo; j++){ int pixelb = (vertically ? (height - j - 1) : j) * width + (horizontal ? (width - i - 1) : i); int pixela = j*width + i; for (int k = 0; k < bytesPerPixel; k++){ dst[pixela*bytesPerPixel + k] = pixels[pixelb*bytesPerPixel + k]; dst[pixelb*bytesPerPixel + k] = pixels[pixela*bytesPerPixel + k]; } } } } else { // I couldn't think of a good way to do this in place. I'm sure there is. mirrorTo(dst,true, false); dst.mirror(false, true); } }