NIOS2 essay--jpeg decoding and VGA display

Source: Internet
Author: User

1. System Overview

This design uses NIOS2 32-bit processor, through the SPI interface to read the JPEG image data in the SD/TF card into memory, SD/TF card file system for FAT32,NIOS2 software to achieve JPEG decoding, start Framereader and clocked Video The output module will eventually display a JPEG image on the VGA display with the following system diagram:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8C/9E/wKiom1hyOLKh4a8LAABiPj1DLCI656.png "title=" Sys_ Block.png "width=" "height=" 327 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:500PX;HEIGHT:327PX; "alt=" Wkiom1hyolkh4a8laabipj1dlci656.png "/>


2. jpeg format

JPEG (Joint Photographic Experts Group) is the first international image compression standard, which provides good compression performance at the same time, has good image quality and is widely used in electronic products and chip design.

There are two ways to save the JPEG file format, Baseline JPEG and progressive JPEG, respectively.

Baseline JPEG: This type of JPEG file is stored as a top-to-bottom scan, keeping each row in a JPEG file. When displayed, the data is displayed as a row from top to bottom.

Progressive JPEG: Contains multiple scans, which are stored in a JPEG file. When displayed, the blurred outline of the entire image is displayed first, and as the number of scans increases, the picture becomes clearer.

The JPEG compression algorithm process is as follows:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8C/9E/wKiom1hyO-7zQcSTAAAFrvAYuH0466.gif "title=" Jpeg_ Decode.gif "alt=" Wkiom1hyo-7zqcstaaafrvayuh0466.gif "/>

3. Tiny JPEG decompressor

Tjpgdec is a generic JPEG image decoding module, developed based on C language and can be used in small embedded systems.

The TJPGDEC provides two API function interfaces:

    • Jd_prepare to prepare enough information for image decoding

    • Jd_decomp Performing decoding tasks

Two I/O function interfaces are also available:

    • Input function: Reads JPEG file data from the input stream

    • Output function: Writes image data to the output device

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8C/9B/wKioL1hyPhHRfpzcAAANDOA7iuw621.png "title=" Jpeg_ Soft.png "alt=" Wkiol1hyphhrfpzcaaandoa7iuw621.png "/>

Open source code can be downloaded from http://elm-chan.org/fsw/tjpgd/00index.html.


3. Build Qsys

On the basis of Bowen NIOS2 essay--fat32 file system, add Framereader and clocked Video output components on Qsys platform, set resolution to 640*480,VGA related content can refer to the blog FPGA Design--VGA ( Altera).

Well-Qsys platform such as:

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8C/9B/wKioL1hyPzKzq5vPAAEtOwmsJNg487.jpg "title=" Qsys_ Jpeg.jpg "alt=" Wkiol1hypzkzq5vpaaetowmsjng487.jpg "/>


4. NIOS2 Software Design

Ttjpgdec is based on the baseline JPEG algorithm, need to save a JPEG image baseline way to the SD card, the image resolution is 640*480, the file name is Desk.jpg, opened in the computer as follows:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8C/9B/wKioL1hyP_zCr3ElAAh-zmph3IM660.png "title=" desk_ Windows.png "alt=" Wkiol1hyp_zcr3elaah-zmph3im660.png "/>

Write software code based on the software of NIOS2 essay--fat32 file system.

Porting the JPEG software decoding module, mainly writing input and output functions. In the VGA display section, to initialize the Framereader component, and then the image data stored in the array will be continuously read to the clocked Video output module, the final data will be sent to the VGA encoded chip display. The written input, output, and main function codes are designed as follows:

============jpeg user function==============/*------------------------------*//* user  defined input funciton  *//*------------------------------*/uint in_func  (jdec*  jd, byte* buff, uint nbyte) {    u32  rb=0;//number  of byte read    f_read (&AMP;TF_JPEG,BUFF,NBYTE,&AMP;RB);    &NBSP;RETURN&NBSP;RB;} /*------------------------------*//* user defined output funciton *//*--------------- ---------------*/uint out_func  (jdec* jd, void* bitmap, jrect* rect) {    BYTE *src, *dst;   UINT y, bws, bwd;     if  (rect->left == 0)  {        printf ("\r% lu%% ",  (Rect->top << jd->scale)  * 100ul / jd->height);     }    src =  (byte*) bitmap;    dst =  picture_buffer + 3 *  (Rect->top * frame_width+ rect->left);     bws = 3 *  (rect->right - rect->left + 1) ;    bwd = 3 * frame_width;    for  (y =  rect->top; y <= rect->bottom; y++)  {         memcpy (DST,&NBSP;SRC,&NBSP;BWS);         src +=  bws; dst += bwd;    }    return 1;} fatfs fs;fil  tf_jpeg; byte res=0;int main  (void) {uint *work; jdec tjpeg_dev; uint x=0; uint y; Framerd_init (); F_mount (&fs, "", 0);//open a jpeg fileres = f_open (&tf_jpeg, "0:/Desk.jpg ", fa_read); Work = malloc (3800);//prepare to decompress    res  = jd_prepare (&tjpeg_dev, in_func, work, 3800, &tf_jpeg);if  (res &NBSP;==&NBSP;JDR_OK)  {        //ready to dcompress.  image info is available here.        printf ( "Image dimensions: %u by %u. %u bytes used.\n", tjpeg_dev.width,  Tjpeg_dev.height, 3800 - tjpeg_dev.sz_pool);         res  = jd_decomp (&tjpeg_dev, out_func, 0);   // start to  decompress with 1/1 scaling        if  (res == &NBSP;JDR_OK)  {            //decompression  succeeded. you have the decompressed image in the frame buffer here.             printf ("\nok  \n");         }        else         {            printf ( "failed to decompress: rc=%d\n",  res);         }     }else{        printf ("Failed to  Prepare: rc=%d\n ",  res);}     f_close (&tf_jpeg);       //close the  Jpeg file    for (y=0;y<frame_size*3;y=y+3)     {     picture_buf[x] = picture_buffer[y]*65536+ (picture_buffer[y+1]) *256+ (picture_buffer[y+2]);     x++;    }    printf ("image processed  done\n "); while (1);     return 0;}


5. Compile and run

After compiling successfully, run in hardware mode, terminal printing progress information, last display: Image processed done!

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8C/9B/wKioL1hyQm7jGpepAAAvyy_w3Nw746.png "title=" Jpg_ Console.png "alt=" Wkiol1hyqm7jgpepaaavyy_w3nw746.png "/>


6. Final results

Picture normal display, and the computer open desk.jpg consistent, this picture or Bo Master 4 years ago with Nokia mobile phone in the group rent inside a picture, full of memories AH.

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/8C/9B/wKioL1hyRFXzuzPOAAB2FBbvZ1c151.jpg "title=" Jpg_ Result.jpg "alt=" Wkiol1hyrfxzuzpoaab2fbbvz1c151.jpg "/>


This article is from the "Shugenyin blog" blog, make sure to keep this source http://shugenyin.blog.51cto.com/4259554/1890239

NIOS2 essay--jpeg decoding and VGA display

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.