High quality image rotation (rotate by shear)

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


  • Jordan shoes mentioned Gene to go for the brand, a segment of Nike

    Posted by TaddyGaffic on 04/22/2013 02:35pm

    In focus groups conducted at 80 community-based organizations around the country, Motivational Educational Entertainment of Philadelphia [url=http://northernroofing.co.uk/roofins.cfm]nike free run 3[/url] identified disturbing trends among youths ages 16 to 20. The "Just Say No" message of abstinence-only campaigns has been lost on this group of young people, who grew up during an era when the hip-hop sensibility of getting cash and clothes did not incorporate values of conscientious sexual behavior or social responsibility. Rappers who mingle [url=http://markwarren.org.uk/goodbuy.cfm]nike free run uk[/url] with glamorous-looking half-naked women rarely mention contraception while they're listing the number of compromising sexual situations they've been in lately. There are number of good brands in the market like Adidas, Nike, Reebok, Asics, Brooks, Puma etc. Most of these brands have shoes tailored for professional and amateur tennis players. New advanced technologies have made these shoes more player-friendly. After that, I eventually like to try to get down to the 150-160 range. I not entirely sure if that a healthy number for a gal my height or not, and I haven looked into it. But, I know that when I was 180 I still didn feel that [url=http://markwarren.org.uk/goodbuy.cfm]nike free run uk[/url] fit, so I think an extra 20 or so will help with that.. Lotto sneakers selling price are generally liable along with using the form of sneakers you choose on. Your Lotto sneakers established fact because of their style along with good quality plus the create. That they create sneakers coming from all varieties much like the loafers,Puma II Shoes, new sandals, sneakers along with task tennis shoes or anything else

  • Most lazy coder

    Posted by Legacy on 09/23/2002 12: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 12: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 12: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 12:00am

    Originally posted by: wrsun0413


  • How cam i use it in VB

    Posted by Legacy on 07/04/2001 12: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 12: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 12: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 12:00am

    Originally posted by: lsteo

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

  • PPM?

    Posted by Legacy on 05/04/1999 12: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.

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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