Diff for /parser3/src/classes/image.C between versions 1.80 and 1.89

version 1.80, 2002/11/22 16:16:33 version 1.89, 2002/11/29 12:13:42
Line 24  static const char* IDENT_IMAGE_C="$Date$ Line 24  static const char* IDENT_IMAGE_C="$Date$
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vfile.h"  #include "pa_vfile.h"
 #include "pa_vimage.h"  #include "pa_vimage.h"
   #include "pa_vdate.h"
   
 // class  // class
   
Line 72  public: Line 73  public:
   
         /*override*/void seek(long value, int whence) {          /*override*/void seek(long value, int whence) {
                 if(lseek(f, value, whence)<0)                  if(lseek(f, value, whence)<0)
                         throw Exception("file.seek",                          throw Exception("image.format",
                                 &file_name,                                   &file_name, 
                                 "seek(value=%ld, whence=%d) failed: %s (%d), actual filename '%s'",                                   "seek(value=%ld, whence=%d) failed: %s (%d), actual filename '%s'", 
                                         value, whence, strerror(errno), errno, fname);                                          value, whence, strerror(errno), errno, fname);
         }          }
   
         /*override*/long tell() { return ::tell(f); }          /*override*/long tell() { return lseek(f, 0, SEEK_CUR); }
   
 private:  private:
         Pool& pool;          Pool& pool;
Line 104  public: Line 105  public:
                 switch(whence) {                  switch(whence) {
                 case SEEK_CUR: new_offset=offset+value; break;                  case SEEK_CUR: new_offset=offset+value; break;
                 case SEEK_SET: new_offset=(size_t)value; break;                  case SEEK_SET: new_offset=(size_t)value; break;
                 default: throw Exception("file.seek", 0, "whence #%d not supported", 0, whence); break;                  default: throw Exception(0, 0, "whence #%d not supported", 0, whence); break; // never
                 }                  }
                                   
                 if((ssize_t)new_offset<0 || new_offset>size)                  if((ssize_t)new_offset<0 || new_offset>size)
                         throw Exception("file.seek",                          throw Exception("image.format",
                                 &file_name,                                   &file_name, 
                                 "seek(value=%l, whence=%d) failed: out of buffer, new_offset>size (%l>%l) or new_offset<0",                                   "seek(value=%l, whence=%d) failed: out of buffer, new_offset>size (%l>%l) or new_offset<0", 
                                         value, whence, new_offset, size);                                          value, whence, new_offset, size);
