From d2c347aff0f521a1e081cfdab55175a52d8ac029 Mon Sep 17 00:00:00 2001 From: mstr2 <43553916+mstr2@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:16:54 +0200 Subject: [PATCH] fix line endings --- .../image/IndexedToBytePixelConverter.java | 158 ++++---- .../javafx/image/impl/EightBitIndexed.java | 364 +++++++++--------- .../sun/javafx/image/impl/FourBitIndexed.java | 364 +++++++++--------- .../sun/javafx/image/impl/OneBitIndexed.java | 356 ++++++++--------- .../sun/javafx/image/impl/TwoBitIndexed.java | 356 ++++++++--------- 5 files changed, 799 insertions(+), 799 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/IndexedToBytePixelConverter.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/IndexedToBytePixelConverter.java index 3afd5ae6d30..f1250eb8b1a 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/IndexedToBytePixelConverter.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/IndexedToBytePixelConverter.java @@ -1,79 +1,79 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.image; - -import java.nio.ByteBuffer; - -public interface IndexedToBytePixelConverter extends PixelConverter { - - /** - * Copies a rectangular region of data from the source array to the destination array. - * - * @param srcarr the byte array containing the source data - * @param srcoff the index in the array of the first source pixel data - * @param srcscanbits number of bits between rows of data in the source - * @param dstarr the byte array containing the destination data - * @param dstoff the index in the array of the first destination pixel data - * @param dstscanbytes number of array indices between rows of data in the destination - * @param w the number of pixels to process across before moving to the next row - * @param h the number of rows of pixels to process - */ - void convert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h); - - /** - * Copies a rectangular region of data from the source buffer to the destination array. - * - * @param srcbuf the nio buffer containing the source data - * @param srcoff the absolute location in the buffer of the first source pixel data - * @param srcscanbits number of bits between rows of data in the source - * @param dstarr the byte array containing the destination data - * @param dstoff the index in the array of the first destination pixel data - * @param dstscanbytes number of array indices between rows of data in the destination - * @param w the number of pixels to process across before moving to the next row - * @param h the number of rows of pixels to process - */ - void convert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h); - - /** - * Copies a rectangular region of data from the source array to the destination buffer. - * - * @param srcarr the byte array containing the source data - * @param srcoff the index in the array of the first source pixel data - * @param srcscanbits number of bits between rows of data in the source - * @param dstbuf the nio buffer containing the destination data - * @param dstoff the absolute location in the buffer of the first destination pixel data - * @param dstscanbytes number of buffer elements between rows of data in the destination - * @param w the number of pixels to process across before moving to the next row - * @param h the number of rows of pixels to process - */ - void convert(byte[] srcarr, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h); -} +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.image; + +import java.nio.ByteBuffer; + +public interface IndexedToBytePixelConverter extends PixelConverter { + + /** + * Copies a rectangular region of data from the source array to the destination array. + * + * @param srcarr the byte array containing the source data + * @param srcoff the index in the array of the first source pixel data + * @param srcscanbits number of bits between rows of data in the source + * @param dstarr the byte array containing the destination data + * @param dstoff the index in the array of the first destination pixel data + * @param dstscanbytes number of array indices between rows of data in the destination + * @param w the number of pixels to process across before moving to the next row + * @param h the number of rows of pixels to process + */ + void convert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h); + + /** + * Copies a rectangular region of data from the source buffer to the destination array. + * + * @param srcbuf the nio buffer containing the source data + * @param srcoff the absolute location in the buffer of the first source pixel data + * @param srcscanbits number of bits between rows of data in the source + * @param dstarr the byte array containing the destination data + * @param dstoff the index in the array of the first destination pixel data + * @param dstscanbytes number of array indices between rows of data in the destination + * @param w the number of pixels to process across before moving to the next row + * @param h the number of rows of pixels to process + */ + void convert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h); + + /** + * Copies a rectangular region of data from the source array to the destination buffer. + * + * @param srcarr the byte array containing the source data + * @param srcoff the index in the array of the first source pixel data + * @param srcscanbits number of bits between rows of data in the source + * @param dstbuf the nio buffer containing the destination data + * @param dstoff the absolute location in the buffer of the first destination pixel data + * @param dstscanbytes number of buffer elements between rows of data in the destination + * @param w the number of pixels to process across before moving to the next row + * @param h the number of rows of pixels to process + */ + void convert(byte[] srcarr, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h); +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/EightBitIndexed.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/EightBitIndexed.java index 0f9a7fe9887..14d668ef692 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/EightBitIndexed.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/EightBitIndexed.java @@ -1,182 +1,182 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.image.impl; - -import com.sun.javafx.image.BytePixelSetter; -import com.sun.javafx.image.IndexedToBytePixelConverter; -import java.nio.ByteBuffer; - -public final class EightBitIndexed { - - private EightBitIndexed() {} - - public static Getter createGetter(int[] colors, Boolean premultiplied) { - return new Getter(colors, premultiplied); - } - - public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { - return new ToByteRgbConverter(src, dst); - } - - public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { - return new ToByteBgraAnyConverter(src, dst); - } - - public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { - Getter(int[] colors, Boolean premultiplied) { - super(colors, premultiplied); - } - - @Override - public int getNumElements() { - return 8; - } - - @Override - public int getArgb(byte[] arr, int offset) { - return preColors[arr[offset]]; - } - - @Override - public int getArgbPre(byte[] arr, int offset) { - return nonPreColors[arr[offset]]; - } - - @Override - public int getArgb(ByteBuffer buf, int offset) { - return preColors[buf.get(offset)]; - } - - @Override - public int getArgbPre(ByteBuffer buf, int offset) { - return nonPreColors[buf.get(offset)]; - } - } - - public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { - public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[srcarr[srcoff + x]]; - dstarr[dstoff++] = (byte) argb; - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 24); - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[srcbuf.get(srcoff + x)]; - dstbuf.put(dstoff, (byte) argb); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) (argb >> 16)); - dstbuf.put(dstoff + 3, (byte) (argb >> 24)); - dstoff += 4; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } - - public static class ToByteRgbConverter extends BaseIndexedToByteConverter { - public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[srcarr[srcoff + x]]; - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) argb; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[srcbuf.get(srcoff + x)]; - dstbuf.put(dstoff, (byte) (argb >> 16)); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) argb); - dstoff += 3; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } -} +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.image.impl; + +import com.sun.javafx.image.BytePixelSetter; +import com.sun.javafx.image.IndexedToBytePixelConverter; +import java.nio.ByteBuffer; + +public final class EightBitIndexed { + + private EightBitIndexed() {} + + public static Getter createGetter(int[] colors, Boolean premultiplied) { + return new Getter(colors, premultiplied); + } + + public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { + return new ToByteRgbConverter(src, dst); + } + + public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { + return new ToByteBgraAnyConverter(src, dst); + } + + public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { + Getter(int[] colors, Boolean premultiplied) { + super(colors, premultiplied); + } + + @Override + public int getNumElements() { + return 8; + } + + @Override + public int getArgb(byte[] arr, int offset) { + return preColors[arr[offset]]; + } + + @Override + public int getArgbPre(byte[] arr, int offset) { + return nonPreColors[arr[offset]]; + } + + @Override + public int getArgb(ByteBuffer buf, int offset) { + return preColors[buf.get(offset)]; + } + + @Override + public int getArgbPre(ByteBuffer buf, int offset) { + return nonPreColors[buf.get(offset)]; + } + } + + public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { + public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[srcarr[srcoff + x]]; + dstarr[dstoff++] = (byte) argb; + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 24); + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[srcbuf.get(srcoff + x)]; + dstbuf.put(dstoff, (byte) argb); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) (argb >> 16)); + dstbuf.put(dstoff + 3, (byte) (argb >> 24)); + dstoff += 4; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } + + public static class ToByteRgbConverter extends BaseIndexedToByteConverter { + public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[srcarr[srcoff + x]]; + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) argb; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[srcbuf.get(srcoff + x)]; + dstbuf.put(dstoff, (byte) (argb >> 16)); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) argb); + dstoff += 3; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/FourBitIndexed.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/FourBitIndexed.java index eeb03f6b203..024cdf945bf 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/FourBitIndexed.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/FourBitIndexed.java @@ -1,182 +1,182 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.image.impl; - -import com.sun.javafx.image.BytePixelSetter; -import com.sun.javafx.image.IndexedToBytePixelConverter; -import java.nio.ByteBuffer; - -public final class FourBitIndexed { - - private FourBitIndexed() {} - - public static Getter createGetter(int[] colors, Boolean premultiplied) { - return new Getter(colors, premultiplied); - } - - public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { - return new ToByteRgbConverter(src, dst); - } - - public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { - return new ToByteBgraAnyConverter(src, dst); - } - - public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { - Getter(int[] colors, Boolean premultiplied) { - super(colors, premultiplied); - } - - @Override - public int getNumElements() { - return 4; - } - - @Override - public int getArgb(byte[] arr, int offset) { - return preColors[(arr[offset / 2] >> (4 - offset % 2 * 4)) & 0xf]; - } - - @Override - public int getArgbPre(byte[] arr, int offset) { - return nonPreColors[(arr[offset / 2] >> (4 - offset % 2 * 4)) & 0xf]; - } - - @Override - public int getArgb(ByteBuffer buf, int offset) { - return preColors[(buf.get(offset / 2) >> (4 - offset % 2 * 4)) & 0xf]; - } - - @Override - public int getArgbPre(ByteBuffer buf, int offset) { - return nonPreColors[(buf.get(offset / 2) >> (4 - offset % 2 * 4)) & 0xf]; - } - } - - public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { - public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 2] >> (4 - x % 2 * 4)) & 0xf]; - dstarr[dstoff++] = (byte) argb; - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 24); - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 2) >> (4 - x % 2 * 4)) & 0xf]; - dstbuf.put(dstoff, (byte) argb); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) (argb >> 16)); - dstbuf.put(dstoff + 3, (byte) (argb >> 24)); - dstoff += 4; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } - - public static class ToByteRgbConverter extends BaseIndexedToByteConverter { - public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 2] >> (4 - x % 2 * 4)) & 0xf]; - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) argb; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 2) >> (4 - x % 2 * 4)) & 0xf]; - dstbuf.put(dstoff, (byte) (argb >> 16)); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) argb); - dstoff += 3; - } - - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } -} +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.image.impl; + +import com.sun.javafx.image.BytePixelSetter; +import com.sun.javafx.image.IndexedToBytePixelConverter; +import java.nio.ByteBuffer; + +public final class FourBitIndexed { + + private FourBitIndexed() {} + + public static Getter createGetter(int[] colors, Boolean premultiplied) { + return new Getter(colors, premultiplied); + } + + public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { + return new ToByteRgbConverter(src, dst); + } + + public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { + return new ToByteBgraAnyConverter(src, dst); + } + + public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { + Getter(int[] colors, Boolean premultiplied) { + super(colors, premultiplied); + } + + @Override + public int getNumElements() { + return 4; + } + + @Override + public int getArgb(byte[] arr, int offset) { + return preColors[(arr[offset / 2] >> (4 - offset % 2 * 4)) & 0xf]; + } + + @Override + public int getArgbPre(byte[] arr, int offset) { + return nonPreColors[(arr[offset / 2] >> (4 - offset % 2 * 4)) & 0xf]; + } + + @Override + public int getArgb(ByteBuffer buf, int offset) { + return preColors[(buf.get(offset / 2) >> (4 - offset % 2 * 4)) & 0xf]; + } + + @Override + public int getArgbPre(ByteBuffer buf, int offset) { + return nonPreColors[(buf.get(offset / 2) >> (4 - offset % 2 * 4)) & 0xf]; + } + } + + public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { + public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 2] >> (4 - x % 2 * 4)) & 0xf]; + dstarr[dstoff++] = (byte) argb; + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 24); + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 2) >> (4 - x % 2 * 4)) & 0xf]; + dstbuf.put(dstoff, (byte) argb); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) (argb >> 16)); + dstbuf.put(dstoff + 3, (byte) (argb >> 24)); + dstoff += 4; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } + + public static class ToByteRgbConverter extends BaseIndexedToByteConverter { + public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 2] >> (4 - x % 2 * 4)) & 0xf]; + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) argb; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 2) >> (4 - x % 2 * 4)) & 0xf]; + dstbuf.put(dstoff, (byte) (argb >> 16)); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) argb); + dstoff += 3; + } + + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/OneBitIndexed.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/OneBitIndexed.java index 7a295cd8abc..b5028d29d12 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/OneBitIndexed.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/OneBitIndexed.java @@ -1,178 +1,178 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.image.impl; - -import com.sun.javafx.image.BytePixelSetter; -import com.sun.javafx.image.IndexedToBytePixelConverter; -import java.nio.ByteBuffer; - -public final class OneBitIndexed { - - private OneBitIndexed() {} - - public static Getter createGetter(int[] colors, Boolean premultiplied) { - return new Getter(colors, premultiplied); - } - - public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { - return new ToByteRgbConverter(src, dst); - } - - public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { - return new ToByteBgraAnyConverter(src, dst); - } - - public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { - Getter(int[] colors, Boolean premultiplied) { - super(colors, premultiplied); - } - - @Override - public int getNumElements() { - return 1; - } - - @Override - public int getArgb(byte[] arr, int offset) { - return preColors[(arr[offset / 8] >> (7 - offset % 8)) & 1]; - } - - @Override - public int getArgbPre(byte[] arr, int offset) { - return nonPreColors[(arr[offset / 8] >> (7 - offset % 8)) & 1]; - } - - @Override - public int getArgb(ByteBuffer buf, int offset) { - return preColors[(buf.get(offset / 8) >> (7 - offset % 8)) & 1]; - } - - @Override - public int getArgbPre(ByteBuffer buf, int offset) { - return nonPreColors[(buf.get(offset / 8) >> (7 - offset % 8)) & 1]; - } - } - - public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { - public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 8] >> (7 - x % 8)) & 1]; - dstarr[dstoff++] = (byte) argb; - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 24); - } - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 8) >> (7 - x % 8)) & 1]; - dstbuf.put(dstoff, (byte) argb); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) (argb >> 16)); - dstbuf.put(dstoff + 3, (byte) (argb >> 24)); - dstoff += 4; - } - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } - - public static class ToByteRgbConverter extends BaseIndexedToByteConverter { - public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 8] >> (7 - x % 8)) & 1]; - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) argb; - } - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 8) >> (7 - x % 8)) & 1]; - dstbuf.put(dstoff, (byte) (argb >> 16)); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) argb); - dstoff += 3; - } - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - } -} +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.image.impl; + +import com.sun.javafx.image.BytePixelSetter; +import com.sun.javafx.image.IndexedToBytePixelConverter; +import java.nio.ByteBuffer; + +public final class OneBitIndexed { + + private OneBitIndexed() {} + + public static Getter createGetter(int[] colors, Boolean premultiplied) { + return new Getter(colors, premultiplied); + } + + public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { + return new ToByteRgbConverter(src, dst); + } + + public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { + return new ToByteBgraAnyConverter(src, dst); + } + + public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { + Getter(int[] colors, Boolean premultiplied) { + super(colors, premultiplied); + } + + @Override + public int getNumElements() { + return 1; + } + + @Override + public int getArgb(byte[] arr, int offset) { + return preColors[(arr[offset / 8] >> (7 - offset % 8)) & 1]; + } + + @Override + public int getArgbPre(byte[] arr, int offset) { + return nonPreColors[(arr[offset / 8] >> (7 - offset % 8)) & 1]; + } + + @Override + public int getArgb(ByteBuffer buf, int offset) { + return preColors[(buf.get(offset / 8) >> (7 - offset % 8)) & 1]; + } + + @Override + public int getArgbPre(ByteBuffer buf, int offset) { + return nonPreColors[(buf.get(offset / 8) >> (7 - offset % 8)) & 1]; + } + } + + public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { + public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 8] >> (7 - x % 8)) & 1]; + dstarr[dstoff++] = (byte) argb; + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 24); + } + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 8) >> (7 - x % 8)) & 1]; + dstbuf.put(dstoff, (byte) argb); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) (argb >> 16)); + dstbuf.put(dstoff + 3, (byte) (argb >> 24)); + dstoff += 4; + } + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } + + public static class ToByteRgbConverter extends BaseIndexedToByteConverter { + public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 8] >> (7 - x % 8)) & 1]; + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) argb; + } + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbits, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 8) >> (7 - x % 8)) & 1]; + dstbuf.put(dstoff, (byte) (argb >> 16)); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) argb); + dstoff += 3; + } + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + } +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/TwoBitIndexed.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/TwoBitIndexed.java index c19e7b57f6d..31416fad98e 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/TwoBitIndexed.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/image/impl/TwoBitIndexed.java @@ -1,178 +1,178 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.image.impl; - -import com.sun.javafx.image.BytePixelSetter; -import com.sun.javafx.image.IndexedToBytePixelConverter; -import java.nio.ByteBuffer; - -public final class TwoBitIndexed { - - private TwoBitIndexed() {} - - public static Getter createGetter(int[] colors, Boolean premultiplied) { - return new Getter(colors, premultiplied); - } - - public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { - return new ToByteRgbConverter(src, dst); - } - - public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { - return new ToByteBgraAnyConverter(src, dst); - } - - public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { - Getter(int[] colors, Boolean premultiplied) { - super(colors, premultiplied); - } - - @Override - public int getNumElements() { - return 2; - } - - @Override - public int getArgb(byte[] arr, int offset) { - return preColors[(arr[offset / 4] >> (6 - offset % 4 * 2)) & 3]; - } - - @Override - public int getArgbPre(byte[] arr, int offset) { - return nonPreColors[(arr[offset / 4] >> (6 - offset % 4 * 2)) & 3]; - } - - @Override - public int getArgb(ByteBuffer buf, int offset) { - return preColors[(buf.get(offset / 4) >> (6 - offset % 4 * 2)) & 3]; - } - - @Override - public int getArgbPre(ByteBuffer buf, int offset) { - return nonPreColors[(buf.get(offset / 4) >> (6 - offset % 4 * 2)) & 3]; - } - } - - public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { - public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbits, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 4] >> (6 - x % 4 * 2)) & 3]; - dstarr[dstoff++] = (byte) argb; - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 24); - } - srcoff += srcscanbits; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbytes, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = switch (setter.getAlphaType()) { - case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; - case PREMULTIPLIED -> getGetter().preColors; - }; - - dstscanbytes -= w * 4; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 4) >> (6 - x % 4 * 2)) & 3]; - dstbuf.put(dstoff, (byte) argb); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) (argb >> 16)); - dstbuf.put(dstoff + 3, (byte) (argb >> 24)); - dstoff += 4; - } - srcoff += srcscanbytes; - dstoff += dstscanbytes; - } - } - } - - public static class ToByteRgbConverter extends BaseIndexedToByteConverter { - public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { - super(getter, setter); - } - - @Override - void doConvert(byte[] srcarr, int srcoff, int srcscanbytes, - byte[] dstarr, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcarr[srcoff / 8 + x / 4] >> (6 - x % 4 * 2)) & 3]; - dstarr[dstoff++] = (byte) (argb >> 16); - dstarr[dstoff++] = (byte) (argb >> 8); - dstarr[dstoff++] = (byte) argb; - } - srcoff += srcscanbytes; - dstoff += dstscanbytes; - } - } - - @Override - void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbytes, - ByteBuffer dstbuf, int dstoff, int dstscanbytes, - int w, int h) { - int[] colors = getGetter().nonPreColors; - dstscanbytes -= w * 3; - - while (--h >= 0) { - for (int x = 0; x < w; x++) { - int argb = colors[(srcbuf.get(srcoff / 8 + x / 4) >> (6 - x % 4 * 2)) & 3]; - dstbuf.put(dstoff, (byte) (argb >> 16)); - dstbuf.put(dstoff + 1, (byte) (argb >> 8)); - dstbuf.put(dstoff + 2, (byte) argb); - dstoff += 3; - } - srcoff += srcscanbytes; - dstoff += dstscanbytes; - } - } - } -} +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.image.impl; + +import com.sun.javafx.image.BytePixelSetter; +import com.sun.javafx.image.IndexedToBytePixelConverter; +import java.nio.ByteBuffer; + +public final class TwoBitIndexed { + + private TwoBitIndexed() {} + + public static Getter createGetter(int[] colors, Boolean premultiplied) { + return new Getter(colors, premultiplied); + } + + public static IndexedToBytePixelConverter createToByteRgb(Getter src, BytePixelSetter dst) { + return new ToByteRgbConverter(src, dst); + } + + public static IndexedToBytePixelConverter createToByteBgraAny(Getter src, BytePixelSetter dst) { + return new ToByteBgraAnyConverter(src, dst); + } + + public static class Getter extends BaseIndexedToByteConverter.IndexedGetter { + Getter(int[] colors, Boolean premultiplied) { + super(colors, premultiplied); + } + + @Override + public int getNumElements() { + return 2; + } + + @Override + public int getArgb(byte[] arr, int offset) { + return preColors[(arr[offset / 4] >> (6 - offset % 4 * 2)) & 3]; + } + + @Override + public int getArgbPre(byte[] arr, int offset) { + return nonPreColors[(arr[offset / 4] >> (6 - offset % 4 * 2)) & 3]; + } + + @Override + public int getArgb(ByteBuffer buf, int offset) { + return preColors[(buf.get(offset / 4) >> (6 - offset % 4 * 2)) & 3]; + } + + @Override + public int getArgbPre(ByteBuffer buf, int offset) { + return nonPreColors[(buf.get(offset / 4) >> (6 - offset % 4 * 2)) & 3]; + } + } + + public static class ToByteBgraAnyConverter extends BaseIndexedToByteConverter { + public ToByteBgraAnyConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbits, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 4] >> (6 - x % 4 * 2)) & 3]; + dstarr[dstoff++] = (byte) argb; + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 24); + } + srcoff += srcscanbits; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbytes, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = switch (setter.getAlphaType()) { + case OPAQUE, NONPREMULTIPLIED -> getGetter().nonPreColors; + case PREMULTIPLIED -> getGetter().preColors; + }; + + dstscanbytes -= w * 4; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 4) >> (6 - x % 4 * 2)) & 3]; + dstbuf.put(dstoff, (byte) argb); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) (argb >> 16)); + dstbuf.put(dstoff + 3, (byte) (argb >> 24)); + dstoff += 4; + } + srcoff += srcscanbytes; + dstoff += dstscanbytes; + } + } + } + + public static class ToByteRgbConverter extends BaseIndexedToByteConverter { + public ToByteRgbConverter(Getter getter, BytePixelSetter setter) { + super(getter, setter); + } + + @Override + void doConvert(byte[] srcarr, int srcoff, int srcscanbytes, + byte[] dstarr, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcarr[srcoff / 8 + x / 4] >> (6 - x % 4 * 2)) & 3]; + dstarr[dstoff++] = (byte) (argb >> 16); + dstarr[dstoff++] = (byte) (argb >> 8); + dstarr[dstoff++] = (byte) argb; + } + srcoff += srcscanbytes; + dstoff += dstscanbytes; + } + } + + @Override + void doConvert(ByteBuffer srcbuf, int srcoff, int srcscanbytes, + ByteBuffer dstbuf, int dstoff, int dstscanbytes, + int w, int h) { + int[] colors = getGetter().nonPreColors; + dstscanbytes -= w * 3; + + while (--h >= 0) { + for (int x = 0; x < w; x++) { + int argb = colors[(srcbuf.get(srcoff / 8 + x / 4) >> (6 - x % 4 * 2)) & 3]; + dstbuf.put(dstoff, (byte) (argb >> 16)); + dstbuf.put(dstoff + 1, (byte) (argb >> 8)); + dstbuf.put(dstoff + 2, (byte) argb); + dstoff += 3; + } + srcoff += srcscanbytes; + dstoff += dstscanbytes; + } + } + } +}