1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import java.awt.image.WritableRaster; |
28 import java.awt.image.WritableRaster; |
29 import java.awt.image.RasterFormatException; |
29 import java.awt.image.RasterFormatException; |
30 import java.awt.image.SampleModel; |
30 import java.awt.image.SampleModel; |
31 import java.awt.image.ComponentSampleModel; |
31 import java.awt.image.ComponentSampleModel; |
32 import java.awt.image.SinglePixelPackedSampleModel; |
32 import java.awt.image.SinglePixelPackedSampleModel; |
33 import java.awt.image.DataBuffer; |
|
34 import java.awt.image.DataBufferByte; |
33 import java.awt.image.DataBufferByte; |
35 import java.awt.Rectangle; |
34 import java.awt.Rectangle; |
36 import java.awt.Point; |
35 import java.awt.Point; |
37 |
36 |
38 /** |
37 /** |
92 * @param sampleModel The SampleModel that specifies the layout. |
91 * @param sampleModel The SampleModel that specifies the layout. |
93 * @param origin The Point that specified the origin. |
92 * @param origin The Point that specified the origin. |
94 */ |
93 */ |
95 public ByteComponentRaster(SampleModel sampleModel, Point origin) { |
94 public ByteComponentRaster(SampleModel sampleModel, Point origin) { |
96 this(sampleModel, |
95 this(sampleModel, |
97 sampleModel.createDataBuffer(), |
96 (DataBufferByte) sampleModel.createDataBuffer(), |
98 new Rectangle(origin.x, |
97 new Rectangle(origin.x, |
99 origin.y, |
98 origin.y, |
100 sampleModel.getWidth(), |
99 sampleModel.getWidth(), |
101 sampleModel.getHeight()), |
100 sampleModel.getHeight()), |
102 origin, |
101 origin, |
109 * it is the same size as the SampleModel. The DataBuffer is not |
108 * it is the same size as the SampleModel. The DataBuffer is not |
110 * initialized and must be a DataBufferByte compatible with SampleModel. |
109 * initialized and must be a DataBufferByte compatible with SampleModel. |
111 * SampleModel must be of type SinglePixelPackedSampleModel |
110 * SampleModel must be of type SinglePixelPackedSampleModel |
112 * or ComponentSampleModel. |
111 * or ComponentSampleModel. |
113 * @param sampleModel The SampleModel that specifies the layout. |
112 * @param sampleModel The SampleModel that specifies the layout. |
114 * @param dataBuffer The DataBufferShort that contains the image data. |
113 * @param dataBuffer The DataBufferByte that contains the image data. |
115 * @param origin The Point that specifies the origin. |
114 * @param origin The Point that specifies the origin. |
116 */ |
115 */ |
117 public ByteComponentRaster(SampleModel sampleModel, |
116 public ByteComponentRaster(SampleModel sampleModel, |
118 DataBuffer dataBuffer, |
117 DataBufferByte dataBuffer, |
119 Point origin) { |
118 Point origin) |
|
119 { |
120 this(sampleModel, |
120 this(sampleModel, |
121 dataBuffer, |
121 dataBuffer, |
122 new Rectangle(origin.x, |
122 new Rectangle(origin.x, |
123 origin.y, |
123 origin.y, |
124 sampleModel.getWidth(), |
124 sampleModel.getWidth(), |
139 * ancestor which has no parent.) |
139 * ancestor which has no parent.) |
140 * |
140 * |
141 * Note that this constructor should generally be called by other |
141 * Note that this constructor should generally be called by other |
142 * constructors or create methods, it should not be used directly. |
142 * constructors or create methods, it should not be used directly. |
143 * @param sampleModel The SampleModel that specifies the layout. |
143 * @param sampleModel The SampleModel that specifies the layout. |
144 * @param dataBuffer The DataBufferShort that contains the image data. |
144 * @param dataBuffer The DataBufferByte that contains the image data. |
145 * @param aRegion The Rectangle that specifies the image area. |
145 * @param aRegion The Rectangle that specifies the image area. |
146 * @param origin The Point that specifies the origin. |
146 * @param origin The Point that specifies the origin. |
147 * @param parent The parent (if any) of this raster. |
147 * @param parent The parent (if any) of this raster. |
148 */ |
148 */ |
149 public ByteComponentRaster(SampleModel sampleModel, |
149 public ByteComponentRaster(SampleModel sampleModel, |
150 DataBuffer dataBuffer, |
150 DataBufferByte dataBuffer, |
151 Rectangle aRegion, |
151 Rectangle aRegion, |
152 Point origin, |
152 Point origin, |
153 ByteComponentRaster parent) { |
153 ByteComponentRaster parent) |
|
154 { |
154 super(sampleModel, dataBuffer, aRegion, origin, parent); |
155 super(sampleModel, dataBuffer, aRegion, origin, parent); |
155 this.maxX = minX + width; |
156 this.maxX = minX + width; |
156 this.maxY = minY + height; |
157 this.maxY = minY + height; |
157 |
158 |
158 if (!(dataBuffer instanceof DataBufferByte)) { |
159 this.data = stealData(dataBuffer, 0); |
159 throw new RasterFormatException("ByteComponentRasters must have " + |
160 if (dataBuffer.getNumBanks() != 1) { |
160 "byte DataBuffers"); |
|
161 } |
|
162 |
|
163 DataBufferByte dbb = (DataBufferByte)dataBuffer; |
|
164 this.data = stealData(dbb, 0); |
|
165 if (dbb.getNumBanks() != 1) { |
|
166 throw new |
161 throw new |
167 RasterFormatException("DataBuffer for ByteComponentRasters"+ |
162 RasterFormatException("DataBuffer for ByteComponentRasters"+ |
168 " must only have 1 bank."); |
163 " must only have 1 bank."); |
169 } |
164 } |
170 int dbOffset = dbb.getOffset(); |
165 int dbOffset = dataBuffer.getOffset(); |
171 |
166 |
172 if (sampleModel instanceof ComponentSampleModel) { |
167 if (sampleModel instanceof ComponentSampleModel) { |
173 ComponentSampleModel ism = (ComponentSampleModel)sampleModel; |
168 ComponentSampleModel ism = (ComponentSampleModel)sampleModel; |
174 this.type = IntegerComponentRaster.TYPE_BYTE_SAMPLES; |
169 this.type = IntegerComponentRaster.TYPE_BYTE_SAMPLES; |
175 this.scanlineStride = ism.getScanlineStride(); |
170 this.scanlineStride = ism.getScanlineStride(); |
821 |
816 |
822 int deltaX = x0 - x; |
817 int deltaX = x0 - x; |
823 int deltaY = y0 - y; |
818 int deltaY = y0 - y; |
824 |
819 |
825 return new ByteComponentRaster(sm, |
820 return new ByteComponentRaster(sm, |
826 dataBuffer, |
821 (DataBufferByte) dataBuffer, |
827 new Rectangle(x0, y0, width, height), |
822 new Rectangle(x0, y0, width, height), |
828 new Point(sampleModelTranslateX+deltaX, |
823 new Point(sampleModelTranslateX+deltaX, |
829 sampleModelTranslateY+deltaY), |
824 sampleModelTranslateY+deltaY), |
830 this); |
825 this); |
831 } |
826 } |