Skip to content

Commit 76402bc

Browse files
committed
8280964: [Linux aarch64] : drawImage dithers TYPE_BYTE_INDEXED images incorrectly
Backport-of: 6f882deddcc094777b45f0dacc7351dbc23993a4
1 parent 2f39462 commit 76402bc

File tree

8 files changed

+100
-17
lines changed

8 files changed

+100
-17
lines changed

src/java.desktop/share/native/libawt/awt/image/cvutils/img_globals.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ make_uns_ordered_dither_array(uns_ordered_dither_array oda,
7777
* color used as an index.
7878
*/
7979
void
80-
make_sgn_ordered_dither_array(char* oda, int minerr, int maxerr)
80+
make_sgn_ordered_dither_array(signed char* oda, int minerr, int maxerr)
8181
{
8282
int i, j, k;
8383

src/java.desktop/share/native/libawt/awt/image/cvutils/img_globals.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef int ImgConvertFcn(void *colormodel,
137137
* The type of the error matrix used in the ordered dithering code.
138138
*/
139139
typedef unsigned char uns_ordered_dither_array[8][8];
140-
typedef char sgn_ordered_dither_array[8][8];
140+
typedef signed char sgn_ordered_dither_array[8][8];
141141

142142
/*
143143
* The function provided for constructing the ordered dithering error
@@ -148,7 +148,7 @@ typedef char sgn_ordered_dither_array[8][8];
148148
JNIEXPORT void JNICALL
149149
make_uns_ordered_dither_array(uns_ordered_dither_array oda,
150150
int quantum);
151-
extern void make_sgn_ordered_dither_array(char* oda, int errmin, int errmax);
151+
extern void make_sgn_ordered_dither_array(signed char* oda, int errmin, int errmax);
152152

153153
/*
154154
* The function provided for calculating the contents of the ImgCMData

src/java.desktop/share/native/libawt/java2d/SurfaceData.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ typedef struct {
129129
* array of bytes indexed by RxGxB where each component is reduced to 5
130130
* bits of precision before indexing.
131131
*
132-
* char *redErrTable;
133-
* char *grnErrTable;
134-
* char *bluErrTable;
132+
* signed char *redErrTable;
133+
* signed char *grnErrTable;
134+
* signed char *bluErrTable;
135135
* [Requires SD_LOCK_INVCOLOR]
136136
* Pointers to the beginning of the ordered dither color error tables
137137
* for the colormap. The error tables are formatted as an 8x8 array
@@ -159,9 +159,9 @@ typedef struct {
159159
unsigned int lutSize; /* # colors in colormap */
160160
jint *lutBase; /* Pointer to colormap[0] */
161161
unsigned char *invColorTable; /* Inverse color table */
162-
char *redErrTable; /* Red ordered dither table */
163-
char *grnErrTable; /* Green ordered dither table */
164-
char *bluErrTable; /* Blue ordered dither table */
162+
signed char *redErrTable; /* Red ordered dither table */
163+
signed char *grnErrTable; /* Green ordered dither table */
164+
signed char *bluErrTable; /* Blue ordered dither table */
165165
int *invGrayTable; /* Inverse gray table */
166166
int representsPrimaries; /* whether cmap represents primary colors */
167167
union {

src/java.desktop/share/native/libawt/java2d/loops/ByteIndexed.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef jubyte ByteIndexedDataType;
4444

4545
#define DeclareByteIndexedStoreVars(PREFIX) \
4646
int PREFIX ## XDither, PREFIX ## YDither, PREFIX ## RepPrims; \
47-
char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \
47+
signed char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \
4848
unsigned char *PREFIX ## InvLut;
4949

5050
#define SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \

src/java.desktop/share/native/libawt/java2d/loops/UshortIndexed.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef jushort UshortIndexedDataType;
5151

5252
#define DeclareUshortIndexedStoreVars(PREFIX) \
5353
int PREFIX ## XDither, PREFIX ## YDither; \
54-
char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \
54+
signed char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \
5555
unsigned char *PREFIX ## InvLut;
5656

5757
#define SetUshortIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \

src/java.desktop/unix/native/common/awt/colordata.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ typedef struct _ColorData {
3939
unsigned char *awt_icmLUT2Colors;
4040
unsigned char *img_grays;
4141
unsigned char *img_clr_tbl;
42-
char* img_oda_red;
43-
char* img_oda_green;
44-
char* img_oda_blue;
42+
signed char* img_oda_red;
43+
signed char* img_oda_green;
44+
signed char* img_oda_blue;
4545
int *pGrayInverseLutData;
4646
int screendata;
4747
int representsPrimaries;

src/java.desktop/windows/native/libawt/windows/colordata.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include "img_globals.h"
2929

3030
typedef struct _ColorData {
31-
char* img_oda_red;
32-
char* img_oda_green;
33-
char* img_oda_blue;
31+
signed char* img_oda_red;
32+
signed char* img_oda_green;
33+
signed char* img_oda_blue;
3434
unsigned char* img_clr_tbl;
3535
int *pGrayInverseLutData;
3636
int representsPrimaries;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2022, 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.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8280964
27+
* @summary Tests that drawing to a ByteIndexed image dithers correctly.
28+
*/
29+
30+
import java.awt.Color;
31+
import java.awt.Graphics2D;
32+
import java.awt.image.BufferedImage;
33+
34+
public class ByteIndexedDitherTest {
35+
36+
public static void main(String[] args) {
37+
BufferedImage bgr = createBGRImage();
38+
BufferedImage indexed = createIndexedImage(bgr);
39+
checkImage(indexed);
40+
}
41+
42+
static BufferedImage createBGRImage() {
43+
44+
int sz = 8;
45+
BufferedImage img;
46+
img = new BufferedImage(sz, sz, BufferedImage.TYPE_3BYTE_BGR);
47+
Graphics2D g = img.createGraphics();
48+
Color c = new Color(0, 0, 254);
49+
g.setColor(c);
50+
g.fillRect(0, 0, sz, sz);
51+
g.dispose();
52+
53+
return img;
54+
}
55+
56+
static BufferedImage createIndexedImage(BufferedImage srcImage) {
57+
58+
int w = srcImage.getWidth(null);
59+
int h = srcImage.getHeight(null);
60+
BufferedImage
61+
indexedImg = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED);
62+
Graphics2D g = indexedImg.createGraphics();
63+
g.drawImage(srcImage, 0, 0, w, h, null);
64+
g.dispose();
65+
return indexedImg;
66+
}
67+
68+
static void checkImage(BufferedImage image) {
69+
int wid = image.getWidth();
70+
int hgt = image.getHeight();
71+
for (int y=0; y<hgt; y++) {
72+
for (int x=0; x<wid; x++) {
73+
int v = image.getRGB(x, y);
74+
if ((v & 0x00ffff00) != 0) {
75+
System.err.println("("+x+","+y+") = " +
76+
Integer.toHexString(v));
77+
throw new RuntimeException("Unexpected Red or Green");
78+
}
79+
}
80+
}
81+
}
82+
}
83+

0 commit comments

Comments
 (0)