Click here to Skip to main content
Licence 
First Posted 9 Dec 2002
Views 91,230
Bookmarked 26 times

RLE (Run-Length-Encoding) compression routine in MFC for 256 color bitmap

By | 9 Dec 2002 | Article
A handy MFC class to compress simple 256 color Windows bitmap

Sample Image - RLEBmp.gif

Introduction

This is a RLE compression routine written in MFC. I wrote this because I could not find handy code for such thing.

RLE compression is useful when saving SIMPLE Windows bitmap. Especially my implementation is rather stupid and not optimized. Therefore, if the source bitmap is complex (like the one in the demo app window shown above), you could even get a bigger bitmap file after compression. :)

The compression routine is wrapped in an MFC bitmap control class, CDVDBitmapControl, which you can put in a dialog conveniently. The usage is easy:

  1. Add a static control (say IDC_STATIC_BITMAP) in the dialog for the bitmap control
  2. Add a #include "DVDBitmapControl.h" in the header file of your dialog
  3. Add a member variable (say m_bmp) of type CDVDBitmapControl in your dialog class.
  4. In OnInitDialog(), add this line: m_bmp.SubclassDlgItem( IDC_STATIC_BITMAP, this);
  5. Call m_bmp.LoadBitmapFile(CString) to load bitmap into control
  6. Call m_bmp.SaveBitmapFile(CString) to save bitmap into 8-bit RLE bitmap

If you need only the compression code, you can extract the CDVDBitmapControl::CompressInRLE8() and CDVDBitmapControl::EndOfLine() routines from DVDBitmapControl.cpp. It is quite straight forward to use them (with some substitutions for bitmap width, bitmap height in code).

I did not write the decompression part because Windows API LoadImage() already does it.

PS: in the demo app, if the loaded bitmap is not in 256 color, [Save] will not work.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Seth Chou



Taiwan Taiwan

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWorks when nothing else does PinmemberRikTheVeggie5:48 2 Nov '11  
Generali need a code source for rle Pinmemberivanny5:04 30 Nov '06  
GeneralRe: i need a code source for rle Pinmemberindrauday22:51 10 Apr '09  
GeneralHelp!!! PinmemberLerka8:56 14 Jan '04  
GeneralRe: Help!!! Pinmemberycl18:10 9 Mar '04  
GeneralAVI RLE compressors PinmemberJohn Ulvr11:32 6 Mar '03  
GeneralPack them in PNG instead PinsussKochise22:23 10 Dec '02  
GeneralA template-based version Pinmembercompiler9:28 10 Dec '02  
GeneralBe careful! PinsussAnonymous2:35 10 Dec '02  
GeneralRe: Be careful! PinmemberSeth Chou2:11 11 Dec '02  
GeneralRe: Be careful! PinsussKochise6:22 11 Dec '02  
GeneralRe: Be careful! PinsussKochise0:06 13 Dec '02  
Generala problem for every student Pinmembermarc1231:21 10 Dec '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 10 Dec 2002
Article Copyright 2002 by Seth Chou
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid