Created
May 11, 2011 03:47
-
-
Save drakeguan/965888 to your computer and use it in GitHub Desktop.
bmpReader for Nuke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <freeimage.h> | |
#include "DDImage/DDWindows.h" | |
#include "DDImage/Reader.h" | |
#include "DDImage/Row.h" | |
#include "DDImage/Knob.h" | |
#include "DDImage/Knobs.h" | |
#include "DDImage/Thread.h" | |
#include "DDImage/Memory.h" | |
using namespace DD::Image; | |
class BmpReader : public Reader | |
{ | |
private: | |
unsigned int m_bpp; | |
unsigned int m_width; | |
unsigned int m_height; | |
FIBITMAP* m_bitmap; | |
FreeImageIO m_io; | |
public: | |
BmpReader(Read*); | |
~BmpReader(); | |
void engine(int y, int x, int r, ChannelMask, Row&); | |
static const Description d; | |
}; | |
BmpReader::BmpReader(Read* r) : Reader(r) | |
{ | |
FreeImage_Initialise(TRUE); | |
m_bpp = 0; | |
m_width = 0; | |
m_height = 0; | |
m_bitmap = FreeImage_Load(FIF_BMP, filename(), BMP_DEFAULT); | |
if( m_bitmap ) { | |
m_bpp = FreeImage_GetBPP(m_bitmap); | |
m_width = FreeImage_GetWidth(m_bitmap); | |
m_height = FreeImage_GetHeight(m_bitmap); | |
//printf("bpp: %d\n", m_bpp); | |
//printf("width: %d\n", m_width); | |
//printf("height: %d\n", m_height); | |
set_info(m_width, m_height, m_bpp/8); | |
} | |
else { | |
} | |
} | |
BmpReader::~BmpReader() | |
{ | |
if( m_bitmap ) { | |
FreeImage_Unload(m_bitmap); | |
m_bitmap = NULL; | |
} | |
FreeImage_DeInitialise(); | |
} | |
void BmpReader::engine(int y, int x, int r, ChannelMask channels, Row& row) | |
{ | |
BYTE* pixel = FreeImage_GetScanLine(m_bitmap, y); | |
// BGR !!!! | |
if( channels & Mask_Blue ) { | |
from_byte(Chan_Blue, row.writable(Chan_Blue)+x, pixel+0, NULL, r-x, m_bpp/8); | |
} | |
if( channels & Mask_Green ) { | |
from_byte(Chan_Green, row.writable(Chan_Green)+x, pixel+1, NULL, r-x, m_bpp/8); | |
} | |
if( channels & Mask_Red ) { | |
from_byte(Chan_Red, row.writable(Chan_Red)+x, pixel+2, NULL, r-x, m_bpp/8); | |
} | |
} | |
static Reader* build(Read* iop, int fd, const unsigned char* b, int n) | |
{ | |
close(fd); | |
return new BmpReader(iop); | |
} | |
static bool test(int fd, const unsigned char* block, int length) | |
{ | |
FreeImage_Initialise(TRUE); | |
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; | |
FIMEMORY* hmem = FreeImage_OpenMemory((BYTE *)block, length); | |
fif = FreeImage_GetFileTypeFromMemory(hmem); | |
FreeImage_DeInitialise(); | |
return(fif == FIF_BMP); | |
} | |
const Reader::Description BmpReader::d("bmp\0", build, test); | |
// vim: set hls is si et sw=4 sts=4 nu: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment