Mercurial > hg > orthanc-java
comparison JavaSDK/be/uclouvain/orthanc/Image.java @ 0:3ecef5782f2c
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Oct 2023 17:59:44 +0200 |
parents | |
children | 26c08ff926a3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3ecef5782f2c |
---|---|
1 package be.uclouvain.orthanc; | |
2 | |
3 /** | |
4 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium | |
5 * SPDX-License-Identifier: GPL-3.0-or-later | |
6 */ | |
7 | |
8 /** | |
9 * Java plugin for Orthanc | |
10 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium | |
11 * | |
12 * This program is free software: you can redistribute it and/or | |
13 * modify it under the terms of the GNU General Public License as | |
14 * published by the Free Software Foundation, either version 3 of the | |
15 * License, or (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, but | |
18 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 * General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program. If not, see http://www.gnu.org/licenses/. | |
24 **/ | |
25 | |
26 | |
27 /** | |
28 * 2D image managed by the Orthanc core | |
29 **/ | |
30 public class Image { | |
31 private long self; | |
32 | |
33 /** | |
34 * Construct a Java object wrapping a C object that is managed by Orthanc. | |
35 * @param self Pointer to the C object. | |
36 **/ | |
37 protected Image(long self) { | |
38 if (self == 0) { | |
39 throw new IllegalArgumentException("Null pointer"); | |
40 } else { | |
41 this.self = self; | |
42 } | |
43 } | |
44 | |
45 /** | |
46 * Return the C object that is associated with this Java wrapper. | |
47 * @return Pointer to the C object. | |
48 **/ | |
49 protected long getSelf() { | |
50 return self; | |
51 } | |
52 | |
53 @Override | |
54 protected void finalize() throws Throwable { | |
55 dispose(); | |
56 super.finalize(); | |
57 } | |
58 | |
59 /** | |
60 * Manually deallocate the C object that is associated with this Java wrapper. | |
61 * | |
62 * This method can be used to immediately deallocate the C object, | |
63 * instead of waiting for the garbage collector to dispose the Java wrapper. | |
64 **/ | |
65 public void dispose() { | |
66 if (self != 0) { | |
67 NativeSDK.OrthancPluginFreeImage(self); | |
68 self = 0; | |
69 } | |
70 } | |
71 | |
72 /** | |
73 * Decode a compressed image. | |
74 * | |
75 * This function decodes a compressed image from a memory buffer. | |
76 * | |
77 * @param data Pointer to a memory buffer containing the compressed image. | |
78 * @param format The file format of the compressed image. | |
79 * @return The newly constructed object. | |
80 **/ | |
81 public static Image uncompressImage( | |
82 byte[] data, | |
83 ImageFormat format) { | |
84 return new Image(NativeSDK.OrthancPluginUncompressImage(data, format.getValue())); | |
85 } | |
86 | |
87 /** | |
88 * Create an image. | |
89 * | |
90 * This function creates an image of given size and format. | |
91 * | |
92 * @param format The format of the pixels. | |
93 * @param width The width of the image. | |
94 * @param height The height of the image. | |
95 * @return The newly constructed object. | |
96 **/ | |
97 public static Image createImage( | |
98 PixelFormat format, | |
99 int width, | |
100 int height) { | |
101 return new Image(NativeSDK.OrthancPluginCreateImage(format.getValue(), width, height)); | |
102 } | |
103 | |
104 /** | |
105 * Decode one frame from a DICOM instance. | |
106 * | |
107 * This function decodes one frame of a DICOM image that is stored in a memory | |
108 * buffer. This function will give the same result as | |
109 * OrthancPluginUncompressImage() for single-frame DICOM images. | |
110 * | |
111 * @param buffer Pointer to a memory buffer containing the DICOM image. | |
112 * @param frameIndex The index of the frame of interest in a multi-frame image. | |
113 * @return The newly constructed object. | |
114 **/ | |
115 public static Image decodeDicomImage( | |
116 byte[] buffer, | |
117 int frameIndex) { | |
118 return new Image(NativeSDK.OrthancPluginDecodeDicomImage(buffer, frameIndex)); | |
119 } | |
120 | |
121 | |
122 /** | |
123 * Return the pixel format of an image. | |
124 * | |
125 * This function returns the type of memory layout for the pixels of the given | |
126 * image. | |
127 * | |
128 * @return The pixel format. | |
129 **/ | |
130 public PixelFormat getImagePixelFormat() { | |
131 return PixelFormat.getInstance(NativeSDK.OrthancPluginGetImagePixelFormat(self)); | |
132 } | |
133 | |
134 /** | |
135 * Return the width of an image. | |
136 * | |
137 * This function returns the width of the given image. | |
138 * | |
139 * @return The width. | |
140 **/ | |
141 public int getImageWidth() { | |
142 return NativeSDK.OrthancPluginGetImageWidth(self); | |
143 } | |
144 | |
145 /** | |
146 * Return the height of an image. | |
147 * | |
148 * This function returns the height of the given image. | |
149 * | |
150 * @return The height. | |
151 **/ | |
152 public int getImageHeight() { | |
153 return NativeSDK.OrthancPluginGetImageHeight(self); | |
154 } | |
155 | |
156 /** | |
157 * Return the pitch of an image. | |
158 * | |
159 * This function returns the pitch of the given image. The pitch is defined as the | |
160 * number of bytes between 2 successive lines of the image in the memory buffer. | |
161 * | |
162 * @return The pitch. | |
163 **/ | |
164 public int getImagePitch() { | |
165 return NativeSDK.OrthancPluginGetImagePitch(self); | |
166 } | |
167 | |
168 /** | |
169 * Change the pixel format of an image. | |
170 * | |
171 * This function creates a new image, changing the memory layout of the pixels. | |
172 * | |
173 * @param targetFormat The target pixel format. | |
174 * @return The newly constructed object. | |
175 **/ | |
176 public Image convertPixelFormat( | |
177 PixelFormat targetFormat) { | |
178 return new Image(NativeSDK.OrthancPluginConvertPixelFormat(self, targetFormat.getValue())); | |
179 } | |
180 | |
181 /** | |
182 * Draw text on an image. | |
183 * | |
184 * This function draws some text on some image. | |
185 * | |
186 * @param fontIndex The index of the font. This value must be less than | |
187 * OrthancPluginGetFontsCount(). | |
188 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated | |
189 * string. | |
190 * @param x The X position of the text over the image. | |
191 * @param y The Y position of the text over the image. | |
192 * @param r The value of the red color channel of the text. | |
193 * @param g The value of the green color channel of the text. | |
194 * @param b The value of the blue color channel of the text. | |
195 **/ | |
196 public void drawText( | |
197 int fontIndex, | |
198 String utf8Text, | |
199 int x, | |
200 int y, | |
201 byte r, | |
202 byte g, | |
203 byte b) { | |
204 NativeSDK.OrthancPluginDrawText(self, fontIndex, utf8Text, x, y, r, g, b); | |
205 } | |
206 | |
207 } |