|
|
| version 1.1, 2001/04/10 13:22:55 | version 1.3, 2001/04/10 14:00:02 |
|---|---|
| Line 27 VStateless_class *image_class; | Line 27 VStateless_class *image_class; |
| class Measure_reader { | class Measure_reader { |
| public: | public: |
| enum { READ_CHUNK_SIZE=10*0x400 }; // 10K | enum { READ_CHUNK_SIZE=0x400 }; // 1K |
| typedef size_t (*Func)(void *& buf, size_t limit, void *info); | typedef size_t (*Func)(void *& buf, size_t limit, void *info); |
| Measure_reader(Func afunc, void *ainfo) : | Measure_reader(Func afunc, void *ainfo) : |
| Line 36 public: | Line 36 public: |
| } | } |
| size_t read(unsigned char *& buf, size_t limit) { | size_t read(unsigned char *& buf, size_t limit) { |
| if(!size) // nothing left | if(offset+limit>size) // nothing left |
| size=(*func)(chunk, READ_CHUNK_SIZE, info); | if(offset==0 || limit==1) { // only one-byte continuations allowed |
| size=(*func)(chunk, READ_CHUNK_SIZE, info); | |
| offset=0; | |
| } else | |
| return 0; // as if EOF | |
| if(!size) // EOF | if(!size) // EOF |
| return 0; | return 0; |
| Line 87 struct JPG_Frame { | Line 91 struct JPG_Frame { |
| char width[2]; // image width | char width[2]; // image width |
| char numComponents; // number of color components | char numComponents; // number of color components |
| }; | }; |
| // JFIF format markers | |
| #define SOI 0xD8 | |
| #define EOI 0xD9 | |
| #define APP0 0xE0 | |
| #define SOF0 0xC0 | |
| #define SOF2 0xC2 | |
| #define COM 0xFE | |
| // | // |
| Line 124 void measure_gif(Pool& pool, const Strin | Line 120 void measure_gif(Pool& pool, const Strin |
| void measure_jpeg(Pool& pool, const String *origin_string, | void measure_jpeg(Pool& pool, const String *origin_string, |
| Measure_reader& reader, int& width, int& height) { | Measure_reader& reader, int& width, int& height) { |
| // JFIF format markers | |
| const unsigned char SOI=0xD8; | |
| const unsigned char EOI=0xD9; | |
| const unsigned char APP0=0xE0; | |
| const unsigned char SOF0=0xC0; | |
| const unsigned char SOF2=0xC2; | |
| const unsigned char COM=0xFE; | |
| unsigned char *screenD_buf; | unsigned char *screenD_buf; |
| unsigned char *h_buf; | unsigned char *h_buf=0; |
| bool flag=false; | bool flag=false; |
| char Spec[]="JFIF"; | |
| unsigned char *prefix; | unsigned char *prefix; |
| const prefix_size=2; | const prefix_size=2; |
| Line 160 void measure_jpeg(Pool& pool, const Stri | Line 163 void measure_jpeg(Pool& pool, const Stri |
| break; | break; |
| JFIF_Header& screenD=*reinterpret_cast<JFIF_Header *>(screenD_buf); | JFIF_Header& screenD=*reinterpret_cast<JFIF_Header *>(screenD_buf); |
| if((bytes_to_int(screenD.length[0], screenD.length[1]) < 16) || | if((bytes_to_int(screenD.length[0], screenD.length[1]) < 16) || |
| strcasecmp(screenD.identifier, Spec)) flag=false; | strcasecmp(screenD.identifier, "JFIF")) flag=false; |
| } | } |
| break; | break; |
| case SOF0: | case SOF0: |
| Line 172 void measure_jpeg(Pool& pool, const Stri | Line 175 void measure_jpeg(Pool& pool, const Stri |
| } | } |
| } while(*marker!=EOI); | } while(*marker!=EOI); |
| if(flag) { | if(flag && h_buf) { |
| JPG_Frame& h=*reinterpret_cast<JPG_Frame *>(h_buf); | JPG_Frame& h=*reinterpret_cast<JPG_Frame *>(h_buf); |
| width=bytes_to_int(h.width[0], h.width[1]); | width=bytes_to_int(h.width[0], h.width[1]); |
| height=bytes_to_int(h.height[0], h.height[1]); | height=bytes_to_int(h.height[0], h.height[1]); |
| Line 269 static void _measure(Request& r, const S | Line 272 static void _measure(Request& r, const S |
| static_cast<VImage *>(r.self)->set(*file_name, width, height); | static_cast<VImage *>(r.self)->set(*file_name, width, height); |
| } | } |
| static void append_attrib_pair(const Hash::Key& key, Hash::Val *val, void *info) { | |
| String& tag=*static_cast<String *>(info); | |
| Value& value=*static_cast<Value *>(val); | |
| // src="a.gif" width=123 ismap[=-1] | |
| tag << " " << key; | |
| if(value.is_string() || value.as_double()>=0) { | |
| tag << "="; | |
| if(value.is_string()) | |
| tag << "\""; | |
| tag << value.as_string(); | |
| if(value.is_string()) | |
| tag << "\""; | |
| } | |
| } | |
| /// ^image.html[] | |
| /// ^image.html[hash] | |
| static void _html(Request& r, const String& method_name, Array *params) { | |
| Pool& pool=r.pool(); | |
| String tag(pool); | |
| tag << "<img"; | |
| static_cast<VImage *>(r.self)->fields().for_each(append_attrib_pair, &tag); | |
| tag << ">"; | |
| r.write_pass_lang(tag); | |
| } | |
| // initialize | // initialize |
| void initialize_image_class(Pool& pool, VStateless_class& vclass) { | void initialize_image_class(Pool& pool, VStateless_class& vclass) { |
| // ^image:measure[DATA] | // ^image:measure[DATA] |
| vclass.add_native_method("measure", Method::CT_DYNAMIC, _measure, 1, 1); | vclass.add_native_method("measure", Method::CT_DYNAMIC, _measure, 1, 1); |
| /// ^image.html[] | |
| /// ^image.html[hash] | |
| vclass.add_native_method("html", Method::CT_DYNAMIC, _html, 0, 1); | |
| } | } |