![]() |
Multimedia »
General Graphics »
Bitmaps
Intermediate
Add fast user-extensible image processing support to CBitmapBy .dan.g.Provides built-in graying, rotating, shearing, resizing, blurring, sharpening, flipping, negating and color replacement to CBitmap as well as support for user-defined processing plug-ins |
VC6Win2K, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

This work builds on my previous CEnBitmap class but is sufficiently new to warrant a separate article.
I read Yves Maurer's excellent bitmap rotation article (see Credits section) recently and was prompted to rewrite a bitmap post-processing library I had written some time ago for a proprietary 3D rendering engine.
Since the CEnBitmap class I had previously developed allowed for loading a variety of graphic formats both off disk and via resource ID, I thought it would provide the ideal vehicle for these further extensions.
What I've implemented then is a user-extensible bitmap processing 'library' with some built-in support for graying, rotating, shearing, blurring and resizing a bitmap, which can be used as simply as this:
:
:
CEnBitmap bitmap;
bitmap.LoadImage("c:\......\image.jpg");
bitmap.GrayImage();
bitmap.RotateImage(90); // can use radians also
bitmap.ResizeImage(0.8);
:
:
pMemDC->SelectObject(&bitmap);
pDC->BitBlt(...);
:
:
To define you own image processing plug-in, just derive a new class from C32BitImageProcessor and override the virtual methods CalcDestSize() and ProcessPixels().
Once you've done this, you simply pass your plug-in to the CEnBitmap object as follows:
:
:
CEnBitmap bitmap;
:
:
bitmap.ProcessImage(&CMyImageProcessor());
:
:
For multi-pass processing, you can also pass an array of plug-in pointers to CEnBitmap as follows:
:
:
CEnBitmap bitmap;
:
:
C32BIPArray aProcessors;
CMyImageProcessor1 p1;
CMyImageProcessor2 p2;
CMyImageProcessor3 p3;
aProcessors.Add(&p1);
aProcessors.Add(&p2);
aProcessors.Add(&p3);
bitmap.ProcessImage(aProcessors);
:
:
This has the advantage of only getting and setting the internal HBITMAP bits at the start and end of the operation, and of doing as few memory allocations as possible.
Try out the 'Spin' button on the sample app to see how quick it is. About 20-30 ms for each iteration on a 200x200 image. (Note: the flipping and shearing plug-ins only take 0-5 ms for a similar sized image).
The key to achieving any degree of real time processing is a good algorithm (see karl Lager's credit) and working on the bitmap at the lowest level (see Yves Maurer's credit).
So all the processing is done on the raw bitmap bits, and not using Set/GetPixel() which would be way too slow.
The addition of color weighting adds a small penalty to the processing speed but gives way better results. However, color weighting is managed via a boolean attribute, so its up to you which way you go.
Carrying out multiple processing using an array of processors gives a small improvement, so its worth doing (see the sample app for details).
This is a simple app which allows you to load a variety of image formats and apply the built-in plug-ins.
Note: the plug-ins are not necessarily applied in the order you select them but in the order that gives the best results.
I've modified the sample app so that the selected plug-ins are also applied when spinning, and can be turned on and off on the fly.
None.
Except :) that I retain copyright of this original work, notwithstanding the work done by those listed in the credits.
If you write a plug-in of your own then you are free to publish it as your own original work and, if appropriate, I'll add it to the CEnBitmap interface and add a link on this page.
I'm happy to receive suggestions for:
IPicture code
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Dec 2002 Editor: Smitha Vijayan |
Copyright 2002 by .dan.g. Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |