12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739 |
- //-----------------------------------------------------------------------------
- // -------------------
- // File ....: bitmap.h
- // -------------------
- // Author...: Tom Hudson
- // Date ....: Sptember 1994
- //
- // History .: Sep, 01 1994 - Started serious coding
- // Oct, 18 1994 - First major revision for DLLs, restructuring
- // Jul, 10 1995 - Began working with it (Gus J Grubba)
- //
- //-----------------------------------------------------------------------------
-
- #ifndef BITMAP_H_DEFINED
- #define BITMAP_H_DEFINED
- #define NOAVIFILE
- #include <vfw.h>
- #undef NOAVIFILE
- #include "linklist.h"
- //-- Defines that may change with compiler
- #define INTBITS (sizeof(int) * 8)
- //-- Class ID's for various DLL's
- #define IMGCLASSID 1
- #define CYCLECLASSID 2
- #define FLICCLASSID 5
- #define TARGACLASSID 6
- #define YUVCLASSID 7
- #define FBCLASSID 8
- #define WSDCLASSID 9
- #define IFLCLASSID 10
- #define BMPCLASSID 11
- #define JPEGCLASSID 12
- #define TARGAPLSCLASSID 13
- #define AVICLASSID 14
- #define RLACLASSID 15
- //-- local definitions
- class BitmapManager;
- class BitmapStorage;
- class BitmapFilter;
- class BitmapDither;
- class BitmapInfo;
- class BitmapPicker;
- class BitmapIO;
- class Bitmap;
- //-- Temporary definitions to make the compiler happy
- class GraphicsWindow;
- class BMMInterface;
- class DllDir;
- //-- External data
- extern int TheSystemFrame; // TO DO: Move to App data structure?
- //-----------------------------------------------------------------------------
- //-- The Primary Bitmap Manager Object
- //
- extern BMMExport BitmapManager *TheManager; // TO DO: Move to App data structure?
- //-- Common Macros ------------------------------------------------------------
- //-- Just to make it shorter
- #define bVirtual BMMExport virtual
- //-- Set up a NULL macro
- #ifndef NULL
- #define NULL (0)
- #endif
- //-- Pixel storage classes ----------------------------------------------------
- typedef struct {
- BYTE r,g,b;
- } BMM_Color_24;
- typedef struct {
- BYTE r,g,b,a;
- } BMM_Color_32;
- typedef struct {
- WORD r,g,b;
- } BMM_Color_48;
- typedef struct {
- WORD r,g,b,a;
- } BMM_Color_64;
- //-- Generic bitmap information structure -------------------------------------
- typedef struct {
- int width,height;
- float aspect,gamma;
- DWORD flags;
- } BMMImageInfo;
- //-- Basic bitmap types supported by Bitmap Manager
- #define BMM_NO_TYPE 0 // Not allocated yet
- #define BMM_LINE_ART 1
- #define BMM_PALETTED 2
- #define BMM_GRAY_8 3
- #define BMM_GRAY_16 4
- #define BMM_TRUE_16 5
- #define BMM_TRUE_32 6
- #define BMM_TRUE_64 7
- //-- Information Only
- #define BMM_TRUE_24 8
- #define BMM_TRUE_48 9
- #define BMM_YUV_422 10
- #define BMM_BMP_4 11 //-- Windows BMP 16 color bitmap
- #define BMM_PAD_24 12 //-- Padded 24 bit (in a 32 bit register)
- //-- Textual Limits
- #define MAX_DESCRIPTION 256
- //-- The number of bitmap formats supported internally
- //#define BMM_FORMATS 6
- //-- File types
- //#define BMM_NOTYPE 0
- //#define BMM_TARGA 1 // System Targa I/O driver
- //#define BMM_GIF 2 // System GIF I.O driver
- //-- Gamma limits
- #define MINGAMMA 0.2f
- #define MAXGAMMA 5.0f
- //-- openMode values
- #define BMM_NOT_OPEN 0 // Not opened yet
- #define BMM_OPEN_R 1 // Read-only
- #define BMM_OPEN_W 2 // Write
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //-- Error Codes for BMMRES type functions
- typedef unsigned short BMMRES; // Traps the use of int or BOOL
- #define BMMRES_SUCCESS 0
- #define BMMRES_ERRORTAKENCARE 1 // Error - Function has already taken action
- #define BMMRES_FILENOTFOUND 2
- #define BMMRES_MEMORYERROR 3
- #define BMMRES_NODRIVER 4 // Device driver responsible for image not present
- #define BMMRES_IOERROR 5
- #define BMMRES_INVALIDFORMAT 6
- #define BMMRES_CORRUPTFILE 7
- #define BMMRES_SINGLEFRAME 8 // Goto request on a single frame image
- #define BMMRES_INVALIDUSAGE 9 // Bad argument passed to function (Developer Mistake)
- #define BMMRES_ERRORRETRY 10 // User selected "Retry" from error dialogue
- #define BMMRES_NUMBEREDFILENAMEERROR 11
- #define BMMRES_INTERNALERROR 12
- #define BMMRES_BADFILEHEADER 13
- #define BMMRES_CANTSTORAGE 14
- #define BMMRES_RETRY 15
- #define BMMRES_BADFRAME 16 // Invalid Frame Number Requested
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //-- BitmapIO usage types ( returned by BitmapIO::Capability() )
- #define BMMIO_NONE 0 // Not defined yet
- #define BMMIO_READER (1<<0) // Reads images
- #define BMMIO_WRITER (1<<1) // Writes images
- #define BMMIO_EXTENSION (1<<2) // Uses file extension (File Filter Type)
- #define BMMIO_MULTIFRAME (1<<3) // "File" contains multiple frames (i.e. FLC, AVI)
- #define BMMIO_THREADED (1<<4) // Thread aware plug-in
- #define BMMIO_RANDOM_ACCESS (1<<5) // Can read and/or write frames in any order
- #define BMMIO_NON_CONCURRENT_ACCESS (1<<6) // Cannot handle multiple, concurrent requests (FLC, AVI, VTR's, etc)
- #define BMMIO_OWN_VIEWER (1<<7) // Driver has its own image viewer for its image type.
- //-- Frame Buffers
- #define BMMIO_FRAMEBUFFER (1<<7) // Frame Buffer Driver
- #define BMMIO_GRABBER (1<<8) // Device Grabs Video
- //-- If the device is able to show its own image info dialogue this flag will be
- // set. Otherwise, the host must use BitmapManager::GetImageInfo() and display
- // a generic info dialogue.
- #define BMMIO_INFODLG (1<<9) // Has Info Dialog
- //-- Special IFL device
- #define BMMIO_IFL (1<<28)
- //-- There is only a single call to the plug-in's control panel but the call specifies
- // the nature of the operation going on. It's up to the plug-in to provide different
- // interfaces if needed. If one control serves two or more services, all the pertinent
- // flags should be set.
- #define BMMIO_CONTROLREAD (1<<29) // Device Driver has Control Panel for Read Operations
- #define BMMIO_CONTROLWRITE (1<<30) // Device Driver has Control Panel for Write Operations
- #define BMMIO_CONTROLGENERIC (1<<31) // Device Driver has a generic Control Panel
- //-----------------------------------------------------------------------------
- //-- Bitmap close options
- #define BMM_CLOSE_COMPLETE 0
- #define BMM_CLOSE_ABANDON 1
- //-- Filter Types
- #define BMM_FILTER_NONE 0
- #define BMM_FILTER_DUMMY 1
- #define BMM_FILTER_SUM 2
- #define BMM_FILTER_PYRAMID 3
- //-- Filter Flag values
- #define BMM_FILTER_NOFLAGS ((DWORD)0)
- #define BMM_FILTER_LERP_WRAP ((DWORD)(1<<0))
- //-- Dither Types
- #define BMM_DITHER_NONE 0
- #define BMM_DITHER_FLOYD 1
- //-- Pyramidal filter information
- #define MAX_PYRAMID_DEPTH 12
- #define LAYER_DIM MAX_PYRAMID_DEPTH+1
- typedef struct {
- WORD dmax;
- void *map[LAYER_DIM];
- void *alpha[LAYER_DIM];
- } BMM_Pyramid;
- //-- Summed-area table information
- typedef struct {
- DWORD *sat_r,*sat_g,*sat_b,*sat_a;
- } BMM_SAT;
- //-- Bitmap::CopyImage options
- #define COPY_IMAGE_CROP 0 // Copy image to current map size w/cropping if necessary
- #define COPY_IMAGE_RESIZE_LO_QUALITY 1 // Resize source image to destination map size (draft)
- #define COPY_IMAGE_RESIZE_HI_QUALITY 2 // Resize source image to destination map size (final)
- #define COPY_IMAGE_USE_CUSTOM 3 // Based on Image Input Options (BitmapInfo *)
- // Class for storing a linked list of file extension strings
- MakeLinkedList(TSTR);
- //-----------------------------------------------------------------------------
- //-- GBuffer defines
- //
- // Recognized types of channels
- #define BMM_CHAN_TYPE_UNKNOWN 0
- #define BMM_CHAN_TYPE_1 1 // 1 bit per pixel
- #define BMM_CHAN_TYPE_8 2 // 1 byte per pixel
- #define BMM_CHAN_TYPE_16 3 // 1 word per pixel
- #define BMM_CHAN_TYPE_32 4 // 2 words per pixel
- #define BMM_CHAN_TYPE_48 5 // 3 words per pixel
- #define BMM_CHAN_TYPE_64 6 // 4 words per pixel
- // Recognized channel ID's (number of bits in parentheses in comments)
- #define BMM_CHAN_NONE 0
- #define BMM_CHAN_Z (1<<0) // (32) Z-buffer depth, float
- #define BMM_CHAN_MTL_ID (1<<1) // ( 8) ID assigned to mtl via mtl editor
- #define BMM_CHAN_NODE_ID (1<<2) // (16) ID assigned to node via properties
- #define BMM_CHAN_UV (1<<3) // (64) UV coordinates - Point2
- #define BMM_CHAN_NORMAL (1<<4) // (32) Normal vector in view space, compressed
- #define BMM_CHAN_REALPIX (1<<5) // (32) Non clamped colors in "RealPixel" format
- //-----------------------------------------------------------------------------
- //-- I/O Handler
- //
-
- class BMM_IOHandler {
- //-- Name and Capabilities ------------------------
-
- TCHAR ioShortDesc[MAX_DESCRIPTION];
- TCHAR ioLongDesc[MAX_DESCRIPTION];
- DWORD ioCapabilities;
- //-- Extension for file types
-
- TSTRList ioExtension;
-
- //-- DLL Handler ----------------------------------
-
- ClassDesc *cd;
-
- public:
- BMMExport BMM_IOHandler();
-
- BMMExport TCHAR *ShortDescription ( const TCHAR *d = NULL );
- BMMExport TCHAR *LongDescription ( const TCHAR *d = NULL );
- BMMExport TCHAR *Extension ( int index, const TCHAR *e = NULL );
- BMMExport int NumExtensions ( ) { return ioExtension.Count(); }
- BMMExport void SetCD ( ClassDesc *dll ) { cd = dll;};
- BMMExport ClassDesc *GetCD ( ) { return cd;};
- BMMExport void SetCapabilities ( DWORD cap ) { ioCapabilities |= cap;};
- BMMExport DWORD GetCapabilities ( ) { return (ioCapabilities);};
- BMMExport BOOL TestCapabilities ( DWORD cap ) { return (ioCapabilities & cap);};
- BMMExport BMM_IOHandler& operator=(BMM_IOHandler &from);
- };
- //-----------------------------------------------------------------------------
- //-- List of I/O Handlers
- //
- // Class for storing a linked list of Bitmap Manager BMM_IOHandler objects
- MakeLinkedList(BMM_IOHandler);
-
- class BMM_IOList: public BMM_IOHandlerList {
- BOOL listed;
-
- public:
- BMM_IOList ( ) { listed = FALSE; }
- BOOL Listed ( BOOL f) { listed = f; return (listed);};
- BOOL Listed ( ) { return (listed);};
- BMMExport int FindDevice ( const TCHAR *name);
- BMMExport int FindDeviceFromFilename ( const TCHAR *name);
- BMMExport int ResolveDevice ( BitmapInfo *bi );
- BMMExport DWORD GetDeviceCapabilities ( const TCHAR *name);
- //-- This Creates an Instance - Make sure to "delete" it after use.
- BMMExport BitmapIO *CreateDevInstance( const TCHAR *d );
- BMMExport BitmapIO *CreateDevInstance( int idx );
- };
- //-----------------------------------------------------------------------------
- //-- RenderInfo Class
- //
- enum ProjectionType { ProjPerspective=0, ProjParallel=1 };
- class RenderInfo {
- public:
- RenderInfo();
- ProjectionType projType;
- float kx,ky; // 3D to 2D projection scale factor
- float xc,yc; // screen origin
- BOOL fieldRender; // field rendered?
- BOOL fieldOdd; // if true, the first field is Odd lines
- // Render time and tranformations for the 2 fields, if field rendering.
- // If not, use renderTime[0], etc.
- TimeValue renderTime[2];
- Matrix3 worldToCam[2];
- Matrix3 camToWorld[2];
- BMMExport Point2 MapWorldToScreen(Point3 p, int field=0) { return MapCamToScreen(worldToCam[field]*p);}
- BMMExport Point2 MapCamToScreen(Point3 p); // map point in camera space to screen
- BMMExport Ray MapScreenToCamRay(Point2 p); // get viewing ray through screen point, in camera space
- BMMExport Ray MapScreenToWorldRay(Point2 p, int field=0); // get viewing ray through screen point, in world space
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap Info Class
- //
- //-- Bitmap flags
- #define MAP_NOFLAGS ((DWORD)0)
- #define MAP_READY ((DWORD)(1<<0))
- #define MAP_HAS_ALPHA ((DWORD)(1<<1))
- #define MAP_ALPHA_PREMULTIPLIED ((DWORD)(1<<2))
- #define MAP_PALETTED ((DWORD)(1<<3))
- #define MAP_FRAME_SYSTEM_LOCKED ((DWORD)(1<<4))
- #define MAP_DITHERED ((DWORD)(1<<5))
- #define MAP_FLIPPED ((DWORD)(1<<6)) // Flipped horizontally
- #define MAP_INVERTED ((DWORD)(1<<7)) // Flipped vertically
- //#define MAP_CUSTOMSIZE ((DWORD)(1<<8)) // Custom size for input
- //#define MAP_RESIZE ((DWORD)(1<<9)) // Resize when input
- #define MAP_VIEW_FILTERED ((DWORD)(1<<31)) // Test stuff
- #define MAP_ALL_FLAGS 0xFFFFFFFF
- //-----------------------------------------------------------------------------
- //-- Messages sent back by various (client) methods
- //-- Sent by the plug-in to notify host of current progress. The host should
- // return TRUE if it's ok to continue or FALSE to abort process.
- #define BMM_PROGRESS WM_USER + 0x120 //-- wParam: Current lParam: Total
- //-- Sent by the plug-in to check for process interruption. The host should
- // return FALSE (by setting lParam) if it's ok to continue or TRUE to abort
- // process.
- #define BMM_CHECKABORT WM_USER + 0x121 //-- wParam: 0 lParam: *BOOL
- //-- Sent by the plug-in to display an optional textual message (for progress
- // report).
- #define BMM_TEXTMSG WM_USER + 0x122 //-- wParam: 0 lParam: LPCTSTR
- class BitmapInfo {
-
- //-- Image name in case of named images such as files -------
- TCHAR name[MAX_PATH];
- //-- Device name gotten from BMM_IOHandler::LongDescription()
- TCHAR device[MAX_DESCRIPTION];
-
- //-- Window Handle to send BMM_UPDATE messages --------------
-
- HWND hWnd;
- //-- Plug-In Parameter Block --------------------------------
-
- void *pidata;
- DWORD pisize;
- //-- Basic Image Data ---------------------------------------
- //
- // When reading an image, or asking for image info, these
- // fields will tell the user what the image is like.
- //
- // When creating an image the user will set these fields to
- // the desired parameters.
- //
- WORD width,height;
- float aspect,gamma;
- int fstart,fend;
- DWORD flags,type;
- //-- User data (what user wants) ----------------------------
- //
- // Custom dimmensions, custom start and end point when
- // reading sequence of imges, frame to fetch/save, etc.
- //
- WORD cwidth,cheight;
- int custxpos,custypos;
- int start,end;
- int step,preset_al;
- float custgamma;
- #define BMM_CUSTOM_GAMMA ((DWORD)(1 << 0))
- #define BMM_CUSTOM_SIZE ((DWORD)(1 << 1))
- #define BMM_CUSTOM_RESFIT ((DWORD)(1 << 2))
- #define BMM_CUSTOM_POS ((DWORD)(1 << 3))
- #define BMM_CUSTOM_FILEGAMMA ((DWORD)(1 << 4))
- #define BMM_CUSTOM_POSNW 0
- #define BMM_CUSTOM_POSN 1
- #define BMM_CUSTOM_POSNE 2
- #define BMM_CUSTOM_POSW 3
- #define BMM_CUSTOM_POSCN 4
- #define BMM_CUSTOM_POSE 5
- #define BMM_CUSTOM_POSSW 6
- #define BMM_CUSTOM_POSS 7
- #define BMM_CUSTOM_POSSE 8
- DWORD customflags;
-
- int fnumber; //-- Defines frame to
- // read or write.
- //-- When reading a sequence of frames, loopflag indicates what to
- // do when reading beyond the end of available frames. It
- // defaults to BMM_SEQ_WRAP.
- #define BMM_SEQ_WRAP 0 //-- Wraps around back to start point
- #define BMM_SEQ_ERROR 1 //-- Generates an error
- #define BMM_SEQ_HOLD 2 //-- Holds last frame when done
-
- WORD loopflag;
- void doConstruct ( );
-
- public:
- BMMExport BitmapInfo ( );
- BMMExport BitmapInfo ( TCHAR *n );
- BMMExport ~BitmapInfo ( );
- //-- Bitmap Flags
-
- BMMExport DWORD Flags ( ) { return (flags); }
- BMMExport DWORD SetFlags ( DWORD f ) { flags |= f; return (flags); }
- BMMExport DWORD ResetFlags ( DWORD f ) { flags &= ~f; return (flags); }
- BMMExport BOOL TestFlags ( DWORD f ) { return (flags & f); }
- //-- Generic Read
- BMMExport WORD Width ( ) { return (width); }
- BMMExport WORD Height ( ) { return (height); }
- BMMExport float Gamma ( ) { return (gamma); }
- BMMExport float Aspect ( ) { return (aspect);}
- BMMExport int Type ( ) { return (type); }
- BMMExport int FirstFrame ( ) { return (fstart); }
- BMMExport int LastFrame ( ) { return (fend); }
- BMMExport int NumberFrames ( ) { return (fend - fstart + 1); }
- BMMExport int CurrentFrame ( ) { return (fnumber); }
- BMMExport WORD SequenceOutBound ( ) { return (loopflag); }
- //-- "Name" returns full path of image file
- BMMExport const TCHAR *Name ( ) { return (const TCHAR *)name; }
- //-- "Filename" returns just the name of image file
- BMMExport const TCHAR *Filename ( );
-
- //-- "Device" is the device reponsible for producing this image.
- // For file types, this is just informative. For non file types
- // this is the way this image is identified. Therefore, it is
- // important to save both name and device in order to properly
- // identify an image.
-
- BMMExport const TCHAR *Device ( ) { return (const TCHAR *)device; }
- //-- Compare Two Bitmaps
- BMMExport BOOL CompareName ( BitmapInfo *bi );
- //-- Copy Image info. Only name, device and image characteristics are
- // copied. User info, such as Custom Width, etc. is not copied.
- BMMExport void CopyImageInfo ( BitmapInfo *from );
- //-- Generic Write
- BMMExport int SetFirstFrame ( int m ) { int o = fstart; fstart = m; return (o);}
- BMMExport int SetLastFrame ( int s ) { int o = fend; fend = s; return (o);}
- BMMExport int SetCurrentFrame ( int v ) { int o = fnumber; fnumber = v; return (o);}
- BMMExport WORD SetSequenceOutBound ( WORD c ) { WORD o = loopflag; loopflag = c; return (o);}
- BMMExport WORD SetWidth ( WORD s ) { WORD o = width; width = s; return (o);}
- BMMExport WORD SetHeight ( WORD u ) { WORD o = height; height = u; return (o);}
- BMMExport float SetGamma ( float c ) { float o = gamma; gamma = c; return (o);}
- BMMExport float SetAspect ( float k ) { float o = aspect; aspect = k; return (o);}
- BMMExport int SetType ( int s ) { int o = type; type = s; return (o);}
- BMMExport const TCHAR *SetName ( const TCHAR *n );
- BMMExport const TCHAR *SetDevice ( const TCHAR *d );
- //-- Custom Input Processing
- BMMExport WORD CustWidth ( ) { return (cwidth); }
- BMMExport WORD CustHeight ( ) { return (cheight); }
- BMMExport void SetCustWidth ( WORD w ) { cwidth = w; }
- BMMExport void SetCustHeight ( WORD h ) { cheight = h; }
- BMMExport int StartFrame ( ) { return (start); }
- BMMExport int EndFrame ( ) { return (end); }
- BMMExport void SetStartFrame ( int s ) { start = s; }
- BMMExport void SetEndFrame ( int e ) { end = e; }
- BMMExport void SetCustomX ( int x ) { custxpos = x; }
- BMMExport void SetCustomY ( int y ) { custypos = y; }
- BMMExport int GetCustomX ( ) { return custxpos; }
- BMMExport int GetCustomY ( ) { return custypos; }
- BMMExport void SetCustomGamma ( float g ) { custgamma = g; }
- BMMExport float GetCustomGamma ( ) { return custgamma; }
- BMMExport void SetCustomStep ( int s ) { step = s; }
- BMMExport int GetCustomStep ( ) { return step; }
- BMMExport void SetPresetAlignment ( int p ) { preset_al = p; }
- BMMExport int GetPresetAlignment ( ) { return preset_al; }
- //-- Custom Input Flags
-
- BMMExport DWORD GetCustomFlags ( ) { return (customflags); }
- BMMExport void SetCustomFlag ( DWORD f ) { customflags |= f; }
- BMMExport void ResetCustomFlag ( DWORD f ) { customflags &= ~f; }
- BMMExport BOOL TestCustomFlags ( DWORD f ) { return (customflags & f); }
- //-- Plug-In Parameter Block
-
- BMMExport void *GetPiData ( ) { return pidata; }
- BMMExport void SetPiData ( void *ptr ) { pidata = ptr; }
- BMMExport DWORD GetPiDataSize ( ) { return pisize; }
- BMMExport void SetPiDataSize ( DWORD s ) { pisize = s; }
- BMMExport void ResetPiData ( );
- BMMExport BOOL AllocPiData ( DWORD size );
- BMMExport void Copy ( BitmapInfo *from ); //\\-- OBSOLETE --\\//
- BMMExport BitmapInfo &operator= ( BitmapInfo &from );
-
- //-- Load/Save
-
- BMMExport IOResult Save ( ISave *isave );
- BMMExport IOResult Load ( ILoad *iload );
- BMMExport void EnumAuxFiles ( NameEnumCallback& nameEnum, DWORD flags);
-
- //-- Miscelaneous
-
- BMMExport BOOL Validate ( );
- BMMExport HWND GetUpdateWindow ( ) { return hWnd; }
- BMMExport void SetUpdateWindow ( HWND hwnd ) { hWnd = hwnd; }
- BMMExport DWORD GetGChannels ( );
- BMMExport DWORD GetDeviceFlags ( );
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap I/O Class
- //
- // None of these methods are to be used directly. Use the BitmapManager for
- // any image I/O.
- //
- class BitmapIO {
- private:
- UWORD* outputGammaTab; // this may be owned by gammaMgr
- UWORD* privGammaTab; // private gamma table owned by the BitmapIO.
-
- protected:
- float gamma;
- Bitmap *map; // The bitmap using this OUTPUT handler
- BitmapStorage *storage; // The storage used by this INPUT handler
- int openMode; // See above
-
- //-- Linked list pointers for multiple output of a single bitmap
- BitmapIO *prevIO;
- BitmapIO *nextIO;
- public:
- // Used by the subclassed BitmapIO's to get pixels for output with
- // the appropriate output gamma correction.
- BMMExport int GetOutputPixels ( int x,int y,int pixels,BMM_Color_64 *ptr);
-
- // Used by the subclassed BitmapIO's to get 32 bit pixels for output with
- // the appropriate output gamma correction and dither.
- BMMExport int GetDitheredOutputPixels ( int x,int y,int pixels,BMM_Color_32 *ptr);
- // Used by the subclassed BitmapIO's to get a DIB for output with
- // the appropriate output gamma correction.
- BMMExport PBITMAPINFO GetOutputDib ( int depth = 24 );
- // Used by the subclassed BitmapIO's to get a DIB for output with
- // the appropriate output gamma correction and dither
- BMMExport PBITMAPINFO GetDitheredOutputDib ( int depth = 24 );
- BMMExport float OutputGamma();
- // If a BitmapIO wants to do its own dithering, it should call
- // these to find out if dithering is wanted. If it is a 24 bit or
- // 32 bit format, it would usually just call GetDitheredOutputPixels instead.
- BMMExport BOOL DitherTrueColor();
- BMMExport BOOL DitherPaletted();
- // Calculate a color palette for output color packing: gamma corrects
- BMMExport int CalcOutputPalette(int palsize, BMM_Color_48 *pal);
-
- BMMExport BitmapIO ( );
- bVirtual ~BitmapIO ( );
-
- BitmapInfo bi;
-
- inline int OpenMode ( ) { return (openMode); }
- inline void SetPrev ( BitmapIO *prev) { prevIO = prev; };
- inline void SetNext ( BitmapIO *next) { nextIO = next; };
- inline BitmapIO *Prev ( ) { return prevIO; };
- inline BitmapIO *Next ( ) { return nextIO; };
-
- BMMExport BitmapStorage *Storage ( );
- inline Bitmap *Map ( ) { return map; };
- bVirtual int ExtCount ( ) = 0; // Number of extemsions supported
- bVirtual const TCHAR *Ext ( int n ) = 0; // Extension #n (i.e. "3DS")
- bVirtual const TCHAR *LongDesc ( ) = 0; // Long ASCII description (i.e. "Targa 2.0 Image File")
- bVirtual const TCHAR *ShortDesc ( ) = 0; // Short ASCII description (i.e. "Targa")
- bVirtual const TCHAR *AuthorName ( ) = 0; // ASCII Author name
- bVirtual const TCHAR *CopyrightMessage ( ) = 0; // ASCII Copyright message
- bVirtual UINT Version ( ) = 0; // Version number * 100 (i.e. v3.01 = 301)
-
- bVirtual int Capability ( ) = 0; // Returns IO module ability flags (see above)
- bVirtual void ShowAbout ( HWND hWnd ) = 0; // Show DLL's "About..." box
- //-- If the BMMIO_OWN_VIEWER flag is set, this method will be called
- // whenever the user wants to view an image for this device. This
- // is for devices which can "play" image sequences such as AVI's, FLIC's, etc.
- //-- TH 2/26/96 -- Added BOOL return to indicate if view worked. If it didn't,
- // it returns FALSE and the caller can view by the normal mechanism.
- bVirtual BOOL ShowImage ( HWND hWnd, BitmapInfo *bi ) { return FALSE; }
- //-- Show DLL's Control Panel
- //
- // If the user exists through an Ok, this function will return TRUE.
- // If the user cancels out, it will return FALSE. False indicates
- // nothing has changed so the system won't bother asking the plug-in
- // if it wants to save data.
- //
- // This function is only called if the plug-in has defined it supports
- // it (through the Capability flag above). The flag will indicate to
- // the plug-in what operation is this control for (read, write, or
- // generic).
- //
-
- bVirtual BOOL ShowControl ( HWND hWnd, DWORD flag ) { return FALSE; }
-
- //-- Parameter Block Load and Save ------------------------------------
- //
- // The host will call EvaluateConfigure() to determine the buffer size
- // required by the plug-in.
- //
- // SaveConfigure() will be called so the plug-in can transfer its
- // parameter block to the host ( ptr is a pre-allocated buffer).
- //
- // LoadConfigure() will be called so the plug-in can load its
- // parameter block back.
- //
- // Memory management is performed by the host using standard
- // LocalAlloc() and LocalFree().
- //
-
- bVirtual DWORD EvaluateConfigure ( ) = 0;
- bVirtual BOOL LoadConfigure ( void *ptr ) = 0;
- bVirtual BOOL SaveConfigure ( void *ptr ) = 0;
- //-- Used internaly to make sure current block belongs to Plug-In
-
- bVirtual BOOL ValidatePiData ( BitmapInfo *bi );
- //-- System Interface
-
- BMMExport BOOL SilentMode ( );
- //-- Calculate Desired Frame
- //
- // This is for multiframe sequences. It processes the desired frame
- // based on user options. It is used at the Load() function to find
- // out which frame to load.
- //
- // "fbi" is the one passed to Load()
- // "frame" is a pointer to an integer to receive the frame number
-
- BMMExport BMMRES GetFrame ( BitmapInfo *fbi, int *frame);
-
- //-- Critical Error Handling
-
- BMMExport BMMRES ProcessImageIOError ( BitmapInfo *bi, TCHAR *string = NULL);
- BMMExport BMMRES ProcessImageIOError ( BitmapInfo *bi, int errorcode);
-
- //---------------------------------------------------------------------
- //-- Channels Required (for Output)
- //
- // By setting this flag, the plug-in can request the host to generate
- // the given channels. Prior to Rendering, the host will scan the
- // plug-ins in the chain of events and list all types of channels
- // being requested. The plug-in, at the time of the Write() call, will
- // have access to these channels through the channel interface
- // described below in BitmapStorage().
- //
- // The generation of these channels should not, normally, be a
- // default setting for a plug-in. These channels are memory hungry and
- // if the plug-in won't use it, it should not ask for it. Normally
- // the plug-in would ask the user which channels to save and set only
- // the proper flags.
- //
-
- bVirtual DWORD ChannelsRequired ( ) { return BMM_CHAN_NONE; }
-
- //-- Image Info
-
- bVirtual BMMRES GetImageInfoDlg ( HWND hWnd, BitmapInfo *bi, const TCHAR *filename = NULL ) {return BMMRES_NODRIVER;}
- bVirtual BMMRES GetImageInfo ( BitmapInfo *bi ) = 0;
-
- //-- Image File Loaders (IFL handlers)
-
- bVirtual BMMRES GetImageName ( BitmapInfo *bi, TCHAR *filename) {filename[0]=0; return (BMMRES_SUCCESS);}
- //-- Image I/O (Not to use directly)
-
- bVirtual BitmapStorage *Load ( BitmapInfo *bi, Bitmap *map, BMMRES *status ) = 0;
- bVirtual BMMRES OpenOutput ( BitmapInfo *bi, Bitmap *map );
- bVirtual BMMRES Write ( int frame );
- bVirtual int Close ( int flag );
- bVirtual PAVIFILE GetPaviFile ( ) { return NULL; }
- // used internally to build output gamma table
- BMMExport void InitOutputGammaTable(BitmapInfo*bi);
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap Storage Class
- //
- // None of these methods are to be used directly. Use the Bitmap class for
- // any image read/write.
- //
- //-- Channel Operations (for Get/Put16Channel)
- #define BMM_CHANNEL_RED 0 //-- Get/Put only Red
- #define BMM_CHANNEL_GREEN 1 //-- Get/Put only Green
- #define BMM_CHANNEL_BLUE 3 //-- Get/Put only Blue
- #define BMM_CHANNEL_ALPHA 4 //-- Get/Put only Alpha
- #define BMM_CHANNEL_Z 5 //-- Get/Put only Z
- #define BMM_CHANNEL_LUMINANCE 6 //-- Get (R+G+B)/3
- class BitmapStorage {
-
- protected:
-
- int openMode; // See above
- UINT usageCount; // Number of Bitmaps using this storage
- BitmapManager *manager;
- int flags;
- int type; // See "Basic bitmap types", below
- BMM_Color_48 palette[256]; // 256 palette entries max
- int paletteSlots;
- UWORD *gammaTable; // Gamma correction table
-
- RenderInfo *rendInfo;
- public:
- BMMExport BitmapStorage ( );
- bVirtual ~BitmapStorage ( );
- BitmapInfo bi;
- // gamma
- BMMExport float SetGamma(float gam);
- inline int HasGamma ( ) { return (gammaTable!=NULL) ? 1:0; };
- BMMExport void SetHasGamma(BOOL onOff);
- void UpdateGammaTable();
- BMMExport UWORD *GetInputGammaTable();
- inline BitmapManager *Manager ( ) { return manager; }
- inline int OpenMode ( ) { return openMode; }
- inline int Width ( ) { return bi.Width(); }
- inline int Height ( ) { return bi.Height(); }
- inline float Aspect ( ) { return bi.Aspect(); }
- inline float Gamma ( ) { return bi.Gamma(); }
-
- inline int Paletted ( ) { return (flags & MAP_PALETTED) ? paletteSlots:0; }
- inline int IsDithered ( ) { return (flags & MAP_DITHERED) ? 1:0; };
- inline int PreMultipliedAlpha ( ) { return (flags & MAP_ALPHA_PREMULTIPLIED) ? 1:0; };
- inline int HasAlpha ( ) { return (flags & MAP_HAS_ALPHA) ? 1:0; };
-
- inline int UsageCount ( ) { return usageCount; };
- inline int Type ( ) { return type; };
- inline int Flags ( ) { return flags; };
- inline void SetFlags ( DWORD f ) { flags |= f; }
- bVirtual int MaxRGBLevel ( ) = 0;
- bVirtual int MaxAlphaLevel ( ) = 0;
-
- //-- Scaling Tools
- bVirtual void Scale ( WORD *, int, WORD *, int );
- bVirtual BOOL GetSRow ( WORD *, int, WORD *, int );
- bVirtual BOOL PutSRow ( WORD *, int, WORD *, int );
- bVirtual BOOL GetSCol ( WORD *, WORD *, int, int );
- bVirtual BOOL PutSCol ( WORD *, WORD *, int, int );
- bVirtual BOOL ScaleY ( Bitmap *, BMM_Color_64 *, WORD *, WORD *, HWND, int cw = 0, int ch = 0 );
- bVirtual BOOL ScaleX ( Bitmap *, BMM_Color_64 *, WORD *, WORD *, HWND, int cw = 0, int ch = 0 );
- //-- This method will try to get a pointer to the begining of the image
- // storage. Not all storage types can return a valid pointer. In those
- // cases, this call will fail and the user should use some other method
- // described below (GG);
- //
-
- bVirtual void *GetStoragePtr ( int *type ) { *type = BMM_NO_TYPE; return (NULL); }
- //-- These methods will handle a single, 16 bit channel. See BMM_CHANNEL above
- // for the different options (GG)
-
- // bVirtual int Get16Channel ( int x,int y,int pixels,unsigned short *ptr, int channel) = 0;
- // bVirtual int Put16Channel ( int x,int y,int pixels,unsigned short *ptr, int channel) = 0;
- //-- These are the standard methods for accessing image pixels
-
- bVirtual int Get16Gray ( int x,int y,int pixels,WORD *ptr) = 0;
- bVirtual int Put16Gray ( int x,int y,int pixels,WORD *ptr) = 0;
- bVirtual int GetLinearPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
- bVirtual int GetPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
- bVirtual int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
- bVirtual int GetIndexPixels ( int x,int y,int pixels,unsigned char *ptr) = 0;
- bVirtual int PutIndexPixels ( int x,int y,int pixels,unsigned char *ptr) = 0;
-
- bVirtual int CropImage ( int width,int height,BMM_Color_64 fillcolor) = 0;
- bVirtual int CropImage ( int width,int height,int fillindex) = 0;
- bVirtual int ResizeImage ( int width,int height,int newpalette) = 0;
- bVirtual int CopyCrop ( Bitmap *from, BMM_Color_64 fillcolor );
- bVirtual int CopyScaleLow ( Bitmap *from );
- bVirtual int CopyScaleHigh ( Bitmap *from, HWND hWnd, BMM_Color_64 **buf = NULL, int w=0, int h=0 );
- bVirtual int CopyImage ( Bitmap *from,int operation,BMM_Color_64 fillcolor, BitmapInfo *bi = NULL);
- bVirtual int CopyImage ( Bitmap *from,int operation,int fillindex);
- bVirtual int GetPalette ( int start,int count,BMM_Color_48 *ptr) = 0;
- bVirtual int SetPalette ( int start,int count,BMM_Color_48 *ptr) = 0;
- bVirtual int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr) = 0;
-
- //-- User Interface
-
- bVirtual int Allocate ( BitmapInfo *bi,BitmapManager *manager,int openMode) = 0;
- bVirtual int Connect ( ) = 0;
- bVirtual int Disconnect ( ) = 0;
- bVirtual int MapReady ( ) = 0;
- bVirtual int ClosestColor ( BMM_Color_48 color);
- bVirtual int ClosestColor ( int r,int g,int b);
- // GBuffer methods ----------------------
- // get a pointer to specified channel: also determine its type for check
- bVirtual void* GetChannel(ULONG channelID, ULONG& chanType) { return NULL;}
- // create the specified channels -- return channels present:
- bVirtual ULONG CreateChannels(ULONG channelIDs) { return 0;}
-
- // delete all the channels in channelIDs
- bVirtual void DeleteChannels(ULONG channelIDs) {}
- // query which channels are present
- bVirtual ULONG ChannelsPresent() { return 0; }
- // For output bitmaps, can get RenderInfo, which is written by the
- // renderer
- // AllocRenderInfo will alloc only if RenderInfo doesn't yet exist.
- BMMExport RenderInfo* AllocRenderInfo();
- // GetRenderInfo just hands back RenderInfo pointer
- BMMExport RenderInfo* GetRenderInfo();
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap Filter Class
- //
- // Private class not to be documented
- //
- class BitmapFilter {
-
- protected:
-
- UINT usageCount; // Number of Bitmaps using this storage
- BitmapManager *manager; // Pointer to bitmap manager
- BitmapStorage *storage; // Pointer to storage itself
- DWORD flags; // Filter flags
- int dirty; // Needs updating flag
- UINT type; // Type index of filter
-
- public:
-
- BMMExport BitmapFilter();
- bVirtual ~BitmapFilter();
-
- inline DWORD Flags ( ) { return flags; };
- inline void SetFlag ( DWORD flag) { flags |= flag; dirty = 1; };
- inline void ToggleFlag ( DWORD flag) { flags ^= flag; dirty = 1; };
- inline void ClearFlag ( DWORD flag) { flags &= (~flag); dirty = 1; };
- inline UINT Type ( ) { return type; };
- inline void SetType ( UINT t) { type = t; };
- BMMExport int Initialize ( BitmapManager *m,BitmapStorage *s);
- virtual int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr) = 0;
- virtual void Free ( ) {};
- BMMExport int Connect ( );
- BMMExport int Disconnect ( );
- BMMExport int SetStorage ( BitmapStorage *storage);
- inline BitmapStorage *GetStorage ( ) { return storage; };
- inline void MakeDirty ( ) { dirty = 1; };
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap Dither Class
- //
- // Private class not to be documented
- class BitmapDither {
-
- protected:
-
- BitmapStorage *storage; // Pointer to storage itself
- int type; // Type index of filter
-
- public:
-
- BMMExport BitmapDither ( );
- bVirtual ~BitmapDither ( );
- inline UINT Type ( ) { return type; };
- inline void SetType ( UINT t) { type = t; };
- BMMExport int Initialize ( BitmapStorage *s);
- virtual int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
- virtual void Free ( ) {};
- BMMExport int SetStorage ( BitmapStorage *storage);
-
- };
- //-----------------------------------------------------------------------------
- //-- Bitmap Picker Class
- //
- /*
- class BitmapPicker {
-
- protected:
-
- BitmapManager *manager;
-
- public:
-
- bVirtual BitmapPicker ( ) {};
- bVirtual ~BitmapPicker ( ) {};
- bVirtual SetManager ( BitmapManager *m ) { manager = m; }
- bVirtual BitmapManager *GetManager ( ) { return (manager); }
- bVirtual BOOL ImageInputOptions ( BitmapInfo *bi, HWND hWnd )=0;
- bVirtual BOOL SelectDeviceInput ( BitmapInfo *bi, HWND hWnd )=0;
- bVirtual BOOL SelectDeviceOutput ( BitmapInfo *bi, HWND hWnd )=0;
- bVirtual BOOL SelectFileOutput ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL)=0;
- bVirtual BOOL SelectFileInput ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL)=0;
-
- bVirtual BOOL SelectFileInputEx ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL)=0;
-
- };
- */
- //-----------------------------------------------------------------------------
- //-- Basic Bitmap Class
- //
- //
-
- #define BMM_SINGLEFRAME -2000000L
- class Bitmap {
-
- private:
-
- DWORD flags; // See above
- BitmapManager *manager; // Manager of this bitmap
- BitmapIO *output; // Head of output handler list
- BitmapFilter *filter; // Filtered access methods
- BitmapDither *dither; // Dither methods
- BitmapStorage *storage; // Actual storage
- ICustToolbar *iTool; // Display Window Toolbar
- HWND hWnd,hTool; // Window handle (Display and Toolbar)
- UINT filterType; // Filtered access type
- UINT ditherType; // Dither type
- int currentBits; // Device Context NUMBITS (Display())
- int Free();
- HWND hList;
- ICustButton *iR,*iG,*iB,*iA;
- ICustStatus *iText;
- ICustButton *iClear,*iSave;
- TCHAR curTitle[128];
- int curPosition;
- int bitx,bity;
- BOOL autonomous;
-
- //-- Channel Display in VFB
-
- #define BMM_MASK_R 0x1
- #define BMM_MASK_G 0x2
- #define BMM_MASK_B 0x4
- #define BMM_MASK_A 0x8
- #define BMM_MODE_RGBA 0
- #define BMM_MODE_Z 1
- #define BMM_MODE_MTL 2
- #define BMM_MODE_NODE 3
- #define BMM_MODE_UV 4
- #define BMM_MODE_NORMAL 5
- #define BMM_MODE_NONCLAMP 6
-
- WORD channelMode;
- WORD channelMask;
- friend LRESULT CALLBACK InputWndProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
-
- public:
- BMMExport Bitmap ( BitmapManager *manager = TheManager );
- BMMExport ~Bitmap ( );
-
- inline BitmapManager *Manager ( ) { return manager; };
- //-- Don't use these unless you know what you're doing ----------------
-
- BMMExport int Create ( BitmapInfo *bi );
- BMMExport BOOL FixDeviceName ( BitmapInfo *bi );
- inline int MapReady ( ) { if (storage) return storage->MapReady(); return 0; };
- BMMExport void AddOutput ( BitmapIO *out );
- BMMExport void RemoveOutput ( BitmapIO *out );
- BMMExport BitmapIO * FindOutput ( BitmapInfo *bi );
- BMMExport PAVIFILE GetPaviFile ( BitmapInfo *bi );
- //-- Display Bitmap (Data and Methods) - Internal Use Only ------------
-
- HDRAWDIB dispHDR;
- HANDLE dispDIB;
- LRESULT Command ( WORD notify, WORD id, HWND hCtrl );
- LRESULT WMNotify ( LPNMHDR hdr );
- LRESULT BimpWndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
- void UpdateToolBar ( );
- BOOL InitBuffer ( );
- BOOL VfbFit ( int *w, int *h );
-
- //-- Public Interface -------------------------------------------------
-
- inline DWORD Flags ( ) { return flags; };
- inline void SetFlag ( DWORD flag ) { flags |= flag; };
- inline void ToggleFlag ( DWORD flag ) { flags ^= flag; };
- inline void ClearFlag ( DWORD flag ) { flags &= (~flag); };
-
- inline int Width ( ) { if (storage) return storage->Width(); return 0; };
- inline int Height ( ) { if (storage) return storage->Height(); return 0; };
- inline float Aspect ( ) { if (storage) return storage->Aspect(); return (float)0.0; };
- inline float Gamma ( ) { if (storage) return storage->Gamma(); return (float)0.0; };
- inline int Paletted ( ) { if (storage) return storage->Paletted(); return 0; };
- inline int IsDithered ( ) { if (storage) return storage->IsDithered(); return 0; };
- inline int PreMultipliedAlpha ( ) { if (storage) return storage->PreMultipliedAlpha(); return 0; };
- inline int HasAlpha ( ) { if (storage) return storage->HasAlpha(); return 0; };
- inline int MaxRGBLevel ( ) { if (storage) return storage->MaxRGBLevel(); return 0; };
- inline int MaxAlphaLevel ( ) { if (storage) return storage->MaxAlphaLevel(); return 0; };
-
- int Put16Gray ( int x,int y,int pixels,WORD *ptr )
- { if (storage) return storage->Put16Gray(x,y,pixels,ptr); return 0; };
- inline void *GetStoragePtr ( int *type )
- { if (storage) return storage->GetStoragePtr(type); return NULL; };
- inline int Get16Gray ( int x,int y,int pixels,WORD *ptr )
- { if (storage) return storage->Get16Gray(x,y,pixels,ptr); return 0; };
- inline int GetPixels ( int x,int y,int pixels,BMM_Color_64 *ptr )
- { if (storage) return storage->GetPixels(x,y,pixels,ptr); return 0; };
- BMMExport int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr );
- inline int GetLinearPixels ( int x,int y,int pixels,BMM_Color_64 *ptr )
- { if (storage) return storage->GetLinearPixels(x,y,pixels,ptr); return 0; };
- inline int GetIndexPixels ( int x,int y,int pixels,BYTE *ptr )
- { if (storage) return storage->GetIndexPixels(x,y,pixels,ptr); return 0; };
- inline int PutIndexPixels ( int x,int y,int pixels,BYTE *ptr )
- { if (storage) return storage->PutIndexPixels(x,y,pixels,ptr); return 0; };
- inline int CropImage ( int width,int height,BMM_Color_64 fillcolor)
- { if (storage) return storage->CropImage(width,height,fillcolor); return 0; };
- inline int CropImage ( int width,int height,int fillindex)
- { if (storage) return storage->CropImage(width,height,fillindex); return 0; };
- inline int ResizeImage ( int width,int height,int newpalette)
- { if (storage) return storage->ResizeImage(width,height,newpalette);return 0; };
- inline int CopyImage ( Bitmap *from,int operation,BMM_Color_64 fillcolor, BitmapInfo *bi = NULL)
- { if (storage) return storage->CopyImage(from,operation,fillcolor,bi); return 0; };
- inline int CopyImage ( Bitmap *from,int operation,int fillindex)
- { if (storage) return storage->CopyImage(from,operation,fillindex); return 0; };
- inline int GetPalette ( int start,int count,BMM_Color_48 *ptr)
- { if (storage) return storage->GetPalette(start,count,ptr); return 0; };
- inline int SetPalette ( int start,int count,BMM_Color_48 *ptr)
- { if (storage) return storage->SetPalette(start,count,ptr); return 0; };
- // GBuffer methods ---------------------
- inline void *GetChannel ( ULONG channelID, ULONG& chanType )
- { if (storage) return storage->GetChannel(channelID, chanType); return NULL; }
- inline ULONG CreateChannels ( ULONG channelIDs )
- { if (storage) return storage->CreateChannels(channelIDs); return 0; }
- inline void DeleteChannels ( ULONG channelIDs )
- { if (storage) storage->DeleteChannels(channelIDs); }
- inline ULONG ChannelsPresent ( )
- { if (storage) return storage->ChannelsPresent(); return 0; }
- inline RenderInfo* GetRenderInfo() { if (storage) return storage->GetRenderInfo(); return NULL; }
- inline RenderInfo* AllocRenderInfo() { if (storage) return storage->AllocRenderInfo(); return NULL; }
- //---------------------------------------------------------------------
- //
- // This call will check with the plug-in (file or device) defined in
- // the given BitmapInfo and prepare (create) the proper channels. If
- // a given channel already exists, no new channel will be created.
- //
- // After creating a bitmap, use this function to define the optional
- // channels that may be required by the given handler.
- //
- BMMExport BOOL PrepareGChannels ( BitmapInfo *bi );
- BMMExport BOOL PrepareGChannels ( DWORD channels );
- BMMExport int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr );
- BMMExport int SetDither ( UINT ditherType );
- BMMExport int SetFilter ( UINT filterType );
- inline int HasFilter ( ) { return (filter) ? 1:0; };
- inline BitmapFilter *Filter ( ) { return filter; };
- BMMExport int SetStorage ( BitmapStorage *storage);
- inline BitmapStorage *Storage ( ) { return storage; };
- inline void NullStorage ( ) { storage = NULL; };
-
- //-- Windows DIB Conversion -------------------------------------------
- //
- // Where depth is either 24 (BGR) or 32 (BGR0)
- //
- BMMExport PBITMAPINFO ToDib ( int depth = 24, UWORD *gam=NULL, BOOL dither=FALSE);
- //-- Do not use this directly. Instead, use BitmapManager::Create(PBITMAPINFO)
- BMMExport BOOL FromDib ( PBITMAPINFO pbmi );
-
- //-- Image output operations ------------------------------------------
- //
- // To write a single image to a file/device:
- //
- // *> Create BitmapInfo class: BitmapInfo bi;
- //
- // *> Define output file/device:
- //
- // Directly: bi.SetName("file.tga");
- // or
- // User Interface: BitmapManager::SelectFileOutput( ... &bi ...)
- //
- // *> Define bitmap:
- //
- // bi.SetWidth(x)
- // bi.SetHeight(y)
- // etc...
- //
- // *> Create bitmap: Bitmap *map = BitmapManager::Create(&bi);
- //
- //
- // *> Do something: map->Fill({0,0,0});
- //
- // *> OpenOutput: map->OpenOutput(&bi);
- //
- // *> Write: map->Write(&bi)
- //
- // *> Close: map->Close(&bi)
- //
- // To write a multiframe file, just keep doing something different to
- // the bimap and keep writting.
- //
- // To write a sequence of images to a file/device:
- //
- // *> Create BitmapInfo class: BitmapInfo bi;
- //
- // *> Define output file/device:
- //
- // Directly: bi.SetName("file.tga");
- // or
- // User Interface: BitmapManager::SelectFileOutput( ... &bi ...)
- //
- // *> Define bitmap:
- //
- // bi.SetWidth(x)
- // bi.SetHeight(y)
- //
- // bi.SetFirstFrame(0)
- // bi.SetLastFrame(29)
- //
- // etc...
- //
- // *> Create bitmap: Bitmap *map = BitmapManager::Create(&bi);
- //
- //
- // *> OpenOutput: map->OpenOutput(&bi);
- //
- // for (x = 0 to 29) {
- // *> Do something to image...
- // *> Write: map->Write(&bi,x);
- // }
- //
- // *> Close: map->Close(&bi)
- //
- //
- // Note: You can add any number of outputs to a bitmap. Just keep
- // calling map->OpenInput() with different outputs (Targa file AND
- // Frame Buffer for instance). To write or close a specific output,
- // use Write() and Close(). To write and close them all at once,
- // use WriteAll() and CloseAll().
- //
- // It is ok to use WriteAll() and CloseAll() if you have just one
- // output defined.
- //
-
- BMMExport BMMRES OpenOutput ( BitmapInfo *bi ); // Open output
- BMMExport BMMRES Write ( BitmapInfo *bi, int frame = BMM_SINGLEFRAME ); // Write frame to file
- BMMExport BMMRES WriteAll ( int frame = BMM_SINGLEFRAME ); // Write all open outputs
- BMMExport int Close ( BitmapInfo *bi, int flag = BMM_CLOSE_COMPLETE ); // Close an open output
- BMMExport int CloseAll ( int flag = BMM_CLOSE_COMPLETE); // Close all open outputs
- //-- Window gravity
- #define BMM_UL 1 //-- Upper Left
- #define BMM_LL 2 //-- Lower Left
- #define BMM_UR 3 //-- Upper Right
- #define BMM_LR 4 //-- Upper Left
- #define BMM_CN 5 //-- Center
- #define BMM_RND 10 //-- Renderer (Save/Restore)
- #define BMM_VPP 11 //-- Video Post Primary (Save/Restore)
- #define BMM_VPS 12 //-- Video Post Secondary (Save/Restore)
- BMMExport int Display ( TCHAR *title = NULL, int position = BMM_CN, BOOL autonomous = FALSE );
- BMMExport int UnDisplay ( );
- BMMExport HWND GetWindow ( );
- BMMExport void RefreshWindow ( RECT *rect = NULL );
- BMMExport void SetWindowTitle ( TCHAR *title );
-
- //-- Get a Different Frame -------------------------------------------
- //
- // For multifrane bitmaps (FLI's, AVI's, DDR devices, etc.), if you
- // simply want to load another frame replacing a previously "Load"ed
- // image.
- //
- // If used with single frame drivers or if the driver doesn't support
- // this function, it returns BMMRES_SINGLEFRAME. If the return value
- // is BMMRES_SUCCESS, a new frame has been loaded into the given
- // bitmap.
- //
- // To define desired frame, use bi->SetCurrentFrame( frame );
- //
-
- BMMExport BMMRES GoTo ( BitmapInfo *bi );
- //-- Handy built-in functions
- BMMExport int Fill ( int r,int g,int b,int alpha);
- };
- //-- Various Bitmap In-Memory Lists -------------------------------------------
- typedef struct {
- BitmapStorage *ptr;
- void *next;
- } BMMStorageList;
- typedef struct {
- BitmapFilter *ptr;
- void *next;
- } BMMFilterList;
- typedef struct {
- Bitmap *ptr;
- void *next;
- } BMMBitmapList;
- typedef struct tag_BMMGammaSettings {
- BitmapManager *mgr;
- BitmapInfo *bi;
- BOOL out;
- } BMMGammaSettings;
- typedef struct tag_BMMVfbPalette {
- BYTE r,g,b;
- } BMMVfbPalette;
- //-----------------------------------------------------------------------------
- //-- Main Bitmap Manager Class
- //
- class BitmapManager {
-
- BitmapInfo *bi;
- BMMInterface *iface;
- Interface *max;
- TCHAR name[MAX_DESCRIPTION];
- BMMStorageList *storageList;
- BMMFilterList *filterList;
- BMMBitmapList *bitmapList;
- TCHAR *windowTitle;
- int storageCount;
- int filterCount;
- int bitmapCount;
- BOOL listdevices;
- BOOL viewonly;
- BOOL silentmode;
- DWORD loglevel;
- HWND hWnd;
- void DoConstruct ( BMMInterface *i, const TCHAR *n );
- void BrowseInput ( HWND hWnd, TCHAR *device );
- void BrowseOutput ( HWND hWnd, TCHAR *device );
- public:
-
- int channelMagn;
- BMMVfbPalette *pal;
- //-- Construction/Destruction
-
- BMMExport BitmapManager ( BMMInterface *i);
- BMMExport BitmapManager ( BMMInterface *i,const TCHAR *name);
- BMMExport ~BitmapManager ( );
- friend void DoConstruct ( BitmapManager *m, BMMInterface *i, const TCHAR *name);
- //-- These are for internal use only
-
- BMMExport int DeleteAllMaps ( );
- BMMExport int AddStorage ( BitmapStorage *s);
- BMMExport int AddFilter ( BitmapFilter *a);
- BMMExport int AddBitmap ( Bitmap *b);
- BMMExport int DelStorage ( BitmapStorage *s);
- BMMExport int DelFilter ( BitmapFilter *a);
- BMMExport int DelBitmap ( Bitmap *b);
- BMMExport BitmapFilter *FindFilter ( BitmapStorage *s,UINT type);
- BMMExport BitmapStorage *FindStorage ( BitmapInfo *bi, int openMode);
- BMMExport int FnametoBitMapInfo ( BitmapInfo *bi );
- BMMExport void FixFileExt ( OPENFILENAME &ofn, const TCHAR *extension);
- BMMExport void MakeVfbPalette ( );
- BMM_IOList ioList;
- BMMExport void ListIO ( );
-
- //-- File Read/Write Processes (internal use only)
- BOOL InputOptionsControl ( HWND,UINT,WPARAM,LPARAM );
- BOOL DeviceInputControl ( HWND,UINT,WPARAM,LPARAM );
- BOOL DeviceOutputControl ( HWND,UINT,WPARAM,LPARAM );
- BOOL ImageInfoDlg ( HWND,UINT,WPARAM,LPARAM );
- BOOL BrowseFiles ( BitmapInfo *, HWND, TCHAR *);
- BOOL OpenFileHook ( HWND,UINT,WPARAM,LPARAM );
- BOOL WriteFileHook ( HWND,UINT,WPARAM,LPARAM );
- BOOL GammaControl ( HWND,UINT,WPARAM,LPARAM, BMMGammaSettings *gs);
- void BuildIFL ( BitmapInfo *bi );
-
- //---------------------------------------------------------------------
- //-- Public Interface -------------------------------------------------
-
- //-- Host Interface
- BMMExport HINSTANCE AppInst ( );
- BMMExport HWND AppWnd ( );
- BMMExport DllDir *AppDllDir ( );
- BMMExport TCHAR *GetDir (int i);
- BMMExport BOOL AddMapDir (TCHAR *dir,int update);
- BMMExport int GetMapDirCount ( );
- BMMExport TCHAR *GetMapDir (int i);
- BMMExport Interface *Max () { return max; }
- //-- These won't stay here. Error handling will be dealt in a couple of
- // different ways. There will be a "Silent" flag that will be set by
- // the client and tested here in order to know if an error dialog should
- // go up. Normally, if the user is sitting in front of the computer
- // this flag will be FALSE. When rendering in the background, or network
- // rendering, etc., this flag will be TRUE. There should be some kind of
- // "preferences" configuration for this behavior.
- //
- // There also will be a method for logging errors. This method will check
- // for a "loggin on/off" flag and either add the entry or ignore it. The
- // bitmap manager and its devices will log everything that goes wrong.
- // When silent mode is on and logging is also on, this is the method to
- // check what went bad. Having each device logging its own error will
- // enable a more accurate description of the problem (as opposed to "I/O
- // error").
- //
- // Gus
- //
-
- BMMExport int Status ( int *sCount, int *aCount, int *bCount);
- BMMExport int Error ( const TCHAR *string);
- //-- Error handling ---------------------------------------------------
- //
- //
- //-- Max Interface (means no logging)
-
- #define LG_NOLOG 0
-
- //-- User Interface
-
- #define LG_FATAL ((DWORD)(1 << 0))
- #define LG_INFO ((DWORD)(1 << 1))
- #define LG_DEBUG ((DWORD)(1 << 2))
- #define LG_WARN ((DWORD)(1 << 3))
- //-- User Interface
-
- BMMExport BOOL SilentMode ( ) { return silentmode; }
- BMMExport void SysLog ( int type, char *format, ... );
- //-- Max Interface (used internally)
-
- BMMExport BOOL SetSilentMode ( BOOL s );
- BMMExport void SetLogLevel ( DWORD level ) { loglevel = level; }
- BMMExport DWORD GetLogLevel ( ) { return (loglevel); }
- //-- Creating a new bitmap from scracth -------------------------------
- //
- // Make sure the given BitmapInfo class has the proper data for the
- // creation of the bitmap. If you used the BitmapManager function to
- // define the bitmap (SelectBitmapOutput()), both filename and device
- // driver have been defined for you.
- //
- // Make sure to set the type of bimap using bi.SetType(). This will
- // define the storage type as in (so far):
- //
- // BMM_LINE_ART
- // BMM_PALETTED
- // BMM_GRAY_8
- // BMM_GRAY_16
- // BMM_TRUE_16
- // BMM_TRUE_32
- // BMM_TRUE_64
- //
- // Do NOT use BMM_TRUE_24 nor BMM_TRUE_48. These are read only types.
- //
- // Example code is in src/app/vpexecut.cpp
- //
- //
- // Once a bitmap has been created, use its own methods for adding
- // outputs and writing it (i.e. map->OpenOutput(), map->Write() and
- // map->Close()).
- //
- // Gus
- //
-
- BMMExport Bitmap *Create ( BitmapInfo *bi );
- //-- Creating a new bitmap from an existing Windows DIB ---------------
- //
- // To Convert a Bitmap to a Windows DIB check Bitmap::ToDib()
- //
- BMMExport Bitmap *Create ( PBITMAPINFO pbmi );
- //-- Loads Bitmap -----------------------------------------------------
- //
- // Loads a bitmap.
- //
- // Like most other bitmap functions, you should define the image to
- // to load (either setting the name/device directly in BitmapInfo bi,
- // or having SelectFileInput() do it for you). Once bi has the name
- // of the image you want to load, call Load() to create a new Bitmap
- // which contains the image. Additional options may be set by calling
- // ImageInputOptions() before calling Load(). That will as the user
- // for special details such as positioning of smaller/larger images,
- // etc. All this does is to set the proper fields in BitmapInfo. It's
- // up to you to use those.
- //
- // BitmapInfo defaults to frame "zero". For multifrane files, such as
- // *.avi, *.ifl, *.flc, etc. you should specify the frame number you
- // want. Do it by using bi.SetCurrentFrame(f) before calling Load().
- //
- //
- // Note: If loading images from a device, make sure bi.Name() is
- // empty (bi.SetName(_T(""));). This is automatic if you use
- // SelectDeviceInput(). If you just create a BitmapInfo
- // instance and set the device name by hand (bi.SetDevice()),
- // this is also automatic as both name and device names are
- // by default empty. This should only be a concern if you
- // reuse a BitmapInfo class previously used for image files.
- //
- //
- // One of the methods in BitmapInfo returns a window handle to send
- // progress report messages. If you want to receive these messages,
- // set the window handle ( bi->SetUpdateWindow(hWnd) ) and process
- // BMM_PROGRESS messages (see above).
- //
- // Gus
- //
-
- BMMExport Bitmap *Load ( BitmapInfo *bi, BMMRES *status = NULL);
- //-- Load Image into an existing Bitmap (Internal Use) ----------------
- BMMExport BMMRES LoadInto ( BitmapInfo *bi, Bitmap **map );
-
- //-- General User Interface -------------------------------------------
-
- BMMExport BMMRES GetImageInfoDlg ( HWND hWnd, BitmapInfo *bi, const TCHAR *filename = NULL );
- BMMExport BMMRES GetImageInfo ( BitmapInfo *bi, const TCHAR *filename = NULL );
- BMMExport BOOL ImageInputOptions ( BitmapInfo *bi, HWND hWnd );
- BMMExport BOOL SelectDeviceInput ( BitmapInfo *bi, HWND hWnd );
- BMMExport BOOL SelectDeviceOutput ( BitmapInfo *bi, HWND hWnd );
- BMMExport BOOL SelectFileOutput ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL);
- BMMExport BOOL SelectFileInput ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL);
-
- BMMExport BOOL SelectFileInputEx ( BitmapInfo *bi,
- HWND hWnd,
- TCHAR *title = NULL,
- BOOL viewonly = FALSE);
-
- };
- //-----------------------------------------------------------------------------
- //-- Forward References for Bitmap Functions
- //
- // Internal Use
- //
- extern int ValidBitmapType ( int type );
- extern BMMExport BitmapStorage *BMMCreateStorage ( BitmapManager *manager,UINT type );
- extern BMMExport BitmapFilter *BMMCreateFilter ( BitmapManager *manager,UINT type );
- extern BMMExport BitmapDither *BMMCreateDither ( BitmapManager *manager,UINT type );
- extern BMMExport int BMMCalcPalette ( Bitmap *map,int colors,BMM_Color_48 *palette );
- extern BMMExport BYTE BMMClosestColor ( BMM_Color_64 *color,BMM_Color_48 *palette,int colors );
- extern BMMExport void OpenBMM ( BMMInterface *i );
- extern BMMExport void CloseBMM ( );
- extern BOOL CALLBACK BMMGammaDlgProc (HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
- extern void ExtractExtension ( TCHAR *string, TCHAR *ext );
- //-----------------------------------------------------------------------------
- //-- Handy-dandy pixel buffer class
- //
- class PixelBuf {
- private:
- BMM_Color_64 *buf;
- int width;
- public:
- inline PixelBuf ( int width) { buf = (BMM_Color_64 *)calloc(width,sizeof(BMM_Color_64)); this->width=width; };
- inline ~PixelBuf ( ) { if(buf) free(buf); };
- inline BMM_Color_64 *Ptr ( ) { return buf; };
- int Fill ( int start, int count, BMM_Color_64 color ) {
- int ix,jx=start+count;
- if (jx > width)
- return 0;
- for(ix=start; ix<jx; buf[ix++]=color);
- return 1;
- };
- };
- //-- Public Utilities ---------------------------------------------------------
- BMMExport int BMMCreateNumberedFilename ( const TCHAR *namein,int frame,TCHAR *nameout );
- BMMExport int BMMGetFullFilename ( BitmapInfo *bi );
- BMMExport BOOL BMMIsFile ( const TCHAR *filename );
- BMMExport void BMMSplitFilename ( const TCHAR *name,TCHAR *p,TCHAR *f,TCHAR *e );
- BMMExport void BMMAppendSlash ( TCHAR *path );
- BMMExport BOOL BMMGetUniversalName ( TCHAR *szUniv, const TCHAR *szDrive );
- BMMExport LPTSTR BMMGetLastErrorText ( LPTSTR lpszBuf, DWORD dwSize );
- //-- 256 color dithering-----------------------------------------------------
- // For packing colors into 256 color paletted representation.
- // Create one with BMMNewColorPacker
- class ColorPacker {
- public:
- virtual void EnableDither(BOOL onoff)=0; // default: MAX default
- virtual void PropogateErrorBetweenLines(BOOL onoff)=0; // default ON;
- virtual void PackLine( BMM_Color_64* in, BYTE *out, int w)=0;
- virtual void PackLine( BMM_Color_48* in, BYTE *out, int w)=0;
- virtual void DeleteThis()=0;
- };
- // Get a color packer. When done, be sure to call its DeleteThis();
- BMMExport ColorPacker *BMMNewColorPacker(
- int w, // width of bitmap to be packed
- BMM_Color_48 *pal, // palette to use
- int npal, // number of entries in the palette
- BYTE* remap=NULL // optional remap done at last stage.
- );
- //---------------------------------------------------------------------
- // Color quantizer, for doing true-color to paletted conversion
- //
- class Quantizer {
- public:
- virtual int AllocHistogram(void)=0;
- virtual int Partition(BMM_Color_48 *pal, int palsize, BMM_Color_64 *forceCol)=0;
- virtual void AddToHistogram(BMM_Color_64 *image, int npix)=0;
- virtual void AddToHistogram(BMM_Color_48 *image, int npix)=0;
- virtual void AddToHistogram(BMM_Color_24 *image, int npix)=0;
- virtual void DeleteThis()=0;
- };
- BMMExport Quantizer *BMMNewQuantizer();
- // Rearrange palette "pal" ( which has colors 0..ncols-1 occupied,
- // in descending order of frequency), into "newpal" so that the colors 10-245 are
- // populated first, then 0-9, then 246-255. Sets optional array "remap" to map the
- // old palette index values to the new ones
- BMMExport void FixPaletteForWindows(BMM_Color_48 *pal, BMM_Color_48 *newpal,int ncols, BYTE *remap=NULL);
- //-- Cleanup ------------------------------------------------------------------
- #undef bVirtual
- #endif BITMAP_H_DEFINED
- //-- EOF: bitmap.h ------------------------------------------------------------
|