1 /*
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
576 while(xRemaining > 8) {
577 data[i++] =
578 (short)(((binaryDataArray[b++] & 0xFF) << 8) |
579 (binaryDataArray[b++] & 0xFF));
580 xRemaining -= 16;
581 }
582 if(xRemaining > 0) {
583 data[i++] =
584 (short)((binaryDataArray[b++] & 0xFF) << 8);
585 }
586 eltOffset += lineStride;
587 }
588 } else if(dataBuffer instanceof DataBufferInt) {
589 int[] data = ((DataBufferInt)dataBuffer).getData();
590
591 for(int y = 0; y < rectHeight; y++) {
592 int xRemaining = rectWidth;
593 int i = eltOffset;
594 while(xRemaining > 24) {
595 data[i++] =
596 (int)(((binaryDataArray[b++] & 0xFF) << 24) |
597 ((binaryDataArray[b++] & 0xFF) << 16) |
598 ((binaryDataArray[b++] & 0xFF) << 8) |
599 (binaryDataArray[b++] & 0xFF));
600 xRemaining -= 32;
601 }
602 int shift = 24;
603 while(xRemaining > 0) {
604 data[i] |=
605 (int)((binaryDataArray[b++] & 0xFF) << shift);
606 shift -= 8;
607 xRemaining -= 8;
608 }
609 eltOffset += lineStride;
610 }
611 }
612 } else { // bitOffset != 0
613 int stride = (rectWidth + 7)/8;
614 int offset = 0;
615 if(dataBuffer instanceof DataBufferByte) {
616 byte[] data = ((DataBufferByte)dataBuffer).getData();
617
618 if((bitOffset & 7) == 0) {
619 for(int y = 0; y < rectHeight; y++) {
620 System.arraycopy(binaryDataArray, offset,
621 data, eltOffset,
622 stride);
623 offset += stride;
624 eltOffset += lineStride;
625 }
818 ((DataBufferUShort)dataBuffer).getData();
819 for(int y = 0; y < rectHeight; y++) {
820 int bOffset = eltOffset*16 + bitOffset;
821 for(int x = 0; x < rectWidth; x++) {
822 if(bdata[k++] != (byte)0) {
823 data[bOffset/16] |=
824 (short)(0x00000001 <<
825 (15 - bOffset % 16));
826 }
827 bOffset++;
828 }
829 eltOffset += lineStride;
830 }
831 } else if(dataBuffer instanceof DataBufferInt) {
832 int[] data = ((DataBufferInt)dataBuffer).getData();
833 for(int y = 0; y < rectHeight; y++) {
834 int bOffset = eltOffset*32 + bitOffset;
835 for(int x = 0; x < rectWidth; x++) {
836 if(bdata[k++] != (byte)0) {
837 data[bOffset/32] |=
838 (int)(0x00000001 <<
839 (31 - bOffset % 32));
840 }
841 bOffset++;
842 }
843 eltOffset += lineStride;
844 }
845 }
846 }
847
848 public static boolean isBinary(SampleModel sm) {
849 return sm instanceof MultiPixelPackedSampleModel &&
850 ((MultiPixelPackedSampleModel)sm).getPixelBitStride() == 1 &&
851 sm.getNumBands() == 1;
852 }
853
854 public static ColorModel createColorModel(ColorSpace colorSpace,
855 SampleModel sampleModel) {
856 ColorModel colorModel = null;
857
858 if(sampleModel == null) {
859 throw new IllegalArgumentException(I18N.getString("ImageUtil1"));
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
576 while(xRemaining > 8) {
577 data[i++] =
578 (short)(((binaryDataArray[b++] & 0xFF) << 8) |
579 (binaryDataArray[b++] & 0xFF));
580 xRemaining -= 16;
581 }
582 if(xRemaining > 0) {
583 data[i++] =
584 (short)((binaryDataArray[b++] & 0xFF) << 8);
585 }
586 eltOffset += lineStride;
587 }
588 } else if(dataBuffer instanceof DataBufferInt) {
589 int[] data = ((DataBufferInt)dataBuffer).getData();
590
591 for(int y = 0; y < rectHeight; y++) {
592 int xRemaining = rectWidth;
593 int i = eltOffset;
594 while(xRemaining > 24) {
595 data[i++] =
596 (((binaryDataArray[b++] & 0xFF) << 24) |
597 ((binaryDataArray[b++] & 0xFF) << 16) |
598 ((binaryDataArray[b++] & 0xFF) << 8) |
599 (binaryDataArray[b++] & 0xFF));
600 xRemaining -= 32;
601 }
602 int shift = 24;
603 while(xRemaining > 0) {
604 data[i] |= ((binaryDataArray[b++] & 0xFF) << shift);
605 shift -= 8;
606 xRemaining -= 8;
607 }
608 eltOffset += lineStride;
609 }
610 }
611 } else { // bitOffset != 0
612 int stride = (rectWidth + 7)/8;
613 int offset = 0;
614 if(dataBuffer instanceof DataBufferByte) {
615 byte[] data = ((DataBufferByte)dataBuffer).getData();
616
617 if((bitOffset & 7) == 0) {
618 for(int y = 0; y < rectHeight; y++) {
619 System.arraycopy(binaryDataArray, offset,
620 data, eltOffset,
621 stride);
622 offset += stride;
623 eltOffset += lineStride;
624 }
817 ((DataBufferUShort)dataBuffer).getData();
818 for(int y = 0; y < rectHeight; y++) {
819 int bOffset = eltOffset*16 + bitOffset;
820 for(int x = 0; x < rectWidth; x++) {
821 if(bdata[k++] != (byte)0) {
822 data[bOffset/16] |=
823 (short)(0x00000001 <<
824 (15 - bOffset % 16));
825 }
826 bOffset++;
827 }
828 eltOffset += lineStride;
829 }
830 } else if(dataBuffer instanceof DataBufferInt) {
831 int[] data = ((DataBufferInt)dataBuffer).getData();
832 for(int y = 0; y < rectHeight; y++) {
833 int bOffset = eltOffset*32 + bitOffset;
834 for(int x = 0; x < rectWidth; x++) {
835 if(bdata[k++] != (byte)0) {
836 data[bOffset/32] |=
837 (0x00000001 << (31 - bOffset % 32));
838 }
839 bOffset++;
840 }
841 eltOffset += lineStride;
842 }
843 }
844 }
845
846 public static boolean isBinary(SampleModel sm) {
847 return sm instanceof MultiPixelPackedSampleModel &&
848 ((MultiPixelPackedSampleModel)sm).getPixelBitStride() == 1 &&
849 sm.getNumBands() == 1;
850 }
851
852 public static ColorModel createColorModel(ColorSpace colorSpace,
853 SampleModel sampleModel) {
854 ColorModel colorModel = null;
855
856 if(sampleModel == null) {
857 throw new IllegalArgumentException(I18N.getString("ImageUtil1"));
|