1 /*
2 * Copyright (c) 1997, 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
1497 alp = (rgb>>24)&0xff;
1498 if (nBits[3] == 8) {
1499 intpixel[3] = alp;
1500 }
1501 else {
1502 intpixel[3] = (int)
1503 (alp * (1.0f / 255.0f) * ((1<<nBits[3]) - 1) + 0.5f);
1504 }
1505 if (isAlphaPremultiplied) {
1506 factor *= (alp * (1.0f / 255.0f));
1507 precision = -1; // force component calculations below
1508 }
1509 }
1510 if (nBits[0] == precision) {
1511 intpixel[0] = red;
1512 }
1513 else {
1514 intpixel[0] = (int) (red * factor * ((1<<nBits[0]) - 1) + 0.5f);
1515 }
1516 if (nBits[1] == precision) {
1517 intpixel[1] = (int)(grn);
1518 }
1519 else {
1520 intpixel[1] = (int) (grn * factor * ((1<<nBits[1]) - 1) + 0.5f);
1521 }
1522 if (nBits[2] == precision) {
1523 intpixel[2] = (int)(blu);
1524 }
1525 else {
1526 intpixel[2] = (int) (blu * factor * ((1<<nBits[2]) - 1) + 0.5f);
1527 }
1528 } else if (is_LinearGray_stdScale) {
1529 red = fromsRGB8LUT16[red] & 0xffff;
1530 grn = fromsRGB8LUT16[grn] & 0xffff;
1531 blu = fromsRGB8LUT16[blu] & 0xffff;
1532 float gray = ((0.2125f * red) +
1533 (0.7154f * grn) +
1534 (0.0721f * blu)) / 65535.0f;
1535 if (supportsAlpha) {
1536 alp = (rgb>>24) & 0xff;
1537 if (nBits[1] == 8) {
1538 intpixel[1] = alp;
1539 } else {
1540 intpixel[1] = (int) (alp * (1.0f / 255.0f) *
1541 ((1 << nBits[1]) - 1) + 0.5f);
1542 }
1543 if (isAlphaPremultiplied) {
|
1 /*
2 * Copyright (c) 1997, 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
1497 alp = (rgb>>24)&0xff;
1498 if (nBits[3] == 8) {
1499 intpixel[3] = alp;
1500 }
1501 else {
1502 intpixel[3] = (int)
1503 (alp * (1.0f / 255.0f) * ((1<<nBits[3]) - 1) + 0.5f);
1504 }
1505 if (isAlphaPremultiplied) {
1506 factor *= (alp * (1.0f / 255.0f));
1507 precision = -1; // force component calculations below
1508 }
1509 }
1510 if (nBits[0] == precision) {
1511 intpixel[0] = red;
1512 }
1513 else {
1514 intpixel[0] = (int) (red * factor * ((1<<nBits[0]) - 1) + 0.5f);
1515 }
1516 if (nBits[1] == precision) {
1517 intpixel[1] = grn;
1518 }
1519 else {
1520 intpixel[1] = (int) (grn * factor * ((1<<nBits[1]) - 1) + 0.5f);
1521 }
1522 if (nBits[2] == precision) {
1523 intpixel[2] = blu;
1524 }
1525 else {
1526 intpixel[2] = (int) (blu * factor * ((1<<nBits[2]) - 1) + 0.5f);
1527 }
1528 } else if (is_LinearGray_stdScale) {
1529 red = fromsRGB8LUT16[red] & 0xffff;
1530 grn = fromsRGB8LUT16[grn] & 0xffff;
1531 blu = fromsRGB8LUT16[blu] & 0xffff;
1532 float gray = ((0.2125f * red) +
1533 (0.7154f * grn) +
1534 (0.0721f * blu)) / 65535.0f;
1535 if (supportsAlpha) {
1536 alp = (rgb>>24) & 0xff;
1537 if (nBits[1] == 8) {
1538 intpixel[1] = alp;
1539 } else {
1540 intpixel[1] = (int) (alp * (1.0f / 255.0f) *
1541 ((1 << nBits[1]) - 1) + 0.5f);
1542 }
1543 if (isAlphaPremultiplied) {
|