/*
Rotate an image passed in imgBuf and pass a Buffer with the result  to 'callback'. If
there are any problems, just return the original buffer unmodified.

Preserves the content type (png, jpeg, bmp) of the original image.
974539
function rotateImage(contentType, imgBuf, callback) {
    try {
        new Jimp(imgBuf, function (err, image) {
            if (err) {
                console.log('Image loading error: ' + err);
                callback(imgBuf);
            } else {
                image.rotate(180)
                .getBuffer(contentType, function (err, rotated) {
                    if (err) {
                        console.log('Image processing error: ' + err);
                        callback(imgBuf);
                    } else {
                        callback(rotated);
                    }
                });
            }
        });
    } catch (err) {
        /*
          Sometimes Jimp throws instead of passing error via the callback as it should.
          Sigh. e.g: "Image loading error: Error: Unsupported interlace method"
         */
        console.log('Jimp threw an error: ' + err);
        callback(imgBuf);
    }
}
583174
private boolean rotateUntilInLowerCorner(Result result) {
		// sanity check corners.  There should only be one exactly one black
		final int topLeft = getTotalGridElements() - gridWidth;
		final int topRight = getTotalGridElements() - 1;
		final int bottomLeft = 0;
		final int bottomRight = gridWidth - 1;

		if (classified[bottomLeft] + classified[bottomRight] + classified[topRight] + classified[topLeft] != 1)
			return true;

		// Rotate until the black corner is in the lower left hand corner on the image.
		// remember that origin is the top left corner
		result.rotation = 0;
		while (classified[topLeft] != 1) {
			result.rotation++;
			rotateClockWise();
		}
		return false;
	}
730753
public static BitmapTextureCallback wrapCallback(
            ResourceCache<GVRImage> cache, BitmapTextureCallback callback) {
        return new BitmapTextureCallbackWrapper(cache, callback);
    }
873269
protected BufferedImage rotate(double angle) {
        BufferedImage target = new BufferedImage(height, width, awt.getType());
        Graphics2D g2 = (Graphics2D) target.getGraphics();
        final int offsetx, offsety;
        if (angle < 0) {
            offsetx = 0;
            offsety = width;
        } else if (angle > 0) {
            offsetx = height;
            offsety = 0;
        } else {
            offsetx = 0;
            offsety = 0;
        }
        g2.translate(offsetx, offsety);
        g2.rotate(angle);
        g2.drawImage(awt, 0, 0, null);
        g2.dispose();
        return target;
    }
739712
function loadImage ($imageElement, newSource, callback) {
        $imageElement.fadeOut(function () {
            $imageElement.attr("src", newSource);
            imgLoad($imageElement, function () {
                $imageElement.removeClass("loading");
                $imageElement.fadeIn();
                if (typeof callback === "function") {
                    callback();
                }
            });
        });
    }
546743
public static void rotateCCW( GrayS64 image ) {
		if( image.width != image.height )
			throw new IllegalArgumentException("Image must be square");

		int w = image.height/2 + image.height%2;
		int h = image.height/2;

		for( int y0 = 0; y0 < h; y0++ ) {
			int y1 = image.height-y0-1;

			for( int x0 = 0; x0 < w; x0++ ) {
				int x1 = image.width-x0-1;

				int index0 = image.startIndex + y0*image.stride + x0;
				int index1 = image.startIndex + x0*image.stride + y1;
				int index2 = image.startIndex + y1*image.stride + x1;
				int index3 = image.startIndex + x1*image.stride + y0;
				
				long tmp0 = image.data[index0];

				image.data[index0] = image.data[index1];
				image.data[index1] = image.data[index2];
				image.data[index2] = image.data[index3];
				image.data[index3] = (long)tmp0;
			}
		}
	}
469609
def post_process(self):
        
        self.image.putdata(self.pixels)
        self.image = self.image.transpose(Image.ROTATE_90)
145935
function(callback) {

      if (this.filters.length === 0) {
        this.setElement(this._originalImage);
        callback && callback();
        return;
      }

      var isLikelyNode = typeof Buffer !== 'undefined' && typeof window === 'undefined',
          imgEl = this._originalImage,
          canvasEl = fabric.document.createElement('canvas'),
          replacement = isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img'),
          _this = this;

        if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
          G_vmlCanvasManager.initElement(canvasEl);
        }

      canvasEl.width = imgEl.width;
      canvasEl.height = imgEl.height;

      canvasEl.getContext('2d').drawImage(imgEl, 0, 0, imgEl.width, imgEl.height);

      this.filters.forEach(function(filter) {
        filter && filter.applyTo(canvasEl);
      });

       /** @ignore */
      replacement.onload = function() {
        _this._element = replacement;
        callback && callback();
        replacement.onload = canvasEl = imgEl = null;
      };
      replacement.width = imgEl.width;
      replacement.height = imgEl.height;

      if (isLikelyNode) {
        var base64str = canvasEl.toDataURL('image/png').replace(/data:image\/png;base64,/, '');
        replacement.src = new Buffer(base64str, 'base64');
        _this._element = replacement;

        // onload doesn't fire in node, so we invoke callback manually
        callback && callback();
      }
      else {
        replacement.src = canvasEl.toDataURL('image/png');
      }

      return this;
    }
