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
44 super(cursor, hotSpot, name);
45 }
46
47 protected void createNativeCursor(Image im, int[] pixels, int width, int height,
48 int xHotSpot, int yHotSpot) {
49
50 class CCount implements Comparable<CCount> {
51 int color;
52 int count;
53
54 public CCount(int cl, int ct) {
55 color = cl;
56 count = ct;
57 }
58
59 public int compareTo(CCount cc) {
60 return cc.count - count;
61 }
62 }
63
64 int tmp[] = new int[pixels.length];
65 for (int i=0; i<pixels.length; i++) {
66 if ((pixels[i] & 0xff000000) == 0) {
67 tmp[i] = -1;
68 } else {
69 tmp[i] = pixels[i] & 0x00ffffff;
70 }
71 }
72 java.util.Arrays.sort(tmp);
73
74 int fc = 0x000000;
75 int bc = 0xffffff;
76 CCount cols[] = new CCount[pixels.length];
77
78 int is = 0;
79 int numColors = 0;
80 while ( is < pixels.length ) {
81 if (tmp[is] != -1) {
82 cols[numColors++] = new CCount(tmp[is], 1);
83 break;
84 }
85 is ++;
86 }
87
88 for (int i = is+1; i < pixels.length; i++) {
89 if (tmp[i] != cols[numColors-1].color) {
90 cols[numColors++] = new CCount(tmp[i], 1);
91 } else {
92 cols[numColors-1].count ++;
93 }
94 }
95 java.util.Arrays.sort(cols, 0, numColors);
96
|
1 /*
2 * Copyright (c) 1997, 2018, 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
44 super(cursor, hotSpot, name);
45 }
46
47 protected void createNativeCursor(Image im, int[] pixels, int width, int height,
48 int xHotSpot, int yHotSpot) {
49
50 class CCount implements Comparable<CCount> {
51 int color;
52 int count;
53
54 public CCount(int cl, int ct) {
55 color = cl;
56 count = ct;
57 }
58
59 public int compareTo(CCount cc) {
60 return cc.count - count;
61 }
62 }
63
64 int[] tmp = new int[pixels.length];
65 for (int i=0; i<pixels.length; i++) {
66 if ((pixels[i] & 0xff000000) == 0) {
67 tmp[i] = -1;
68 } else {
69 tmp[i] = pixels[i] & 0x00ffffff;
70 }
71 }
72 java.util.Arrays.sort(tmp);
73
74 int fc = 0x000000;
75 int bc = 0xffffff;
76 CCount[] cols = new CCount[pixels.length];
77
78 int is = 0;
79 int numColors = 0;
80 while ( is < pixels.length ) {
81 if (tmp[is] != -1) {
82 cols[numColors++] = new CCount(tmp[is], 1);
83 break;
84 }
85 is ++;
86 }
87
88 for (int i = is+1; i < pixels.length; i++) {
89 if (tmp[i] != cols[numColors-1].color) {
90 cols[numColors++] = new CCount(tmp[i], 1);
91 } else {
92 cols[numColors-1].count ++;
93 }
94 }
95 java.util.Arrays.sort(cols, 0, numColors);
96
|