VOICE Home Page: http://www.os2voice.org
|By Armin Schwarz © January 2004|
Have you ever wanted to convert an image file from one format to another without having to search through the internet for OS/2 applications that support the desired formats? Have you ever wanted to do the conversion from within your own application without having to re-invent the wheel and actually write your own conversion routine? Have you ever wanted to display an image from your own REXX program but the GUI toolkit did not support that particular image format?
If the answer is yes to these questions, then this article may be of interest to you. Granted, this subject may be more geared towards developers, but if you know a little bit of REXX, you will be able to write your own script to do basic conversion and even image processing without breaking a sweat.
Recently I had the need to do image conversion for one of my projects. The simple task was to convert BMPs to JPGs or GIFs so they could be sent over the internet faster. A number of command line image converters are available that do the job, but there had to be a more elegant and compact way.
Looking through the OS/2 Dev Toolkit I found a sample image browser that would not only display images, but also allowed to convert them to a number of different formats. That's exactly what I needed. I looked through the code and multimedia documentation and eventually figured out how to do it from within my own program in no time at all. Well, ok, it took me a bit longer than that.
OS/2 has provisions to allow multimedia control through the much more understandable REXX language (REXXMCI), but only a select set of commands are supported and most of them deal with multimedia device control. Image conversion was unfortunately not one of them.
The lack of this feature demanded a solution and the result was a small REXX-callable DLL that contains routines to convert images, finds image formats supported and reports image size and resolution of a particular image. All these functions were already built into the multimedia subsystem included with every OS/2 or eCS installation and the DLL essentially only acts as an intermediary between the REXX calling code and the multimedia system.
Here is a simple REXX script to convert TEST.BMP to TEST.GIF. The source file (TEST.BMP) is assumed to be a 24-bit, unencoded BMP (OS/2 or Windows format).
/*TESTCVRT.CMD */ /*load RXMMIO.DLL */ CALL RXFuncAdd 'rxMIOLoadFuncs', 'RXMMIO', 'rxMIOLoadFuncs' CALL rxMIOLoadFuncs /* convert the BMP image to GIF, flags are for TIF and PCD formats */ rc = rxMIOConvert('TEST.BMP', 'TEST.GIF', 0, -1) /* Error handling */ IF rc = 0 THEN SAY "rxMIOConvert successful" ELSE SAY "Conversion error = " || rc /* drop the DLL */ CALL rxMIODROPFuncs EXIT
Not too complicated is it?
[Note: Since I submitted the article, I enhanced the DLL with "true" image format detection. Some developers mentioned to me that they encountered images that were renamed from GIF to PNG for example. The enhancement can now detect the true format by looking at the image header. This is all documented in the latest archive.]
1 TIF FAX Compressed
2 TIF Motorola Uncompressed
3 TIF Motorola Compressed
4 TIF Intel Uncompressed
5 TIF Intel Compressed
6 TGA Image Uncompressed
7 TGA Image Compressed
8 PCX Image Compressed
9 GIF Image Compressed
10 Baseline JPEG
11 IBM OS/2 2.0 BMP
12 IBM OS/2 1.3 PM Bitmap Image
13 MS Windows DIB Image
14 IBM MMotion Still Video Image
15 IBM AVC Still Video Image
16 RIFF DIB Image
17 Kodak PhotoCD
An OS/2 Warp 4 system will look identical. As you can see, basic image formats like BMP, TIF, GIF and JPG are included. This same function will also report formats installed for audio, digital video, movies and midi media files.
Unfortunately, the OS/2 multimedia image converters (IOProcs) have not been aggressively updated. There are just two updates available. An enhanced JPG IOProc is available that supports progressive JPGs. This support is available through Chris Wohlgemuth's CW-Classes (http://www.os2world.com/cdwriting/mmclasses/mmclassesold.htm). The JPEG support is based on the Generalized Bitmap Module (GBM). Unfortunately, the CW-Classes have been discontinued. For reasons see this link (http://www.os2world.com/cdwriting/mmclasses/mmclassesmain.htm)
A PNG IOProc is also available on Hobbes (http://hobbes.nmsu.edu/pub/os2/apps/graphics/viewer/mmiogpng.zip) that allows viewing only of PNGs. Saving as PNG (converting to PNG) is therefore not possible as the PNG encoder routine is not included in the IOProc. See below for links to these programs. RXMMIO.DLL is designed to work with these additional IOProcs and any new or updated converters.
The multimedia system has been designed as an open system to allow additional IOProcs to be added by third parties or existing ones can even be replaced. Anybody feel up to the challenge to write an IOProc for full PNG support? Sample code for IOProcs is available in the Dev Toolkit.
How well do these IOProcs perform? Doing some quick performance comparison between
image conversion routines (MM/2), Globalized Bitmap Module (GBMREF) and NConvert v3.16 yields the following data:
BMP to GIF -308% -292%
BMP to PCX +43% +20%
BMP to JPG *1* +59%
BMP to TGA +56% +65%
BMP to TIF +53% +43%
GIF to BMP 0% -50%
GIF to JPG *2* -5%
GIF to PCX -32% -79%
PCX to BMP 0% +36%
PCX* to JPG* +49% +52%
PCX to GIF -430% -3%
JPG* to BMP* -62% -3%
JPG* to PCX* +10% -13%
JPG to GIF *2* -318%
Notes: All images except the ones marked with an (*) are 8-bit (GBMREF does not support reading of 24-bit BMPs). All images marked (*) are 24-bit. The test were performed with CW-Classes-0.2.5 installed which provide updated JPG support for OS/2 through the GBM module.
This data has been normalized to the MM/2 conversion times. Positive percentages mean speed advantage goes to MM/2. Negative percentages give speed advantage to either GBM or NConvert over MM/2. BMP conversion to PCX, TGA or TIF are well supported by MM/2 and are fast. Conversion of any image to GIF using MM/2 is quite slow. There is a noticeable delay before the process is completed, even with small images. Unless you convert hundreds of images a day, you have to ask yourself if speed is really an issue here.
Please note: these conversion tests were done with calls from a REXX script and output was redirected to a file to minimize output to screen. The calls for GBMREF were in the form 'GBMREF test.bmp test.gif' and for NConvert it was in the form of 'NCONVERT -quiet -out gif -o test.gif test.bmp'. This represents a fairly even comparison between all three methods. The main idea here is to show how feasible it is to call these image conversion routines from a REXX script under real-world conditions. It is not solely intended to measure conversion time of each method. You can now decide on your own if any of these methods appeal for you.
Figure 1. Conversion Speed Advantage for MM/2
Figure 2. Conversion Speed Disadvantage for MM/2 (all values exceeding 80% have been cut-off at 100% for scaling reasons)
These multi-image BMP files may contain an unlimited number of images (limited only by available disk space), size may be different and may even contain different image subjects. The OS/2 multimedia contains routines to create and extract these images. Rxmmio.dll gives access to these routines and is able to create multi-image BMPs. Individual images can also be extracted. The Kodak PhotoCD (PCD) files are multi-image files as well and the OS/2 multimedia system is able to read this proprietary format. Rxmmio.dll can extract individual images from PCDs and save them in any MM/2 supported write format. Should you have any images on a Kodak PhotoCD you can now extract your desired resolution images with a simple REXX script and save them as bitmaps to do further processing.
Functions to trim, size and enlarge (zoom) images are included. Trimming simply removes a number of pixels given from the edges of the image. Individual values can be given for the top, bottom, left or right edges.
Sizing reduces the image to a desired value by removing rows and columns of pixels. This function can be used to create thumbnail images. The result of the division of original size and new size must be an integer for proper sizing to work. For example, a valid reduction is a 640x350 to 320x175 image. A reduction of the same image to 200x100 is not valid. This is obviously built-in by design to keep the algorithm simple but should still prove useful for a lot of applications. Height and width can be individually sized by entering appropriate values.
The zoom function multiplies each pixel by the factors 2, 3, or 4. Any enlarging of images past these values will result in a grainy image.
Functions to convert an image to grayscale, brighten and darken and creating negatives which simply inverts the colors are also included. For printing purposes these may be useful.
Video file support in OS/2 has essentially stayed unchanged since 1996. Basic AVI and MPG-1 video viewing exists, but the audio runs at accelerated speed giving MPG-1 movies a chipmunk sound. The Video In application that came as part of the bonus application handles video file conversions but support is limited to now outdated formats. Video In installation also installs the AVI File Utility which lets you retrieve movie file information and creates AVI files from still images. You can easily create animated movies or stitch together time laps photos and interleave them with audio files.
Conversion of sound and video files from within a REXX script much like rxmmio.dll does for image files is certainly possible. The structures are in place. It remains to be unlocked in the future, however.
Will this lack of support for certain image and video formats ever be filled? They are certainly not trivial projects to take on. We as OS/2 or eCS users can do a small part by encouraging developers who have taken on these challenges in the past. Give them positive feedback (always) and constructive criticism (if you have to). Only time will tell if someone will step in and fill the missing gaps.
With rxmmio.dll you can now easily manipulate any OS/2 multimedia supported images, convert them and even display them with REXX GUI application development systems like Dr. Dialog or similar. It is free of charge for personal use. If you develop freeware, you can include this DLL royalty-free as well. Full documentation and sample code is included. You can obtain the package either from Hobbes or from the VOICE website.
< Previous Page | Newsletter Index | Next Page >
VOICE Home Page: http://www.os2voice.org