[Post] Game Development 3 based on Nokia s60

Source: Internet
Author: User
Tags transparent color
Symbian OS can be understood as a bitmap-Oriented Operating System. All applications in Symbian OS can use bitmaps, especially game programs. Although the basic drawing method (such as drawline and drawellipse) can be used to draw a smaller image, the bitmap can draw a screen more effectively and the output image is more delicate.

Symbian OS has its own bitmap file format MBM, which is a multi-bitmap file. The window bitmap uses a bitmap Conversion Tool bmconv to create MBM. Because an MBM file may contain multiple bitmaps, bmconv also generates a Bitmap header file mbg, which provides an access bitmap ID. When a bitmap is loaded from an MBM file, the corresponding header file should be included, and an appropriate identifier should be used as a parameter for the method for loading the bitmap. Bitmap can be defined in the project file:

Start bitmap [target-file]
Header
Targetpath [targetpath]
Sourcepath [sourcepath]
Source [color-depth] [Source-bitmap]
End

Bmconv can create two different types of Symbian OS bitmaps: Read-only and non-read-only storage bitmaps. Non-read-only storage bitmaps, also known as file storage bitmaps, are compressed using the encoding Rle. They need to be loaded into RAM before use. To speed up the plotting, read-only bitmaps are generally not compressed and can be used directly from the Rom. By default, bmconv creates a file storage Bitmap (that is, a non-read-only storage Bitmap ).

Symbian OS supports masks. The mask is a black-and-white bitmap, and the white area is transparent. Only the pixels in the black area in the mask are drawn from the original bitmap based on the desired image. Because the masks only need two colors, they should be converted to 1-bit bitmaps to save storage space. Figure 1 shows an example of using a mask.


Figure 1 example of using a mask to describe a transparent bitmap

Series 60 provides a command line tool named makemask to create a 1-bit mask from an 8-Bit Bitmap. Makemask uses the last palette index in the original bitmap as the transparent color.

Although Symbian OS provides application programming interfaces for setting the bitmap palette, these interfaces are not implemented. Once these application programming interfaces are added, the system supports color display. When added, Symbian OS determines that only the color cube correction of the Netscape color palette is supported. Series 60 provides its own 8-Bit Bitmap palette. Bmvconv is modified to convert an 8-Bit Bitmap to a Series 60 color palette (216 colors and 10 gray tones are provided ). This prevents third-party developers from using their own color palette, because using their own color palette often affects bitmap output. In particular, bitmaps with multiple colors are needed. For example, to create a color gradient bitmap, at least 12 bitmaps should be converted. The Series 60 palette is defined in the thirdpartybitmap. Pal palette file.

Bitmap management is implemented by the cfbsbitmap class. This class provides methods for creating and loading bitmaps and defines their color depth and size. It uses the rfbssession class to access FBS, so users cannot access the session class. Cfbsbitmap also provides a method to directly access bitmap image data. You can use the dataaddress method to obtain a pointer to the data address, and use the getscanline method to access a specified Scan Line.

Based on the size of the bitmap, the bitmap is decomposed into two different stacks in FBS. A Bitmap smaller than 4 kb is saved to one heap, and a bitmap larger than 4 kb is saved to another heap. This type of decomposition is used to prevent storage fragments. Storage fragments often occur when large bitmaps are created and destroyed. The large bitmap heap can automatically organize fragments. Due to fragment, the heap needs to be locked when large bitmap content is operated. To prevent fragment and operation synchronization, the tbitmaputil class provides operations to lock and unlock the heap. You must lock the heap only when the image data of a bitmap is directly edited. The tracking and copying methods provide the automatic locking function. In the following example, the FBS is locked when the bitmap is large and the bitmap is filled with color. It assumes that each pixel of the bitmap uses 16 bits. This applies to 12-bit and 16-bit bitmaps.

// Lock the heap if a large bitmap
If (Bitmap-> islargebitmap ())
{
Tbitmaputil bitmaputil (Bitmap );
Bitmaputil. Begin (tpoint (0, 0 ));
}
// Edit bitmap
Tsize bitmapsize = Bitmap-> sizeinpixels ();
Tuint16 * bitmapdata = (tuint16 *) Bitmap-> dataaddress ();
Tuint16 color = 0;
For (tint y = 0; y <bitmapsize. iheight; y ++ );
{
For (tint x = 0; x <bitmapsize. iwidth; X ++)
{
* Bitmapdata ++ = color ++;
}
}
// Release the heap
If (Bitmap-> islargebitmap ())
{
Bitmaputil. End ();
}

To make the bitmap faster than cfbsbitmaps, the window server provides its own bitmap class cwsbitmap. It removes unnecessary context conversion between the window server and FBS by obtaining the ownership of Bitmap Processing. Cwsbitmap inherits from cfbsbitmap and implements all the same methods. If you pay great attention to the plotting speed when developing applications, you should use cwsbitmap to replace its base class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.