1 | package org.expeditee.gio;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.net.HttpURLConnection;
|
---|
6 | import java.net.URL;
|
---|
7 |
|
---|
8 | import org.expeditee.core.Colour;
|
---|
9 | import org.expeditee.core.Dimension;
|
---|
10 | import org.expeditee.core.Image;
|
---|
11 |
|
---|
12 | import com.sun.pdfview.PDFPage;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Manager in charge of creating and working with images in memory. Maintains a mapping
|
---|
16 | * from org.expeditee.core.Image handles to the underlying images, and provides methods
|
---|
17 | * for manipulating the underlying images through those handles.
|
---|
18 | *
|
---|
19 | * @author cts16
|
---|
20 | */
|
---|
21 | public abstract class ImageManager {
|
---|
22 |
|
---|
23 | /*
|
---|
24 | *
|
---|
25 | * Image-creation functions
|
---|
26 | *
|
---|
27 | */
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Creates an image of the given size in either main or video RAM.
|
---|
31 | *
|
---|
32 | * @param hintUseAcceleratedMemory
|
---|
33 | * True to use video RAM, false for main memory.
|
---|
34 | */
|
---|
35 | public Image createImage(Dimension size, boolean hintUseAcceleratedMemory)
|
---|
36 | {
|
---|
37 | if (size == null) return null;
|
---|
38 |
|
---|
39 | return createImage(size.width, size.height, hintUseAcceleratedMemory);
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Creates an image of the given width and height in either main or video RAM.
|
---|
44 | *
|
---|
45 | * @param hintUseAcceleratedMemory
|
---|
46 | * True to use video RAM, false for main memory.
|
---|
47 | */
|
---|
48 | public abstract Image createImage(int width, int height, boolean hintUseAcceleratedMemory);
|
---|
49 |
|
---|
50 | /** Creates an image in main memory with the given size. */
|
---|
51 | public Image createImage(Dimension size)
|
---|
52 | {
|
---|
53 | return createImage(size, false);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /** Creates an image in main memory with the given width and height. */
|
---|
57 | public Image createImage(int width, int height)
|
---|
58 | {
|
---|
59 | return createImage(width, height, false);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** Creates an image from packed 32-bit ARGB data in an array. */
|
---|
63 | public abstract Image createImage(int width, int height, int[] pixelData);
|
---|
64 |
|
---|
65 | /** Creates an image of a PDF page. */
|
---|
66 | public abstract Image createImage(int width, int height, PDFPage page);
|
---|
67 |
|
---|
68 | /** Creates a new image which is a cropped section of another image. */
|
---|
69 | public abstract Image createImageAsCroppedCopy(Image orig, int x, int y, int width, int height);
|
---|
70 |
|
---|
71 | /** Gets image data from a URL. */
|
---|
72 | public abstract Image getImage(URL url);
|
---|
73 |
|
---|
74 | /** Gets image data from a file. */
|
---|
75 | public abstract Image getImage(String filename);
|
---|
76 |
|
---|
77 | /** Gets image data from a HTTP connection. */
|
---|
78 | public abstract Image getImage(HttpURLConnection connection) throws IOException;
|
---|
79 |
|
---|
80 | /*
|
---|
81 | *
|
---|
82 | * Image-destruction functions
|
---|
83 | *
|
---|
84 | */
|
---|
85 |
|
---|
86 | /** Tells the image manager that the given image is no longer needed. */
|
---|
87 | public abstract void releaseImage(Image image);
|
---|
88 |
|
---|
89 | /*
|
---|
90 | *
|
---|
91 | * Image info getters
|
---|
92 | *
|
---|
93 | */
|
---|
94 |
|
---|
95 | /** Checks if the given handle corresponds to a real image in the image manager. */
|
---|
96 | public abstract boolean isImageValid(Image image);
|
---|
97 |
|
---|
98 | /** Gets the width of the given image. */
|
---|
99 | public abstract int getWidth(Image image);
|
---|
100 |
|
---|
101 | /** Gets the height of the given image. */
|
---|
102 | public abstract int getHeight(Image image);
|
---|
103 |
|
---|
104 | /** Gets the colours of an area of pixels from the image. */
|
---|
105 | public abstract Colour[] getPixels(Image image, int x, int y, int width, int height);
|
---|
106 |
|
---|
107 | /** Gets the colour of a single pixel in the image. */
|
---|
108 | public Colour getPixel(Image image, int x, int y)
|
---|
109 | {
|
---|
110 | Colour[] pixels = getPixels(image, x, y, 1, 1);
|
---|
111 |
|
---|
112 | if (pixels == null) return null;
|
---|
113 |
|
---|
114 | return pixels[0];
|
---|
115 | }
|
---|
116 |
|
---|
117 | /*
|
---|
118 | *
|
---|
119 | * Image-manipulation functions
|
---|
120 | *
|
---|
121 | */
|
---|
122 |
|
---|
123 | /** Sets the colour of a single pixel in the image. */
|
---|
124 | public abstract void setPixel(Image image, int x, int y, Colour c);
|
---|
125 |
|
---|
126 | /** Writes the image data to disk. Format should be png, bmp, etc. */
|
---|
127 | public abstract boolean writeImageToDisk(Image image, String format, File file) throws IOException;
|
---|
128 |
|
---|
129 | }
|
---|