Virtual Developer Workshop: Containerized Development with Docker

Rotation sample:

Unlike traditional rotation of images, where every n'th pixel is sampled and copied to the result image, this template provides much more accurate image rotation features (weighing the pixels).

The template is instantiated with a specific pixel format and must be inherited to support pixel access functions for a specific bitmap implementation. This provides abstaction of the rotation mechanism from the actual bitmap representation.

Major features:

  • Provides professional quality image rotation.
  • Code is optimized for image quality, not speed.
  • Rotated image retains size and aspect ratio of source image (destination image size is usally bigger).
  • Supports double precision rotation angles (0..360).
  • Supports generic bitmap structures. Specific bitmap structure is defined by inheritance.
  • Template based - no need for libraries, DLLs etc. No linkage problems.

How to use the rotation template:

You must derive you own class from the rotation template.
For example:

class CRotateByShearRGB : public CRotateByShear<COLORREF>
will define a concrete class where each pixel is of COLORREF type.
Next, you must override 5 abstract functions which support creation, destruction of bitmap buffers and pixel level access to the bitmap buffers.
Next, you instantiate your derived class and call the AllocAndRotate(...) function which allocates a new destination bitmap buffer and rotates the input image into it.
That's it.

For further instructions please view the attached sample command-line project (Rotate.cpp).
It is a simple command line utility which reads PPM (ASCII or binary) image file into a DIB structure, rotates it and saves it to another PPM image file.

Download template - 4 KB

Download sample command line application - 21 KB


  • Most lazy coder

    Posted by Legacy on 09/23/2002 07:00am

    Originally posted by: Akash Kava

    No GUI, no facility for direct Bitmap images.. you need to design your code in better way to make it template free, templates are old fasion of designs.

  • Bugs

    Posted by Legacy on 04/26/2002 07:00am

    Originally posted by: Grohotov Andrey

    The original code does not work with any colour of a background 
    and in function VertSkew one column is lost

    In functions HorizSkew and VertSkew
    To replace COLORREF pxlOldLeft = clrBack;
    on COLORREF pxlOldLeft = RGB (BYTE ( double (GetRValue (clrBack)) * dWeight ),
    BYTE ( double (GetGValue (clrBack)) * dWeight ),
    BYTE ( double (GetBValue (clrBack)) * dWeight ));
    To replace
    if (i < sDst.cx)
    // If still in image bounds, put leftovers there
    SetRGB (pDst, sDst, i, uRow, pxlOldLeft);
    if (i < sDst.cx)
    COLORREF pxlLeft = RGB (BYTE ( double (GetRValue (clrBack)) * dWeight ),
    BYTE ( double (GetGValue (clrBack)) * dWeight ),
    BYTE ( double (GetBValue (clrBack)) * dWeight ));
    COLORREF pxlDst = RGB ( GetRValue (clrBack) - ( GetRValue (pxlLeft) - GetRValue (pxlOldLeft) ),
    GetGValue (clrBack) - ( GetGValue (pxlLeft) - GetGValue (pxlOldLeft) ),
    GetBValue (clrBack) - ( GetBValue (pxlLeft) - GetBValue (pxlOldLeft) ));
    SetRGB (pDst, sDst, i, uRow, pxlDst);

    In functions VertSkew
    To replace
    // Go to bottom point of skew
    i = iYPos;
    // Go to bottom point of skew
    i = iYPos + 1;

  • Rotation at the centre of true colour image

    Posted by Legacy on 01/25/2002 08:00am

    Originally posted by: halim

    Could you give examples of rotating about another point in the true colour image (e.g. the center of the image while maintainig the original size of the input image)

  • PPM tool

    Posted by Legacy on 07/23/2001 07:00am

    Originally posted by: wrsun0413


  • How cam i use it in VB

    Posted by Legacy on 07/04/2001 07:00am

    Originally posted by: Kanhai Chhugani

    Hi I would like to use this in VB, can u provide any thing like that....

    such as a VB class file or a COM Dll file etc....


    Kanhai Chhugani

  • what is ppm?

    Posted by Legacy on 04/20/2001 07:00am

    Originally posted by: Oh Sun

    What is ppm? Is a graphic file format?
    Where can i get ppm file?

  • RotateByShear doesn't work with white background color

    Posted by Legacy on 07/22/1999 07:00am

    Originally posted by: Laurent MOTTAIS

    if you change your code by
    COLORREF *pDst = Rot.AllocAndRotate (
    the destination file is not correctly rotate !..

  • Where to find MSVCP60.DLL?

    Posted by Legacy on 05/05/1999 07:00am

    Originally posted by: lsteo

    MSVCP60.DLL not found! Where can I get it?

  • PPM?

    Posted by Legacy on 05/04/1999 07:00am

    Originally posted by: Bill Oatman

    Looks interesting, but how about adding a 'LoadBMP' function to CDIB so bitmaps can be loaded. I still haven't found a graphics package that will save in PPM format.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date