mustafayalcin.com

ABAP Bitmap Image Processing Class

by on Haz.03, 2010, under SAP

Introduction

Last week Alvaro Tejada (Blag) posted a weblog posing the requirement to flip a bitmap using ABAP. Well I got all caught up in the fun challenge and now here are the results for your downloading pleasure.

What Blag wanted to do was simply flip an existing Bitmap that he was reading out of the BDS (Business Document Store).  The problem that he was facing is that there is no easy method for doing this in ABAP. He tried just reversing the Byte Stream, but quickly found out that this corrupted the image.  A bitmap isn’t just stored as a simple data stream – it has header information and a complex structure that must be taken into consideration when doing any manipulations on it.

But many other languages have simple processes for working with Bitmaps – what was wrong with ABAP.  Well these other languages just have libraries that have already been created that abstract the actual process of working with the Bitmap.  These libraries directly expose attributes like the bitmap height and width, so that programmers don’t have to know the detailed structure of the Bitmap header.  They also usually have methods to allow for basic manipulation of the Bitmap.

To my best knowledge, no one in ABAP had created such a library.  So while it was perfectly possible to manipulate the Bitmap at a low level in ABAP, it was more tedious than necessarily because it didn’t have one of these helper libraries.  Historically ABAP has been all about processing business data, so it hasn’t been a big issue that you couldn’t flip bitmaps or convert them to grey scale.  But with ABAP being used increasingly for forms output and web pages, this is functionality that might be useful from time to time.  So I decided to take the rough solution that I built for Blag and turn it into a reusable bitmap class.

Bitmap Processing

Before we get into the actual solution of the ABAP Bitmap Library, I thought I would cover some basics of the processing that is going on within the library.  If you are interested in how Bitmaps are stored and processed then keep reading this section. If you really couldn’t care less and just want to get started using the library, then skip down to the next section (after all the purpose of creating this library was so people wouldn’t have to care how a bitmap works internally).

When I started looking into Blag’s problem, I had no real experience with how bitmaps are structured.  So I started my investigation via the internet.  I found lots of good articles on Bitmaps, but probably the best summary of information I found was on Wikipedia.

The linked Wikipedia article does an excellent job of describing the inner layout of the Bitmap – how you have a section for the header information and then a separate section for the data.  It also describes for each pixel is stored.  The color of the pixel (in 24 bits per pixel) is stored as three separate integers – one each for Red, Green, and Blue.  It is important to understand that you can’t just manipulate data within the Bitmap at the byte level, but instead the pixel level so you can keep from altering the RGB color as you move bytes around.

The second complexity is that bitmaps are not stored top to bottom within the data area.  Instead the first visible row of data on the screen is stored as the list “line” in the bitmap data area.  All the data is also stored together in a single stream. Therefore for easier processing you generally break the stream down by horizontal row. But because processing is easier if divisible by 4, null-bytes are added to the end of the line to pad the file.  All of these aspects are especially important when trying to rotate a bitmap.

The final complexity that I faced in my processing was that much of the data in the bitmap header was stored as either 2 or 4 byte DWORDs. This meant that I couldn’t just cast these byte values into ABAP Integers.  Instead I had to create small macros to change the byte order.

The ABAP Bitmap Library

OK, enough of the deep stuff.  Now it is time to see just how easy we can make working with Bitmaps in ABAP.  For that purpose I have created a Class called ZCL_ABAP_BITMAP.

Devamı : http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/7249

:, , ,
No comments for this entry yet...

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...