Android Training Course (22)

Source: Internet
Author: User

A logo image will be displayed during initialization. How can this image be displayed? The Code is as follows:

#001/* 565RLE image format: [count (2 bytes), rle (2 bytes)] */

#002

#003 int load_565rle_image (char * fn)

#004 {

This code is used to load the LOGO image in the 565RLE format. The parameter of the function is the image path.

 

#005 struct FB;

#006 struct stat s;

#007 unsigned short * data, * bits, * ptr;

#008 unsigned count, max;

#009 int fd;

#010

#011 if (vt_set_mode (1 ))

#012 return-1;

This Code sets the display output to the image mode.

 

#013

#014 fd = open (fn, O_RDONLY );

#015 if (fd <0 ){

#016 ERROR ("cannot open % s", fn );

#017 goto fail_restore_text;

#018}

This code is used to open the image to be displayed.

 

#019

#020 if (fstat (fd, & s) <0 ){

#021 goto fail_close_file;

#022}

This code is used to obtain information about the opened file, such as the file size.

 

#023

#024 data = mmap (0, s. st_size, PROT_READ, MAP_SHARED, fd, 0 );

#025 if (data = MAP_FAILED)

#026 goto fail_close_file;

This code maps image files to memory.

 

#027

#028 if (fb_open (& fb ))

#029 goto fail_unmap_data;

This Code enables the display cache to put the image data in the display cache.

 

#030

#031 max = fb_width (& fb) * fb_height (& fb );

#032 ptr = data;

#033 count = s. st_size;

#034 bits = fb. bits;

#035 while (count> 3 ){

#036 unsigned n = ptr [0];

#037 if (n> max)

#038 break;

#039 android_memset16 (bits, ptr [1], n <1 );

#040 bits + = n;

#041 max-= n;

#042 ptr + = 2;

#043 count-= 4;

#044}

This Code fills in the image data in the display cache.

 

#045

#046 munmap (data, s. st_size );

#047 fb_update (& fb );

This code updates the display cache and displays the LOGO.

 

#048 fb_close (& fb );

#049 close (fd );

#050 unlink (fn );

This code disables the resources opened above and deletes the LOGO image file. Because android loads the LOGO image into the memory and the LOGO is displayed completely, it does not work any more and resources are recycled in time. If you do not want to delete this image, you need to delete this line of code, or dynamically copy it to this line before each display.

 

#051 return 0;

#052

#053 fail_unmap_data:

#054 munmap (data, s. st_size );

#055 fail_close_file:

#056 close (fd );

#057 fail_restore_text:

#058 vt_set_mode (0 );

#059 return-1;

This section of code indicates the handling failure.

 

#060}

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.