66
|
1 |
/*
|
|
2 |
* Copyright (c) 1999 - 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
package javax.microedition.lcdui;
|
|
20 |
|
|
21 |
import javax.microedition.lcdui.game.Sprite;
|
|
22 |
import java.util.Enumeration;
|
|
23 |
import java.util.Hashtable;
|
|
24 |
import java.lang.Math;
|
|
25 |
|
|
26 |
import com.nokia.mj.impl.rt.legacy.NativeError;
|
|
27 |
import com.nokia.mid.ui.DirectUtils;
|
|
28 |
import com.nokia.mj.impl.rt.support.ApplicationInfo;
|
|
29 |
import com.nokia.mj.impl.rt.support.Finalizer;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* MIDP LCDUI API class providing methods to draw graphics primitives
|
|
33 |
* on a Canvas, CustomItem or Image.
|
|
34 |
*
|
|
35 |
* Implementation writes commands into a (currently per-MIDlet) global
|
|
36 |
* buffer. Each command is of the following form:
|
|
37 |
*
|
|
38 |
* [header][data]
|
|
39 |
*
|
|
40 |
* The header is a 32 bit integer divided into two 16 bit fields, the most
|
|
41 |
* significant halfword contains the opcode. The opcode is further subdivided
|
|
42 |
* into three fields:
|
|
43 |
*
|
|
44 |
* 15-12 11-10 9-0
|
|
45 |
* [clear][mode][op]
|
|
46 |
*
|
|
47 |
* The top 4 bits are clear, although this may change in future, the top two bits
|
|
48 |
* must always remain clear as these bits are used by the buffer itself.
|
|
49 |
*
|
|
50 |
* Bits 10 and 11 contain a mode identifier which is used by the native layer
|
|
51 |
* to try to minimize the number of state changes to the native graphics context.
|
|
52 |
*
|
|
53 |
* Bits 0 to 9 contains an integer opcode. These must match the opcodes declared in
|
|
54 |
* MMIDGraphics in lcdgr.h, and must remain contiguous.
|
|
55 |
*/
|
|
56 |
public class Graphics
|
|
57 |
{
|
|
58 |
private static final int TRANS_MIN = javax.microedition.lcdui.game.Sprite.TRANS_NONE;
|
|
59 |
private static final int TRANS_MAX = javax.microedition.lcdui.game.Sprite.TRANS_MIRROR_ROT90;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Pixel formats.
|
|
63 |
*
|
|
64 |
* These must be kept in sync with MMIDGraphics::TPixelType
|
|
65 |
*
|
|
66 |
* Only TYPE_INT_ARGB_8888 is currently used - in Graphics.drawRGB
|
|
67 |
* The others may be useful in the implementation of extension APIs but
|
|
68 |
* will require modifications to the MMIDGraphics implementation.
|
|
69 |
*/
|
|
70 |
private static final int TYPE_INT_ARGB_8888 = 0; // supported
|
|
71 |
private static final int TYPE_SHORT_ARGB_4444 = 1; // not supported yet
|
|
72 |
private static final int TYPE_PACKED_ECOLOR_4K = 2; // not supported yet
|
|
73 |
|
|
74 |
//
|
|
75 |
// Anchor specs
|
|
76 |
//
|
|
77 |
public static final int HCENTER = 1;
|
|
78 |
public static final int VCENTER = 2;
|
|
79 |
public static final int LEFT = 4;
|
|
80 |
public static final int RIGHT = 8;
|
|
81 |
public static final int TOP = 16;
|
|
82 |
public static final int BOTTOM = 32;
|
|
83 |
public static final int BASELINE = 64;
|
|
84 |
|
|
85 |
//
|
|
86 |
// StrokeStyle consts
|
|
87 |
//
|
|
88 |
public static final int SOLID = 0;
|
|
89 |
public static final int DOTTED = 1;
|
|
90 |
|
|
91 |
//
|
|
92 |
// Anchor masks
|
|
93 |
//
|
|
94 |
private static final int STRING_ANCHOR_MASK = HCENTER|LEFT|RIGHT|TOP|BOTTOM|BASELINE;
|
|
95 |
private static final int IMAGE_ANCHOR_MASK = HCENTER|VCENTER|LEFT|RIGHT|TOP|BOTTOM;
|
|
96 |
private static final int HMASK = HCENTER|LEFT|RIGHT;
|
|
97 |
private static final int VMASK = VCENTER|TOP|BOTTOM|BASELINE;
|
|
98 |
|
|
99 |
//
|
|
100 |
// These must be kept in sync with MMIDGraphics::TGraphicsOp
|
|
101 |
//
|
|
102 |
private static final int OP_SET_COLOR = 0;
|
|
103 |
private static final int OP_SET_STROKE = 1;
|
|
104 |
private static final int OP_SET_FONT = 2;
|
|
105 |
private static final int OP_SET_CLIPRECT = 3;
|
|
106 |
private static final int OP_TRANSLATE = 4;
|
|
107 |
private static final int OP_RESET = 5;
|
|
108 |
|
|
109 |
private static final int OP_DRAW_LINE = 6;
|
|
110 |
private static final int OP_DRAW_RECT = 7;
|
|
111 |
private static final int OP_FILL_RECT = 8;
|
|
112 |
private static final int OP_DRAW_ROUNDRECT = 9;
|
|
113 |
private static final int OP_FILL_ROUNDRECT = 10;
|
|
114 |
private static final int OP_DRAW_ARC = 11;
|
|
115 |
private static final int OP_FILL_ARC = 12;
|
|
116 |
private static final int OP_DRAW_STRING = 13;
|
|
117 |
private static final int OP_DRAW_IMAGE = 14;
|
|
118 |
private static final int OP_DRAW_REGION = 15;
|
|
119 |
private static final int OP_COPY_AREA = 16;
|
|
120 |
private static final int OP_FILL_TRIANGLE = 17;
|
|
121 |
private static final int OP_DRAW_PIXELS = 18;
|
|
122 |
|
|
123 |
/* special ops */
|
|
124 |
private static final int OP_FLUSH = 19;
|
|
125 |
|
|
126 |
private static final int OP_DRAW_BACKGROUND = 20;
|
|
127 |
/* NGA specific change */
|
|
128 |
private static final int OP_COPY_GRAPHICS = 21;
|
|
129 |
|
|
130 |
// Default color
|
|
131 |
private static final int BLACK = 0xff000000;
|
|
132 |
|
|
133 |
Font iDefaultFont;
|
|
134 |
|
|
135 |
//
|
|
136 |
Toolkit iToolkit;
|
|
137 |
Buffer iBuffer;
|
|
138 |
Object iTarget;
|
|
139 |
Image iImage; // target is image
|
|
140 |
int iHandle;
|
|
141 |
int iDirectGraphicsHandle;
|
|
142 |
int iWidth;
|
|
143 |
int iHeight;
|
|
144 |
private char[] iChar; // Buffer for string/character drawing.
|
|
145 |
|
|
146 |
// State
|
|
147 |
private int iTransX;
|
|
148 |
private int iTransY;
|
|
149 |
private int iClipX;
|
|
150 |
private int iClipY;
|
|
151 |
private int iClipWidth;
|
|
152 |
private int iClipHeight;
|
|
153 |
|
|
154 |
private int iColor; // color value ARGB with 8 bits each
|
|
155 |
private int iStrokeStyle; // one of (SOLID,DOTTED)
|
|
156 |
private Font iFont;
|
|
157 |
private Font iScalableFont;
|
|
158 |
private boolean iFontSet;
|
|
159 |
private boolean iScalableFontSet;
|
|
160 |
private boolean iPrevScalingFlag = false;
|
|
161 |
|
|
162 |
private int iOnScreenWidth; // width of screen
|
|
163 |
private int iOnScreenHeight; // height of screen
|
|
164 |
|
|
165 |
//flag if is original size set in JAD file
|
|
166 |
private boolean iIsSetOriginalSize;
|
|
167 |
// flag if set target size in JAD file
|
|
168 |
private boolean iIsSetTargetSize;
|
|
169 |
|
|
170 |
// size from Nokia-MIDlet-Canvas-Scaling-Orientation-Switch JAD attribute
|
|
171 |
private int iTargetHeight;
|
|
172 |
private int iTargetWidth;
|
|
173 |
|
|
174 |
// NokiaUI DirectGraphics is stored here in order to allow a proper
|
|
175 |
// garbage collection.
|
|
176 |
DirectGraphicsImpl iDirectGraphics;
|
|
177 |
|
|
178 |
private Finalizer mFinalizer = new Finalizer()
|
|
179 |
{
|
|
180 |
public void finalizeImpl()
|
|
181 |
{
|
|
182 |
doFinalize();
|
|
183 |
}
|
|
184 |
};
|
|
185 |
|
|
186 |
/*
|
|
187 |
* Constructor
|
|
188 |
*/
|
|
189 |
Graphics(Toolkit aToolkit,
|
|
190 |
Object aTarget,
|
|
191 |
int aDrawable,
|
|
192 |
int aWidth,
|
|
193 |
int aHeight)
|
|
194 |
{
|
|
195 |
// saving of given parameters
|
|
196 |
iToolkit = aToolkit;
|
|
197 |
iBuffer = aToolkit.iBuffer;
|
|
198 |
iTarget = aTarget;
|
|
199 |
iIsSetTargetSize = false;
|
|
200 |
// If a Graphics is drawing to image then a image is saved. Null otherwise
|
|
201 |
iImage = (aTarget instanceof Image) ? (Image)aTarget : null;
|
|
202 |
|
|
203 |
// creating of native side graphics
|
|
204 |
iHandle = NativeError.check(_create(aToolkit.getHandle(), aDrawable));
|
|
205 |
|
|
206 |
// default values
|
|
207 |
iChar = new char[1];
|
|
208 |
iIsSetOriginalSize = false;
|
|
209 |
iIsSetTargetSize = false;
|
|
210 |
iDefaultFont = Font.getDefaultFont();
|
|
211 |
|
|
212 |
// this get a correct iIsSetOriginalSize and iIsSetTargetSize values.
|
|
213 |
//
|
|
214 |
// getting JAD attributes
|
|
215 |
ApplicationInfo appInfo = ApplicationInfo.getInstance();
|
|
216 |
if (appInfo.getAttribute("Nokia-MIDlet-Original-Display-Size") != null)
|
|
217 |
{
|
|
218 |
iIsSetOriginalSize = true;
|
|
219 |
}
|
|
220 |
String targetSize = appInfo.getAttribute("Nokia-MIDlet-Target-Display-Size");
|
|
221 |
if (targetSize != null)
|
|
222 |
{
|
|
223 |
// setting of iTargetHeight and iTargetWidth
|
|
224 |
setTargetSize(targetSize);
|
|
225 |
}
|
|
226 |
|
|
227 |
// resenting of state of Graphics
|
|
228 |
resetState(aWidth, aHeight);
|
|
229 |
}
|
|
230 |
|
|
231 |
/**
|
|
232 |
* This method set iTargetHeight and iTargetWidth according to targetSize String.
|
|
233 |
* @param targetSize string with Nokia-MIDlet-Target-Display-Size param
|
|
234 |
*/
|
|
235 |
private void setTargetSize(String targetSize)
|
|
236 |
{
|
|
237 |
iIsSetTargetSize = false;
|
|
238 |
String current = "";
|
|
239 |
int indexString = 0;
|
|
240 |
int indexArray = 0;
|
|
241 |
|
|
242 |
// deleting of leading spaces
|
|
243 |
targetSize = targetSize.trim();
|
|
244 |
|
|
245 |
// loading of help string for iTargetWidth
|
|
246 |
current += targetSize.charAt(indexString++);
|
|
247 |
while ((indexString < targetSize.length()) && (Character.isDigit(targetSize.charAt(indexString))))
|
|
248 |
{
|
|
249 |
current += (targetSize.charAt(indexString++));
|
|
250 |
}
|
|
251 |
|
|
252 |
// If first next non-space char is not ',', input string is wrong.
|
|
253 |
while (targetSize.charAt(indexString) == ' ')
|
|
254 |
{
|
|
255 |
indexString++;
|
|
256 |
}
|
|
257 |
if (targetSize.charAt(indexString++) != ',')
|
|
258 |
{
|
|
259 |
return;
|
|
260 |
}
|
|
261 |
|
|
262 |
// setting of iTargetWidth
|
|
263 |
iTargetWidth = Integer.parseInt(current);
|
|
264 |
|
|
265 |
// set to targetSize String for iTargetHeight without spaces
|
|
266 |
targetSize = targetSize.substring(indexString).trim();
|
|
267 |
indexString = 0;
|
|
268 |
indexArray = 0;
|
|
269 |
current = "";
|
|
270 |
|
|
271 |
// loading of help string for iTargetHeight
|
|
272 |
current += targetSize.charAt(indexString++);
|
|
273 |
while ((indexString < targetSize.length()) && (Character.isDigit(targetSize.charAt(indexString))))
|
|
274 |
{
|
|
275 |
current += (targetSize.charAt(indexString++));
|
|
276 |
}
|
|
277 |
|
|
278 |
// setting of iTargetHeight
|
|
279 |
iTargetHeight = Integer.parseInt(current);
|
|
280 |
|
|
281 |
// Set of flag iIsSetTargetSize.
|
|
282 |
iIsSetTargetSize = true;
|
|
283 |
}
|
|
284 |
|
|
285 |
void dispose()
|
|
286 |
{
|
|
287 |
final int handle;
|
|
288 |
synchronized (iBuffer)
|
|
289 |
{
|
|
290 |
handle = iHandle;
|
|
291 |
iHandle = 0;
|
|
292 |
}
|
|
293 |
if (0 != handle)
|
|
294 |
{
|
|
295 |
iToolkit.disposeObject(handle);
|
|
296 |
}
|
|
297 |
}
|
|
298 |
|
|
299 |
private void doFinalize()
|
|
300 |
{
|
|
301 |
if (mFinalizer != null)
|
|
302 |
{
|
|
303 |
registeredFinalize();
|
|
304 |
mFinalizer = null;
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
void registeredFinalize()
|
|
309 |
{
|
|
310 |
dispose();
|
|
311 |
}
|
|
312 |
|
|
313 |
private void resetState(int aWidth, int aHeight)
|
|
314 |
{
|
|
315 |
// set of size of iTarget.
|
|
316 |
iWidth = aWidth;
|
|
317 |
iHeight = aHeight;
|
|
318 |
// get of size of screen
|
|
319 |
iToolkit.getDevice().getDeviceSizeWithoutKeypad();
|
|
320 |
iOnScreenWidth = iToolkit.getDevice().iScreenWidth;
|
|
321 |
iOnScreenHeight = iToolkit.getDevice().iScreenHeight;
|
|
322 |
if (iOnScreenWidth == 0)
|
|
323 |
{
|
|
324 |
iOnScreenWidth = iWidth;
|
|
325 |
}
|
|
326 |
if (iOnScreenHeight == 0)
|
|
327 |
{
|
|
328 |
iOnScreenHeight = iHeight;
|
|
329 |
}
|
|
330 |
|
|
331 |
// reset of traslation, clip, color, stroke style and font
|
|
332 |
iTransX = 0;
|
|
333 |
iTransY = 0;
|
|
334 |
iClipX = 0;
|
|
335 |
iClipY = 0;
|
|
336 |
iClipWidth = aWidth;
|
|
337 |
iClipHeight = aHeight;
|
|
338 |
iColor = BLACK;
|
|
339 |
iStrokeStyle = SOLID;
|
|
340 |
iFont = iDefaultFont;
|
|
341 |
iFontSet = false;
|
|
342 |
iScalableFontSet = false;
|
|
343 |
|
|
344 |
// If target is Canvas in fullscreen mode and
|
|
345 |
// MIDlet have set original size and have't set target size,
|
|
346 |
// then it is required set correct values of iOnScreenWidth and
|
|
347 |
// iOnScreenHeight.
|
|
348 |
if ((iTarget instanceof Canvas) &&
|
|
349 |
((Canvas)iTarget).getFullScreenMode() &&
|
|
350 |
!iIsSetTargetSize && iIsSetOriginalSize)
|
|
351 |
{
|
|
352 |
// This code checks if some of measures is
|
|
353 |
// bigger of target Canvas is bigger than
|
|
354 |
// measure of screen.
|
|
355 |
float ratioX = (float)iWidth / iOnScreenWidth;
|
|
356 |
float ratioY = (float)iHeight / iOnScreenHeight;
|
|
357 |
|
|
358 |
if (Math.max(ratioX, ratioY) > 1)
|
|
359 |
{
|
|
360 |
// Canvas has smaller ratio for width to for height than screen.
|
|
361 |
if (ratioY > ratioX)
|
|
362 |
{
|
|
363 |
// setting correct value of iOnScreenWidth
|
|
364 |
iOnScreenWidth = (iOnScreenHeight * iWidth) / iHeight;
|
|
365 |
}
|
|
366 |
// Canvas has bigger ratio for width to for height than screen
|
|
367 |
// (or the same).
|
|
368 |
else
|
|
369 |
{
|
|
370 |
// setting correct value of iOnScreenHeight
|
|
371 |
iOnScreenHeight = (iOnScreenWidth * iHeight) / iWidth;
|
|
372 |
}
|
|
373 |
}
|
|
374 |
}
|
|
375 |
// setting of target size
|
|
376 |
if ((iTarget instanceof Canvas) &&
|
|
377 |
((Canvas)iTarget).getFullScreenMode() &&
|
|
378 |
iIsSetTargetSize && iIsSetOriginalSize)
|
|
379 |
{
|
|
380 |
iOnScreenHeight = iTargetHeight;
|
|
381 |
iOnScreenWidth = iTargetWidth;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
void reset(int aWidth, int aHeight)
|
|
386 |
{
|
|
387 |
synchronized (iBuffer)
|
|
388 |
{
|
|
389 |
if (iHandle != 0)
|
|
390 |
{
|
|
391 |
resetState(aWidth, aHeight);
|
|
392 |
iBuffer.write(iHandle, OP_RESET, aWidth, aHeight);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
public void translate(int aDx,int aDy)
|
|
398 |
{
|
|
399 |
synchronized (iBuffer)
|
|
400 |
{
|
|
401 |
// If is downscaling on, then we change parameters.
|
|
402 |
if (isDownscaled())
|
|
403 |
{
|
|
404 |
aDx = (aDx * iOnScreenWidth) / iWidth;
|
|
405 |
aDy = (aDy * iOnScreenHeight) / iHeight;
|
|
406 |
}
|
|
407 |
// setting of translate in java class Graphics
|
|
408 |
iTransX += aDx;
|
|
409 |
iTransY += aDy;
|
|
410 |
iClipX -= aDx;
|
|
411 |
iClipY -= aDy;
|
|
412 |
// setting of translate in native graphics
|
|
413 |
iBuffer.write(iHandle, OP_TRANSLATE, iTransX, iTransY);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
public int getTranslateX()
|
|
418 |
{
|
|
419 |
// If is downscaling on, then it return downscaled traslate of x.
|
|
420 |
if (isDownscaled())
|
|
421 |
return (iTransX * iWidth) / iOnScreenWidth;
|
|
422 |
// If is downscaling off, then it return non-scaled traslate of x.
|
|
423 |
else
|
|
424 |
return iTransX;
|
|
425 |
}
|
|
426 |
|
|
427 |
public int getTranslateY()
|
|
428 |
{
|
|
429 |
// If is downscaling on, then it return downscaled traslate of y.
|
|
430 |
if (isDownscaled())
|
|
431 |
return (iTransY * iHeight) / iOnScreenHeight;
|
|
432 |
// If is downscaling off, then it return non-scaled traslate of y.
|
|
433 |
else
|
|
434 |
return iTransY;
|
|
435 |
}
|
|
436 |
|
|
437 |
public int getColor()
|
|
438 |
{
|
|
439 |
return (iColor & 0x00ffffff);
|
|
440 |
}
|
|
441 |
|
|
442 |
public int getRedComponent()
|
|
443 |
{
|
|
444 |
return (iColor >>> 16) & 0xff;
|
|
445 |
}
|
|
446 |
|
|
447 |
public int getGreenComponent()
|
|
448 |
{
|
|
449 |
return (iColor >>> 8) & 0xff;
|
|
450 |
}
|
|
451 |
|
|
452 |
public int getBlueComponent()
|
|
453 |
{
|
|
454 |
return (iColor & 0xff);
|
|
455 |
}
|
|
456 |
|
|
457 |
public int getGrayScale()
|
|
458 |
{
|
|
459 |
final int color = iColor;
|
|
460 |
final int r = (color >>> 16) & 0xff;
|
|
461 |
final int g = (color >>> 8) & 0xff;
|
|
462 |
final int b = color & 0xff;
|
|
463 |
return Math.max(r, Math.max(g,b));
|
|
464 |
}
|
|
465 |
|
|
466 |
public void setColor(int aRed,int aGreen,int aBlue)
|
|
467 |
{
|
|
468 |
/*
|
|
469 |
* For all valid arguments, only the least significant
|
|
470 |
* byte can contain non-zero bits.
|
|
471 |
*/
|
|
472 |
if (((aRed|aGreen|aBlue)>>>8)!=0)
|
|
473 |
{
|
|
474 |
throw new IllegalArgumentException();
|
|
475 |
}
|
|
476 |
setColor((aRed << 16) | (aGreen << 8) | aBlue);
|
|
477 |
}
|
|
478 |
|
|
479 |
public void setColor(int aRgb)
|
|
480 |
{
|
|
481 |
//
|
|
482 |
// Drawing colors are fully opaque.
|
|
483 |
//
|
|
484 |
final int color = (aRgb | 0xff000000);
|
|
485 |
synchronized (iBuffer)
|
|
486 |
{
|
|
487 |
if (iColor != color)
|
|
488 |
{
|
|
489 |
iColor = color;
|
|
490 |
iBuffer.write(iHandle, OP_SET_COLOR, color);
|
|
491 |
}
|
|
492 |
}
|
|
493 |
}
|
|
494 |
|
|
495 |
public void setGrayScale(int aValue)
|
|
496 |
{
|
|
497 |
setColor(aValue, aValue, aValue);
|
|
498 |
}
|
|
499 |
|
|
500 |
public Font getFont()
|
|
501 |
{
|
|
502 |
return iFont;
|
|
503 |
}
|
|
504 |
|
|
505 |
public void setFont(Font aFont)
|
|
506 |
{
|
|
507 |
if (aFont == null)
|
|
508 |
{
|
|
509 |
aFont = Font.getDefaultFont();
|
|
510 |
}
|
|
511 |
synchronized (iBuffer)
|
|
512 |
{
|
|
513 |
if (iFont != aFont)
|
|
514 |
{
|
|
515 |
iFont = aFont;
|
|
516 |
iFontSet = false;
|
|
517 |
iScalableFontSet = false;
|
|
518 |
}
|
|
519 |
}
|
|
520 |
}
|
|
521 |
/**
|
|
522 |
* If the downscaling is on, it is created and used the new scaled font.
|
|
523 |
*/
|
|
524 |
private void setScalableFont()
|
|
525 |
{
|
|
526 |
if (!iScalableFontSet && iFont != null)
|
|
527 |
{
|
|
528 |
int fontHeight = iFont.getHeight();
|
|
529 |
fontHeight = (fontHeight * iOnScreenHeight) / iHeight;
|
|
530 |
iScalableFont = DirectUtils.getFont(iFont.getFace(), iFont.getStyle(), fontHeight);
|
|
531 |
iFontSet = false;
|
|
532 |
iScalableFontSet = false;
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
/**
|
|
537 |
* set font with buffer locked.
|
|
538 |
*/
|
|
539 |
private void UseFont()
|
|
540 |
{
|
|
541 |
if (!iFontSet)
|
|
542 |
{
|
|
543 |
if (!isDownscaled())
|
|
544 |
{
|
|
545 |
iBuffer.write(iHandle, OP_SET_FONT, iFont.iHandle);
|
|
546 |
iFontSet = true;
|
|
547 |
}
|
|
548 |
else if (!iScalableFontSet)
|
|
549 |
{
|
|
550 |
iBuffer.write(iHandle, OP_SET_FONT, iScalableFont.iHandle);
|
|
551 |
iFontSet = true;
|
|
552 |
iScalableFontSet = true;
|
|
553 |
}
|
|
554 |
}
|
|
555 |
}
|
|
556 |
|
|
557 |
public int getClipX()
|
|
558 |
{
|
|
559 |
return iClipX;
|
|
560 |
}
|
|
561 |
|
|
562 |
public int getClipY()
|
|
563 |
{
|
|
564 |
return iClipY;
|
|
565 |
}
|
|
566 |
|
|
567 |
public int getClipWidth()
|
|
568 |
{
|
|
569 |
return iClipWidth;
|
|
570 |
}
|
|
571 |
|
|
572 |
public int getClipHeight()
|
|
573 |
{
|
|
574 |
return iClipHeight;
|
|
575 |
}
|
|
576 |
|
|
577 |
public void clipRect(int aX, int aY, int aWidth,int aHeight)
|
|
578 |
{
|
|
579 |
// finding of correct clip
|
|
580 |
final int cx2 = Math.min(iClipX + iClipWidth, aX + aWidth);
|
|
581 |
final int cy2 = Math.min(iClipY + iClipHeight, aY + aHeight);
|
|
582 |
// setting of clip to Java Graphics
|
|
583 |
iClipX = Math.max(aX, iClipX);
|
|
584 |
iClipY = Math.max(aY, iClipY);
|
|
585 |
iClipWidth = cx2 - iClipX;
|
|
586 |
iClipHeight = cy2 - iClipY;
|
|
587 |
int clipX = iClipX;
|
|
588 |
int clipY = iClipY;
|
|
589 |
int clipWidth = iClipWidth;
|
|
590 |
int clipHeight = iClipHeight;
|
|
591 |
// If is downscaling on, then it downscales clip.
|
|
592 |
if (isDownscaled())
|
|
593 |
{
|
|
594 |
clipX = (clipX * iOnScreenWidth) / iWidth;
|
|
595 |
clipY = (clipY * iOnScreenHeight) / iHeight;
|
|
596 |
clipWidth = (clipWidth * iOnScreenWidth) / iWidth;
|
|
597 |
clipHeight = (clipHeight * iOnScreenHeight) / iHeight;
|
|
598 |
}
|
|
599 |
// Setting clip to native graphics
|
|
600 |
synchronized (iBuffer)
|
|
601 |
{
|
|
602 |
iBuffer.write(iHandle, OP_SET_CLIPRECT, clipX, clipY, clipWidth, clipHeight);
|
|
603 |
if (iDirectGraphicsHandle != 0)
|
|
604 |
iBuffer.write(iDirectGraphicsHandle, OP_SET_CLIPRECT, clipX, clipY, clipWidth, clipHeight);
|
|
605 |
}
|
|
606 |
}
|
|
607 |
|
|
608 |
public void setClip(int aX, int aY, int aWidth, int aHeight)
|
|
609 |
{
|
|
610 |
// setting of clip to Java Graphics
|
|
611 |
iClipX = aX;
|
|
612 |
iClipY = aY;
|
|
613 |
iClipWidth = aWidth;
|
|
614 |
iClipHeight = aHeight;
|
|
615 |
int clipX = iClipX;
|
|
616 |
int clipY = iClipY;
|
|
617 |
int clipWidth = iClipWidth;
|
|
618 |
int clipHeight = iClipHeight;
|
|
619 |
// If is downscaling on, then it downscales clip.
|
|
620 |
if (isDownscaled())
|
|
621 |
{
|
|
622 |
clipX = (clipX * iOnScreenWidth) / iWidth;
|
|
623 |
clipY = (clipY * iOnScreenHeight) / iHeight;
|
|
624 |
clipWidth = (clipWidth * iOnScreenWidth) / iWidth;
|
|
625 |
clipHeight = (clipHeight * iOnScreenHeight) / iHeight;
|
|
626 |
}
|
|
627 |
synchronized (iBuffer)
|
|
628 |
{
|
|
629 |
// Setting clip to native graphics
|
|
630 |
iBuffer.write(iHandle, OP_SET_CLIPRECT, clipX, clipY, clipWidth, clipHeight);
|
|
631 |
if (iDirectGraphicsHandle != 0)
|
|
632 |
iBuffer.write(iDirectGraphicsHandle, OP_SET_CLIPRECT, clipX, clipY, clipWidth, clipHeight);
|
|
633 |
}
|
|
634 |
}
|
|
635 |
|
|
636 |
public void drawLine(int aX1, int aY1, int aX2, int aY2)
|
|
637 |
{
|
|
638 |
// If is downscaling on, then it downscales line's ends.
|
|
639 |
if (isDownscaled())
|
|
640 |
{
|
|
641 |
aX1 = (aX1 * iOnScreenWidth) / iWidth;
|
|
642 |
aY1 = (aY1 * iOnScreenHeight) / iHeight;
|
|
643 |
aX2 = (aX2 * iOnScreenWidth) / iWidth;
|
|
644 |
aY2 = (aY2 * iOnScreenHeight) / iHeight;
|
|
645 |
}
|
|
646 |
synchronized (iBuffer)
|
|
647 |
{
|
|
648 |
// Send line to native graphics
|
|
649 |
iBuffer.write(iHandle, OP_DRAW_LINE, aX1, aY1, aX2, aY2);
|
|
650 |
}
|
|
651 |
}
|
|
652 |
|
|
653 |
public void fillRect(int aX, int aY, int aWidth, int aHeight)
|
|
654 |
{
|
|
655 |
// If is downscaling on, then it downscales rectagle.
|
|
656 |
if (isDownscaled())
|
|
657 |
{
|
|
658 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
659 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
660 |
/* Prevents bad drawing of thin rect.
|
|
661 |
Rounding up the final rect after downscaling.
|
|
662 |
*/
|
|
663 |
if (aWidth > aHeight)
|
|
664 |
{
|
|
665 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
666 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
667 |
}
|
|
668 |
else if (aHeight > aWidth)
|
|
669 |
{
|
|
670 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
671 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
672 |
}
|
|
673 |
else
|
|
674 |
{
|
|
675 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
676 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
677 |
}
|
|
678 |
}
|
|
679 |
synchronized (iBuffer)
|
|
680 |
{
|
|
681 |
// Send rectagle to native graphics.
|
|
682 |
iBuffer.write(iHandle, OP_FILL_RECT, aX, aY, aWidth, aHeight);
|
|
683 |
}
|
|
684 |
}
|
|
685 |
|
|
686 |
public void drawRect(int aX, int aY, int aWidth, int aHeight)
|
|
687 |
{
|
|
688 |
// If is downscaling on, then it downscales rectagle.
|
|
689 |
if (isDownscaled())
|
|
690 |
{
|
|
691 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
692 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
693 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
694 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
695 |
}
|
|
696 |
synchronized (iBuffer)
|
|
697 |
{
|
|
698 |
// Send rectagle to native graphics.
|
|
699 |
iBuffer.write(iHandle, OP_DRAW_RECT, aX, aY, aWidth, aHeight);
|
|
700 |
}
|
|
701 |
}
|
|
702 |
|
|
703 |
public void drawRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight)
|
|
704 |
{
|
|
705 |
// If is downscaling on, then it downscales rectagle and arches.
|
|
706 |
if (isDownscaled())
|
|
707 |
{
|
|
708 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
709 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
710 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
711 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
712 |
aArcWidth = (aArcWidth * iOnScreenWidth) / iWidth;
|
|
713 |
aArcHeight = (aArcHeight * iOnScreenHeight) / iHeight;
|
|
714 |
}
|
|
715 |
synchronized (iBuffer)
|
|
716 |
{
|
|
717 |
// Send rectagle and arches to native graphics.
|
|
718 |
iBuffer.write(iHandle, OP_DRAW_ROUNDRECT, aX, aY, aWidth, aHeight, aArcWidth, aArcHeight);
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
public void fillRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight)
|
|
723 |
{
|
|
724 |
// If is downscaling on, then it downscales rectagle and arches.
|
|
725 |
if (isDownscaled())
|
|
726 |
{
|
|
727 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
728 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
729 |
|
|
730 |
/* Prevents bad drawing of thin rect.
|
|
731 |
Rounding up the final rect after downscaling.
|
|
732 |
*/
|
|
733 |
if (aWidth > aHeight)
|
|
734 |
{
|
|
735 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
736 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
737 |
}
|
|
738 |
else if (aHeight > aWidth)
|
|
739 |
{
|
|
740 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
741 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
742 |
}
|
|
743 |
else
|
|
744 |
{
|
|
745 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
746 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
747 |
}
|
|
748 |
aArcWidth = (aArcWidth * iOnScreenWidth) / iWidth;
|
|
749 |
aArcHeight = (aArcHeight * iOnScreenHeight) / iHeight;
|
|
750 |
}
|
|
751 |
synchronized (iBuffer)
|
|
752 |
{
|
|
753 |
// Send rectagle and arches to native graphics.
|
|
754 |
iBuffer.write(iHandle, OP_FILL_ROUNDRECT, aX, aY, aWidth, aHeight, aArcWidth, aArcHeight);
|
|
755 |
}
|
|
756 |
}
|
|
757 |
|
|
758 |
public void fillArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle)
|
|
759 |
{
|
|
760 |
// If is downscaling on, then it downscales centre and measures.
|
|
761 |
if (isDownscaled())
|
|
762 |
{
|
|
763 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
764 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
765 |
/* Prevents bad drawing of thin rect.
|
|
766 |
Rounding up the final rect after downscaling.
|
|
767 |
*/
|
|
768 |
if (aWidth > aHeight)
|
|
769 |
{
|
|
770 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
771 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
772 |
}
|
|
773 |
else if (aHeight > aWidth)
|
|
774 |
{
|
|
775 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
776 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
777 |
}
|
|
778 |
else
|
|
779 |
{
|
|
780 |
aWidth = (int)Math.ceil(((double)aWidth * iOnScreenWidth) / iWidth);
|
|
781 |
aHeight = (int)Math.ceil(((double)aHeight * iOnScreenHeight) / iHeight);
|
|
782 |
}
|
|
783 |
}
|
|
784 |
synchronized (iBuffer)
|
|
785 |
{
|
|
786 |
// Send arch to native graphics.
|
|
787 |
iBuffer.write(iHandle, OP_FILL_ARC, aX, aY, aWidth, aHeight, aStartAngle, aArcAngle);
|
|
788 |
}
|
|
789 |
}
|
|
790 |
|
|
791 |
public void drawArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle)
|
|
792 |
{
|
|
793 |
// If is downscaling on, then it downscales centre and measures.
|
|
794 |
if (isDownscaled())
|
|
795 |
{
|
|
796 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
797 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
798 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
799 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
800 |
}
|
|
801 |
synchronized (iBuffer)
|
|
802 |
{
|
|
803 |
// Send arch to native graphics.
|
|
804 |
iBuffer.write(iHandle, OP_DRAW_ARC, aX, aY, aWidth, aHeight, aStartAngle, aArcAngle);
|
|
805 |
}
|
|
806 |
}
|
|
807 |
|
|
808 |
public void drawString(String aString, int aX, int aY, int aAnchor)
|
|
809 |
{
|
|
810 |
// If is downscaling on, then it downscales drawing point.
|
|
811 |
if (isDownscaled())
|
|
812 |
{
|
|
813 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
814 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
815 |
setScalableFont();
|
|
816 |
}
|
|
817 |
final int length = aString.length();
|
|
818 |
synchronized (iBuffer)
|
|
819 |
{
|
|
820 |
// checking of anchor or setting default
|
|
821 |
aAnchor = checkAnchor(aAnchor, STRING_ANCHOR_MASK);
|
|
822 |
// set a current font for use
|
|
823 |
UseFont();
|
|
824 |
// Send text, drawing point and anchor to native graphics.
|
|
825 |
iBuffer.writeStr(iHandle, OP_DRAW_STRING, aString, 0, length, aX, aY, aAnchor);
|
|
826 |
}
|
|
827 |
}
|
|
828 |
|
|
829 |
public void drawSubstring(String aString, int aOffset, int aLength, int aX, int aY, int aAnchor)
|
|
830 |
{
|
|
831 |
// If is downscaling on, then it downscales drawing point.
|
|
832 |
if (isDownscaled())
|
|
833 |
{
|
|
834 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
835 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
836 |
setScalableFont();
|
|
837 |
}
|
|
838 |
synchronized (iBuffer)
|
|
839 |
{
|
|
840 |
// checking of anchor or setting default
|
|
841 |
aAnchor = checkAnchor(aAnchor, STRING_ANCHOR_MASK);
|
|
842 |
|
|
843 |
// Checking if offset and length are correct.
|
|
844 |
final int stringLength = aString.length();
|
|
845 |
final int beg = aOffset;
|
|
846 |
final int end = aOffset + aLength;
|
|
847 |
if ((beg < 0) || (end > stringLength) || (end < beg))
|
|
848 |
{
|
|
849 |
throw new StringIndexOutOfBoundsException();
|
|
850 |
}
|
|
851 |
|
|
852 |
// set a current font for use
|
|
853 |
UseFont();
|
|
854 |
// Send text, drawing point and anchor to native graphics.
|
|
855 |
iBuffer.writeStr(iHandle, OP_DRAW_STRING, aString, aOffset, aLength, aX, aY, aAnchor);
|
|
856 |
}
|
|
857 |
}
|
|
858 |
|
|
859 |
public void drawChar(char aChar, int aX, int aY, int aAnchor)
|
|
860 |
{
|
|
861 |
// Calling of drawChars with array with size 1.
|
|
862 |
iChar[0] = aChar;
|
|
863 |
DrawChars(iChar, 0, 1, aX, aY, aAnchor);
|
|
864 |
}
|
|
865 |
|
|
866 |
public void drawChars(char[] aChars,int aOffset,int aLength,int aX,int aY,int aAnchor)
|
|
867 |
{
|
|
868 |
synchronized (iBuffer)
|
|
869 |
{
|
|
870 |
// Checking if offset and length are correct.
|
|
871 |
final int charLength = aChars.length; // throws NullPointerException
|
|
872 |
final int beg = aOffset;
|
|
873 |
final int end = aOffset + aLength;
|
|
874 |
if ((beg < 0) || (end > charLength) || (end < beg))
|
|
875 |
{
|
|
876 |
throw new ArrayIndexOutOfBoundsException();
|
|
877 |
}
|
|
878 |
// Calling of DrawChars.
|
|
879 |
DrawChars(aChars, aOffset, aLength, aX, aY, aAnchor);
|
|
880 |
}
|
|
881 |
}
|
|
882 |
|
|
883 |
private void DrawChars(char[] aChars,int aOffset,int aLength,int aX,int aY,int aAnchor)
|
|
884 |
{
|
|
885 |
// If is downscaling on, then it downscales drawing point.
|
|
886 |
if (isDownscaled())
|
|
887 |
{
|
|
888 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
889 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
890 |
}
|
|
891 |
// checking of anchor or setting default
|
|
892 |
aAnchor = checkAnchor(aAnchor, STRING_ANCHOR_MASK);
|
|
893 |
if (isDownscaled())
|
|
894 |
{
|
|
895 |
setScalableFont();
|
|
896 |
}
|
|
897 |
// set a current font for use
|
|
898 |
UseFont();
|
|
899 |
// Send text, drawing point and anchor to native graphics.
|
|
900 |
iBuffer.writeChars(iHandle, OP_DRAW_STRING, aChars, aOffset, aLength, aX, aY, aAnchor);
|
|
901 |
}
|
|
902 |
|
|
903 |
public void drawImage(Image aImage, int aX, int aY, int aAnchor)
|
|
904 |
{
|
|
905 |
// check if iTarget is downscaled
|
|
906 |
if (isDownscaled())
|
|
907 |
{
|
|
908 |
// It is downscaled.
|
|
909 |
// downscaling drawing point
|
|
910 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
911 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
912 |
|
|
913 |
// getting size of aImage
|
|
914 |
int widthL = aImage.getWidth();
|
|
915 |
int heightL = aImage.getHeight();
|
|
916 |
|
|
917 |
// create RGB array for aImage.
|
|
918 |
int rgbL[] = new int[widthL * heightL];
|
|
919 |
|
|
920 |
// getting a RGB data from aImage
|
|
921 |
aImage.getRGB(rgbL, 0, widthL, 0, 0, widthL, heightL);
|
|
922 |
|
|
923 |
// downscaling size of aImage
|
|
924 |
int widthSL = (widthL * iOnScreenWidth) / iWidth;
|
|
925 |
int heightSL = (heightL * iOnScreenHeight) / iHeight;
|
|
926 |
|
|
927 |
// create RGB array for downscaled image
|
|
928 |
int rgbSL[] = new int[widthSL * heightSL];
|
|
929 |
|
|
930 |
// getting downscaled rgb data
|
|
931 |
getDownscaledRGB(rgbSL, rgbL, widthL, heightL);
|
|
932 |
|
|
933 |
// creating a image from downscaled RGB data
|
|
934 |
Image image = Image.createRGBImage(rgbSL, widthSL, heightSL, true);
|
|
935 |
synchronized (iBuffer)
|
|
936 |
{
|
|
937 |
// checking of anchor
|
|
938 |
aAnchor = checkAnchor(aAnchor, IMAGE_ANCHOR_MASK);
|
|
939 |
// send downscaled image with downscaled drawing point
|
|
940 |
// to native side
|
|
941 |
iBuffer.write(iHandle, OP_DRAW_IMAGE, image.iHandle, aX, aY, aAnchor);
|
|
942 |
}
|
|
943 |
}
|
|
944 |
else
|
|
945 |
{
|
|
946 |
// It is not downscaled.
|
|
947 |
synchronized (iBuffer)
|
|
948 |
{
|
|
949 |
// checking of anchor
|
|
950 |
aAnchor = checkAnchor(aAnchor, IMAGE_ANCHOR_MASK);
|
|
951 |
|
|
952 |
// Prevent aImage to be disposed when in use
|
|
953 |
synchronized (aImage)
|
|
954 |
{
|
|
955 |
// Check that aImage haven't been disposed yet
|
|
956 |
if (aImage.iHandle != 0)
|
|
957 |
{
|
|
958 |
// send image with drawing point to native side
|
|
959 |
iBuffer.write(iHandle, OP_DRAW_IMAGE, aImage.iHandle, aX, aY, aAnchor);
|
|
960 |
}
|
|
961 |
}
|
|
962 |
}
|
|
963 |
}
|
|
964 |
}
|
|
965 |
|
|
966 |
/**
|
|
967 |
* Sets the copy-graphics command into the command buffer.
|
|
968 |
* @param aSrcGraphics The source graphics
|
|
969 |
* @since s60 9.2
|
|
970 |
*/
|
|
971 |
void copyGraphics(Graphics aSrcGraphics)
|
|
972 |
{
|
|
973 |
synchronized (iBuffer)
|
|
974 |
{
|
|
975 |
iBuffer.write(iHandle, OP_COPY_GRAPHICS, aSrcGraphics.iHandle);
|
|
976 |
}
|
|
977 |
}
|
|
978 |
|
|
979 |
public void setStrokeStyle(int aStyle)
|
|
980 |
{
|
|
981 |
if ((aStyle != SOLID) && (aStyle != DOTTED))
|
|
982 |
{
|
|
983 |
throw new IllegalArgumentException();
|
|
984 |
}
|
|
985 |
synchronized (iBuffer)
|
|
986 |
{
|
|
987 |
iStrokeStyle = aStyle;
|
|
988 |
iBuffer.write(iHandle, OP_SET_STROKE, aStyle);
|
|
989 |
}
|
|
990 |
}
|
|
991 |
|
|
992 |
public int getStrokeStyle()
|
|
993 |
{
|
|
994 |
return iStrokeStyle;
|
|
995 |
}
|
|
996 |
|
|
997 |
/**
|
|
998 |
* Check that aAnchor contains a valid anchor spec.
|
|
999 |
* Using zero for the anchor point value gives results identical to using TOP | LEFT.
|
|
1000 |
* The definition of the anchor point must be one of the horizontal constants
|
|
1001 |
* (LEFT, HCENTER, RIGHT) combined with one of the vertical constants (TOP, BASELINE, BOTTOM)
|
|
1002 |
*/
|
|
1003 |
private static int checkAnchor(int aAnchor, int aMask)
|
|
1004 |
{
|
|
1005 |
if (0 == aAnchor)
|
|
1006 |
{
|
|
1007 |
aAnchor = LEFT|TOP;
|
|
1008 |
return aAnchor;
|
|
1009 |
}
|
|
1010 |
|
|
1011 |
final boolean excess = (aAnchor & ~aMask) != 0;
|
|
1012 |
final int horz = aAnchor & HMASK;
|
|
1013 |
final int vert = aAnchor & VMASK;
|
|
1014 |
|
|
1015 |
if (excess || multipleBits(vert) || multipleBits(horz))
|
|
1016 |
{
|
|
1017 |
throw new IllegalArgumentException();
|
|
1018 |
}
|
|
1019 |
if (horz == 0 || vert == 0)
|
|
1020 |
{
|
|
1021 |
throw new IllegalArgumentException("anchor is not a legal value");
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
return aAnchor;
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
/**
|
|
1028 |
*@return true if aAnchor contains more than one bit set.
|
|
1029 |
*/
|
|
1030 |
private static boolean multipleBits(int aAnchor)
|
|
1031 |
{
|
|
1032 |
return (aAnchor & (aAnchor-1)) != 0;
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
// New in MIDP 2.0
|
|
1036 |
public int getDisplayColor(int aColor)
|
|
1037 |
{
|
|
1038 |
int i = 0;
|
|
1039 |
synchronized (iToolkit)
|
|
1040 |
{
|
|
1041 |
i = _getDisplayColor(iToolkit.getHandle(), iHandle, aColor);
|
|
1042 |
}
|
|
1043 |
return i;
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
//
|
|
1047 |
// New in MIDP 2.0
|
|
1048 |
//
|
|
1049 |
// Semantics of negative width/height are not defined in the spec
|
|
1050 |
// but could be used to implement reflections.
|
|
1051 |
//
|
|
1052 |
public void drawRGB(
|
|
1053 |
int[] aRgbData,
|
|
1054 |
int aOffset,
|
|
1055 |
int aScanLength,
|
|
1056 |
int aX,
|
|
1057 |
int aY,
|
|
1058 |
int aWidth,
|
|
1059 |
int aHeight,
|
|
1060 |
boolean aProcessAlpha)
|
|
1061 |
{
|
|
1062 |
// setting of help variables
|
|
1063 |
int len = aRgbData.length;
|
|
1064 |
int width = aWidth >= 0 ? aWidth : -aWidth;
|
|
1065 |
int height = aHeight >= 0 ? aHeight : -aHeight;
|
|
1066 |
|
|
1067 |
// get RGB array for drawing
|
|
1068 |
int rgbSL[] = aRgbData;
|
|
1069 |
|
|
1070 |
// This checks if downscaling is on.
|
|
1071 |
if (isDownscaled())
|
|
1072 |
{
|
|
1073 |
// dowscaling of drawing point and size of image
|
|
1074 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
1075 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
1076 |
int widthSL = (width * iOnScreenWidth) / iWidth;
|
|
1077 |
int heightSL = (height * iOnScreenHeight) / iHeight;
|
|
1078 |
|
|
1079 |
// set drawing array to new array with downscaled size
|
|
1080 |
rgbSL = new int[widthSL * heightSL];
|
|
1081 |
|
|
1082 |
// preparing of aRgbData to use getDownscaledRGB method
|
|
1083 |
aRgbData = cleanRGB(aRgbData, aOffset, aScanLength, width, height);
|
|
1084 |
|
|
1085 |
// downscaling of RGB data
|
|
1086 |
getDownscaledRGB(rgbSL, aRgbData, width, height);
|
|
1087 |
|
|
1088 |
//setting parameters do downscaled values
|
|
1089 |
aWidth = widthSL;
|
|
1090 |
aHeight = heightSL;
|
|
1091 |
aOffset = 0;
|
|
1092 |
aScanLength = widthSL;
|
|
1093 |
}
|
|
1094 |
int scanLength;
|
|
1095 |
int transform;
|
|
1096 |
|
|
1097 |
long end64 = (long)len - 1;
|
|
1098 |
long offset64;
|
|
1099 |
long scanLength64;
|
|
1100 |
|
|
1101 |
|
|
1102 |
if (aScanLength >= 0)
|
|
1103 |
{
|
|
1104 |
// If aScanLength is positive, we can use RGB data forward.
|
|
1105 |
scanLength = aScanLength;
|
|
1106 |
transform = Sprite.TRANS_NONE;
|
|
1107 |
offset64 = (long)aOffset;
|
|
1108 |
}
|
|
1109 |
else
|
|
1110 |
{
|
|
1111 |
// If aScanlength is negative, we have to use RGB data backward.
|
|
1112 |
scanLength = -aScanLength;
|
|
1113 |
transform = Sprite.TRANS_MIRROR_ROT180; // relection in horizontal axis
|
|
1114 |
offset64 = (long)aOffset - (long)scanLength * ((long)height - 1);
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
scanLength64 = (long)scanLength;
|
|
1118 |
long min64 = offset64;
|
|
1119 |
long max64 = offset64 + scanLength64 * ((long)height - 1) + (long)width - 1;
|
|
1120 |
|
|
1121 |
// They are given incorrect data.
|
|
1122 |
if ((min64 < 0) || (max64 > end64))
|
|
1123 |
{
|
|
1124 |
throw new ArrayIndexOutOfBoundsException();
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
|
|
1128 |
//
|
|
1129 |
// IMPROVEMENT: clip down the data to transfer.
|
|
1130 |
//
|
|
1131 |
int x1 = aX;
|
|
1132 |
int y1 = aY;
|
|
1133 |
int x2 = aX + aWidth;
|
|
1134 |
int y2 = aY + aHeight;
|
|
1135 |
|
|
1136 |
int clipX2 = iClipX+iClipWidth;
|
|
1137 |
int clipY2 = iClipY+iClipHeight;
|
|
1138 |
|
|
1139 |
x1 = iClipX > x1 ? iClipX : x1;
|
|
1140 |
y1 = iClipY > y1 ? iClipY : y1;
|
|
1141 |
x2 = clipX2 < x2 ? clipX2 : x2;
|
|
1142 |
y2 = clipY2 < y2 ? clipY2 : y2;
|
|
1143 |
|
|
1144 |
width = x2 - x1;
|
|
1145 |
height = y2 - y1;
|
|
1146 |
|
|
1147 |
//
|
|
1148 |
// This will also clip out any attempt
|
|
1149 |
// to draw with negative width/height.
|
|
1150 |
//
|
|
1151 |
if ((width<=0) || (height<=0))
|
|
1152 |
{
|
|
1153 |
return;
|
|
1154 |
}
|
|
1155 |
|
|
1156 |
//
|
|
1157 |
// move offset to start of clipped region, note we use top-left corner here
|
|
1158 |
// because we have already regularized the scanlength : the tranform takes
|
|
1159 |
// care of vertical flip for negative scan case.
|
|
1160 |
//
|
|
1161 |
offset64 += scanLength64 * (long)(y1 - aY) + (long)(x1 - aX);
|
|
1162 |
//
|
|
1163 |
// adjust length
|
|
1164 |
//
|
|
1165 |
long length64 = ((long)height - 1L) * scanLength64 + (long)width;
|
|
1166 |
final int alpha = aProcessAlpha ? 1 : 0;
|
|
1167 |
|
|
1168 |
synchronized (iBuffer)
|
|
1169 |
{
|
|
1170 |
//
|
|
1171 |
// ensure pending drawing commands are complete first
|
|
1172 |
//
|
|
1173 |
iBuffer.sync();
|
|
1174 |
|
|
1175 |
//
|
|
1176 |
// Blocking server call to do Bitblt server side:
|
|
1177 |
//
|
|
1178 |
NativeError.check(_drawPixels(
|
|
1179 |
iBuffer.getHandle(),
|
|
1180 |
iHandle,
|
|
1181 |
TYPE_INT_ARGB_8888,
|
|
1182 |
rgbSL,
|
|
1183 |
(int)offset64,
|
|
1184 |
(int)length64,
|
|
1185 |
(int)scanLength64,
|
|
1186 |
aProcessAlpha,
|
|
1187 |
x1,
|
|
1188 |
y1,
|
|
1189 |
width,
|
|
1190 |
height,
|
|
1191 |
transform
|
|
1192 |
));
|
|
1193 |
}
|
|
1194 |
}
|
|
1195 |
|
|
1196 |
public void fillTriangle(int aX1, int aY1, int aX2, int aY2, int aX3, int aY3)
|
|
1197 |
{
|
|
1198 |
if (isDownscaled())
|
|
1199 |
{
|
|
1200 |
// If is downscaling on, then it downscales triangle.
|
|
1201 |
aX1 = (aX1 * iOnScreenWidth) / iWidth;
|
|
1202 |
aY1 = (aY1 * iOnScreenHeight) / iHeight;
|
|
1203 |
aX2 = (aX2 * iOnScreenWidth) / iWidth;
|
|
1204 |
aY2 = (aY2 * iOnScreenHeight) / iHeight;
|
|
1205 |
aX3 = (aX3 * iOnScreenWidth) / iWidth;
|
|
1206 |
aY3 = (aY3 * iOnScreenHeight) / iHeight;
|
|
1207 |
}
|
|
1208 |
synchronized (iBuffer)
|
|
1209 |
{
|
|
1210 |
// Send triangle to native graphics.
|
|
1211 |
iBuffer.write(iHandle, OP_FILL_TRIANGLE, aX1, aY1, aX2, aY2, aX3, aY3);
|
|
1212 |
}
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
// New in MIDP 2.0
|
|
1216 |
public void copyArea(int aXsrc,int aYsrc,int aWidth,int aHeight,int aXdest,int aYdest,int aAnchor)
|
|
1217 |
{
|
|
1218 |
synchronized (iBuffer)
|
|
1219 |
{
|
|
1220 |
if (null == iImage)
|
|
1221 |
{
|
|
1222 |
throw new IllegalStateException("cannot copyArea on display");
|
|
1223 |
}
|
|
1224 |
|
|
1225 |
/*
|
|
1226 |
* Silently ignore - even if the source point is out of bounds.
|
|
1227 |
*/
|
|
1228 |
if (aWidth <= 0 || aHeight <= 0)
|
|
1229 |
{
|
|
1230 |
return;
|
|
1231 |
}
|
|
1232 |
|
|
1233 |
final int sx1 = aXsrc;
|
|
1234 |
final int sy1 = aYsrc;
|
|
1235 |
final int sx2 = aXsrc + aWidth;
|
|
1236 |
final int sy2 = aYsrc + aHeight;
|
|
1237 |
|
|
1238 |
//
|
|
1239 |
// (sx1,sy1,sx2,sy2) source rectangle is inclusive-exclusive
|
|
1240 |
//
|
|
1241 |
// Top left coordinate must be contained within drawing surface.
|
|
1242 |
//
|
|
1243 |
// Bottom right coordinate may extend one pixel to right or below
|
|
1244 |
// drawing surface bottom right coordinate.
|
|
1245 |
//
|
|
1246 |
if ((sx1<0) || (sx1>=iWidth) || (sy1<0) || (sy1>=iHeight) ||
|
|
1247 |
(sx2<0) || (sx2>iWidth) || (sy2<0) || (sy2>iHeight))
|
|
1248 |
{
|
|
1249 |
throw new IllegalArgumentException("copyArea source rect out of bounds");
|
|
1250 |
}
|
|
1251 |
|
|
1252 |
checkAnchor(aAnchor, IMAGE_ANCHOR_MASK);
|
|
1253 |
|
|
1254 |
|
|
1255 |
iBuffer.write(
|
|
1256 |
iHandle,
|
|
1257 |
OP_COPY_AREA,
|
|
1258 |
aXsrc,
|
|
1259 |
aYsrc,
|
|
1260 |
aWidth,
|
|
1261 |
aHeight,
|
|
1262 |
aXdest,
|
|
1263 |
aYdest,
|
|
1264 |
aAnchor
|
|
1265 |
);
|
|
1266 |
}
|
|
1267 |
}
|
|
1268 |
|
|
1269 |
public void drawRegion(
|
|
1270 |
Image aImage,
|
|
1271 |
int aXsrc,
|
|
1272 |
int aYsrc,
|
|
1273 |
int aWidth,
|
|
1274 |
int aHeight,
|
|
1275 |
int aTransform,
|
|
1276 |
int aXdest,
|
|
1277 |
int aYdest,
|
|
1278 |
int aAnchor)
|
|
1279 |
{
|
|
1280 |
// giving a size of aImage
|
|
1281 |
int srcWidth = aImage.getWidth();
|
|
1282 |
int srcHeight = aImage.getHeight();
|
|
1283 |
|
|
1284 |
// If drawing area is empty, then return.
|
|
1285 |
if ((aWidth <= 0) || (aHeight <= 0))
|
|
1286 |
{
|
|
1287 |
return;
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
// Drawing from image to the same image is not allowed.
|
|
1291 |
if (iTarget == aImage)
|
|
1292 |
{
|
|
1293 |
throw new IllegalArgumentException("Cannot draw image onto itself");
|
|
1294 |
}
|
|
1295 |
|
|
1296 |
// checking if drawing area is correct
|
|
1297 |
int sx1 = aXsrc;
|
|
1298 |
int sy1 = aYsrc;
|
|
1299 |
int sx2 = aXsrc + aWidth;
|
|
1300 |
int sy2 = aYsrc + aHeight;
|
|
1301 |
if (sx1 < 0 || sy1 < 0 || sx2 > srcWidth || sy2 > srcHeight)
|
|
1302 |
{
|
|
1303 |
throw new IllegalArgumentException();
|
|
1304 |
}
|
|
1305 |
|
|
1306 |
// checking of anchor
|
|
1307 |
checkAnchor(aAnchor, IMAGE_ANCHOR_MASK);
|
|
1308 |
|
|
1309 |
// checking of legality of trasformation
|
|
1310 |
if (aTransform < TRANS_MIN || aTransform > TRANS_MAX)
|
|
1311 |
{
|
|
1312 |
throw new IllegalArgumentException("Transform");
|
|
1313 |
}
|
|
1314 |
|
|
1315 |
// checking if downscaling is on
|
|
1316 |
if (isDownscaled())
|
|
1317 |
{
|
|
1318 |
// downscaling of drawing point and area
|
|
1319 |
aXdest = (aXdest * iOnScreenWidth) / iWidth;
|
|
1320 |
aYdest = (aYdest * iOnScreenHeight) / iHeight;
|
|
1321 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
1322 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
1323 |
|
|
1324 |
// getting of size of non-scaled image
|
|
1325 |
int widthL = aImage.getWidth();
|
|
1326 |
int heightL = aImage.getHeight();
|
|
1327 |
|
|
1328 |
// array for RGB data from non-scaled image
|
|
1329 |
int rgbL[] = new int[widthL * heightL];
|
|
1330 |
|
|
1331 |
// getting RGB data
|
|
1332 |
aImage.getRGB(rgbL, 0, widthL, 0, 0, widthL, heightL);
|
|
1333 |
|
|
1334 |
// downscaling of size of image
|
|
1335 |
int widthSL = (widthL * iOnScreenWidth) / iWidth;
|
|
1336 |
int heightSL = (heightL * iOnScreenHeight) / iHeight;
|
|
1337 |
|
|
1338 |
// array for RGB data for scaled image
|
|
1339 |
int rgbSL[] = new int[widthSL * heightSL];
|
|
1340 |
|
|
1341 |
// downscaling RGB data
|
|
1342 |
getDownscaledRGB(rgbSL, rgbL, widthL, heightL);
|
|
1343 |
|
|
1344 |
// creating image from scaled RGB data
|
|
1345 |
Image image = Image.createRGBImage(rgbSL, widthSL, heightSL, true);
|
|
1346 |
|
|
1347 |
// scaling of size of size of image
|
|
1348 |
aXsrc = ((widthSL * aXsrc) / widthL);
|
|
1349 |
aYsrc = ((heightSL * aYsrc) / heightL);
|
|
1350 |
|
|
1351 |
//
|
|
1352 |
// finding of new drawing start point in source image
|
|
1353 |
// This is the same algorithm like in getDownscaledRGB method.
|
|
1354 |
//
|
|
1355 |
int srcXL = widthSL;
|
|
1356 |
int srcYL = heightSL;
|
|
1357 |
int residueWidth = widthL;
|
|
1358 |
int residueHeight = heightL;
|
|
1359 |
for (int i = 0; i < widthSL; i++)
|
|
1360 |
{
|
|
1361 |
residueWidth -= (int)((double)((float)residueWidth /
|
|
1362 |
(float)(widthSL - i)) + 0.5D);
|
|
1363 |
if (widthL - residueWidth > aXsrc)
|
|
1364 |
break;
|
|
1365 |
}
|
|
1366 |
|
|
1367 |
for (int j = 0; j < heightSL; j++)
|
|
1368 |
{
|
|
1369 |
residueHeight -= (int)((double)((float)residueHeight /
|
|
1370 |
(float)(heightSL - j)) + 0.5D);
|
|
1371 |
if (heightL - residueHeight > aYsrc)
|
|
1372 |
break;
|
|
1373 |
}
|
|
1374 |
|
|
1375 |
synchronized (iBuffer)
|
|
1376 |
{
|
|
1377 |
// sending data to native side
|
|
1378 |
iBuffer.write(iHandle,
|
|
1379 |
OP_DRAW_REGION,
|
|
1380 |
image.iHandle,
|
|
1381 |
widthL - residueWidth,
|
|
1382 |
heightL - residueHeight,
|
|
1383 |
aWidth, aHeight,
|
|
1384 |
aTransform,
|
|
1385 |
aXdest,
|
|
1386 |
aYdest,
|
|
1387 |
aAnchor);
|
|
1388 |
}
|
|
1389 |
}
|
|
1390 |
else
|
|
1391 |
{
|
|
1392 |
synchronized (iBuffer)
|
|
1393 |
{
|
|
1394 |
// Prevent aImage to be disposed when in use
|
|
1395 |
synchronized (aImage)
|
|
1396 |
{
|
|
1397 |
// Check that aImage haven't been disposed yet
|
|
1398 |
if (aImage.iHandle != 0)
|
|
1399 |
{
|
|
1400 |
// If downscaling off,
|
|
1401 |
// then it only send data to native side
|
|
1402 |
iBuffer.write(iHandle,
|
|
1403 |
OP_DRAW_REGION,
|
|
1404 |
aImage.iHandle,
|
|
1405 |
aXsrc,
|
|
1406 |
aYsrc,
|
|
1407 |
aWidth,
|
|
1408 |
aHeight,
|
|
1409 |
aTransform,
|
|
1410 |
aXdest,
|
|
1411 |
aYdest,
|
|
1412 |
aAnchor);
|
|
1413 |
}
|
|
1414 |
}
|
|
1415 |
}
|
|
1416 |
}
|
|
1417 |
}
|
|
1418 |
|
|
1419 |
void flush(int aX, int aY, int aWidth, int aHeight)
|
|
1420 |
{
|
|
1421 |
if (isDownscaled())
|
|
1422 |
{
|
|
1423 |
// If downscaling on, then it downscales flushed area.
|
|
1424 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
1425 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
1426 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
1427 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
1428 |
}
|
|
1429 |
synchronized (iBuffer)
|
|
1430 |
{
|
|
1431 |
// sending data to native side
|
|
1432 |
iBuffer.write(iHandle, OP_FLUSH, aX, aY, aWidth, aHeight);
|
|
1433 |
iBuffer.sync();
|
|
1434 |
}
|
|
1435 |
}
|
|
1436 |
|
|
1437 |
/**
|
|
1438 |
* Send draw background command to native side
|
|
1439 |
* @param aDisplayable The target Displayable object
|
|
1440 |
* @param aX X position
|
|
1441 |
* @param aY Y position
|
|
1442 |
* @param aWidth Width
|
|
1443 |
* @param aHeight Height
|
|
1444 |
* @since S60 5.0
|
|
1445 |
*/
|
|
1446 |
void drawBackground(Displayable aDisplayable,
|
|
1447 |
int aX,
|
|
1448 |
int aY,
|
|
1449 |
int aWidth,
|
|
1450 |
int aHeight)
|
|
1451 |
{
|
|
1452 |
// If aDisplayable is not Canvas or a Displayable is null,
|
|
1453 |
// then drawBackround do nothing.
|
|
1454 |
if (aDisplayable == null || !(aDisplayable instanceof Canvas))
|
|
1455 |
return;
|
|
1456 |
if (isDownscaled())
|
|
1457 |
{
|
|
1458 |
// If downscaling on, then it downscales flushed area.
|
|
1459 |
aX = (aX * iOnScreenWidth) / iWidth;
|
|
1460 |
aY = (aY * iOnScreenHeight) / iHeight;
|
|
1461 |
aWidth = (aWidth * iOnScreenWidth) / iWidth;
|
|
1462 |
aHeight = (aHeight * iOnScreenHeight) / iHeight;
|
|
1463 |
}
|
|
1464 |
synchronized (iBuffer)
|
|
1465 |
{
|
|
1466 |
// sending data to native side
|
|
1467 |
iBuffer.write(iHandle, 20, aDisplayable.getContentHandle(), aX, aY, aWidth, aHeight);
|
|
1468 |
}
|
|
1469 |
}
|
|
1470 |
|
|
1471 |
|
|
1472 |
/**
|
|
1473 |
* This function return flag if Graphics is downscaled.
|
|
1474 |
* Graphics is downscaled on if we have set original size, this size is bigger then screen
|
|
1475 |
* (at least on one measure) and iTarget is Canvas in full screen Canvas or a target size is
|
|
1476 |
* smaller than original size.
|
|
1477 |
* @return true if Graphics is downscaled, false otherwise
|
|
1478 |
*/
|
|
1479 |
boolean isDownscaled()
|
|
1480 |
{
|
|
1481 |
boolean ret = false;
|
|
1482 |
// If M3G is drawnig then downscaling is turn off.
|
|
1483 |
if ((iTarget instanceof Canvas) && ((Canvas)iTarget).getFullScreenMode()
|
|
1484 |
&& iIsSetOriginalSize && !((Canvas)iTarget).m3gDraw())
|
|
1485 |
{
|
|
1486 |
ret = iOnScreenHeight < iHeight || iOnScreenWidth < iWidth;
|
|
1487 |
}
|
|
1488 |
// If downscaling is turn off then disable scalable font
|
|
1489 |
if (iPrevScalingFlag != ret && iPrevScalingFlag == true)
|
|
1490 |
{
|
|
1491 |
iFontSet = false;
|
|
1492 |
iScalableFontSet = false;
|
|
1493 |
}
|
|
1494 |
iPrevScalingFlag = ret;
|
|
1495 |
return ret;
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
/**
|
|
1499 |
* This function returns downscaled GRB data from input RGB data. It scales
|
|
1500 |
* according iOnScreenWidth, iOnScreenHeight, iWidth and iHeight.
|
|
1501 |
* @param aRgbS array for output RGB data. This have to be defined with needed lenght.
|
|
1502 |
* @param aRgb input data
|
|
1503 |
* @param aWidth width of aRgb
|
|
1504 |
* @param aHeight height of aRgb
|
|
1505 |
*/
|
|
1506 |
private void getDownscaledRGB(int aRgbS[], int aRgb[], int aWidth, int aHeight)
|
|
1507 |
{
|
|
1508 |
// downscaling of size of aRgb
|
|
1509 |
int widthS = (aWidth * iOnScreenWidth) / iWidth;
|
|
1510 |
int heightS = (aHeight * iOnScreenHeight) / iHeight;
|
|
1511 |
|
|
1512 |
// help variables for remaining columns and rows
|
|
1513 |
int residueWidth = aWidth;
|
|
1514 |
int residueHeight = aHeight;
|
|
1515 |
|
|
1516 |
// help variables for count of columns and rows of non-scaled RGB data
|
|
1517 |
// scaled to one pixel of downscaled image
|
|
1518 |
int columnWidths[] = new int[widthS];
|
|
1519 |
int rowHeights[] = new int[heightS];
|
|
1520 |
|
|
1521 |
// If aRgbS has lenght shorter then needed.
|
|
1522 |
if (aRgbS.length < widthS * heightS)
|
|
1523 |
throw new IllegalArgumentException();
|
|
1524 |
|
|
1525 |
// computing of count of columns of non-scaled RGB data
|
|
1526 |
// scaled to one column of downscaled image
|
|
1527 |
for (int i = 0; i < widthS; i++)
|
|
1528 |
{
|
|
1529 |
columnWidths[i] = (int)((double)((float)residueWidth /
|
|
1530 |
(float)(widthS - i)) + 0.5D);
|
|
1531 |
residueWidth -= columnWidths[i];
|
|
1532 |
}
|
|
1533 |
|
|
1534 |
// computing of count of rows of non-scaled RGB data
|
|
1535 |
// scaled to one row of downscaled image
|
|
1536 |
for (int i = 0; i < heightS; i++)
|
|
1537 |
{
|
|
1538 |
rowHeights[i] = (int)((double)((float)residueHeight /
|
|
1539 |
(float)(heightS - i)) + 0.5D);
|
|
1540 |
residueHeight -= rowHeights[i];
|
|
1541 |
}
|
|
1542 |
|
|
1543 |
// It goes through all columns of output image.
|
|
1544 |
int posX = 0;
|
|
1545 |
for (int i = 0; i < widthS; i++)
|
|
1546 |
{
|
|
1547 |
// getting of number of columns which will be scaled to one column
|
|
1548 |
int w = columnWidths[i];
|
|
1549 |
int posY = 0;
|
|
1550 |
// It goes through all rows of output image.
|
|
1551 |
for (int j = 0; j < heightS; j++)
|
|
1552 |
{
|
|
1553 |
// getting of number of rows which will be scaled to one row
|
|
1554 |
int h = rowHeights[j];
|
|
1555 |
|
|
1556 |
if (w == 1 && h == 1)
|
|
1557 |
{
|
|
1558 |
// The recalculating of this pixel is not needed.
|
|
1559 |
aRgbS[j * widthS + i] = aRgb[posY * aWidth + posX];
|
|
1560 |
posY++;
|
|
1561 |
}
|
|
1562 |
else
|
|
1563 |
{
|
|
1564 |
// The recalculating of this pixel is needed.
|
|
1565 |
|
|
1566 |
// We have to use char because char is only one
|
|
1567 |
// unsigned integer type in Java.
|
|
1568 |
char sumRed = '\0';
|
|
1569 |
char sumGreen = '\0';
|
|
1570 |
char sumBlue = '\0';
|
|
1571 |
char sumAlpha = '\0';
|
|
1572 |
|
|
1573 |
// It goes through columns of output image,
|
|
1574 |
// what will be downscaled to one column.
|
|
1575 |
for (int k = 0; k < w; k++)
|
|
1576 |
{
|
|
1577 |
// It goes through rows of output image,
|
|
1578 |
// what will be downscaled to one row.
|
|
1579 |
for (int l = 0; l < h; l++)
|
|
1580 |
{
|
|
1581 |
// getting of current pixel
|
|
1582 |
int pixel = aRgb[(posY + l) * aWidth + (posX + k)];
|
|
1583 |
|
|
1584 |
// adding values of one pixel
|
|
1585 |
sumRed += (pixel & 0xff0000) >> 16;
|
|
1586 |
sumGreen += (pixel & 0xff00) >> 8;
|
|
1587 |
sumBlue += pixel & 0xff;
|
|
1588 |
sumAlpha += (pixel & 0xff000000) >> 24;
|
|
1589 |
}
|
|
1590 |
|
|
1591 |
}
|
|
1592 |
|
|
1593 |
// calculating of new pixel
|
|
1594 |
aRgbS[j * widthS + i] = sumRed / (w * h) << 16 |
|
|
1595 |
sumGreen / (w * h) << 8 |
|
|
1596 |
sumBlue / (w * h)|
|
|
1597 |
sumAlpha / (w * h) << 24;
|
|
1598 |
|
|
1599 |
// new set of rows
|
|
1600 |
posY += h;
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
// new set of columns
|
|
1605 |
posX += w;
|
|
1606 |
}
|
|
1607 |
|
|
1608 |
}
|
|
1609 |
|
|
1610 |
/**
|
|
1611 |
* This function returns array with the same RGB data as input,
|
|
1612 |
* but with scanlenght > 0 and offset = 0.
|
|
1613 |
* @param aRgb input RGB data
|
|
1614 |
* @param aOffset offset of aRgb
|
|
1615 |
* @param aScanlenght scalenght of aRgb
|
|
1616 |
* @param aWidth width of aRgb
|
|
1617 |
* @param aHeight height of aRgb
|
|
1618 |
*/
|
|
1619 |
private int[] cleanRGB(int aRgb[],
|
|
1620 |
int aOffset,
|
|
1621 |
int aScanlenght,
|
|
1622 |
int aWidth,
|
|
1623 |
int aHeight)
|
|
1624 |
{
|
|
1625 |
// creating output array
|
|
1626 |
int output[] = new int[aWidth * aHeight];
|
|
1627 |
|
|
1628 |
// resorting of input array to output array
|
|
1629 |
for (int i = 0; i < aHeight; i++)
|
|
1630 |
{
|
|
1631 |
for (int j = 0; j < aWidth; j++)
|
|
1632 |
{
|
|
1633 |
output[i * aWidth + j] = aRgb[aOffset + i * aScanlenght + j];
|
|
1634 |
}
|
|
1635 |
}
|
|
1636 |
|
|
1637 |
// return of resorted array
|
|
1638 |
return output;
|
|
1639 |
}
|
|
1640 |
|
|
1641 |
private native int _create(int i, int j);
|
|
1642 |
|
|
1643 |
private static native int _drawPixels
|
|
1644 |
(
|
|
1645 |
int aBuffer,
|
|
1646 |
int aHandle,
|
|
1647 |
int aType,
|
|
1648 |
int[] aArray,
|
|
1649 |
int aOffset,
|
|
1650 |
int aLength,
|
|
1651 |
int aScanLength,
|
|
1652 |
boolean aProcessAlpha,
|
|
1653 |
int aX,
|
|
1654 |
int aY,
|
|
1655 |
int aWidth,
|
|
1656 |
int aHeight,
|
|
1657 |
int aTransform
|
|
1658 |
);
|
|
1659 |
|
|
1660 |
private static native int _getDisplayColor(int aToolkit, int aHandle, int aRgb);
|
|
1661 |
}
|