5,695,118 members and growing! (15,120 online)
Email Password   helpLost your password?
Multimedia » General Graphics » General     Intermediate

SUN Raster File Decoder

By Amol Kakhandki

This article provides information on the decoder for Sun Raster files.
VC6, C++Windows, Win2K, MFC, VS6, Visual Studio, Dev

Posted: 10 Jul 2004
Updated: 10 Jul 2004
Views: 19,665
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
5 votes for this Article.
Popularity: 1.57 Rating: 2.25 out of 5
2 votes, 40.0%
1
0 votes, 0.0%
2
1 vote, 20.0%
3
1 vote, 20.0%
4
1 vote, 20.0%
5

Sample Image - RAS_Decoder.jpg

Introduction

This article provides information on the decoder for Sun Raster files. I had been using a free image library for quiet some time. A few days back, I wanted to support the Sun Raster file format (.ras). Since the library I am currently using doesn't support this format, I started looking for a decoder. I found that the FreeImage Imaging Library supports this format. So I used this library as a reference to write a standalone decoder.

The RAS File Format

The RAS format is described here.

The RAS Header

The RAS header is as follows:

struct RASHEADER {
DWORD magic;            // Magic number

DWORD width;            // Image width in pixels

DWORD height;           // Image height in pixels

DWORD depth;           // Depth (1, 8, 24 or 32 bits) of each pixel

DWORD length;          // Image length (in bytes)

DWORD type;            // Format of file

DWORD maptype;      // Type of colormap

DWORD maplength;   // Length of colormap (in bytes) 

} RASHEADER;

Note the following:

#define RAS_MAGIC 0x59A66A95 // Magic number for Sun rasterfiles

A check for the above number should be done after reading the header information to verify if it's a SUN Raster file.

The RAS decoder consists of a class CLibRAS having the following functions:

  • BMP * LoadRAS(FILE* handle);
  • unsigned GetWidth(BMP *dib);
  • BYTE *GetBits(BMP *dib);
  • unsigned GetHeight(BMP *dib);
  • BITMAPINFO *GetInfo(BMP *dib);
  • unsigned GetLine(BMP *dib);
  • unsigned GetBPP(BMP *dib);
  • unsigned GetColorsUsed(BMP *dib);
  • RGBQUAD * GetPalette(BMP *dib);
  • unsigned GetPitch(BMP *dib);

The LoadRAS function returns the image in a DIB format which can be used with the StretchDIBits function to draw the image on the device context.

A simple usage of the class would be as follows:

CLibRAS Decoder;
BMP *dib = Decoder.LoadRAS(fopen("C:\\lady256.ras","rb"));
  
  ::StretchDIBits(AfxGetMainWnd()->GetDC()->m_hDC,
                  10,                       // Destination x

                  10,                       // Destination y

                  Decoder.GetWidth(dib),    // Destination width

                  Decoder.GetHeight(dib),   // Destination height

                  0,                        // Source x

                  0,                        // Source y

                  Decoder.GetWidth(dib),    // Source width

                  Decoder.GetHeight(dib),   // Source height

                  Decoder.GetBits(dib),     // Pointer to bits

                  Decoder.GetInfo(dib),     // BITMAPINFO

                  DIB_RGB_COLORS,           // Options

                  SRCCOPY);                 // Raster operator code

Would appreciate if you post the results after usage.

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

Amol Kakhandki


Amol is currently working for a software company in India.His background is an engineering degree in Industrial Electronics.
He has been implementing projects in COM,DCOM,LDAP using VC++ ,MFC,ATL.
Email:amol_kakhandki@hotmail.com
Occupation: Web Developer
Location: India India

Other popular General Graphics articles:

  • A flexible charting library for .NET
    Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
  • CxImage
    CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
  • 3D Pie Chart
    A class library for drawing 3D pie charts.
  • Really cool visual FX
    A set of classes for doing stunning visual effects, including water, plasma and fire.
  • ImageStone
    An article on a library for image manipulation.
Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 10 Jul 2004
Editor: Smitha Vijayan
Copyright 2004 by Amol Kakhandki
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project