How to move (or copy) pixels with exact color on new location?

Hello,
How to move pixels with exact color on other location.
e.g. all red pixels for 10 pixels to right and for 5 pixels to up on one image.
Thanks a lot.
Regards

You can do this with a small script, for example:

  red = Color.red.getRGB();
  img = IJ.getImage();
  ip = img.getProcessor();
  ip2 = ip.duplicate();
  // clear red pixels in original image
  for (i=0; i<ip.getPixelCount(); i++) {
    if (ip.get(i)==red)
       ip.set(i,0);
  }
  // move red pixels
  for (y=0; y<ip.getHeight(); y++) {
     for (x=0; x<ip.getWidth(); x++) {
       value = ip2.getPixel(x,y);
       if (value==red)
         ip.putPixel(x+10,y-5,value);
     }
 }
 img.updateAndDraw();

This can’t easily be done using the macro language because it requires working with a copy of the image.

Thanks a lot.
If someone has example how to do this with imagej macro language please welcome to share here also.
Regards