int XILWindowAssistor::consume(const VideoFrame* vf) { int len=0,dofree=0; u_char *bp,*p=NULL; float scale[3], offset[3]; XilColorspace ycc, rgb; // fprintf(stderr,"XILWindowAssistor::"__FUNCTION__"\n"); switch (type_) { case FT_JPEG|FT_HW: { JpegFrame* jf = (JpegFrame*)vf; if ( (jf->type_ != lastjpegtype_) || (jf->q_ != inq_) || (jf->width_ != width_) || (jf->height_ != height_) ) { //fprintf(stderr,"w=%d,h=%d,q=%d\n",jf->width_,jf->height_,jf->q_); reset(jf->type_,jf->q_, jf->width_, jf->height_); } len=jf->len_; bp=jf->bp_; dofree=1; if (sentfirstheader) { p = new u_char[sizeof(jfif_header2)+len]; memcpy(p,jfif_header2,sizeof(jfif_header2)); memcpy(p+sizeof(jfif_header2),bp,len); len+=sizeof(jfif_header2); } else { p = new u_char[sizeof(jfif_header1)+len]; memcpy(p,jfif_header1,sizeof(jfif_header1)); memcpy(p+sizeof(jfif_header1),bp,len); len+=sizeof(jfif_header1); sentfirstheader=1; } break; } case FT_CELLB: { CellBFrame* hf = (CellBFrame*) vf; len=hf->len_; p=hf->bp_; xil_cis_set_attribute(cis_, "WIDTH", (void *)hf->width_); xil_cis_set_attribute(cis_, "HEIGHT", (void *)hf->height_); break; } case FT_H261: { H261Frame* hf = (H261Frame*) vf; len=hf->len_; p=hf->bp_; //Don't accept double zero bytes. xil chokes on that. while ((p[0]==0)&&(p[1]==0)&&len) { p++;len--; } break; } } xil_cis_put_bits(cis_,len,1/*framecount*/,p); if (dofree) delete[] p; //move this to the end, if you use put_bits_ptr //SV-XXX: Debian outputtype = xil_cis_get_output_type(cis_); xil_imagetype_get_info(outputtype, &cis_xsize, &cis_ysize,&cis_nbands, &cis_datatype); if (!imageYCC || (lastcisw!=cis_xsize) || (lastcish!=cis_ysize)) { lastcish = cis_ysize; lastcisw = cis_xsize; //fprintf(stderr," w=%d,h=%d,b=%d,t=%d\n",cis_xsize,cis_ysize,cis_nbands,cis_datatype); if (imageYCC) xil_destroy(imageYCC); if (ximage_) xil_destroy(ximage_); ximage_ = xil_create(xil_,cis_xsize,cis_ysize,cis_nbands,cis_datatype); imageYCC = xil_create(xil_,cis_xsize,cis_ysize,cis_nbands,cis_datatype); } if (visual == PSEUDOCOLOR) { scale[0] = 255.0 / (235.0 - 16.0); scale[1] = 255.0 / (240.0 - 16.0); scale[2] = 255.0 / (240.0 - 16.0); offset[0] = -16.0 * scale[0]; offset[1] = -16.0 * scale[1]; offset[2] = -16.0 * scale[2]; if (!x_cmap) { colorcube = xil_lookup_get_by_name(xil_, "cc855"); dmask = xil_dithermask_get_by_name(xil_, "dm443"); xil_cmap = create_cmap(&x_cmap, FT_JPEG, NULL, xil_lookup_get_by_name(xil_, "yuv_to_rgb"), colorcube ); } /* Begin XIL Molecule... */ xil_decompress( cis_, imageYCC ); xil_rescale(imageYCC, imageYCC, scale, offset); xil_scale(imageYCC,ximage_,"nearest",(1.0*targetw_)/lastcisw,(1.0*targeth_)/lastcish); xil_ordered_dither( ximage_, displayimage_, colorcube, dmask); /* End of XIL Molecule */ } if (visual == TRUECOLOR) { ycc = xil_colorspace_get_by_name(xil_, "ycc601"); rgb = xil_colorspace_get_by_name(xil_, "rgb709"); /* for H261, XIL may drop core on the last frame * to avoid this, only continue as long as 2 or * more frames in the CIS */ /* Begin XIL molecule */ xil_set_attribute(displayimage_,"HW_DECOMPRESS_CIS",(void *)-1); xil_decompress(cis_, imageYCC); if ((targetw_ == lastcisw) && (targeth_ == lastcish)) { xil_set_colorspace(imageYCC, ycc); xil_set_colorspace(displayimage_, rgb); xil_color_convert(imageYCC, displayimage_); } else { xil_set_colorspace(imageYCC, ycc); xil_set_colorspace(ximage_, rgb); xil_color_convert(imageYCC, ximage_); xil_scale(ximage_,displayimage_,"nearest",(1.0*targetw_)/lastcisw,(1.0*targeth_)/lastcish); } /* End of XIL molecule */ } xil_cis_sync(cis_); xil_toss(imageYCC); xil_toss(ximage_); xil_cis_reset(cis_); return (0); }
void IResourceManager::start(const std::string &name, Attrs &attr) { if (name == "resources") { _tw = atol(attr["tile_width"].c_str()); if (_tw == 0) throw_ex(("resources tag must contain `tile_width' attribute (default tile width)")); _th = atol(attr["tile_height"].c_str()); if (_th == 0) throw_ex(("resources tag must contain `tile_height' attribute (default tile height)")); if (attr["version"].empty()) throw_ex(("resources tag must contain `version' attribute")); LOG_DEBUG(("file version: %s", attr["version"].c_str())); } else if (name == "animation") { status = "animation"; const std::string &id = attr["id"]; if (id.empty()) throw_ex(("animation.id was not set")); const std::string &model = attr["model"]; if (model.empty()) throw_ex(("animation.model was not set")); long tw = atol(attr["tile_width"].c_str()); long th = atol(attr["tile_height"].c_str()); long sz = atol(attr["size"].c_str()); if (tw == 0) tw = _tw; if (th == 0) th = _th; if (sz != 0) tw = th = sz; sdlx::Surface *s = NULL; sdlx::CollisionMap *cmap = NULL; bool real_load = !attr["persistent"].empty(); GET_CONFIG_VALUE("engine.preload", bool , preload_all, false); real_load |= preload_all; std::string &tile = attr["tile"]; if (_base_dir.empty()) throw_ex(("base directory was not defined (multiply resources tag ? invalid resource structure?)")); if (_surfaces.find(tile) == _surfaces.end()) { TRY { if (real_load) { mrt::Chunk data; std::string tname = "tiles/" + tile; Finder->load(data, tname); s = new sdlx::Surface; s->load_image(data); s->display_format_alpha(); cmap = create_cmap(s, tname); LOG_DEBUG(("loaded animation '%s'", id.c_str())); } _surfaces[tile] = s; s = NULL; _cmaps[tile] = cmap; cmap = NULL; } CATCH(mrt::format_string("loading animation \"%s\"", tile.c_str()).c_str(), { delete s; s = NULL; delete cmap; cmap = NULL; throw; });