image.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 #if !defined IMAGE_HEADER
00020 #define IMAGE_HEADER
00021 
00025 
00026 #include "whiptk/whipcore.h"
00027 #include "whiptk/file.h"
00028 #include "whiptk/drawable.h"
00029 #include "whiptk/colormap.h"
00030 
00031 #define WD_EXPECTED_GROUP3X_FACTOR  0.2
00032 
00034 class WT_Huffman
00035 {
00036 public:
00037 
00039     enum Bitonal_Value
00040     {
00041         Background = 0, 
00042         Foreground = 1  
00043     };
00044 
00046     enum Raster_Encoding
00047     {
00048         Group3 = 0x00,
00049         Group3X = 0x01,
00050         Literal = 0x02,
00051         Reserved = 0x03
00052     };
00053 
00055     int run;
00056 
00058     struct Code
00059     {
00060         WT_Byte    value;
00061         WT_Byte    length;
00062     }           code[2];
00063 };
00064 
00069 
00070 
00074 class WHIPTK_API WT_Image : public WT_Drawable
00075 {
00076         friend class WT_W2D_Class_Factory;
00077         friend class WT_Opcode;
00078 
00079 public:
00081     enum WT_Image_Format
00082     {
00083         Bitonal_Mapped      = WD_IMAGE_BITONAL_MAPPED_EXT_OPCODE,
00084         Group3X_Mapped      = WD_IMAGE_GROUP3X_MAPPED_EXT_OPCODE,
00085         Indexed             = WD_IMAGE_INDEXED_EXT_OPCODE,
00086         Mapped              = WD_IMAGE_MAPPED_EXT_OPCODE,
00087         RGB                 = WD_IMAGE_RGB_EXT_OPCODE,
00088         RGBA                = WD_IMAGE_RGBA_EXT_OPCODE,
00089         JPEG                = WD_IMAGE_JPEG_EXT_OPCODE
00090     };
00091 
00092 public:
00093 
00094     WT_Unsigned_Integer16   m_rows;
00095     WT_Unsigned_Integer16   m_columns;
00096     WT_Byte                 m_format;
00097     WT_Integer32            m_identifier;
00098     WT_Integer32            m_dpi;
00099 
00100     WT_Color_Map *          m_color_map;
00101     WT_Integer32            m_data_size;
00102     WT_Byte *               m_data;
00103 
00104     WT_Logical_Point        m_min_corner;
00105     WT_Logical_Point        m_max_corner;
00106 
00107     WT_Boolean              m_transformed;
00108     WT_Boolean              m_relativized;
00109     WT_Boolean              m_local_data_copy;
00110     WT_Boolean              m_local_color_map_copy;
00111 
00112     // Scratchpad for conversion method use
00113     WT_Byte *               m_source_data;
00114     int                     m_src_byte_position;
00115     int                     m_src_bits_used;
00116     int                     m_dst_bits_used;
00117     int                     m_data_allocated;
00118 
00119     enum
00120     {
00121         Starting,
00122         Getting_Columns,
00123         Getting_Col_Row_Comma,
00124         Getting_Rows,
00125         Getting_Min_Corner,
00126         Getting_Max_Corner,
00127         Getting_Format,
00128         Getting_Identifier,
00129         Getting_Color_Map_Opcode,
00130         Getting_Color_Map,
00131         Getting_Pre_Data_Size_Whitespace,
00132         Getting_Pre_Data_Size_Open_Paren,
00133         Getting_Data_Size,
00134         Getting_Data,
00135         Getting_Close
00136     }                       m_stage;
00137 
00138     WT_Opcode               m_colormap_opcode;
00139 
00140     WT_Image (WT_Image const &)
00141       : WT_Drawable()
00142       , m_rows()
00143       , m_columns()
00144       , m_format()
00145       , m_identifier()
00146       , m_dpi()
00147       , m_color_map()
00148       , m_data_size()
00149       , m_data()
00150       , m_min_corner()
00151       , m_max_corner()
00152       , m_transformed()
00153       , m_relativized()
00154       , m_local_data_copy()
00155       , m_local_color_map_copy()
00156       , m_source_data()
00157       , m_src_byte_position()
00158       , m_src_bits_used()
00159       , m_dst_bits_used()
00160       , m_data_allocated()
00161       , m_stage()
00162       , m_colormap_opcode()
00163     {
00164         WD_Complain ("cannot copy WT_Image");
00165     } // prohibited
00166 
00167     WT_Image & operator= (WT_Image const &)
00168     {
00169         WD_Complain ("cannot assign WT_Image");
00170         return *this;
00171     } // prohibited
00172 
00173     inline WT_Result        add_code (WT_Huffman::Code const & code);
00174     inline int              get_next_bit();
00175     inline WT_Result        output_group3x_code(int run_color, int run_length, WT_Boolean skip_trailing_zero);
00176 
00177 public:
00178 
00179     // Constructors, Destructors
00180 
00182     WT_Image () 
00183                 : m_rows(0)
00184                 , m_columns(0)
00185                 , m_format(RGBA)
00186                 , m_identifier(0)
00187                 , m_dpi(-1)
00188                 , m_color_map(WD_Null)
00189                 , m_data_size(0)
00190                 , m_data(WD_Null)
00191                 , m_min_corner(0,0)
00192                 , m_max_corner(0,0)
00193                 , m_transformed(WD_False)
00194                 , m_relativized(WD_False)
00195                 , m_local_data_copy(WD_False)
00196                 , m_local_color_map_copy(WD_False)
00197                 , m_stage(Starting)
00198             { }
00199 
00201     WT_Image (int image_type) 
00202                 : m_rows(0)
00203                 , m_columns(0)
00204                 , m_format(static_cast<WT_Byte>(image_type))
00205                 , m_identifier(0)
00206                 , m_dpi(-1)
00207                 , m_color_map(WD_Null)
00208                 , m_data_size(0)
00209                 , m_data(WD_Null)
00210                 , m_min_corner(0,0)
00211                 , m_max_corner(0,0)
00212                 , m_transformed(WD_False)
00213                 , m_relativized(WD_False)
00214                 , m_local_data_copy(WD_False)
00215                 , m_local_color_map_copy(WD_False)
00216                 , m_stage(Getting_Columns)
00217             { }
00218 
00219 
00221     WT_Image(
00222             WT_Unsigned_Integer16       rows, 
00223             WT_Unsigned_Integer16       columns, 
00224             WT_Image_Format             format, 
00225             WT_Integer32                identifier, 
00226             WT_Color_Map const *        color_map, 
00227             WT_Integer32                data_size, 
00228             WT_Byte *                   data, 
00229             WT_Logical_Point const &    min_corner, 
00230             WT_Logical_Point const &    max_corner, 
00231             WT_Boolean                  copy, 
00232             WT_Integer32                dpi = -1 
00233             ) throw(WT_Result);
00234 
00236     virtual ~WT_Image()
00237     {
00238         if (m_local_data_copy)
00239             delete [] m_data;
00240 
00241         if (m_local_color_map_copy)
00242             delete m_color_map;
00243     }
00244 
00245 public:
00247 
00248     WT_Color_Map const * color_map() const
00249     {   return m_color_map;     }
00251     WT_Unsigned_Integer16 columns() const
00252     {   return m_columns;  }
00253     WT_Unsigned_Integer16& columns()
00254     {   return m_columns;   }
00256     WT_Byte const * data() const
00257     {   return m_data;  }
00259     WT_Integer32 data_size() const
00260     {   return m_data_size; }
00262     WT_Byte format() const
00263     {   return m_format;  }
00264     WT_Byte& format() 
00265     {   return m_format; }
00267     WT_Integer32 identifier() const
00268     {   return m_identifier;    }
00269     WT_Integer32 const& dpi() const
00270     {   return m_dpi;   }
00271     WT_Integer32& dpi()
00272     {   return m_dpi;   }
00274     WT_Logical_Point const & max_corner() const
00275     {   return m_max_corner;    }
00276     WT_Logical_Point& max_corner() 
00277     {   return m_max_corner;    }
00279     WT_Logical_Point const & min_corner() const
00280     {   return m_min_corner;    }
00281     WT_Logical_Point& min_corner()
00282     {   return m_min_corner;    }
00284     WT_Unsigned_Integer16 rows() const
00285     {   return m_rows;  }
00286     WT_Unsigned_Integer16& rows()
00287     {   return m_rows;   }
00288 
00289     WT_Result set(WT_Color_Map const* pColorMap);
00291 
00293 
00294 
00298     WT_Result      convert_bitonal_to_group_3X ();
00300 
00303     WT_Result      convert_group_3X_to_bitonal();
00305 
00308     WT_Result      convert_group_3X_to_mapped();
00310 
00312 
00313     virtual void        de_relativize(WT_File & file);
00315     virtual void        relativize(WT_File & file);
00317     virtual void           transform(WT_Transform const & transform);
00319 
00321     WT_ID            object_id() const;
00322     WT_Result        serialize(WT_File & file) const;
00323     WT_Result        materialize(WT_Opcode const & opcode, WT_File & file);
00324     WT_Result        skip_operand(WT_Opcode const & opcode, WT_File & file);
00325     WT_Result        process(WT_File & file);
00326     virtual void     update_bounds(WT_File * file);
00328 
00330 
00332     static WT_Result default_process(
00333         WT_Image & item, 
00334         WT_File & file 
00335         );
00336 };
00337 
00339 
00340 #endif // IMAGE_HEADER

Generated on Tue Jan 6 22:41:13 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5