001 /* 002 * Rotate90Right 003 * 004 * Copyright (c) 2001, 2002, 2003 Marco Schmidt. 005 * All rights reserved. 006 */ 007 008 package net.sourceforge.jiu.geometry; 009 010 import net.sourceforge.jiu.data.PixelImage; 011 import net.sourceforge.jiu.data.IntegerImage; 012 import net.sourceforge.jiu.ops.ImageToImageOperation; 013 import net.sourceforge.jiu.ops.MissingParameterException; 014 import net.sourceforge.jiu.ops.WrongParameterException; 015 016 /** 017 * Rotates images by 90 degrees clockwise (to the right). 018 * Input image must implement {@link net.sourceforge.jiu.data.IntegerImage}. 019 * <h3>Usage example</h3> 020 * <pre> 021 * Rotate90Right rotate = new Rotate90Right(); 022 * rotate.setInputImage(image); 023 * rotate.process(); 024 * PixelImage rotatedImage = rotate.getOutputImage(); 025 * </pre> 026 * @author Marco Schmidt 027 */ 028 public class Rotate90Right extends ImageToImageOperation 029 { 030 private void process(IntegerImage in, IntegerImage out) 031 { 032 final int WIDTH = in.getWidth(); 033 final int HEIGHT = in.getHeight(); 034 if (out == null) 035 { 036 out = (IntegerImage)in.createCompatibleImage(HEIGHT, WIDTH); 037 setOutputImage(out); 038 } 039 int totalItems = in.getNumChannels() * HEIGHT; 040 int processedItems = 0; 041 for (int c = 0; c < in.getNumChannels(); c++) 042 { 043 for (int y = 0; y < HEIGHT; y++) 044 { 045 for (int x = 0; x < WIDTH; x++) 046 { 047 out.putSample(c, (HEIGHT - y - 1), x, in.getSample(c, x, y)); 048 } 049 setProgress(processedItems++, totalItems); 050 } 051 } 052 } 053 054 public void process() throws 055 MissingParameterException, 056 WrongParameterException 057 { 058 ensureInputImageIsAvailable(); 059 PixelImage in = getInputImage(); 060 ensureOutputImageResolution(in.getHeight(), in.getWidth()); 061 if (in instanceof IntegerImage) 062 { 063 process((IntegerImage)in, (IntegerImage)getOutputImage()); 064 } 065 else 066 { 067 throw new WrongParameterException("Input image must implement IntegerImage."); 068 } 069 } 070 }