File: Rotate90Left.java

package info (click to toggle)
java-imaging-utilities 0.14.3-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: java: 31,233; python: 71; xml: 31; makefile: 26; sh: 5
file content (70 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Rotate90Left
 * 
 * Copyright (c) 2001, 2002, 2003 Marco Schmidt.
 * All rights reserved.
 */

package net.sourceforge.jiu.geometry;

import net.sourceforge.jiu.data.PixelImage;
import net.sourceforge.jiu.data.IntegerImage;
import net.sourceforge.jiu.ops.ImageToImageOperation;
import net.sourceforge.jiu.ops.MissingParameterException;
import net.sourceforge.jiu.ops.WrongParameterException;

/**
 * Rotates images by 90 degrees counter-clockwise (to the left).
 * Input image must implement {@link net.sourceforge.jiu.data.IntegerImage}.
 * <h3>Usage example</h3>
 * <pre>
 * Rotate90Left rotate = new Rotate90Left();
 * rotate.setInputImage(image);
 * rotate.process();
 * PixelImage rotatedImage = rotate.getOutputImage();
 * </pre>
 * @author Marco Schmidt
 */
public class Rotate90Left extends ImageToImageOperation
{
	private void process(IntegerImage in, IntegerImage out)
	{
		final int WIDTH = in.getWidth();
		final int HEIGHT = in.getHeight();
		if (out == null)
		{
			out = (IntegerImage)in.createCompatibleImage(HEIGHT, WIDTH);
			setOutputImage(out);
		}
		int totalItems = in.getNumChannels() * HEIGHT;
		int processedItems = 0;
		for (int c = 0; c < in.getNumChannels(); c++)
		{
			for (int y = 0; y < HEIGHT; y++)
			{
				for (int x = 0; x < WIDTH; x++)
				{
					out.putSample(c, y, (WIDTH - x - 1), in.getSample(c, x, y));
				}
				setProgress(processedItems++, totalItems);
			}
		}
	}

	public void process() throws
		MissingParameterException,
		WrongParameterException
	{
		ensureInputImageIsAvailable();
		PixelImage in = getInputImage();
		ensureOutputImageResolution(in.getHeight(), in.getWidth());
		if (in instanceof IntegerImage)
		{
			process((IntegerImage)in, (IntegerImage)getOutputImage());
		}
		else
		{
			throw new WrongParameterException("Input image must implement IntegerImage.");
		}
	}
}