|
|
| version 1.2, 2001/04/10 13:24:49 | version 1.4, 2001/04/10 14:18:28 |
|---|---|
| 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 125 void measure_jpeg(Pool& pool, const Stri | Line 129 void measure_jpeg(Pool& pool, const Stri |
| const unsigned char COM=0xFE; | 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; |
| Line 171 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 268 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); |
| } | } |
| struct Attrib_info { | |
| String *tag; | |
| Hash *skip; | |
| }; | |
| static void append_attrib_pair(const Hash::Key& key, Hash::Val *val, void *info) { | |
| Attrib_info& ai=*static_cast<Attrib_info *>(info); | |
| if(ai.skip && ai.skip->get(key)) | |
| return; | |
| Value& value=*static_cast<Value *>(val); | |
| // src="a.gif" width=123 ismap[=-1] | |
| *ai.tag << " " << key; | |
| if(value.is_string() || value.as_double()>=0) { | |
| *ai.tag << "="; | |
| if(value.is_string()) | |
| *ai.tag << "\""; | |
| *ai.tag << value.as_string(); | |
| if(value.is_string()) | |
| *ai.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"; | |
| Hash& fields=static_cast<VImage *>(r.self)->fields(); | |
| Hash *temporary=0; | |
| if(params->size()) { | |
| if(temporary=static_cast<Value *>(params->get(0))->get_hash()) { | |
| Attrib_info attrib_info={&tag, 0}; | |
| temporary->for_each(append_attrib_pair, &attrib_info); | |
| } else | |
| PTHROW(0, 0, | |
| &method_name, | |
| "parameter must be hash"); | |
| } | |
| Attrib_info attrib_info={&tag, temporary}; | |
| fields.for_each(append_attrib_pair, &attrib_info); | |
| 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); | |
| } | } |