TexturePtr TextureManager::loadTexture(std::stringstream& file) { TexturePtr texture; apng_data apng; if(load_apng(file, &apng) == 0) { Size imageSize(apng.width, apng.height); if(apng.num_frames > 1) { // animated texture std::vector<ImagePtr> frames; std::vector<int> framesDelay; for(uint i=0;i<apng.num_frames;++i) { uchar *frameData = apng.pdata + ((apng.first_frame+i) * imageSize.area() * apng.bpp); int frameDelay = apng.frames_delay[i]; framesDelay.push_back(frameDelay); frames.push_back(ImagePtr(new Image(imageSize, apng.bpp, frameData))); } AnimatedTexturePtr animatedTexture = new AnimatedTexture(imageSize, frames, framesDelay); m_animatedTextures.push_back(animatedTexture); texture = animatedTexture; } else { ImagePtr image = ImagePtr(new Image(imageSize, apng.bpp, apng.pdata)); texture = TexturePtr(new Texture(image)); } free_apng(&apng); } return texture; }
std::pair<ImagePtr, RectD> TrackMarker::getMarkerImage(TimeValue time, const RectD& roi) const { assert( !roi.isNull() ); NodePtr node = getModel()->getNode(); NodePtr input = node->getInput(0); if (!input) { return std::make_pair(ImagePtr(), roi); } TreeRender::CtorArgsPtr args(new TreeRender::CtorArgs); { args->treeRootEffect = input->getEffectInstance(); args->time = time; args->view = ViewIdx(0); // Render default plane args->plane = 0; args->mipMapLevel = 0; args->proxyScale = RenderScale(1.); args->canonicalRoI = &roi; args->draftMode = false; args->playback = false; args->byPassCache = false; } TreeRenderPtr render = TreeRender::create(args); FrameViewRequestPtr outputRequest; ActionRetCodeEnum stat = render->launchRender(&outputRequest); if (isFailureRetCode(stat)) { return std::make_pair(ImagePtr(), roi); } ImagePtr sourceImage = outputRequest->getRequestedScaleImagePlane(); // Make sure the Natron image rendered is RGBA full rect and on CPU, we don't support other formats if (sourceImage->getStorageMode() != eStorageModeRAM) { Image::InitStorageArgs initArgs; initArgs.bounds = sourceImage->getBounds(); initArgs.plane = sourceImage->getLayer(); initArgs.bufferFormat = eImageBufferLayoutRGBAPackedFullRect; initArgs.storage = eStorageModeRAM; initArgs.bitdepth = sourceImage->getBitDepth(); ImagePtr tmpImage = Image::create(initArgs); if (!tmpImage) { return std::make_pair(ImagePtr(), roi); } Image::CopyPixelsArgs cpyArgs; cpyArgs.roi = initArgs.bounds; tmpImage->copyPixels(*sourceImage, cpyArgs); sourceImage = tmpImage; } return std::make_pair(sourceImage, roi); } // TrackMarker::getMarkerImage
void PeerData::updateUserpic( PhotoId photoId, const MTPFileLocation &location) { const auto size = kUserpicSize; const auto loc = StorageImageLocation::FromMTP(size, size, location); const auto photo = loc.isNull() ? ImagePtr() : ImagePtr(loc); setUserpicChecked(photoId, loc, photo); }
ImagePtr TrackedStream::getChangingImage() { if(!mVideoSource) return ImagePtr(); if (!mImage) mImage = ImagePtr(new Image(this->getUid()+"_TrackedStreamHelper", mVideoSource->getVtkImageData(), this->getName()+"_TrackedStreamHelper")); return mImage; }
void BackgroundInner::gotWallpapers(const MTPVector<MTPWallPaper> &result) { App::WallPapers wallpapers; wallpapers.push_back(App::WallPaper(0, ImagePtr(st::msgBG0), ImagePtr(st::msgBG0))); const QVector<MTPWallPaper> &v(result.c_vector().v); for (int i = 0, l = v.size(); i < l; ++i) { const MTPWallPaper w(v.at(i)); switch (w.type()) { case mtpc_wallPaper: { const MTPDwallPaper &d(w.c_wallPaper()); const QVector<MTPPhotoSize> &sizes(d.vsizes.c_vector().v); const MTPPhotoSize *thumb = 0, *full = 0; int32 thumbLevel = -1, fullLevel = -1; for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) { char size = 0; int32 w = 0, h = 0; switch (j->type()) { case mtpc_photoSize: { const string &s(j->c_photoSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoSize().vw.v; h = j->c_photoSize().vh.v; } break; case mtpc_photoCachedSize: { const string &s(j->c_photoCachedSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoCachedSize().vw.v; h = j->c_photoCachedSize().vh.v; } break; } if (!size || !w || !h) continue; int32 newThumbLevel = qAbs((st::backgroundSize.width() * cIntRetinaFactor()) - w), newFullLevel = qAbs(2560 - w); if (thumbLevel < 0 || newThumbLevel < thumbLevel) { thumbLevel = newThumbLevel; thumb = &(*j); } if (fullLevel < 0 || newFullLevel < fullLevel) { fullLevel = newFullLevel; full = &(*j); } } if (thumb && full && full->type() != mtpc_photoSizeEmpty) { wallpapers.push_back(App::WallPaper(d.vid.v ? d.vid.v : INT_MAX, App::image(*thumb), App::image(*full))); } } break; case mtpc_wallPaperSolid: { const MTPDwallPaperSolid &d(w.c_wallPaperSolid()); } break; } } App::cSetServerBackgrounds(wallpapers); updateWallpapers(); }
void Texture::upload() { if (!_img) return; if (_img->isLoaded()) { const GLenum mode = _img->hasAlpha() ? GL_RGBA : GL_RGB; glTexImage2D(GL_TEXTURE_2D, 0, mode, _img->width(), _img->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, _img->data()); _img = ImagePtr(); _state = io::IOSTATE_LOADED; } else if (_img->isFailed()) { _state = io::IOSTATE_FAILED; _img = ImagePtr(); } }
ImagePtr Client::nextImage() { if (shared_mem_client_.initialized()) { ImagePtr img(new Image); // TODO if (shared_mem_client_.nextImage(*img)) return img; else return ImagePtr(); } image_ptr_ = 0; cb_queue_.callAvailable(); return ImagePtr(image_ptr_); }
void StickerSetInner::paintEvent(QPaintEvent *e) { QRect r(e->rect()); Painter p(this); if (_pack.isEmpty()) return; int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0); int32 from = qFloor(e->rect().top() / st::stickersSize.height()), to = qFloor(e->rect().bottom() / st::stickersSize.height()) + 1; for (int32 i = from; i < to; ++i) { for (int32 j = 0; j < StickerPanPerRow; ++j) { int32 index = i * StickerPanPerRow + j; if (index >= _pack.size()) break; DocumentData *doc = _pack.at(index); QPoint pos(st::stickerPanPadding + j * st::stickersSize.width(), i * st::stickersSize.height()); bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128)); if (goodThumb) { doc->thumb->load(); } else { bool already = !doc->already().isEmpty(), hasdata = !doc->data.isEmpty(); if (!doc->loader && doc->status != FileFailed && !already && !hasdata) { doc->save(QString()); } if (doc->sticker->img->isNull() && (already || hasdata)) { if (already) { doc->sticker->img = ImagePtr(doc->already()); } else { doc->sticker->img = ImagePtr(doc->data); } } } float64 coef = qMin((st::stickersSize.width() - st::msgRadius * 2) / float64(doc->dimensions.width()), (st::stickersSize.height() - st::msgRadius * 2) / float64(doc->dimensions.height())); if (coef > 1) coef = 1; int32 w = qRound(coef * doc->dimensions.width()), h = qRound(coef * doc->dimensions.height()); if (w < 1) w = 1; if (h < 1) h = 1; QPoint ppos = pos + QPoint((st::stickersSize.width() - w) / 2, (st::stickersSize.height() - h) / 2); if (goodThumb) { p.drawPixmapLeft(ppos, width(), doc->thumb->pix(w, h)); } else if (!doc->sticker->img->isNull()) { p.drawPixmapLeft(ppos, width(), doc->sticker->img->pix(w, h)); } } } p.fillRect(0, _bottom - st::stickersAddOrShare, width(), st::stickersAddOrShare, st::emojiPanHeaderBg->b); }
ImagePtr D3D9VideoBufferManager::CreateImage(int iWidth, int iHeight, FORMAT Format) { IDirect3DTexture9 * texture; HRESULT hr = D3DXCreateTexture(mD3D9Device, iWidth, iHeight, 1, 0, D3D9Mapping::GetD3DFormat(Format), D3DPOOL_SYSTEMMEM, &texture); D3DErrorExceptionFunction(D3DXCreateTexture, hr); IDirect3DSurface9 * surface; texture->GetSurfaceLevel(0, &surface); D3DSURFACE_DESC desc; surface->GetDesc(&desc); D3D9Image * image = new D3D9Image(); image->mWidth = desc.Width; image->mHeight = desc.Height; image->mSrcWidth = iWidth; image->mSrcHeight = iHeight; image->mFormat = D3D9Mapping::GetFormat(desc.Format); image->mMipmapLevel = texture->GetLevelCount(); image->mD3D9Texture = texture; surface->Release(); return ImagePtr(image); }
/** * \brief Combine image, mask and center into a color image */ ImagePtr VCurveFocusWork::combine(ImagePtr image, FWHMInfo& fwhminfo) { // first build the red channel from the mask Image<unsigned char> *red = dynamic_cast<Image<unsigned char> *>(&*fwhminfo.mask); if (NULL == red) { throw std::logic_error("internal error, mask has not 8bit pixel type"); } // then build the green channel from the original image Image<unsigned char> *green = FocusWork::green(image); ImagePtr greenptr(green); // create the blue image CrosshairAdapter<unsigned char> crosshair(image->size(), fwhminfo.maxpoint, 20); CircleAdapter<unsigned char> circle(image->size(), fwhminfo.center, fwhminfo.radius); MaxAdapter<unsigned char> blue(crosshair, circle); // now use a combination adapter to put all these images together // into a single color image CombinationAdapter<unsigned char> combinator(*red, *green, blue); Image<RGB<unsigned char> > *result = new Image<RGB<unsigned char> >(combinator); return ImagePtr(result); }
void VolumetricRep::setImage(ImagePtr image) { if (image==mImage) { return; } if (mImage) { mVolumeProperty->setImage(ImagePtr()); disconnect(mImage.get(), &Image::vtkImageDataChanged, this, &VolumetricRep::vtkImageDataChangedSlot); disconnect(mImage.get(), &Image::transformChanged, this, &VolumetricRep::transformChangedSlot); mMonitor.reset(); mMapper->SetInputData( (vtkImageData*)NULL ); } mImage = image; if (mImage) { connect(mImage.get(), &Image::vtkImageDataChanged, this, &VolumetricRep::vtkImageDataChangedSlot); connect(mImage.get(), &Image::transformChanged, this, &VolumetricRep::transformChangedSlot); mVolumeProperty->setImage(mImage); this->vtkImageDataChangedSlot(); mMonitor = ImageMapperMonitor::create(mVolume, mImage); } }
ImagePtr PixelStreamSynchronizer::getTileImage( const uint tileIndex ) const { if( !_updater ) return ImagePtr(); return _updater->getTileImage( tileIndex ); }
ImagePtr Image::copy() { vtkImageDataPtr baseImageDataCopy; if(mBaseImageData) { baseImageDataCopy = vtkImageDataPtr::New(); baseImageDataCopy->DeepCopy(mBaseImageData); } ImagePtr retval = ImagePtr(new Image(mUid, baseImageDataCopy, mName)); retval->mUnsigned = mUnsigned; retval->mModality = mModality; retval->mImageType = mImageType; retval->mMaxRGBIntensity = mMaxRGBIntensity; retval->mInterpolationType = mInterpolationType; retval->mImageLookupTable2D = mImageLookupTable2D; retval->mImageTransferFunctions3D = mImageTransferFunctions3D; retval->mInitialWindowWidth = mInitialWindowWidth; retval->mInitialWindowLevel = mInitialWindowLevel; //From cx::Data retval->mRegistrationStatus = mRegistrationStatus; retval->m_rMd_History = m_rMd_History; return retval; }
TexturePtr LightView::generateLightBubble(float centerFactor) { int bubbleRadius = 256; int centerRadius = bubbleRadius * centerFactor; int bubbleDiameter = bubbleRadius * 2; ImagePtr lightImage = ImagePtr(new Image(Size(bubbleDiameter, bubbleDiameter))); for(int x = 0; x < bubbleDiameter; x++) { for(int y = 0; y < bubbleDiameter; y++) { float radius = std::sqrt((bubbleRadius - x)*(bubbleRadius - x) + (bubbleRadius - y)*(bubbleRadius - y)); float intensity = stdext::clamp<float>((bubbleRadius - radius) / (float)(bubbleRadius - centerRadius), 0.0f, 1.0f); // light intensity varies inversely with the square of the distance intensity = intensity * intensity; uint8_t colorByte = intensity * 0xff; uint8_t pixel[4] = {colorByte,colorByte,colorByte,0xff}; lightImage->setPixel(x, y, pixel); } } TexturePtr tex = TexturePtr(new Texture(lightImage, true)); tex->setSmooth(true); return tex; }
/** Create object from file. * If file or file+.mhd exists, use this, * Otherwise assume input is split over several * files and try to load all mhdFile + i + ".mhd". * forall i. */ USFrameDataPtr USFrameData::create(QString inputFilename) { QFileInfo info(inputFilename); TimeKeeper timer; QString mhdSingleFile = info.absolutePath()+"/"+info.completeBaseName()+".mhd"; if (QFileInfo(mhdSingleFile).exists()) { vtkImageDataPtr image = MetaImageReader().loadVtkImageData(mhdSingleFile); // load from single file USFrameDataPtr retval = USFrameData::create(ImagePtr(new Image(mhdSingleFile, image))); retval->mName = QFileInfo(mhdSingleFile).completeBaseName(); timer.printElapsedms(QString("Loading single %1").arg(inputFilename)); return retval; } else { USFrameDataPtr retval(new USFrameData()); retval->mName = QFileInfo(inputFilename).completeBaseName(); retval->mImageContainer.reset(new cx::CachedImageDataContainer(inputFilename, -1)); retval->resetRemovedFrames(); return retval; } }
Texture::Texture(const ImagePtr& image, bool buildMipmaps) { m_id = 0; if(!setupSize(image->getSize(), buildMipmaps)) return; createTexture(); ImagePtr glImage = image; if(m_size != m_glSize) { glImage = ImagePtr(new Image(m_glSize, image->getBpp())); glImage->paste(image); } else glImage = image; bind(); if(buildMipmaps) { int level = 0; do { setupPixels(level++, glImage->getSize(), glImage->getPixelData(), glImage->getBpp()); } while(glImage->nextMipmap()); m_hasMipmaps = true; } else setupPixels(0, glImage->getSize(), glImage->getPixelData(), glImage->getBpp()); setupWrap(); setupFilters(); }
ImagePtr EglDisplay::getImage(EGLImageKHR img) const { emugl::Mutex::AutoLock mutex(m_lock); /* img is "key" in map<unsigned int, ImagePtr>. */ unsigned int hndl = SafeUIntFromPointer(img); ImagesHndlMap::const_iterator i( m_eglImages.find(hndl) ); return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL); }
void Image::save(const QString& basePath) { QString filename = basePath + "/Images/" + this->getUid() + ".mhd"; this->setFilename(QDir(basePath).relativeFilePath(filename)); ImagePtr self = ImagePtr(this, null_deleter()); MetaImageReader().saveImage(self, filename); }
void PeerData::clearUserpic() { const auto photoId = PhotoId(0); const auto loc = StorageImageLocation(); const auto photo = [&] { if (id == peerFromUser(ServiceUserId)) { auto image = Messenger::Instance().logoNoMargin().scaledToWidth( kUserpicSize, Qt::SmoothTransformation); auto pixmap = App::pixmapFromImageInPlace(std::move(image)); return _userpic ? _userpic : ImagePtr(std::move(pixmap), "PNG"); } return ImagePtr(); }(); setUserpicChecked(photoId, loc, photo); }
ImagePtr Image::create( int width, int height ) { ImagePtr img = ImagePtr( new Image() ); img->m_data = (unsigned char *)malloc( width*height*4*sizeof(char) ); img->m_width = width; img->m_height = height; return img; }
/** * \brief Refresh by creating a copy of the image, and updating the offset */ void RefreshingTracker::refresh(const ConstImageAdapter<double>& adapter, const Point offset) { _image = new Image<double>(adapter); debug(LOG_DEBUG, DEBUG_LOG, 0, "refreshing with image %s", _image->size().toString().c_str()); _imageptr = ImagePtr(_image); _offset = _offset + offset; _lastimagetime = Timer::gettime(); }
ImagePtr LoadImage(const std::string& name) { int width, height, comp; uint8_t* rawData = stbi_load(name.c_str(), &width, &height, &comp, STBI_rgb); if (!rawData) { printf("Failed to open image file %s - %s\n", name.c_str(), stbi_failure_reason()); // TODO : return default texture return ImagePtr(); } std::vector<uint8_t> data; data.assign(rawData, rawData + (width * height * comp)); stbi_image_free(rawData); return ImagePtr(new ImageData(data, width, height, comp)); }
void Result::createPhoto() { if (_photo) return; if (_thumb_url.isEmpty()) { QSize thumbsize = shrinkToKeepAspect(_width, _height, 100, 100); _thumb = ImagePtr(thumbsize.width(), thumbsize.height()); } else { _thumb = ImagePtr(_thumb_url, QSize(320, 320)); } // ImagePtr medium = ImagePtr(_content_url, QSize(320, 320)); QSize mediumsize = shrinkToKeepAspect(_width, _height, 320, 320); ImagePtr medium = ImagePtr(mediumsize.width(), mediumsize.height()); ImagePtr full = ImagePtr(_content_url, _width, _height); auto photoId = rand_value<PhotoId>(); _photo = App::photoSet(photoId, 0, 0, unixtime(), _thumb, medium, full); _photo->thumb = _thumb; }
/** * \brief Create a chart */ Chart::Chart(const SkyRectangle rectangle, const ImageSize& size) : _rectangle(rectangle), _size(size) { // create the image _image = new Image<double>(size); _imageptr = ImagePtr(_image); _image->fill(0); // add the metadata rectangle.addMetadata(*_image); }
ImagePtr EglDisplay::getImage(EGLImageKHR img) { android::Mutex::Autolock mutex(m_lock); /* img is "key" in map<unsigned int, ImagePtr>. In 64-bit the upper 32-bit should be all zero. Assert for that. */ uintptr_t hndlptr = (uintptr_t)img; unsigned int hndl = (unsigned int)hndlptr; assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr); ImagesHndlMap::iterator i( m_eglImages.find(hndl) ); return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL); }
ShadingWidget::ShadingWidget(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) : BaseWidget(parent, "shading_widget", "Shading"), mLayout(new QVBoxLayout(this)), mActiveData(activeData), mActiveImageProxy(ActiveImageProxyPtr()), mImage(ImagePtr()), mImagePropertiesWidget(ImageRenderPropertiesWidgetPtr()) { this->init(connectToActiveImage); }
TrackedStream::TrackedStream(const QString& uid, const QString& name, const ToolPtr &probe, const VideoSourcePtr &videosource) : Data(uid, name), mProbeTool(probe), mVideoSource(VideoSourcePtr()), mImage(ImagePtr()), mSpaceProvider(SpaceProviderPtr()) { if(mProbeTool) emit newTool(mProbeTool); setVideoSource(videosource); }
void Image::createThresholdPreviewLookupTable2D(const Eigen::Vector2d &threshold) { ImageDefaultTFGenerator tfGenerator(ImagePtr(this, null_deleter())); ColorMap colors = this->createPreviewColorMap(threshold); mTresholdPreviewLookupTable2D = tfGenerator.generate2DTFPreset(); mTresholdPreviewLookupTable2D->resetColor(colors); mTresholdPreviewLookupTable2D->setLLR(threshold[0]); }
void Texture::load() { glGenTextures(1, &_textureHandle); glBindTexture(GL_TEXTURE_2D, _textureHandle); static const int empty = 0x00000000; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &empty); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); _img = ImagePtr(new Image(_filename)); _img->loadAsync(); }
ImagePtr ImageManager::getPtr(ResourceHandle handle) { ImageHandleMapConstIterator it = m_imgHandleMap.find(handle); if (it != m_imgHandleMap.end()) { return it->second; } FL_WARN(_log, LMsg("ImageManager::getPtr(ResourceHandle) - ") << "Resource handle " << handle << " is undefined."); return ImagePtr(); }