Debian Codegraph @

src/main/java/nom/tam/fits/compression/algorithm/uncompressed/NoCompressCompressor.java

raw
1 package nom.tam.fits.compression.algorithm.uncompressed;
2
3 import java.nio.Buffer;
4 import java.nio.ByteBuffer;
5 import java.nio.DoubleBuffer;
6 import java.nio.FloatBuffer;
7 import java.nio.IntBuffer;
8 import java.nio.LongBuffer;
9 import java.nio.ShortBuffer;
10
11 import nom.tam.fits.compression.algorithm.api.ICompressor;
12 import nom.tam.util.type.ElementType;
13
14 /*
15 * #%L
16 * nom.tam FITS library
17 * %%
18 * Copyright (C) 1996 - 2024 nom-tam-fits
19 * %%
20 * This is free and unencumbered software released into the public domain.
21 *
22 * Anyone is free to copy, modify, publish, use, compile, sell, or
23 * distribute this software, either in source code form or as a compiled
24 * binary, for any purpose, commercial or non-commercial, and by any
25 * means.
26 *
27 * In jurisdictions that recognize copyright laws, the author or authors
28 * of this software dedicate any and all copyright interest in the
29 * software to the public domain. We make this dedication for the benefit
30 * of the public at large and to the detriment of our heirs and
31 * successors. We intend this dedication to be an overt act of
32 * relinquishment in perpetuity of all present and future rights to this
33 * software under copyright law.
34 *
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
39 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
40 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
41 * OTHER DEALINGS IN THE SOFTWARE.
42 * #L%
43 */
44
45 /**
46 * (<i>for internal use</i>) This compression algorithm will just copy the input to the output and do nothing at all.
47 *
48 * @param <T> the buffer type of the pixel data
49 */
50 @SuppressWarnings("javadoc")
51 public abstract class NoCompressCompressor<T extends Buffer> implements ICompressor<T> {
52
53 public static class ByteNoCompressCompressor extends NoCompressCompressor<ByteBuffer> {
54
55 @Override
56 public boolean compress(ByteBuffer pixelData, ByteBuffer compressed) {
57 compressed.put(pixelData);
58 return true;
59 }
60
61 @Override
62 public void decompress(ByteBuffer compressed, ByteBuffer pixelData) {
63 pixelData.put(compressed);
64 }
65 }
66
67 public static class DoubleNoCompressCompressor extends NoCompressCompressor<DoubleBuffer> {
68
69 @Override
70 public boolean compress(DoubleBuffer pixelData, ByteBuffer compressed) {
71 int size = pixelData.remaining();
72 compressed.asDoubleBuffer().put(pixelData);
73 compressed.position(compressed.position() + size * ElementType.DOUBLE.size());
74 return true;
75 }
76
77 @Override
78 public void decompress(ByteBuffer compressed, DoubleBuffer pixelData) {
79 pixelData.put(compressed.asDoubleBuffer());
80 }
81 }
82
83 public static class FloatNoCompressCompressor extends NoCompressCompressor<FloatBuffer> {
84
85 @Override
86 public boolean compress(FloatBuffer pixelData, ByteBuffer compressed) {
87 int size = pixelData.remaining();
88 compressed.asFloatBuffer().put(pixelData);
89 compressed.position(compressed.position() + size * ElementType.FLOAT.size());
90
91 return true;
92 }
93
94 @Override
95 public void decompress(ByteBuffer compressed, FloatBuffer pixelData) {
96 pixelData.put(compressed.asFloatBuffer());
97 }
98 }
99
100 public static class IntNoCompressCompressor extends NoCompressCompressor<IntBuffer> {
101
102 @Override
103 public boolean compress(IntBuffer pixelData, ByteBuffer compressed) {
104 int size = pixelData.remaining();
105 compressed.asIntBuffer().put(pixelData);
106 compressed.position(compressed.position() + size * ElementType.INT.size());
107 return true;
108 }
109
110 @Override
111 public void decompress(ByteBuffer compressed, IntBuffer pixelData) {
112 pixelData.put(compressed.asIntBuffer());
113 }
114 }
115
116 public static class LongNoCompressCompressor extends NoCompressCompressor<LongBuffer> {
117
118 @Override
119 public boolean compress(LongBuffer pixelData, ByteBuffer compressed) {
120 int size = pixelData.remaining();
121 compressed.asLongBuffer().put(pixelData);
122 compressed.position(compressed.position() + size * ElementType.LONG.size());
123 return true;
124 }
125
126 @Override
127 public void decompress(ByteBuffer compressed, LongBuffer pixelData) {
128 pixelData.put(compressed.asLongBuffer());
129 }
130 }
131
132 public static class ShortNoCompressCompressor extends NoCompressCompressor<ShortBuffer> {
133
134 @Override
135 public boolean compress(ShortBuffer pixelData, ByteBuffer compressed) {
136 int size = pixelData.remaining();
137 compressed.asShortBuffer().put(pixelData);
138 compressed.position(compressed.position() + size * ElementType.SHORT.size());
139 return true;
140 }
141
142 @Override
143 public void decompress(ByteBuffer compressed, ShortBuffer pixelData) {
144 pixelData.put(compressed.asShortBuffer());
145 }
146 }
147
148 }