bitmaps.h

Go to the documentation of this file.
00001 /*  
00002  *      BitMaps.h - MAX bitmap access classes
00003  *
00004  *          Copyright (c) John Wainwright 1996
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "..\kernel\value.h"
00011 #include "..\..\bmmlib.h"
00012 // forward declarations
00013 class MAXBitMapWindow;
00014 class MotionTracker;
00015 class MAXBitMap;
00016 
00017 // entry in MAXBitMap window table
00018 struct mbm_window               
00019 {
00020     HWND        window;
00021     MAXBitMap*  mbm;
00022 };
00023 
00024 /* ------------------------ MAXBitMap ------------------------------ */
00025 
00026 applyable_class (MAXBitMap)
00027 
00028 class MAXBitMap : public Value
00029 {
00030 public:
00031     BitmapInfo            bi;                   // our BitMapInfo 
00032     Bitmap*               bm;                   // the actual bitmap
00033     Tab<MotionTracker*>   trackers;             // any motion trackers
00034     MotionTracker*        dragger;              // tracker currently under drag
00035     WNDPROC               main_window_proc;     // original display window proc if ours installed
00036     GBuffer*              gb;                   // GBuffer if non-NULL
00037     GBufReader*           gbr;                  // current GBuffer reader if non-NULL
00038     short                 flags;    
00039 
00040     static Tab<mbm_window> windows;             // table of MAXBitMap windows currently open
00041 
00042     ScripterExport MAXBitMap();
00043     ScripterExport MAXBitMap(BitmapInfo bi, Bitmap* bm);
00044                ~MAXBitMap();
00045 
00046     static void setup();
00047     static MAXBitMap* find_window_mbm(HWND hwnd);
00048 
00049                 classof_methods (MAXBitMap, Value);
00050 #   define      is_bitmap(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(MAXBitMap))
00051     void        collect() { delete this; }
00052     void        gc_trace();
00053     ScripterExport void sprin1(CharStream* s);
00054 
00055     Value*      new_motionTracker();
00056     void        install_window_proc();
00057 
00058 #include "..\macros\define_implementations.h"
00059     def_visible_generic ( display,          "display"); 
00060     def_visible_generic ( unDisplay,        "unDisplay" ); 
00061     def_visible_generic ( save,             "save" ); 
00062     def_visible_generic ( gotoFrame,        "gotoFrame"); 
00063     def_visible_generic ( close,            "close");
00064     def_visible_generic ( getTracker,       "getTracker" ); 
00065     def_visible_generic ( deleteTracker,    "deleteTracker" ); 
00066     use_generic         ( copy,             "copy" ); 
00067     def_visible_generic ( zoom,             "zoom" ); 
00068     def_visible_generic ( crop,             "crop" ); 
00069     def_visible_generic ( setAsBackground,  "setAsBackground" ); 
00070     def_visible_generic ( getPixels,        "getPixels" ); 
00071     def_visible_generic ( setPixels,        "setPixels" ); 
00072     def_visible_generic ( getIndexedPixels, "getIndexedPixels" ); 
00073     def_visible_generic ( setIndexedPixels, "setIndexedPixels" ); 
00074     def_visible_generic ( getChannel,       "getChannel" ); 
00075     def_visible_generic ( getChannelAsMask, "getChannelAsMask" ); 
00076     use_generic         ( free,             "free");
00077 
00078     Value*      get_property(Value** arg_list, int count);
00079     Value*      set_property(Value** arg_list, int count);
00080 
00081     ScripterExport void     to_fpvalue(FPValue& v);
00082 };
00083 
00084 #define BM_SAVED        0x0001          // bitmap has been written to and output steam is open
00085 #define BM_READONLY 0x0002          // existing bitmap opened (and so readonly).
00086 #define BM_FILEBACKED   0x0004          // bitmap is backed by a file
00087 
00088 /* -------------------- MotionTracker -------------------------- */
00089 
00090 applyable_class (MotionTracker)
00091 
00092 class MotionTracker : public Value
00093 {
00094 public:
00095     MAXBitMap*  mbm;            // the bitmap I'm tracking
00096     int         index;          // which tracker in that bitmap
00097     int         cur_frame;      // frame I last tracked
00098     POINT       center;         // current feature center
00099     RECT        bounds;         // feature bounds relative to center
00100     RECT        motion_bounds;  // maximum frame-to-frame motion relative to feature center
00101     POINT       mouse_down_at;  // mouse pos at mousedown
00102     int         handle_x;       // handle pos at mouse_down..
00103     int         handle_y;       // handle pos at mouse_down..
00104     int         handle;         // which handle is dragging
00105     BYTE*       target;         // current target image as 3 BYTE RGB per pixel
00106     POINT*      track_cache;    // keeps a cache of tracking coords, one per frame (inval if change gizmo)
00107     short       compare_mode;   // feature matching space: rgb color, luminence, edge-filtered, etc.
00108     float       match_distance; // last tracking match 'distance'
00109     HBITMAP     id_bitmap;      // unbelievable - I need to use a bitmap copy to do XOR text drawing
00110     short       flags;
00111 
00112                 MotionTracker(MAXBitMap* imbm, int iindex);
00113                ~MotionTracker();
00114 
00115                 classof_methods(MotionTracker, Value);
00116     void        collect() { delete this; }
00117     ScripterExport void sprin1(CharStream* s);
00118     void        gc_trace();
00119 
00120     void        track();
00121     void        clear_track_cache();
00122     void        set_center(int x, int y);
00123     void        set_index(int i);
00124     void        copy_target();
00125     void        draw(HWND hWnd);
00126     void        draw_gizmo(HDC hdc);
00127     void        inval_gizmo();
00128     BOOL        start_drag(HWND hwnd, int wParam, long lParam);
00129     void        drag(HWND hwnd, int wParam, long lParam);
00130     void        end_drag(HWND hwnd);
00131     void        move(HWND hwnd, int dx, int dy);
00132     void        deselect(HWND hwnd);
00133 
00134     def_visible_generic ( resample,    "resample");
00135     def_visible_generic ( reset,       "reset");
00136 
00137     def_property ( center );
00138     Value*      get_property(Value** arg_list, int count);
00139     Value*      set_property(Value** arg_list, int count);
00140 };
00141 
00142 #define MT_GIZMO_SELECTED       0x0001
00143 #define MT_GIZMO_MOVED          0x0002
00144 #define MT_ENABLED              0x0004
00145 
00146 #define MT_MATCH_RGB            0
00147 #define MT_MATCH_GRAY           1
00148 #define MT_MATCH_EDGE           2
00149 #define MT_MATCH_RANK           3
00150 
00151 #define MT_NO_HANDLE            0       // handle codes...
00152 #define MT_CENTER               1       
00153 #define MT_TOPLEFT_BOUNDS       2
00154 #define MT_BOTLEFT_BOUNDS       3
00155 #define MT_TOPRIGHT_BOUNDS      4
00156 #define MT_BOTRIGHT_BOUNDS      5
00157 #define MT_TOPLEFT_MBOUNDS      6
00158 #define MT_BOTLEFT_MBOUNDS      7
00159 #define MT_TOPRIGHT_MBOUNDS     8
00160 #define MT_BOTRIGHT_MBOUNDS     9
00161 
00162