<< Chapter < Page Chapter >> Page >

Once a stream is created, you can use the get and put commands in a loop, to bring in or put out line/s of data. Calling dstr_get on an input stream will give you a buffer where data is present to be read off. And calling an output stream will give you a buffer to which you can write data (which will be transported out on the next dstr_put call).

Remember, you have to be careful how many times you call these functions as you so not want to overflow. For example in our output example, we could call the dstr_put() upto 480 times – the number of single row transfers. Anymore, and the system may crash.

Also please remember to close the stream once you are done with it, i.e after all iterations. See the color_convert function to see when we close the streams using dstr_close(…). This is VERY important, since not closing a stream will cause random crashing of your system. The system may seem to run as you expected, but it will crash, if not after 1 second, then after 1 minute or 1 hour. This problem is one of the first you should look for when debugging such symptoms.

Also take a look at the streams for the input color components YCbCr to see how they are setup. You will find the figure on Device Driver Paper page 3-8 very useful in deciphering these streams. Understand them and you are set!

Quick-Test: Write a stream to obtain one-line buffers for columns 31 through 50 (20 columns) of the output buffer, with 50 rows. This rectangular region should start at pixel (100, 200). So each transfer should give a buffer of 20 * 2 bytes worth of information. Think of how you’d setup the stream.

Memory tricks and tips

Some simple memory tips are given here, you can come up with your own too.

  • Know how data flows in your system, this will help you increse efficiency and possibly eliminate complex stream use as well.
  • The dstr_get_2D and dstr_put_2D are used for multiple line transfers. Use these to your advantage.
  • You can use a simple memory ping-pong system to lessen memory use. If you need to use, say 200 X 300 rectangular region and filter it repeatedly. Then keep two memory 200 X 300 memory spaces. Write to the first, filter out to the second. Then filter the second out to the first, and so on until you're done.

Limitations

  • Space is a always a factor, especially with internal memory.
  • It's harder to extract columns of data as opposed to rows. To transfer a column, you need to setup a different stream, one that skips a whole ‘row-1’ of data with each dstr_get statement. Then you will need to iterate this to get the pixel on each row of that column. Multiple get's are necessary because the data is not contiguous in memory.

Idk libraries

To make your life easier, the IDK has some libraries which you can use for common image processing tasks. One such function is the Sobel (edge-detect) filter. These functions are usually hand coded in assembly and are extremely efficient, so it's best not to try to beat them.

The Sobel filter is contained in the file 'sobel_h.asm' and the header file needed is 'sobel_h.h'. You must add the program file and it's header in the project to use them. Next you will need to create a wrapper function and use the #include "sobel_h.h" directive in the wrapper function at the top. Don't forget to create a header function for your wrapper as well and add it to your project.

Next you will need to setup the streams and provide the assembly function the needed parameters. Namely, it needs a pointer to 3 lines worth of input data to be processed, one line of output data, the number of columns and number of rows. The library Sobel filter works on 3 lines of input and produces 1 line of output with each call. Look at the 'sobel_h.asm' to get a better understanding of the parameters

This material should be familiar from the previous lab where we explored wrapper and component functions. Now time for the assignment!

The assignment

Your assignment, should you choose to accept it is to build a simple filter system. You will start with the basic color conversion program given to you in: V:\ece320\projects\colorcool The system will copy the red-component of a 100 by 100 area of the screen (let’s call this area M). It will place this in a different area of the screen. Also you will need to place a Sobel filtered version of this red-area to the screen as well. The locations where the copied and filtered images are placed must be quickly modifiable on request (use variable position as parameters to wrapper functions rather than fixed coordinates)

Tips, tricks and treats

  • Plan the system before hand to make efficient use of modular functions and memory
  • For example, you only need just one “output area if size M” function to screen.
  • Keep handy pointers to the different memory spaces.
  • Use wrapper functions for the filter and copy_to_screen operations.
  • Write the modules so that they can be tested independently.
  • Be careful with color conversion. For example when copying the red-component of M, you need only 8 bits per pixel.
  • Keep the previous lab in mind when deciding when/where to extract the area M.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing laboratory (ece 420). OpenStax CNX. Sep 27, 2006 Download for free at http://cnx.org/content/col10236/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing laboratory (ece 420)' conversation and receive update notifications?

Ask