822422
function( shot, callback ) {

        var scope = this;

        scope.getShotBuffer( shot, function( err, data ) {

            if( err ) {

                callback( err );

                return;

            }

            var base64 = scope.getBase64FromBuffer( data );

            callback( null, base64 );

        });

    }
182070
function(file, callback, quality) {
		quality = !quality?85:quality;
		
		var data = this.jpeg_encode.encode(this, quality);
		
		var fd =  this.fs.openSync(file, 'w');
		var bf = new Buffer(data);
		
		this.fs.writeSync(fd, bf, 0, bf.length);
		this.fs.closeSync(fd);
		
		if(callback) {
			callback.call(this);
		}
	}
327588
def do_rotation(self, mirror, rot):
        """"""
        if (not mirror and rot == 0.0):
            self.logger.debug("rotation: no rotation (nop)")
        else:
            # FIXME - with PIL one can use the transpose() method to do 90deg
            # FIXME - rotations as well as mirroring. This would be more efficient
            # FIXME - for these cases than mirror _then_ rotate.
            if (mirror):
                self.logger.debug("rotation: mirror (about vertical axis)")
                self.image = self.image.transpose(Image.FLIP_LEFT_RIGHT)
            if (rot != 0.0):
                self.logger.debug("rotation: by %f degrees clockwise" % (rot))
                self.image = self.image.rotate(-rot, expand=True)
584183
function exifRotate(img) {
  const exif = img._exif;

  if (exif && exif.tags && exif.tags.Orientation) {
    switch (img._exif.tags.Orientation) {
      case 1: // Horizontal (normal)
        // do nothing
        break;
      case 2: // Mirror horizontal
        img.mirror(true, false);
        break;
      case 3: // Rotate 180
        img.rotate(180, false);
        break;
      case 4: // Mirror vertical
        img.mirror(false, true);
        break;
      case 5: // Mirror horizontal and rotate 270 CW
        img.rotate(-90, false).mirror(true, false);
        break;
      case 6: // Rotate 90 CW
        img.rotate(-90, false);
        break;
      case 7: // Mirror horizontal and rotate 90 CW
        img.rotate(90, false).mirror(true, false);
        break;
      case 8: // Rotate 270 CW
        img.rotate(-270, false);
        break;
      default:
        break;
    }
  }

  return img;
}
519356
def __callback (self, rgb, d):
        '''
        

        '''
        data = Images2Rgbd(rgb, d)

        self.lock.acquire()
        self.data = data
        self.lock.release()
1270988
public static BufferedImage rotateImage(BufferedImage image, double angle) {
        double theta = Math.toRadians(angle);
        double sin = Math.abs(Math.sin(theta));
        double cos = Math.abs(Math.cos(theta));
        int w = image.getWidth();
        int h = image.getHeight();
        int newW = (int) Math.floor(w * cos + h * sin);
        int newH = (int) Math.floor(h * cos + w * sin);

        BufferedImage tmp = new BufferedImage(newW, newH, image.getType());
        Graphics2D g2d = tmp.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.translate((newW - w) / 2, (newH - h) / 2);
        g2d.rotate(theta, w / 2, h / 2);
        g2d.drawImage(image, 0, 0, null);
        g2d.dispose();
        return tmp;
    }
816295
function handleImageLoad(adElement, adLoadedCallback) {
    var adImage = adElement.querySelector("img");
    if (adImage) {
        (function (adToInsert, adImage) {
            adImage.onload = function () {
                adLoadedCallback(adToInsert, true);
            };
        })(adElement, adImage);
    } else {
        adLoadedCallback(adElement, false);
    }
}
1246944
function encode(buf, options, cb) {
  try {
    const imageData = {
      data: buf,
      width: options.width,
      height: options.height
    };
    const data = (0, _encoder2.default)(imageData, options.quality);
    cb(null, data);
  } catch (err) {
    cb(err);
  }
}
22254
function BmpDecoder(buffer,is_with_alpha) {
  this.pos = 0;
  this.buffer = buffer;
  this.is_with_alpha = !!is_with_alpha;
  this.bottom_up = true;
  this.flag = this.buffer.toString("utf-8", 0, this.pos += 2);
  if (this.flag != "BM") throw new Error("Invalid BMP File");
  this.parseHeader();
  this.parseRGBA();
}