|
1 /* |
|
2 * Copyright 2000-2003 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 #include "malloc.h" |
|
27 |
|
28 #include "SurfaceData.h" |
|
29 #include "sun_awt_image_DataBufferNative.h" |
|
30 |
|
31 #include "jni_util.h" |
|
32 #include "debug_trace.h" |
|
33 #include <stdio.h> |
|
34 |
|
35 unsigned char *DBN_GetPixelPointer(JNIEnv *env, jint x, int y, |
|
36 SurfaceDataRasInfo *lockInfo, |
|
37 SurfaceDataOps *ops, int lockFlag) |
|
38 { |
|
39 if (ops == NULL) { |
|
40 return NULL; |
|
41 } |
|
42 |
|
43 lockInfo->bounds.x1 = x; |
|
44 lockInfo->bounds.y1 = y; |
|
45 lockInfo->bounds.x2 = x + 1; |
|
46 lockInfo->bounds.y2 = y + 1; |
|
47 if (ops->Lock(env, ops, lockInfo, lockFlag) != SD_SUCCESS) { |
|
48 return NULL; |
|
49 } |
|
50 ops->GetRasInfo(env, ops, lockInfo); |
|
51 if (lockInfo->rasBase) { |
|
52 unsigned char *pixelPtr = ( |
|
53 (unsigned char*)lockInfo->rasBase + |
|
54 (x * lockInfo->pixelStride + y * lockInfo->scanStride)); |
|
55 return pixelPtr; |
|
56 } |
|
57 SurfaceData_InvokeRelease(env, ops, lockInfo); |
|
58 SurfaceData_InvokeUnlock(env, ops, lockInfo); |
|
59 return NULL; |
|
60 } |
|
61 |
|
62 /* |
|
63 * Class: sun_awt_image_DataBufferNative |
|
64 * Method: getElem |
|
65 * Signature: |
|
66 */ |
|
67 JNIEXPORT jint JNICALL |
|
68 Java_sun_awt_image_DataBufferNative_getElem(JNIEnv *env, jobject dbn, |
|
69 jint x, jint y, jobject sd) |
|
70 { |
|
71 jint returnVal = -1; |
|
72 unsigned char *pixelPtr; |
|
73 SurfaceDataRasInfo lockInfo; |
|
74 SurfaceDataOps *ops; |
|
75 |
|
76 ops = SurfaceData_GetOps(env, sd); |
|
77 |
|
78 if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo, |
|
79 ops, SD_LOCK_READ))) |
|
80 { |
|
81 return returnVal; |
|
82 } |
|
83 switch (lockInfo.pixelStride) { |
|
84 case 4: |
|
85 returnVal = *(int *)pixelPtr; |
|
86 break; |
|
87 /* REMIND: do we need a 3-byte case (for 24-bit) here? */ |
|
88 case 2: |
|
89 returnVal = *(unsigned short *)pixelPtr; |
|
90 break; |
|
91 case 1: |
|
92 returnVal = *pixelPtr; |
|
93 break; |
|
94 default: |
|
95 break; |
|
96 } |
|
97 SurfaceData_InvokeRelease(env, ops, &lockInfo); |
|
98 SurfaceData_InvokeUnlock(env, ops, &lockInfo); |
|
99 return returnVal; |
|
100 } |
|
101 |
|
102 |
|
103 /* |
|
104 * Class: sun_awt_image_DataBufferNative |
|
105 * Method: setElem |
|
106 * Signature: |
|
107 */ |
|
108 JNIEXPORT void JNICALL |
|
109 Java_sun_awt_image_DataBufferNative_setElem(JNIEnv *env, jobject dbn, |
|
110 jint x, jint y, jint val, jobject sd) |
|
111 { |
|
112 SurfaceDataRasInfo lockInfo; |
|
113 SurfaceDataOps *ops; |
|
114 unsigned char *pixelPtr; |
|
115 |
|
116 |
|
117 ops = SurfaceData_GetOps(env, sd); |
|
118 |
|
119 if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo, |
|
120 ops, SD_LOCK_WRITE))) |
|
121 { |
|
122 return; |
|
123 } |
|
124 |
|
125 switch (lockInfo.pixelStride) { |
|
126 case 4: |
|
127 *(int *)pixelPtr = val; |
|
128 break; |
|
129 /* REMIND: do we need a 3-byte case (for 24-bit) here? */ |
|
130 case 2: |
|
131 *(unsigned short *)pixelPtr = (unsigned short)val; |
|
132 break; |
|
133 case 1: |
|
134 *pixelPtr = (unsigned char)val; |
|
135 break; |
|
136 default: |
|
137 break; |
|
138 } |
|
139 SurfaceData_InvokeRelease(env, ops, &lockInfo); |
|
140 SurfaceData_InvokeUnlock(env, ops, &lockInfo); |
|
141 } |