Implementation of the image display tool in QNX Character Mode

Source: Internet
Author: User

I. Environment preparation

Start io-Display

Io-display-v-dvid = 0x8086, vid = 8108

 

2. Project Settings

Add/usr/libgf. So and/lib/libimg. So to the project's linker External library.

 

Iii. Code

# Include <stdlib. h> <br/> # include <stdio. h> <br/> # include <string. h> <br/> # include <GF/GF. h> <br/> # include <br/> # define dev_attach_error-1 <br/> # define display_attach_error-2 <br/> # define display_null-3 <br/> # define layer_attach_error-4 <br /># define surface_create_error-5 <br/> # define context_create_error-6 <br/> # define surface_set_error-7 <br/> int setup (gf_dev_t * p_gdev, gf_disp Lay_t * p_display, implements * p_layer, gf_surface_t * p_surface, implements * p_context); <br/> int draw (gf_dev_t * p_gdev, implements * p_layer, implements * p_surface, gf_context_t * p_context, char * p_imgname); <br/> void dispose (gf_dev_t * p_gdev, gf_display_t * p_display, gf_layer_t * p_layer, gf_surface_t * p_surface, gf_context_t * p_context ); <br/> gf_format_t img_fmt_to_gf (img_format_t img_format ); <Br/> int main (INT argc, char * argv []) {<br/> int result = 0; <br/> // graphics variable <br/> gf_dev_t gdev; <br/> gf_display_t display; <br/> gf_layer_t layer; <br/> gf_surface_t surface; <br/> gf_context_t context; <br/> char * imgname; <br/> // parameter check <br/> If (argc! = 2) {<br/> printf ("image file name missing/N"); <br/> return exit_failure; <br/>}< br/> imgname = argv [1]; <br/> result = setup (& gdev, & display, & layer, & surface, & context ); <br/> If (result = exit_success) {<br/> result = draw (& gdev, & layer, & surface, & context, imgname ); <br/>}< br/> while (1) {<br/> sleep (99999); <br/>}< br/> dispose (& gdev, & display, & layer, & surface, & context); <br/> return exit_succe SS; <br/>}< br/> int setup (gf_dev_t * p_gdev, gf_display_t * p_display, gf_layer_t * p_layer, gf_surface_t * p_surface, gf_context_t * p_context) {<br/> int result; <br/> gf_dev_info_t gdev_info; <br/> gf_display_info_t display_info; <br/> // attaching to a device <br/> result = gf_dev_attach (p_gdev, gf_device_index (0), & gdev_info); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_dev_attach () failed [% d]/n", result); <br/> return dev_attach_error; <br/>}< br/> // printf ("Number of displays: % d/N", gdev_info.ndisplays); <br/> // int I; <br/> // for (I = 0; I <gdev_info.ndisplays; I ++) {<br/> // printf ("display % d:", I ); <br/> // If (gf_display_attach (p_display, * p_gdev, I, & display_info) = gf_err_ OK) {<br/> // printf ("% DX % d, refresh = % DHZ/N ", display_ I Nfo. xres, <br/> // display_info.yres, display_info.refresh); <br/> // printf ("number of layers: % d/N", display_info.nlayers ); <br/> //} else {<br/> // printf ("gf_display_attach () failed/N "); <br/> //} <br/> result = gf_display_attach (p_display, * p_gdev, 0, & display_info ); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_display_attach () failed [% d]/n", result); <br/> return display_attach_error; <br/>}< br/> If (* p_display = NULL) {<br/> printf ("display is null/N"); <br/> return display_null; <br/>}< br/> // attaching to a display layer <br/> result = gf_layer_attach (p_layer, * p_display, display_info.main_layer_index, gf_layer_attach_passive ); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_layer_attach () failed [% d]/n", result); <br/> return layer_attach_error; <br/>}< br/> // create and set surfaces <br/> result = gf_surface_create_layer (p_surface, p_layer, 1, 0, display_info.xres, display_info.yres, display_info.format, null, 0); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_surface_create_layer () failed [% d]/n", result); <br/> return surface_create_error; <br/>}< br/> gf_layer_set_surfaces (* p_layer, p_surface, 1); <br/> // create context <br/> result = gf_context_create (p_context ); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_context_create () failed [% d]/n", result); <br/> return context_create_error; <br/>}< br/> // set surface <br/> result = gf_context_set_surface (* p_context, * p_surface); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_context_create () failed [% d]/n", result); <br/> return surface_set_error; <br/>}< br/> return exit_success; <br/>}< br/> int draw (gf_dev_t * p_gdev, gf_layer_t * p_layer, gf_surface_t * p_surface, gf_context_t * p_context, char * p_imgname) {<br/> int result; <br/> img_lib_t ilib = NULL; <br/> img_t IMG; <br/> gf_palette_t palette; <br/> // begin draw <br/> result = gf_draw_begin (* P_context); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_draw_begin () failed [% d]/n", result); <br/> return-1; <br/>}< br/> /// draw something <br/> // gf_context_set_fgcolor (* p_context, 0 xffffff ); <br/> // gf_draw_rect (* p_context, 10, 10, 50, 50); <br/> // gf_context_set_fgcolor (* p_context, 0x000000 ); <br/> // gf_draw_rect (* p_context, 20, 40, 40); <br/> /// draw line <br/> // gf_context_set_fgcolor (* p_context, 0x0000ff ); <br/> // gf_point_t PTS [3]; <br/> // PTS [0]. X = 10; <br/> // PTS [0]. y = 100; <br/> // PTS [1]. X = 150; <br/> // PTS [1]. y = 250; <br/> // PTS [2]. X = 200; <br/> // PTS [2]. y = 100; <br/> // gf_context_set_penwidth (* p_context, 10); <br/> // gf_context_set_linejoin (* p_context, gf_context_linejoin_round ); <br/> // gf_draw_polyline (* p_context, PTS, 3, 0); <br/> // gf_context_set_fgcolor (* p_context, 0x000000 ); // black <br/> // gf_context_set_penw Idth (* p_context, 3); <br/> // gf_draw_polyline (* p_context, PTS, 3, 0); <br/> // PTS [1]. X = 100; <br/> // PTS [1]. y = 260; <br/> // PTS [0]. y = 400; <br/> // PTS [2]. X = 200; <br/> // PTS [2]. y = 400; <br/> // gf_context_set_antialias (* p_context, 1); <br/> // gf_context_set_fgcolor (* p_context, 0x0000ff ); <br/> // gf_context_set_penwidth (* p_context, 2); <br/> // gf_draw_polyline (* p_context, PTS, 3, 0); <br/> // load Image Library <br/> result = img_lib_attach (& ilib); <br/> If (result! = Img_err_ OK) {<br/> printf ("img_lib_attach () failed [% d]/n", result); <br/> return-1; <br/>}< br/> // Initialize an img_t by setting its flags to 0 <br/> IMG. flags = 0; <br/>/* If we want, we can preselect a format (ie force the image to be <br/> loaded in the format we specify) by enabling the following two <br/> lines */<br/> IMG. format = img_fmt_pkle_xrgb8888; <br/> IMG. flags | = img_format; <br/> /* Likewise, we can 'clip' the loaded image by enabling the following */<br/> IMG. W = 800; <br/> IMG. flags | = img_w; <br/> IMG. H = 480; <br/> IMG. flags | = img_h; <br/> result = img_load_file (ilib, p_imgname, null, & IMG); <br/> If (result! = Img_err_ OK) {<br/> printf ("img_load_file (% s) failed: % d/N", p_imgname, result); <br/> return-1; <br/>}< br/> // printf ("IMG is % DX % d/N", IMG. w, IMG. h, img_fmt_bpp (IMG. format); <br/>/* for our purposes we ''re done with the IMG lib */<br/> img_lib_detach (ilib ); <br/> // attaching to a surface <br/> If (IMG. format & img_fmt_palette) {<br/>/* setup palette if necessary */<br/> palette. ncolors = IMG. Npalette; <br/> palette. colors = IMG. palette; <br/>} else if (IMG. format = img_fmt_g8) {<br/>/* We can render G8 images in GF by using a palette of grays */<br/> palette. ncolors = 256; <br/> printf ("IMG. format = img_fmt_g8/N "); <br/> // palette. colors = (img_color_t *) g8pal; <br/> palette. colors = IMG. palette; <br/>}< br/>/* attach a surface to the image data; this allows us to BWS the image <br/> d ATA to another surface (or the display) in GF */<br/> result = gf_surface_attach (p_surface, * p_gdev, IMG. w, IMG. h, IMG. access. direct. stride, <br/> img_fmt_to_gf (IMG. format), & palette, IMG. access. direct. data, 0); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_surface_attach () failed: % d/N", result ); <br/>/* might fail here if the decoder gave us a format that cannot <br/> map to GF; in this case we cocould have preselected a format <br/> that is supported by GF (code above shows how to do this) */<br/> return-1; <br/>}< br/> If (IMG. flags & img_transparency) {<br/>/* We can handle transparency in GF using chroma */<br/> Gf_chroma_t chroma; <br/> memset (& chroma, 0, sizeof chroma); <br/> chroma. mode = gf_chroma_op_src_match | gf_chroma_op_no_draw; <br/> If (IMG. format & img_fmt_palette) {<br/> chroma. color0 = IMG. palette [img. transparency. index]; <br/>} else if (img_fmt_bpp (IMG. format) <24) {<br/> chroma. color0 = IMG. transparency. rgb16; <br/>}else {<br/> chroma. color0 = IMG. transparency. rgb32; <br/>}< br/> Gf_context_set_chroma (* p_context, & chroma); <br/>}< br/> If (IMG. format & img_fmt_alpha) {<br/> gf_alpha_t Alpha; <br/> memset (α, 0, sizeof alpha); <br/> alpha. mode = gf_alpha_m1_src_pixel_alpha | gf_blend_src_m1 | <br/> gf_blend_dst_1mm1; <br/> gf_context_set_alpha (* p_context, α ); <br/>}< br/> // BThe the image onto a target surface <br/> gf_draw_blit2 (* p_context, * p_surface, null, 0, 0, IMG. w-1, IMG. h-1, 0, 0); <br/> // finish draw <br/> gf_draw_flush (* p_context); <br/> result = gf_draw_finish (* p_context ); <br/> If (result! = Gf_err_ OK) {<br/> printf ("gf_draw_finish () failed [% d]/n", result); <br/> return-1; <br/>}< br/> gf_draw_end (* p_context); <br/> gf_layer_update (* p_layer, 0); <br/> If (IMG. format & img_fmt_alpha) {<br/> gf_context_disable_alpha (* p_context); <br/>}< br/> If (IMG. flags & img_transparency) {<br/> gf_context_disable_chroma (* p_context); <br/>}< br/> free (IMG. access. direct. data); <br/> gf_context_free (* p_context); <br/> gf_surface_free (* p_surface); <br/> gf_layer_detach (* p_layer); <br/> return exit_success; <br/>}< br/> void dispose (gf_dev_t * p_gdev, gf_display_t * p_display, gf_layer_t * p_layer, gf_surface_t * p_surface, gf_context_t * p_context) {<br/> // free resource <br/> gf_display_detach (* p_display); <br/> gf_dev_detach (* p_gdev ); <br/>}< br/> gf_format_t img_fmt_to_gf (img_format_t img_format) {<br/> // printf ("img_fmt_to_gf (% d)/n", img_format ); <br/> switch (img_format) {<br/> case img_fmt_invalid: <br/> return gf_format_invalid; <br/> case img_fmt_mono: <br/> return gf_format_byte; <br/> case img_fmt_g8: <br/> return gf_format_pal8; <br/> case img_fmt_a8: <br/> return gf_format_pal8; <br/> case img_fmt_pal1: <br/> return gf_format_pal8; <br/> case img_fmt_pal4: <br/> return gf_format_pal8; <br/> case img_fmt_pal8: <br/> return gf_format_pal8; <br/> case when: <br/> return gf_format_pkle_rgb565; <br/> case when: <br/> return gf_format_pkbe_rgb565; <br/> case img_fmt_pkle_argb1555: <br/> return gf_format_pack_argb1555; <br/> case when: <br/> return gf_format_pack_argb1555; <br/> case when: <br/> return gf_format_pkle_argb1555; <br/> case when: <br/> return gf_format_pkbe_argb1555; <br/> case img_fmt_bgr888: <br/> return gf_format_bgr888; <br/> case img_fmt_rgb888: <br/> return gf_format_bgra8888; <br/> case img_fmt_pkle_abgr8888: <br/> return gf_format_argb8888; <br/> case when: <br/> return gf_format_argb8888; <br/> case when: <br/> return gf_format_argb8888; <br/> case when: <br/> return gf_format_argb8888; <br/> case img_fmt_pkle_argb8888: <br/> return gf_format_argb8888; <br/> case img_fmt_pkbe_argb8888: <br/> return gf_format_argb8888; <br/> case when: <br/> return gf_format_bgra8888; <br/> case img_fmt_pkbe_xrgb8888: <br/> return gf_format_bgra8888; <br/> case img_fmt_yuv888: <br/> return gf_format_pkbe_yuv_v422; <br/>}< br/> // default 32 <br/> return gf_format_bgra8888; <br/>}

 

4. execute shell

#! /Bin/sh

/Mnt/showimage/usr/mcy/images/background-1.png &
Sleep 5
Pro_simg = 'ps-A | grep showimage | awk '{print $1 }''
/Mnt/showimage/usr/mcy/images/background-2.png &
Sleep 1
Slay $ pro_simg;
Sleep 10
Slay showimage

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.