Line 189  struct JPG_Exif_IFD_entry { Line 190  struct JPG_Exif_IFD_entry {
   
 #define JPG_IFD_TAG_EXIF_OFFSET 0x8769  #define JPG_IFD_TAG_EXIF_OFFSET 0x8769
   
   #define JPEG_EXIF_DATE_CHARS 20
   
 //  //
   
 inline ushort x_endian_to_ushort(uchar b0, uchar b1) {  inline ushort x_endian_to_ushort(uchar b0, uchar b1) {
Line 212  inline uint endian_to_uint(bool is_big, Line 215  inline uint endian_to_uint(bool is_big,
 static void measure_gif(Pool& pool, const String *origin_string,   static void measure_gif(Pool& pool, const String *origin_string, 
                          Measure_reader& reader, ushort& width, ushort& height) {                           Measure_reader& reader, ushort& width, ushort& height) {
   
         void *buf;          const void *buf;
         const int head_size=sizeof(GIF_Header);          const int head_size=sizeof(GIF_Header);
         if(reader.read(buf, head_size)<head_size)          if(reader.read(buf, head_size)<head_size)
                 throw Exception("image.format",                   throw Exception("image.format", 
Line 275  static Value *parse_IFD_entry_formatted_ Line 278  static Value *parse_IFD_entry_formatted_
         return 0;          return 0;
 }  }
   
   // date.C
   time_t cstr_to_time_t(char *cstr, const String *report_error_origin);
   
 static Value *parse_IFD_entry_formatted_value(Pool& pool,  static Value *parse_IFD_entry_formatted_value(Pool& pool,
                                                                                           bool is_big, ushort format,                                                                                             bool is_big, ushort format, 
                                                                                           size_t component_size, uint components_count,                                                                                             size_t component_size, uint components_count, 
Line 282  static Value *parse_IFD_entry_formatted_ Line 288  static Value *parse_IFD_entry_formatted_
         if(format==2) { // ascii string, exception: the only type with varying size          if(format==2) { // ascii string, exception: the only type with varying size
                 const char *cstr=(const char *)value;                  const char *cstr=(const char *)value;
                 size_t size=components_count;                  size_t size=components_count;
                   // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes
                   if(size==JPEG_EXIF_DATE_CHARS 
                           && isdigit(cstr[0])
                           && cstr[JPEG_EXIF_DATE_CHARS-1]==0) {
                           char cstr_writable[JPEG_EXIF_DATE_CHARS]; 
                           strcpy(cstr_writable, cstr);
   
                           time_t t=cstr_to_time_t(cstr_writable, 0/* do not throw exception, just return bad result */);
                           if(t>=0)
                                   return new(pool) VDate(pool, t);
                   }
   
                 if(const char *premature_zero_pos=(const char *)memchr(cstr, 0, size))                  if(const char *premature_zero_pos=(const char *)memchr(cstr, 0, size))
                         size=premature_zero_pos-cstr;                          size=premature_zero_pos-cstr;
                 return new(pool) VString(*new(pool) String(pool, cstr, size, true/*tainted*/));                  return new(pool) VString(*new(pool) String(pool, cstr, size, true/*tainted*/));
Line 456  static void measure_jpeg(Pool& pool, con Line 474  static void measure_jpeg(Pool& pool, con
         const uchar CODE_SIZE_D=0xC3;          const uchar CODE_SIZE_D=0xC3;
         const uchar CODE_EXIF=0xE1;          const uchar CODE_EXIF=0xE1;
   
         void *buf;          const void *buf;
         const size_t prefix_size=2;          const size_t prefix_size=2;
         if(reader.read(buf, prefix_size)<prefix_size)          if(reader.read(buf, prefix_size)<prefix_size)
                 throw Exception("image.format",                   throw Exception("image.format", 
Line 517  static void measure_jpeg(Pool& pool, con Line 535  static void measure_jpeg(Pool& pool, con
 static void measure_png(Pool& pool, const String *origin_string,   static void measure_png(Pool& pool, const String *origin_string, 
                          Measure_reader& reader, ushort& width, ushort& height) {                           Measure_reader& reader, ushort& width, ushort& height) {
   
         void *buf;          const void *buf;
         const int head_size=sizeof(PNG_Header);          const int head_size=sizeof(PNG_Header);
         if(reader.read(buf, head_size)<head_size)          if(reader.read(buf, head_size)<head_size)
                 throw Exception("image.format",                   throw Exception("image.format", 
Line 637  static void _html(Request& r, const Stri Line 655  static void _html(Request& r, const Stri
                 Value &vattribs=r.process_to_value(params->get(0),                  Value &vattribs=r.process_to_value(params->get(0),
                         /*0/*no name* /,*/                          /*0/*no name* /,*/
                         false/*don't intercept string*/);                          false/*don't intercept string*/);
                 if(vattribs.is_defined()) // allow 'void'                  if(!vattribs.is_string()) // allow empty
                         if(attribs=vattribs.get_hash(&method_name)) {                          if(attribs=vattribs.get_hash(&method_name)) {
                                 Attrib_info attrib_info={&tag, 0};                                  Attrib_info attrib_info={&tag, 0};
                                 attribs->for_each(append_attrib_pair, &attrib_info);                                  attribs->for_each(append_attrib_pair, &attrib_info);
Line 891  static void _polybar(Request& r, const S Line 909  static void _polybar(Request& r, const S
   
 // font  // font
   
 #define Y(y)(y+index*height+1)  #define Y(y)(y+index*height)
   
 /// simple gdImage-based font storage & text output   /// simple gdImage-based font storage & text output 
 class Font : public Pooled {  class Font: public Pooled {
 public:  public:
                   
         const static int letter_spacing;          const static int letter_spacing;
Line 906  public: Line 924  public:
                   
         Font(Pool& pool,           Font(Pool& pool, 
                 const String& aalphabet,                   const String& aalphabet, 
                 gdImage& aifont, int aheight, int amonospace, int aspacebarspace) : Pooled(pool),                   gdImage& aifont, int aheight, int amonospace, int aspacebarspace): Pooled(pool), 
                 alphabet(aalphabet),                   alphabet(aalphabet), 
                 height(aheight), monospace(amonospace),  spacebarspace(aspacebarspace),                  height(aheight), monospace(amonospace),  spacebarspace(aspacebarspace),
                 ifont(aifont) {                  ifont(aifont) {
Line 924  public: Line 942  public:
                         return spacebarspace;                          return spacebarspace;
                 int tr=ifont.GetTransparent();                  int tr=ifont.GetTransparent();
                 for(int x=ifont.SX()-1; x>=0; x--) {                  for(int x=ifont.SX()-1; x>=0; x--) {
                         for(int y=0; y<height-1; y++)                          for(int y=0; y<height; y++)
                                 if(ifont.GetPixel(x, Y(y))!=tr)                                   if(ifont.GetPixel(x, Y(y))!=tr) 
                                         return x+1;                                          return x+1;
                 }                  }
Line 933  public: Line 951  public:
                   
         void index_display(gdImage& image, int x, int y, int index){          void index_display(gdImage& image, int x, int y, int index){
                 if(index>=0)                   if(index>=0) 
                         ifont.Copy(image, x, y, 0, Y(0), index_width(index), height-1);                          ifont.Copy(image, x, y, 0, Y(0), index_width(index), height);
         }          }
                   
         /* ******************************** string ********************************** */          /* ******************************** string ********************************** */
                   
           int step_width(int index) {
                   return letter_spacing + (monospace ? monospace : index_width(index));
           }
   
           // counts trailing letter_spacing, consider this OK. useful for contiuations
         int string_width(const String& s){          int string_width(const String& s){
                 const char *cstr=s.cstr();                  const char *cstr=s.cstr();
                 int result=0;                  int result=0;
                 for(; *cstr; cstr++)                  for(; *cstr; cstr++)
                         result+=index_width(index_of(*cstr));                          result+=step_width(index_of(*cstr));
                 return result;                  return result;
         }          }
                   
Line 951  public: Line 974  public:
                 if(cstr) for(; *cstr; cstr++) {                  if(cstr) for(; *cstr; cstr++) {
                         int index=index_of(*cstr);                          int index=index_of(*cstr);
                         index_display(image, x, y, index);                          index_display(image, x, y, index);
                         x+=letter_spacing + (monospace ? monospace : index_width(index));                          x+=step_width(index);
                 }                  }
         }          }
                   
Line 976  static void _font(Request& r, const Stri Line 999  static void _font(Request& r, const Stri
                 throw Exception("parser.runtime",                  throw Exception("parser.runtime",
                         &method_name,                          &method_name,
                         "alphabet must not be empty");                          "alphabet must not be empty");
   
           if(int remainder=image.SY() % alphabet.size())
                   throw Exception("parser.runtime",
                           &method_name,
                           "font-file height(%d) not divisable by alphabet size(%d), remainder=%d",
                                   image.SY(), alphabet.size(), remainder);
                   
         static_cast<VImage *>(r.get_self())->font=new(pool) Font(pool,           static_cast<VImage *>(r.get_self())->font=new(pool) Font(pool, 
                 alphabet,                   alphabet, 

Removed from v.1.80  
changed lines
  Added in v.1.89


E-mail: