Advanced Multimedia

THE JSR 234 Advanced Multimedia Supplements (AMMS) specification
defines standard extensions to MMAPI. Most of the API is composed of addi-
tional Controls, but some additional infrastructure is also provided. The AMMS
specification defines six capabilities that serve as groups of functionality.
• imagepostprocessing supplies a structure for applying image effects like
blurring, sharpening, or posterization.
• imageencoding allows applications to encode images using standard file
formats.
• music provides volume and equalization controls for audio playback.
• audio3d enables your applications to place sound sources in a virtual 3D
space surrounding the listener.
• camera provides access to camera features like flash and exposure control.
• tuner allows applications to control a device’s FM or AM radio.
A device that supports a capability provides some minimum functionality, which
is described in the specification. At runtime, you can find out which capabilities
are supported by retrieving the system property supports.mediacapabilities.
It contains a list of capability names separated by spaces.
The MSA specification requires devices to support imagepostprocessing and
imageencoding. If the device has a camera, the camera capability must also be sup-
ported. If the device has a radio tuner, the tuner capability must also be supported
24.1 Image Processing
If your platform supports it, applications can use AMMS to perform common
image operations like blurring, sharpening, posterizing, resizing, and rotating.
Image processing is performed by a MediaProcessor, which knows how to manip-
ulate a certain type of input. You can get a MediaProcessor from GlobalManager
by specifying the input type. Both MediaProcessor and GlobalManager are in
javax.microedition.amms.
For example, to process JPEG images, you would do this:
MediaProcessor mp =
GlobalManager.createMediaProcessor("image/jpeg");
You can find out what input formats are supported by calling GlobalManager’s
static getSupportedMediaProcessorInputTypes() method. The Sun Java Wire-
less Toolkit returns image/png, image/jpeg, and image/raw, although only
image/jpeg and image/raw are required. Raw means that the MediaProcessor
will manipulate Image objects rather than manipulating byte streams.
Tell the MediaProcessor about your input (source) image with setInput().
One form of the method accepts an InputStream and a byte length, which can
be MediaProcess.UNKNOWN. For example, you can use a JPEG image as input
like this:
InputStream in = getClass().getResourceAsStream("/orca.jpg");
mp.setInput(in, MediaProcessor.UNKNOWN);
The MediaProcessor writes the processed image to an output stream. Use set-
Output() to tell MediaProcessor where your output should go.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
mp.setOutput(bout);
The next step is picking the transformations you want to apply to the image. These
are accessible as Controls on the MediaProcessor. You can get useful controls
from MediaProcessor by specifying their class names, just like you can with
Players. Common photographic effects are encapsulated by ImageEffect-
Control, which includes useful presets. Choose a preset by passing its name to
setPreset(). monochrome and negative must be supported, but other possibili-
ties include emboss, sepia, solarize, and redeyereduction. Call getPreset-
Names() for a list of available presets. Take a look at the API documentation for
ImageEffectControl for a description of each preset.
In this example, the emboss preset is used. Note that you must enable the control
for it to affect the output image.
String p = "javax.microedition.amms.control.";
ImageEffectControl iec = (ImageEffectControl)
mp.getControl(p + "imageeffect.ImageEffectControl");
iec.setPreset("emboss");
iec.setEnabled(true);
Other controls might be available. The following example shows how to scale an
image to 80% of its original size using an ImageTransformControl:
ImageTransformControl itc = (ImageTransformControl)
mp.getControl(p + "imageeffect.ImageTransformControl");
int ow = itc.getSourceWidth();
int oh = itc.getSourceHeight();
int w = ow * 80 / 100;
int h = oh * 80 / 100;
itc.setTargetSize(w, h, 0);
itc.setEnabled(true);
Useful controls for image processing live in the javax.microedition.amms.
control.imageeffect package.
You can control the output of the MediaProcessor with an ImageFormatControl.
When you are finished working with the Controls of the MediaProcessor, the
start() method kicks off the processing. If you’ve registered a MediaProcessor-
Listener, you’ll be notified when the processing is finished. If you’d prefer to
wait instead, you can call complete().
mp.complete();
If you prefer, you can use a MediaProcessor that works with Image objects
directly instead of a MediaProcessor that works on byte streams. In this case,
use an image/rawMediaProcessor. The other form of setInput() accepts an
Image object directly:
MediaProcessor mp =
GlobalManager.createMediaProcessor("image/raw");
InputStream in = getClass().getResourceAsStream("/orca.jpg");
Image i = Image.createImage(in);
mp.setInput(i);
In the example code for this chapter, HanzUndFranzMIDlet contains two meth-
ods that illustrate aspects of image processing:
runImagePostProcessingJPEG()
runImagePostProcessingRaw()
The first uses a JPEG file as InputStream input. The other shows how to pass an
Image directly to an image/rawMediaProcessor. In both cases, the source
image is shrunk and embossed. The source and processed images are both dis-
played. See Figure 24.1.
4.2 Controlling Image Format
Unless you say otherwise, MediaProcessor spits out the same format you feed
it. For example, if you create an image/pngMediaProcessor, the output will be
a PNG image.
You can control the output format with an ImageFormatControl. Here is an exam-
ple that sets the output format to PNG:
ImageFormatControl ifc = (ImageFormatControl)
mp.getControl(p + "ImageFormatControl");
ifc.setFormat("image/png");
This capability can be used without any processing to encode images in any
available formats. The available formats are returned by ImageFormatControl’s
method getSupportedFormats().
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值