Rename ntt-docomo-doja-api to vendor-api-ntt-docomo-doja.
[SquirrelJME.git] / modules / nokia-api / src / main / java / com / nokia / mid / ui / DirectUtils.java
blobf3592fa4887d4d6db6a2a3ae90aa3214f268214b
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package com.nokia.mid.ui;
12 import cc.squirreljme.runtime.cldc.annotation.Api;
13 import cc.squirreljme.runtime.lcdui.mle.PencilGraphics;
14 import javax.microedition.lcdui.Graphics;
15 import javax.microedition.lcdui.Image;
17 /**
18 * This class acts as a placeholder for utility methods.
20 * @since 2019/10/07
22 @Api
23 public class DirectUtils
25 /**
26 * Creates a mutable image with the given ARGB color for all pixels.
28 * @param __w The width.
29 * @param __h The height.
30 * @param __argb The ARGB color to do.
31 * @return The created mutable image.
32 * @throws IllegalArgumentException If the width and/or height or negative
33 * or exceed the array bounds.
34 * @since 2019/10/07
36 @Api
37 public static Image createImage(int __w, int __h, int __argb)
38 throws IllegalArgumentException
40 return Image.createImage(__w, __h, true, __argb);
43 /**
44 * Loads a mutable image from the specified byte array.
46 * @param __b The byte data.
47 * @param __o The offset.
48 * @param __l The length.
49 * @return The mutable image.
50 * @throws ArrayIndexOutOfBoundsException If the offset and/or length are
51 * negative or exceed the array bounds.
52 * @throws IllegalArgumentException If the image could not be decoded.
53 * @throws NullPointerException On null arguments.
54 * @since 2019/10/07
56 @Api
57 public static Image createImage(byte[] __b, int __o, int __l)
58 throws ArrayIndexOutOfBoundsException, IllegalArgumentException,
59 NullPointerException
61 // Load the base image
62 Image base = Image.createImage(__b, __o, __l);
64 // Create blank mutable
65 int w, h;
66 Image mutable = Image.createImage((w = base.getWidth()),
67 (h = base.getHeight()), base.hasAlpha(), 0);
69 // Setup graphics state, use SRC blending mode since it is just a
70 // copy of the alpha channel data!
71 Graphics g = mutable.getGraphics();
72 g.setBlendingMode(Graphics.SRC);
74 // Draw image on top
75 g.drawRegion(base, 0, 0, w, h, 0, 0, 0, 0);
77 // Use resulting image
78 return mutable;
81 /**
82 * Returns an interface which wraps the given graphics and provides raw
83 * pixel data access to it.
85 * @param __g The graphics object to wrap.
86 * @return The direct graphics.
87 * @throws NullPointerException On null arguments.
88 * @since 2019/10/07
90 @Api
91 public static DirectGraphics getDirectGraphics(Graphics __g)
92 throws NullPointerException
94 if (__g == null)
95 throw new NullPointerException("NARG");
97 // If this is already a Nokia graphics, use it
98 if (__g instanceof DirectGraphics)
99 return (DirectGraphics)__g;
101 // {@squirreljme.error EB3o Can only make a Nokia DirectGraphics from
102 // a PencilGraphics instance.}
103 if (!(__g instanceof PencilGraphics))
104 throw new RuntimeException("EB3o");
106 // Otherwise wrap it
107 return new __NokiaGraphics__((PencilGraphics)__g);