include/kate/kate.h

Go to the documentation of this file.
00001 /* Copyright (C) 2008 Vincent Penquerc'h.
00002    This file is part of the Kate codec library.
00003    Written by Vincent Penquerc'h.
00004 
00005    Use, distribution and reproduction of this library is governed
00006    by a BSD style source license included with this source in the
00007    file 'COPYING'. Please read these terms before distributing. */
00008 
00009 
00010 #ifndef _KATE_CODEC_H_
00011 #define _KATE_CODEC_H_
00012 
00017 #include <stddef.h>
00018 #include <stdint.h>
00019 #include <ogg/ogg.h>
00020 
00021 #ifdef KATE_INTERNAL
00022 #define kate_const
00023 #else
00024 #define kate_const const
00025 #endif
00026 
00027 typedef int32_t kate_int32_t;
00028 typedef int64_t kate_int64_t;
00029 typedef float kate_float;
00030 
00033 #define KATE_VERSION_MAJOR 0             
00034 #define KATE_VERSION_MINOR 1             
00035 #define KATE_VERSION_PATCH 1             
00040 #define KATE_BITSTREAM_VERSION_MAJOR 0   
00041 #define KATE_BITSTREAM_VERSION_MINOR 1   
00044 #ifndef kate_malloc
00045 #define kate_malloc malloc
00046 #endif
00047 #ifndef kate_realloc
00048 #define kate_realloc realloc
00049 #endif
00050 #ifndef kate_free
00051 #define kate_free free
00052 #endif
00053 
00055 typedef enum {
00056   kate_utf8                      
00057 } kate_text_encoding;
00058 
00060 typedef enum {
00061   kate_pixel,                    
00062   kate_percentage                
00063 } kate_space_metric;
00064 
00066 typedef struct kate_region {
00067   kate_space_metric metric;      
00068   int x;                         
00069   int y;                         
00070   int w;                         
00071   int h;                         
00072   int style;                     
00073   uintptr_t pad[6];
00074 } kate_region;
00075 
00077 typedef struct kate_color {
00078   unsigned char r;               
00079   unsigned char g;               
00080   unsigned char b;               
00081   unsigned char a;               
00082 } kate_color;
00083 
00085 typedef struct kate_style {
00086   kate_float halign;                 
00087   kate_float valign;                 
00089   kate_color text_color;             
00090   kate_color background_color;       
00091   kate_color draw_color;             
00093   kate_space_metric font_metric;     
00094   kate_float font_width;             
00095   kate_float font_height;            
00097   kate_space_metric margin_metric;   
00098   kate_float left_margin;            
00099   kate_float top_margin;             
00100   kate_float right_margin;           
00101   kate_float bottom_margin;          
00103   uint32_t bold:1;                   
00104   uint32_t italics:1;                
00105   uint32_t underline:1;              
00106   uint32_t strike:1;                 
00107   uint32_t pad0:28;
00108   uintptr_t pad1[10];
00109 } kate_style;
00110 
00112 typedef enum kate_curve_type {
00113   kate_curve_none,                   
00114   kate_curve_static,                 
00115   kate_curve_linear,                 
00116   kate_curve_catmull_rom_spline,     
00117   kate_curve_bezier_cubic_spline,    
00118   kate_curve_bspline,                
00119 } kate_curve_type;
00120 
00122 typedef struct kate_curve {
00123   kate_curve_type type;              
00124   size_t npts;                       
00125   kate_float *pts;                   
00126   uintptr_t pad[5];
00127 } kate_curve;
00128 
00130 typedef enum kate_motion_mapping {
00131   /* these can be used for a x/y position mapping */
00132   kate_motion_mapping_none,                  
00133   kate_motion_mapping_frame,                 
00134   kate_motion_mapping_window,                
00135   kate_motion_mapping_region,                
00136   kate_motion_mapping_event_duration,        
00138 #if 0
00139   text is useful, find a way to readd it easily
00140   kate_motion_mapping_text,                  
00141 #endif
00142 
00143   /* more mapping may be added in future versions */
00144 
00145   kate_motion_mapping_user=128               
00146 } kate_motion_mapping;
00147 
00149 typedef enum kate_motion_semantics {
00150   kate_motion_semantics_time,                    
00151   kate_motion_semantics_z,                       
00152   kate_motion_semantics_region_position,         
00153   kate_motion_semantics_region_size,             
00154   kate_motion_semantics_text_alignment_int,      
00155   kate_motion_semantics_text_alignment_ext,      
00156   kate_motion_semantics_text_position,           
00157   kate_motion_semantics_text_size,               
00158   kate_motion_semantics_marker1_position,        
00159   kate_motion_semantics_marker2_position,        
00160   kate_motion_semantics_marker3_position,        
00161   kate_motion_semantics_marker4_position,        
00162   kate_motion_semantics_glyph_pointer_1,         
00163   kate_motion_semantics_glyph_pointer_2,         
00164   kate_motion_semantics_glyph_pointer_3,         
00165   kate_motion_semantics_glyph_pointer_4,         
00166   kate_motion_semantics_text_color_rg,           
00167   kate_motion_semantics_text_color_ba,           
00168   kate_motion_semantics_background_color_rg,     
00169   kate_motion_semantics_background_color_ba,     
00170   kate_motion_semantics_draw_color_rg,           
00171   kate_motion_semantics_draw_color_ba,           
00172   kate_motion_semantics_style_morph,             
00173   kate_motion_semantics_text_path,               
00174   kate_motion_semantics_text_path_section,       
00175   kate_motion_semantics_draw,                    
00176   kate_motion_semantics_text_visible_section,    
00177   kate_motion_semantics_horizontal_margins,      
00178   kate_motion_semantics_vertical_margins,        
00180   /* more semantics may be added in future versions */
00181 
00182   kate_motion_semantics_user = 128               
00183 } kate_motion_semantics;
00184 
00186 typedef struct kate_motion {
00187   size_t ncurves;                                
00188   kate_curve **curves;                           
00189   kate_float *durations;                         
00190   kate_motion_mapping x_mapping;                 
00191   kate_motion_mapping y_mapping;                 
00192   kate_motion_semantics semantics;               
00193   uint32_t periodic:1;                           
00194   uint32_t pad0:31;
00195   uintptr_t pad1[5];
00196 } kate_motion;
00197 
00199 typedef enum kate_text_directionality {
00200   kate_l2r_t2b,                                  
00201   kate_r2l_t2b,                                  
00202   kate_t2b_r2l,                                  
00203   kate_t2b_l2r                                   
00204 } kate_text_directionality;
00205 
00207 typedef struct kate_palette {
00208   size_t ncolors;                                
00209   kate_color *colors;                            
00210   uintptr_t pad[2];
00211 } kate_palette;
00212 
00214 typedef struct kate_bitmap {
00215   size_t width;                                  
00216   size_t height;                                 
00217   unsigned char bpp;                             
00218   unsigned char pad0[3];
00219   int palette;                                   
00220   unsigned char *pixels;                         
00221   uintptr_t pad1[3];
00222 } kate_bitmap;
00223 
00225 typedef struct kate_font_range {
00226   int first_code_point;                          
00227   int last_code_point;                           
00228   int first_bitmap;                              
00229   uintptr_t pad[5];
00230 } kate_font_range;
00231 
00233 typedef struct kate_font_mapping {
00234   size_t nranges;                                
00235   kate_font_range **ranges;                      
00236   uintptr_t pad[6];
00237 } kate_font_mapping;
00238 
00244 typedef struct kate_info {
00245   unsigned char bitstream_version_major;         
00246   unsigned char bitstream_version_minor;         
00247   unsigned char pad0[2];
00248 
00249   kate_text_encoding text_encoding;              
00250   kate_text_directionality text_directionality;  
00252   unsigned char num_headers;                     
00253   unsigned char granule_shift;                   
00254   unsigned char pad1[2];
00255 
00256   kate_int32_t gps_numerator;                    
00257   kate_int32_t gps_denominator;                  
00259   kate_const char *language;                     
00261   kate_const char *category;                     
00263   size_t nregions;                               
00264   kate_const kate_region *kate_const *regions;   
00266   size_t nstyles;                                
00267   kate_const kate_style *kate_const *styles;     
00269   size_t ncurves;                                
00270   kate_const kate_curve *kate_const *curves;     
00272   size_t nmotions;                               
00273   kate_const kate_motion *kate_const *motions;   
00275   size_t npalettes;                              
00276   kate_const kate_palette *kate_const *palettes; 
00278   size_t nbitmaps;                               
00279   kate_const kate_bitmap *kate_const *bitmaps;   
00281   size_t nfont_ranges;                                       
00282   kate_const kate_font_range *kate_const *font_ranges;       
00284   size_t nfont_mappings;                                     
00285   kate_const kate_font_mapping *kate_const *font_mappings;   
00287   uintptr_t pad2[14];
00288 
00289   /* internal */
00290   int remove_markup;
00291   int no_limits;
00292   int probe;
00293 
00294   uintptr_t pad3[13];
00295 } kate_info;
00296 
00297 struct kate_encode_state; /* internal */
00298 struct kate_decode_state; /* internal */
00299 
00301 typedef struct kate_state {
00302   kate_const kate_info *ki;                      
00304   /* internal */
00305   kate_const struct kate_encode_state *kes;
00306   kate_const struct kate_decode_state *kds;
00307 
00308   uintptr_t pad[5];
00309 } kate_state;
00310 
00312 typedef struct kate_comment {
00313   char **user_comments;                         
00314   int *comment_lengths;                         
00315   int comments;                                 
00316   char *vendor;                                 
00317 } kate_comment;
00318 
00323 typedef struct kate_event {
00324   kate_int64_t start;                           
00325   kate_int64_t duration;                        
00326   kate_int64_t backlink;                        
00328   kate_float start_time;                        
00329   kate_float end_time;                          
00331   kate_int32_t id;                              
00333   kate_text_encoding text_encoding;             
00334   kate_text_directionality text_directionality; 
00335   kate_const char *language;                    
00336   kate_const char *text;                        
00337   size_t len;                                   
00338   size_t len0;                                  
00340   size_t nmotions;                              
00341   kate_const kate_motion *kate_const *motions;  
00343   kate_const kate_region *region;               
00344   kate_const kate_style *style;                 
00345   kate_const kate_style *secondary_style;       
00346   kate_const kate_font_mapping *font_mapping;   
00348   uintptr_t pad0[11];
00349 
00350   /* internal */
00351   const kate_info *ki;
00352   size_t trackers;
00353 
00354   uintptr_t pad1[10];
00355 } kate_event;
00356 
00358 typedef struct kate_tracker {
00359   const kate_info *ki;                          
00360   kate_const kate_event *event;                 
00361   kate_float t;                                 
00363   struct {
00364     uint32_t region:1;                          
00365     uint32_t text_alignment_int:1;              
00366     uint32_t text_alignment_ext:1;              
00367     uint32_t text_pos:1;                        
00368     uint32_t text_size:1;                       
00369     uint32_t marker_pos:4;                      
00370     uint32_t text_color:1;                      
00371     uint32_t background_color:1;                
00372     uint32_t draw_color:1;                      
00373     uint32_t glyph_pointer:4;                   
00374     uint32_t path:1;                            
00375     uint32_t draw:1;                            
00376     uint32_t visible_section:1;                 
00377     uint32_t z:1;                               
00378     uint32_t hmargins:1;                        
00379     uint32_t vmargins:1;                        
00380     /* 22 bits */
00381     uint32_t pad0:10;
00382     uint32_t pad1:32;
00383     /* 64 bits */
00384   } has;                                        
00386   int window_w;                                 
00387   int window_h;                                 
00388   int frame_x;                                  
00389   int frame_y;                                  
00390   int frame_w;                                  
00391   int frame_h;                                  
00393   /* has.region */
00394   kate_float region_x;                          
00395   kate_float region_y;                          
00396   kate_float region_w;                          
00397   kate_float region_h;                          
00399   /* has.text_alignment (int/ext) */
00400   kate_float text_halign;                       
00401   kate_float text_valign;                       
00403   /* has.text_pos */
00404   kate_float text_x;                            
00405   kate_float text_y;                            
00407   /* has.text_size */
00408   kate_float text_size_x;                       
00409   kate_float text_size_y;                       
00411   /* has.marker_pos&(1<<n) */
00412   kate_float marker_x[4];                       
00413   kate_float marker_y[4];                       
00415   /* has.text_color */
00416   kate_color text_color;                        
00418   /* has.background_color */
00419   kate_color background_color;                  
00421   /* has.draw_color */
00422   kate_color draw_color;                        
00424   /* has.glyph_pointer&(1<<n) */
00425   kate_float glyph_pointer[4];                  
00426   kate_float glyph_height[4];                   
00428   /* has.path */
00429   kate_float path_start;                        
00430   kate_float path_end;                          
00432   /* has.draw */
00433   kate_float draw_x;                            
00434   kate_float draw_y;                            
00436   /* has.visible_section */
00437   kate_float visible_x;                         
00438   kate_float visible_y;                         
00440   /* has.z */
00441   kate_float z;                                 
00443   /* has.hmargins */
00444   kate_float left_margin;                       
00445   kate_float right_margin;                      
00447   /* has.vmargins */
00448   kate_float top_margin;                        
00449   kate_float bottom_margin;                     
00451   /* internal */
00452   size_t nglyphs;
00453 
00454   uintptr_t pad[32];
00455 
00456 } kate_tracker;
00457 
00459 typedef struct kate_packet {
00460   size_t nbytes;             
00461   void *data;                
00462 } kate_packet;
00463 
00464 #ifdef __cplusplus
00465 extern "C" {
00466 #endif
00467 
00469 extern int kate_get_version(void);
00470 extern const char *kate_get_version_string(void);
00471 extern int kate_get_bitstream_version(void);
00472 extern const char *kate_get_bitstream_version_string(void);
00473 
00475 extern int kate_info_init(kate_info *ki);
00476 extern int kate_info_set_granule_encoding(kate_info *ki,kate_float resolution,kate_float max_length,kate_float max_event_lifetime);
00477 extern int kate_info_set_language(kate_info *ki,const char *language);
00478 extern int kate_info_set_text_directionality(kate_info *ki,kate_text_directionality text_directionality);
00479 extern int kate_info_set_category(kate_info *ki,const char *category);
00480 extern int kate_info_add_region(kate_info *ki,kate_region *kr);
00481 extern int kate_info_add_style(kate_info *ki,kate_style *ks);
00482 extern int kate_info_add_curve(kate_info *ki,kate_curve *kc);
00483 extern int kate_info_add_motion(kate_info *ki,kate_motion *km);
00484 extern int kate_info_add_palette(kate_info *ki,kate_palette *kp);
00485 extern int kate_info_add_bitmap(kate_info *ki,kate_bitmap *kb);
00486 extern int kate_info_add_font_range(kate_info *ki,kate_font_range *kfr);
00487 extern int kate_info_add_font_mapping(kate_info *ki,kate_font_mapping *kfm);
00488 extern int kate_info_matches_language(const kate_info *ki,const char *language);
00489 extern int kate_info_remove_markup(kate_info *ki,int flag);
00490 extern int kate_info_no_limits(kate_info *ki,int flag);
00491 extern int kate_info_clear(kate_info *ki);
00492 
00494 extern int kate_granule_shift(const kate_info *ki);
00495 extern kate_float kate_granule_time(const kate_info *ki,kate_int64_t granulepos);
00496 extern kate_int64_t kate_duration_granule(const kate_info *ki,kate_float duration);
00497 extern kate_float kate_granule_duration(const kate_info *ki,kate_int64_t duration);
00498 
00499 extern int kate_clear(kate_state *k);
00500 extern int kate_motion_get_point(const kate_motion *km,kate_float duration,kate_float t,kate_float *x,kate_float *y);
00501 
00503 extern int kate_text_get_character(kate_text_encoding text_encoding,const char ** const text,size_t *len0);
00504 extern int kate_text_set_character(kate_text_encoding text_encoding,int c,char ** const text,size_t *len0);
00505 extern int kate_text_remove_markup(kate_text_encoding text_encoding,char *text,size_t *len0);
00506 extern int kate_text_validate(kate_text_encoding text_encoding,const char *text,size_t len0);
00507 
00509 extern int kate_comment_init(kate_comment *kc);
00510 extern int kate_comment_clear(kate_comment *kc);
00511 extern int kate_comment_add(kate_comment *kc,const char *comment);
00512 extern int kate_comment_add_length(kate_comment *kc,const char *comment,size_t len);
00513 extern int kate_comment_add_tag(kate_comment *kc,const char *name,const char *value);
00514 extern const char *kate_comment_query(const kate_comment *kc,const char *tag,int count);
00515 extern int kate_comment_query_count(const kate_comment *kc,const char *tag);
00516 
00518 extern int kate_encode_init(kate_state *k,kate_info *ki);
00519 extern int kate_encode_headers(kate_state *k,kate_comment *kc,kate_packet *kp);
00520 extern int kate_encode_text(kate_state *k,kate_float start_time,kate_float stop_time,const char *text,size_t sz,kate_packet *kp); /* text is not null terminated */
00521 extern int kate_encode_keepalive(kate_state *k,kate_float t,kate_packet *kp);
00522 extern int kate_encode_finish(kate_state *k,kate_float t,kate_packet *kp); /* t may be negative to use the end granule of the last event */
00523 extern int kate_encode_set_id(kate_state *k,kate_int32_t id);
00524 extern int kate_encode_set_language(kate_state *k,const char *language); /* language can be NULL */
00525 extern int kate_encode_set_text_encoding(kate_state *k,kate_text_encoding text_encoding);
00526 extern int kate_encode_set_text_directionality(kate_state *k,kate_text_directionality text_directionality);
00527 extern int kate_encode_set_region_index(kate_state *k,size_t region);
00528 extern int kate_encode_set_region(kate_state *k,kate_region *kr);
00529 extern int kate_encode_set_style_index(kate_state *k,size_t style);
00530 extern int kate_encode_set_style(kate_state *k,kate_style *ks);
00531 extern int kate_encode_set_secondary_style_index(kate_state *k,size_t style);
00532 extern int kate_encode_set_secondary_style(kate_state *k,kate_style *ks);
00533 extern int kate_encode_set_font_mapping_index(kate_state *k,size_t font_mapping);
00534 extern int kate_encode_add_motion(kate_state *k,kate_motion *km,int destroy);
00535 extern int kate_encode_add_motion_index(kate_state *k,size_t motion);
00536 
00538 extern int kate_decode_is_idheader(const kate_packet *kp);
00539 extern int kate_decode_init(kate_state *k,kate_info *ki);
00540 extern int kate_decode_headerin(kate_info *ki,kate_comment *kc,kate_packet *kp);
00541 extern int kate_decode_packetin(kate_state *k,kate_packet *kp);
00542 extern int kate_decode_eventout(kate_state *k,kate_const kate_event **ev); /* event can be NULL */
00543 
00545 extern int kate_tracker_init(kate_tracker *kin,const kate_info *ki,kate_const kate_event *ev);
00546 extern int kate_tracker_clear(kate_tracker *kin);
00547 extern int kate_tracker_update(kate_tracker *kin,kate_float t,int window_w,int window_h,int frame_x,int frame_y,int frame_w,int frame_h);
00548 extern int kate_tracker_morph_styles(kate_style *style,kate_float t,const kate_style *from,const kate_style *to);
00549 extern int kate_tracker_get_text_path_position(kate_tracker *kin,size_t glyph,int *x,int *y);
00550 
00552 extern int kate_font_get_index_from_code_point(const kate_font_mapping *kfm,int c);
00553 
00555 extern int kate_high_decode_init(kate_state *k);
00556 extern int kate_high_decode_packetin(kate_state *k,kate_packet *kp,kate_const kate_event **ev);
00557 extern int kate_high_decode_clear(kate_state *k);
00558 
00560 extern int kate_packet_wrap(kate_packet *kp,size_t nbytes,const void *data);
00561 extern int kate_packet_init(kate_packet *kp,size_t nbytes,const void *data);
00562 extern int kate_packet_clear(kate_packet *kp);
00563 
00564 #ifdef __cplusplus
00565 }
00566 #endif
00567 
00570 #define KATE_E_NOT_FOUND (-1)            
00571 #define KATE_E_INVALID_PARAMETER (-2)    
00572 #define KATE_E_OUT_OF_MEMORY (-3)        
00573 #define KATE_E_BAD_GRANULE (-4)          
00574 #define KATE_E_INIT (-5)                 
00575 #define KATE_E_BAD_PACKET (-6)           
00576 #define KATE_E_TEXT (-7)                 
00577 #define KATE_E_LIMIT (-8)                
00578 #define KATE_E_VERSION (-9)              
00579 #define KATE_E_NOT_KATE (-10)            
00582 #endif
00583 

Generated on Sun Mar 30 21:18:28 2008 for libkate by  doxygen 1.5.4