Bitmap rw library for scientific use

I work with my brother's professor on a university project.
We do cerebrovascular research, and our image-processing code is done mostly in Matlab (the rest is Mex/C).
All of our MRA data sets have one constant; the images are all grayscale 512x512 8bpp bitmaps.
I dislike Matlab for many reasons, but here's the major one: it's very slow.
So in the interest of speeding things up, I wrote a library in C++ that can read/write to these bitmaps.
The performance gain is amazing, even considering that the code has been highly optimized.
Most of the code is derived from Paul Macklin's ebmp library.
I've eliminated a lot (literally thousands of lines of) useless stuff - useless to me anyways, and re-written all of the functions to be noticeably faster. Enjoy .
// sample usage
#include "sbi_bmp.h" // iostream included in there
int main() {
BMP slice;
slice.read("sub76_001.bmp");
* BMP objects have these public members;
* - (short) slice.Pixels[][] : you can read/modify all of the pixels
* - (short) slice.histogram[] : 1-255
* bmpFileHeader data, slice.bmfh
* bmpInfoHeader data, slice.bmih
slice.write("final_001.bmp");
I find this library to be very hackable, so feel free to remove the histogram code or add your own manipulation functions.
* sbi_bmp.h
* -vk
* This file offers basic r/w capabilities for 8bit 512x512 Windows BMPs.
* Big-endian support has been removed, but it should work well on POSIX
* compliant operating systems, both 32 and 64 bit.
* The code is derived from Paul Macklin's ebmp library.
#include <iostream>
typedef unsigned char bmpByte;
typedef unsigned short bmpWord;
typedef unsigned int bmpDWord;
typedef unsigned long ulong;
typedef unsigned short ushort;
inline bool isBigEndian() {
short word = 0x0001;
return ((*(char*)& word) != 0x01);
inline bool typeChecks() {
return sizeof(bmpByte) == 1
&& sizeof(bmpWord) == 2
&& sizeof(bmpDWord) == 4
&& !isBigEndian();
bool errmsg(const char* msg) {
std::cout << "cvp_err:: " << msg << "\n";
return false;
class bmpFileHeader {
public:
bmpWord bfType;
bmpDWord bfSize;
bmpWord bfReserved1;
bmpWord bfReserved2;
bmpDWord bfOffBits;
bmpFileHeader() {
bfType = 19778;
bfReserved1 = 0;
bfReserved2 = 0;
class bmpInfoHeader {
public:
bmpDWord biSize;
bmpDWord biWidth;
bmpDWord biHeight;
bmpWord biPlanes;
bmpWord biBitCount;
bmpDWord biCompression;
bmpDWord biSizeImage;
bmpDWord biXPelsPerMeter;
bmpDWord biYPelsPerMeter;
bmpDWord biClrUsed;
bmpDWord biClrImportant;
bmpInfoHeader() {
biPlanes = 1;
biCompression = 0;
biXPelsPerMeter = 3780;
biYPelsPerMeter = 3780;
biClrUsed = 0;
biClrImportant = 0;
biWidth = 512;
biHeight = 512;
biBitCount = 8;
typedef struct {
bmpByte r, g, b, a;
} rgbaPix;
rgbaPix numToPix(ushort n) {
rgbaPix temp;
temp.r = n;
temp.g = n;
temp.b = n;
temp.a = 0;
return temp;
class BMP {
private:
bool canWrite;
inline bool fileRead(char* buf, ushort size, ushort number, FILE* fptr) {
if (feof(fptr)) {
return false;
return !(((ushort) fread(buf, size, number, fptr)) < number);
void r8bitRow(bmpByte* Buffer, ushort Row) {
for (ushort i=0; i < 512; ++i) {
Pixels[Row][i] = Buffer[i];
histogram[ Pixels[Row][i] ] += 1;
inline void w8bitRow(bmpByte* Buffer, ushort Row) {
for (ushort i=0; i < 512; ++i) {
Buffer[i] = Pixels[Row][i];
public:
ushort Pixels[512][512];
ulong histogram[256];
bmpFileHeader bmfh;
bmpInfoHeader bmih;
BMP() {
if (!typeChecks()) {
errmsg("typechecks failed. Unsupported platform.");
for (ushort q=0; q < 256; ++q) {
histogram[q] = 0;
canWrite = false;
~BMP() {
for (int q=0; q < 512; ++q) {
delete[] Pixels[q];
delete[] Pixels;
delete[] histogram;
void reset() {
ushort y = 0, q = 0;
for (; q < 256; ++q) {
histogram[q] = 0;
for (q=0; q < 512; ++q) {
for (; y < 512; ++y) {
Pixels[q][y] = 0;
canWrite = false;
void forcew() {
canWrite = true;
bool write(const char* filepath) {
FILE* fptr = fopen(filepath, "wb");
if (fptr == NULL || !canWrite) {
errmsg("Cannot write to file.");
fclose(fptr);
return false;
fwrite((char*) &(bmfh.bfType), 2, 1, fptr);
fwrite((char*) &(bmfh.bfSize), 4, 1, fptr);
fwrite((char*) &(bmfh.bfReserved1), 2, 1, fptr);
fwrite((char*) &(bmfh.bfReserved2), 2, 1, fptr);
fwrite((char*) &(bmfh.bfOffBits), 4, 1, fptr);
fwrite((char*) &(bmih.biSize), 4, 1, fptr);
fwrite((char*) &(bmih.biWidth), 4, 1, fptr);
fwrite((char*) &(bmih.biHeight), 4, 1, fptr);
fwrite((char*) &(bmih.biPlanes), 2, 1, fptr);
fwrite((char*) &(bmih.biBitCount), 2, 1, fptr);
fwrite((char*) &(bmih.biCompression), 4, 1, fptr);
fwrite((char*) &(bmih.biSizeImage), 4, 1, fptr);
fwrite((char*) &(bmih.biXPelsPerMeter), 4, 1, fptr);
fwrite((char*) &(bmih.biYPelsPerMeter), 4, 1, fptr);
fwrite((char*) &(bmih.biClrUsed), 4, 1, fptr);
fwrite((char*) &(bmih.biClrImportant), 4, 1, fptr);
rgbaPix temp;
for (ushort n=0; n < 256; ++n) {
temp = numToPix(n);
fwrite((char*) &temp, 4, 1, fptr);
int j = 0;
bmpByte* Buffer = new bmpByte[512];
j = 511;
while (j > -1) {
w8bitRow(Buffer, j);
int BytesWritten = (int) fwrite((char*) Buffer, 1, 512, fptr);
if (BytesWritten != 512) {
j = -1;
--j;
delete[] Buffer;
fclose(fptr);
return true;
bool read(const char* filepath) {
FILE* fptr = fopen(filepath, "rb");
if (fptr == NULL) {
return errmsg("Invalid filepath.");
bool safe = true;
safe &= fileRead((char*) &(bmfh.bfType), 2, 1, fptr);
safe &= fileRead((char*) &(bmfh.bfSize), 4, 1, fptr);
safe &= fileRead((char*) &(bmfh.bfReserved1), 2, 1, fptr);
safe &= fileRead((char*) &(bmfh.bfReserved2), 2, 1, fptr);
safe &= fileRead((char*) &(bmfh.bfOffBits), 4, 1 , fptr);
safe &= fileRead((char*) &(bmih.biSize), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biWidth), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biHeight), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biPlanes), 2, 1, fptr);
safe &= fileRead((char*) &(bmih.biBitCount), 2, 1, fptr);
safe &= fileRead((char*) &(bmih.biCompression), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biSizeImage), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biXPelsPerMeter), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biYPelsPerMeter), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biClrUsed), 4, 1, fptr);
safe &= fileRead((char*) &(bmih.biClrImportant), 4, 1, fptr);
if (!safe || bmih.biCompression >= 1 || bmih.biBitCount != 8) {
fclose(fptr);
return errmsg("Invalid bitmap. Cannot proceed with read operation.");
rgbaPix temp;
for (ushort n=0; n < 256; ++n) {
fileRead((char*) &temp, 4, 1, fptr);
bmpByte* Buffer = new bmpByte[512];
int j = 511;
while (j > -1) {
fread((char*) Buffer, 1, 512, fptr);
r8bitRow(Buffer, j);
--j;
delete[] Buffer;
fclose(fptr);
canWrite = true;
return true;
Last edited by vkumar (2008-12-31 01:07:58)

Hello tfmp,
there appears to be a Sun implementation of S3L contained in the package dowloadable at
http://www.sun.com/products/hpc/communitysource/technical.html
Obviously you have an account here, so you should be able to get it.
As to your questions:
1) it should be possible
2) Maybe you need the SUN Studio compilers, so Solaris is required (Linux of SunStudio is alpha, give it a try)
3) The release notes don't mention it. But you may not need it, since the s3l comes with SunMPI.
4) No.
I had to tweak the configure script to make it swallow the Sun cc/CC instead of the Forte as well as disable the check for gmake 3.78 (I have 3.80 here).
Hope this helps. I'm giving it a try on my humble PIII notebook under Solaris 10 with Sun Studio 11.
Cheers, Peter.

Similar Messages

  • ADOBE PROJECT ROME for scientific use?

    Dear developer,
    Dear ADOBE,
    the official website of ADOBE PROJECT ROME released the following status:
    November 30, 2010
    [...] The trial of Project ROME for Education has concluded. However, the commercial version of Project ROME will remain free to the public via Adobe Labs. No additional Project ROME software updates are planned at this time.
    source: http://rome.adobe.com/index.html (October 23, 2011)
    May I use the software ADOBE PROJECT ROME for scientific use? I am planning to create mathematical assistance content just like material which is used in real repetitional lessons. I would like to publish the material, which was created by the software via my homepage.
    I am looking forward to hear from you!
    Best regards
    SpWheel

    im not adobe, nor am i a developer which works for adobe...
    But it seems to me that the quote u made is also the answer to your question..
    The commercial version will remain free..
    commercial usually means u can use it either way, privately or commercially.
    Besides, why shouldnt u make use of it?
    This program is great, and i really do not understand why Adobe stopped support for it.

  • Use Graphic style library for commercial use

    Hi,
    I just need to clarify if those images/background from the adobe illustrator library can be used as it is(without editing at all) for commercial purpose e.g... in games/ poster/advertisement?
    Will there be copyright issues on the image or I have to do some editing to whats given by Ai before it can be used commercially?

    I just need to clarify if those images/background from the adobe illustrator library can be used as it is
    Yes.
    Mylenium

  • How to Search Lightroom Library for Photos Using Specific Camera Profiles?

    Photos processed using Lightroom 5.6 camera profiles for the Nikon D810 displayed posterized colors. A temporary workaround was published by Adobe, as described here:
    Nikon D810 camera profiles display posterized colors
    Lightroom 5.7 resolved the issue, but I still have a lot of photos that were processed with the "v2 beta" camera profiles provided by Adobe, and those profiles still remain on my computer. I'd like to find all the photos in my Library that were processed using a v2 beta camera profile, update them to the respective new 5.7 profiles, then remove the v2 beta profiles from my computer so they no longer show as options in the Lightroom Camera Calibration pane.
    How can I search my Library to find all the photos that used one of the beta Camera Profiles?
    Thanks.

    The Data Explorer, DevMeta, and Any Filter plugins can search for specific camera profiles.  (You can't do it with LR smart collections or filters.)

  • Can i generate more than 1 library for 2 ipods?

    I have a mini ipod and just bought a nano ipod for someone else. We are using the same computer. how can i generate another library for his use?

    Candice,
    Welcome to Apple Discussions.
    How to use multiple iPods with one computer.
    JJ
    Don't steal music !! Just a statement, not an accusation

  • HT2905 How to find and remove duplicate items in your iTunes library for iTunes 11

    I found instructions for iTunes 10, not the same as 11. New to iTunes - have LOTS of duplicates. There must be a way to delete them besides one at a time! Please help...

    If you don't see a menu bar press Ctrl+B to reveal it or Alt to show it temporarily. To check your library for duplicates use Shift > View > Show Exact Duplicates as this is normally a more useful selection. Keep holding down shift until you have clicked on the text Show Exact Duplicates or it may still use the loser definition.
    If you find that you have true duplicates you need to manually select all but one of each group to remove, or use my DeDuper script if you don't want to do it by hand. The script attempts to take account of different types of duplicates which need to be handled differently, merges playcounts and preserves playlist membership. Please take note of the warning to backup your library before deduping. See this thread for background.
    tt2

  • Licensing XML libraries for commercial use...

    After reading the license terms for the XML parser for 'C', I am confused. The license document embedded in the download package, says you need to contact Oracle to license the library for commercial use. However, the click-wrap license for the OTN says you can use the technologies in commercial products. These totally contradict each other. I called Oracle and asked the following question, and after talking with 3 people, nobody knew a difinitive answer.
    Here is the question: If I use the Oracle XML parser for 'C' library in the construction of a commercial application that I am selling, do I need purchase a license from Oracle to do this? If so, who do I contact?
    Thanks,
    - Ted
    null

    It doesn't matter to me as much that the two agreements are different. What I am most concerned with is that BOTH say that I cannot build commercial/for-sale products using the kit without paying for a license. Who do I contact to get a license to use?
    I called the number on the agreement and spoke to people who had no idea what I was talking about, nor who I could talk to.
    Also, since you asked, I have attached the two different sections from the two license agreements below.
    Thanks,
    - Ted
    [email protected]
    DEVELOPMENT ONLY LIMITED LICENSE: Oracle grants Customer a nonexclusive, nontransferable limited license to use the Programs for development purposes only in the indicated operating environment identified by Oracle for a single developer user (one person) on a single computer. Customer may not use the Programs for internal data processing operations or any other commercial or production use. If Customer desires to use the Programs for any use other than the development use allowed under this Agreement, Customer must contact Oracle, or an Oracle reseller, to obtain the appropriate licenses. Customer may make one copy of each licensed Program for backup. No other copies shall be made without Oracle's prior written consent. Customer shall not: (a) remove any product identification, copyright notices, or other notices or proprietary restrictions from Programs; (b) use Programs for commercial timesharing, rental, or service bureau use; (c) transfer, sell, assign or otherwise convey
    Programs to another party without Oracle's prior written consent; (d) cause or permit reverse engineering, disassembly, or decompilation of Programs, except to the extent required for interoperability or to the extent that the foregoing restriction is expressly prohibited by law; or (e) disclose results of any benchmark tests of any Program to any third party without Oracle's prior written approval. This Agreement does not authorize Customer to use any Oracle name, trademark or logo.
    ----->
    II. PROGRAM DISTRIBUTION RIGHTS: Oracle grants to Customer a nonexclusive, nontransferable right to copy and distribute the Programs to third party users ("User(s)") under the terms specified herein, provided that such distribution is free of charge. Prior to distributing the Programs for use by Users, Customer shall require Users to execute a written agreement binding Users to contractual provisions identical to those contained in Section I, III-XI inclusive, a provision specifying that Users shall have no right to distribute the Programs, and a provision specifying Oracle as a third party beneficiary of the User Agreement to the extent permitted by applicable law ("User Agreement"). Customer agrees that it is Customer's responsibility to obtain User Agreements

  • Distribute a static library for iOS. Which Apple agreement applies?

    There are many third party static libraries for iOS.  So distributing a static library (not via App Store) seems to be possible.
    Our company has developed a static library for iOS using xcode and wants to distribute it to our customers as part of a commercial product to help our customers to build iOS applications.
    Can you please advise which Apple agreement will allow to distribute a static library for iOS?

    Thanks much Michael,
    Do you suggest that the xcode license agreement will be sufficient? However, except the introductory note where it is mentioned that "This software may be used to reproduce, modify, publish and distribute materials", there is no other reference to distribution.
    On the other hand, xcode comes with iOS SDK and our static library of course uses it. But in the "iOS SDK Agreement" at the article 3.2 (d) it is stated that:
    "d) You will not distribute Applications created with the SDK absent a separate agreement with Apple;"
    So, which is this separate agreement? The Program License Agreement allows distribution only along App Store.

  • How do I use one library for multiple iPods

    I have three girls that recently got iPod nano's. I would like to use only one library for their music etc. How do I do this. when I installed the first one it worked great. Then when I installed the second one it won't recognize the first one. Then when I went back to factory settings on the first and synched her music the second one is not recognized. Help......

    Sorry, guess I am not using the "technical lingo". I already had itunes on my computer for a medical review course that I purchased to study for a certification exam. When nano #1 was purchased I hooked it up, registered it, and synched music to it. When my daughter tried to play songs, the songs titles and songs were mixed (song didn't match title). I hooked it up to the computer. It said it needed to be formatted. So I did and reregistered and synced the songs back on. Everything ok. Second nano hooked up, registered, named different name than #1, synched with the music she wanted. Tried to hook up #1 and it didn't recognize the nano. I went to the website and found out how to "find" it on the computer, followed the instructions to find it, and again it had to be "formatted" to have it recognized. I was again able to sync her music. Will I have to do this everytime I try to sync more music? that could be a real pain!
    thanks for any help for this sometimes electronically challenged mom.

  • How can I use my itunes library for iphoto slideshow?

    how can I use my itunes library for iphoto slideshow?

    Here's a possible workaround:
    Create the slideshow in Iphoto and add a theme and music.
    Install Picasa  and it will include the slideshow on it's indexed list.
    Upload the slideshow to PicasaWebAlbums and send the link to anyone you wish.
    The music and theme is preserved.
    Caveat: My playback pictures appear darker than usual but that could be just lousy photography...:)
    Example:https://picasaweb.google.com/mb2180/Kona2011?authuser=0&authkey=Gv1sRgCPGWz_qPrM XKZA&feat=directlink

  • Use 1 itunes library for multiple user accounts

    Is there a way to use 1 library for multi-user accounts on mac osx? I have 4 iphones and was previously using the main account only. I'm getting tired of having everyones contact lists downloaded into my main phone. I can't seem to figure out how to sync the music to the same library.

    Hi There,
    I sync 2 iphones with the same library, and to stop the other iphones contacts adding to mine I have two groups in the address book, one has my contacts in and the other my friends. I then just sync the appropriate address book in the info pane when the iphone is plugged in.
    Hope this helps.

  • Using single iTunes library for multiple computers

    With the new Airport Disk utility, can I attach an external hard drive with my iTunes library and have multiple computers point to that library as the library for each?

    BKRonline wrote:
    neptune2000 wrote:
    A BIG WARNING (...) If you are a good guy and use ONLY one computer to read/write (i.e., to copy music to it) and all the others are read only (which cannot be enforced in software), then you're OK. Consider yourself warned.
    just to clarify...
    Use ONE computer and ONE COMPUTER ONLY for purchasing / adding new content to the 'master' iTunes library area. Use ANY OTHER COMPUTER that's looking at that 'master' iTunes library for reading (playing back).
    Yes. If you can enforce it by "persuasion", not software
    Would there be a conflict if someone rates songs from other computers etc?
    Yes. If they both rate at the same time.

  • I have an iPad1 and just purchased an iPad Air, both on the same iTunes account. Is it possible to UNSYNC the two iPads. I would like to use the iPad1 as a library for my frequent guests: KINDLE, AUDIBLE,

    I have an iPad1 and just purchased an iPad Air, both of which are on the same iTunes account. Is it possible to UNSYNC the two iPads with the purpose of using the iPad1 as a "Bare-Bones" library for my frequent guests: The content of my KINDLE, AUDIBLE, &amp; ZINIO Accounts/Apps. How would I go about doing this, if it is at all possible?

    Is it possible to have an Iphone and an IPAD on the same Itunes account on a PC?
    yes.
    the number of mobile devices you can use with a single instance of iTunes is virtually unlimited.
    How to use multiple iPods with one computer

  • HT1660 how can I use one single library for all users on the same laptop?

    how can I use one single library for all users on the same laptop?

    You are most of the way there. Each user having access to hard drive is the key. If users are limited in file privileges this is harder.
    Any files you add to your library and any files she adds to her library are available to the other. Just not automatically. Each user must add the files to their own library using the add file or add folder option from menu bar.
    What I have done is set library location to a location outside of My Documents\My Music. On my network storage I have a folder names s:\itunes. Both accounts iTunes are set to use this location for the library.

  • I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    Yes

Maybe you are looking for

  • Steps in bursting Xml publisher report

    hey, can anyone give all the steps required to burst a xml report. like the output should go to different destinations like mail,fax etc. thanks RDM

  • ITunes changes Quicktime film name to ''my great movie'' on import to iTunes

    Quicktime film called ''Minnie is 1'' changes its name to ''my great movie'' when going to iTunes. Why is it doing this? And how do i make it keep the name i gave it? Even if i change the name in the info window, when closing the info window, the fil

  • Create Costumer & Account creation, enterprise Services

    Hi guys! I'm searching for Enterprises Services that resembles to the TX codes: FD01 (Cosutmer Creation) and F-36 (Account Creation). I want to use an existing enterprise service insted of developing an interface where I can Create a Costumer (tx FD0

  • Assigning Role while create a BP

    Hi , I am creating business partner using BAPI : BAPI_BUPA_CREATE_FROM_DATA I didnot find any parameter to assign role while creation. If this is not possible , can anyone please help me to assign role say 'CRM Consumer' to the BP Thanks in advance.

  • N95 8GB ( how can I change the language ? )

    I have a N95 8GB phone mobile , and it's cool !!! But I want to convert the language from English to Arabic How can I do that ???