QImage BitBltRecord::image() { return m_bitmap->image(); #if 0 if ( ! hasImage() ) { return 0; } if ( m_image != 0 ) { return m_image; } QImage::Format format = QImage::Format_Invalid; if ( m_BmiSrc->bitCount() == BI_BITCOUNT_4 ) { if ( m_BmiSrc->compression() == 0x00 ) { format = QImage::Format_RGB555; } else { kDebug(33100) << "Unexpected compression format for BI_BITCOUNT_4:" << m_BmiSrc->compression(); Q_ASSERT( 0 ); } } else if ( m_BmiSrc->bitCount() == BI_BITCOUNT_5 ) { format = QImage::Format_RGB888; } else { kDebug(33100) << "Unexpected format:" << m_BmiSrc->bitCount(); Q_ASSERT( 0 ); } m_image = new QImage( (const uchar*)m_imageData.constData(), m_BmiSrc->width(), m_BmiSrc->height(), format ); return m_image; #endif }
void FrameEditor::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::SmoothPixmapTransform, false); painter.setRenderHint(QPainter::Antialiasing, false); // If we don't have an image, show an empty view if (!hasImage()) { painter.fillRect(0, 0, this->width(), this->height(), COLOR_CLEAR); return; } // Draw the image and tool preview painter.drawImage(QRect(0, 0, frameData.width()*pixelScale+.5, frameData.height()*pixelScale), frameData); if (!instrument.isNull() && instrument->hasPreview()) painter.drawImage(QRect(0, 0, frameData.width()*pixelScale+.5, frameData.height()*pixelScale), (instrument->getPreview())); if (pixelScale >= GRID_MIN_Y_SCALE) painter.drawImage(0, 0, gridPattern); // TODO: How to do this more generically? // if(deviceModel->showPlaybackIndicator()) { if (!fixture.isNull() && showPlaybackIndicator) { // int playbackRow = deviceModel->getFrameIndex(); // const float outputScale = deviceModel->getDisplaySize().width()*xScale; int playbackRow = frameIndex; int fixtureWidth = fixture->getSize().width(); int fixtureHeight = fixture->getSize().height(); // Draw the playback indicator // Note that we need to compute the correct width based on the rounding error of // the current cell, otherwise it won't line up correctly with the actual image. painter.setPen(COLOR_PLAYBACK_EDGE); painter.drawRect(playbackRow*pixelScale +.5, 0, int((playbackRow+fixtureWidth)*pixelScale +.5) - int(playbackRow*pixelScale +.5), fixtureHeight*pixelScale); painter.fillRect(playbackRow*pixelScale +.5, 0, int((playbackRow+fixtureWidth)*pixelScale +.5) - int(playbackRow*pixelScale +.5), fixtureHeight*pixelScale, COLOR_PLAYBACK_TOP); painter.drawRect((playbackRow-frameData.width())*pixelScale +.5, 0, int((playbackRow+fixtureWidth)*pixelScale +.5) - int(playbackRow*pixelScale +.5), fixtureHeight*pixelScale); painter.fillRect((playbackRow-frameData.width())*pixelScale +.5, 0, int((playbackRow+fixtureWidth)*pixelScale +.5) - int(playbackRow*pixelScale +.5), fixtureHeight*pixelScale, COLOR_PLAYBACK_TOP); } }
void Txtr::loadAlpha(const fschar *fileName, gl_ubyte defaultAlpha, bool initialize) { dAssert(isConsistent()); dAssert(!hasImage() || !initialize); gl_uint w; gl_uint h; Pixel3 *colorPixels = loadFile(fileName, &w, &h); if (colorPixels) { if (initialize) { width = w; height = h; pixels = new Pixel4[w*h]; } if ((w == width) && (h == height)) { for(uint i=0; i<width*height; ++i) { //pixels[i].a = static_cast<GLubyte>(colorPixels[i].getBWColor() / 3); pixels[i].a = colorPixels[i].getBWColor(); } } else { for(uint i=0; i<width*height; ++i) { pixels[i].a = defaultAlpha; } } delete[] colorPixels; } }
void CoverWidget::dropEvent(QDropEvent *e) { auto mimeData = e->mimeData(); QImage img; if (mimeData->hasImage()) { img = qvariant_cast<QImage>(mimeData->imageData()); } else { auto urls = mimeData->urls(); if (urls.size() == 1) { auto &url = urls.at(0); if (url.isLocalFile()) { img = App::readImage(Platform::File::UrlToLocal(url)); } } } if (!_dropArea->hiding()) { _dropArea->hideAnimated([this](Profile::CoverDropArea *area) { dropAreaHidden(area); }); } e->acceptProposedAction(); showSetPhotoBox(img); App::wnd()->activateWindow(); }
void FrameEditor::mouseMoveEvent(QMouseEvent *event) { if (!hasImage() || instrument.isNull()) return; // Ignore the update request if it came too quickly static intervalFilter rateLimiter(MIN_MOUSE_INTERVAL); if(!rateLimiter.check()) return; static int oldX = -1; static int oldY = -1; Q_UNUSED(oldX); Q_UNUSED(oldY); int x = event->x()/pixelScale; int y = event->y()/pixelScale; // If the position hasn't changed, don't do anything. // This is to avoid expensive reprocessing of the tool preview window. if (x == oldX && y == oldY) return; oldX = x; oldY = y; instrument->mouseMoveEvent(event, *this, QPoint(x, y)); lazyUpdate(); }
void Txtr::loadColors(const fschar *fileName, bool initialize) { dAssert(isConsistent()); dAssert(!hasImage() || !initialize); gl_uint w; gl_uint h; Pixel3 *colorPixels = loadFile(fileName, &w, &h); //Pixel3 *colorPixels = loadFile(fileName, &height, &width); if (colorPixels) { if (initialize) { width = w; height = h; } if ((w == width) && (h == height)) { uint size = width*height; pixels = new Pixel4[size]; for(uint i=0; i<size; ++i) { pixels[i].r = colorPixels[i].r; pixels[i].g = colorPixels[i].g; pixels[i].b = colorPixels[i].b; } } delete[] colorPixels; } }
void Txtr::load(const fschar *colorsFileName, const fschar *alphaFileName) { removeImage(); if (colorsFileName) loadColors(colorsFileName); if (alphaFileName && hasImage()) loadAlpha(alphaFileName, 255); else setAlpha(255); }
void FrameEditor::setFrameData(int index, const QImage data) { // Don't update if we are currently in a draw operation if(!instrument.isNull() && instrument->hasPreview()) return; if (data.isNull()) { frameData = data; frameIndex = index; this->setBaseSize(1, 1); update(); return; } // TODO: Unclear logic bool updateSize = (!hasImage() || (data.size() != frameData.size())); frameData = data; frameIndex = index; if (updateSize) { updateGridSize(); // Compute a new viewport size, based on the current viewport height float scale = float(size().height())/data.size().height(); this->setMinimumWidth(data.size().width()*scale); } // and force a screen update update(); }
void Keyframe::setImage( const Image& img ) { if( !hasImage() ){ _img = new Image( img ); } else { *_img = img; } }
void FrameEditor::dragEnterEvent(QDragEnterEvent *event) { if (!hasImage()) return; if (event->mimeData()->hasUrls()) event->acceptProposedAction(); }
void FrameEditor::mousePressEvent(QMouseEvent *event) { if (!hasImage() || instrument.isNull()) return; setCursor(instrument->cursor()); instrument->mousePressEvent(event, *this, QPoint(event->x()/pixelScale, event->y()/pixelScale)); lazyUpdate(); }
void FrameEditor::mouseReleaseEvent(QMouseEvent *event) { setCursor(Qt::ArrowCursor); if (!hasImage() || instrument.isNull()) return; instrument->mouseReleaseEvent(event, *this, QPoint(event->x()/pixelScale, event->y()/pixelScale)); lazyUpdate(); }
/** * @brief haven't done yet */ void MainWindow::dragEnterEvent(QDragEnterEvent *event) { qDebug()<<"drag enter event"; auto data = event->mimeData(); qDebug()<<"has image : "<<data->hasImage(); qDebug()<<"has text : "<<data->hasText(); qDebug()<<"has urls : "<<data->hasUrls(); //if (event->mimeData()->hasImage()){ event->acceptProposedAction(); //} }
LLViewerImage* LLViewerImageList::getImageFromFile(const std::string& filename, BOOL usemipmaps, BOOL level_immediate, LLGLint internal_format, LLGLenum primary_format, const LLUUID& force_id) { if (gNoRender) { // Never mind that this ignores image_set_id; // getImage() will handle that later. return getImage(IMG_DEFAULT, TRUE, TRUE); } std::string full_path = gDirUtilp->findSkinnedFilename("textures", filename); if (full_path.empty()) { llwarns << "Failed to find local image file: " << filename << llendl; return getImage(IMG_DEFAULT, TRUE, TRUE); } // generate UUID based on hash of filename LLUUID new_id; if (force_id.notNull()) { new_id = force_id; } else { new_id.generate(full_path); } LLPointer<LLViewerImage> imagep = hasImage(new_id); if (imagep.isNull()) { imagep = new LLViewerImage(full_path, new_id, usemipmaps); if (internal_format && primary_format) { imagep->setExplicitFormat(internal_format, primary_format); } addImage(imagep); if (level_immediate) { imagep->dontDiscard(); imagep->setBoostLevel(LLViewerImage::BOOST_UI); } } return imagep; }
XMLNode* Keyframe::serialize() const { XMLElement* node = new XMLElement( "Keyframe" ); String kfId; kfId.sprintf( "%d", _id ); XMLAttribute* attr = new XMLAttribute( "id", kfId ); node->addChild( attr ); XMLElement* element; // the pose: element = new XMLElement( "Pose" ); Matrix4d mat; EigenBridge::toCVT( mat, _pose.transformation() ); element->addChild( new XMLText( mat.toString() ) ); node->addChild( element ); if( hasImage() ){ if( !FileSystem::exists( "keyframe_images" ) ){ FileSystem::mkdir( "keyframe_images" ); } String filename; filename.sprintf( "keyframe_images/keyframe_%06d.cvtraw", _id ); _img->save( filename ); element = new XMLElement( "Image" ); element->addChild( new XMLAttribute( "file", filename ) ); node->addChild( element ); } // measurements: XMLElement* meas = new XMLElement( "Measurements" ); MeasurementIterator it = _featMeas.begin(); const MeasurementIterator itEnd = _featMeas.end(); XMLAttribute* featId; String val; while( it != itEnd ){ element = new XMLElement( "Measurement" ); // the id: val.sprintf( "%d", it->first ); featId = new XMLAttribute( "featureId", val ); element->addChild( featId ); element->addChild( it->second.serialize() ); meas->addChild( element ); ++it; } node->addChild( meas ); return node; }
void Txtr::duplicateRectangleEdges(int x, int y, int width, int height) { if ( ! hasImage()) return; restrain<int>(x, 0, this->width-1); restrain<int>(y, 0, this->height-1); restrain<int>(width, 1, this->width-x); restrain<int>(height, 1, this->height-y); dAssert((x >= 0) && (y >= 0)); int leftSpace = x; int bottomSpace = y; int rightSpace = this->width - (x+width); int topSpace = this->height - (y+height); // duplicate in four directions duplicateColumn(x, y, height, -1, leftSpace); // left area duplicateColumn(x+width-1, y, height, 1, rightSpace); // right area duplicateRow(x, y, width, -1, bottomSpace); // bottom area duplicateRow(x, y+height-1, width, 1, topSpace); // bottom area //selectAndDuplicate(x, y, 0, 1, height, -1, 0, leftSpace); // left area //selectAndDuplicate(x, y, 1, 0, width, 0, -1, bottomSpace); // bottom area //selectAndDuplicate(x+width, y+height, 0, -1, height, 1, 0, rightSpace); // right area //selectAndDuplicate(x+width, y+height, -1, 0, width, 0, 1, topSpace); // top area //// duplicate the duplicates into the corners //selectAndDuplicate(x, y, 0, -1, bottomSpace, -1, -1, leftSpace); // left bottom down //selectAndDuplicate(x, y, -1, 0, leftSpace, -1, -1, leftSpace); // left bottom left //selectAndDuplicate(x, y+height, -1, 0, leftSpace, -1, 1, leftSpace); // left top left //selectAndDuplicate(x, y+height, 0, 1, topSpace, -1, 1, leftSpace); // left top up //selectAndDuplicate(x+width, y+height, 0, 1, topSpace, 1, 1, rightSpace); // right top up //selectAndDuplicate(x+width, y+height, 1, 0, rightSpace, 1, 1, rightSpace); // right top right //selectAndDuplicate(x+width, y, 1, 0, rightSpace, 1, -1, rightSpace); // right bottom right //selectAndDuplicate(x+width, y, 0, -1, bottomSpace, 1, -1, rightSpace); // right bottom down // fill corners fillArea(0, 0, leftSpace, bottomSpace, getPixel(x, y)); // left bottom fillArea(0, y+height, leftSpace, topSpace, getPixel(x, y+height-1)); // top left fillArea(x+width, y+height, rightSpace, topSpace, getPixel(x+width-1, y+height-1)); // top right fillArea(x+width, 0, rightSpace, bottomSpace, getPixel(x+width-1, y)); // right bottom }
bool Txtr::removeImage() { dAssert(isConsistent()); if (hasImage()) { delete[] pixels; pixels = nullptr; width = 0; height = 0; return true; } return false; }
LLViewerImage* LLViewerImageList::getImageFromUrl(const std::string& url, BOOL usemipmaps, BOOL level_immediate, LLGLint internal_format, LLGLenum primary_format, const LLUUID& force_id) { if (gNoRender) { // Never mind that this ignores image_set_id; // getImage() will handle that later. return getImage(IMG_DEFAULT, TRUE, TRUE); } // generate UUID based on hash of filename LLUUID new_id; if (force_id.notNull()) { new_id = force_id; } else { new_id.generate(url); } LLPointer<LLViewerImage> imagep = hasImage(new_id); if (imagep.isNull()) { imagep = new LLViewerImage(url, new_id, usemipmaps); if (internal_format && primary_format) { imagep->setExplicitFormat(internal_format, primary_format); } addImage(imagep); if (level_immediate) { imagep->dontDiscard(); imagep->setBoostLevel(LLViewerImageBoostLevel::BOOST_UI); } } imagep->setGLTextureCreated(true); return imagep; }
LLViewerImage* LLViewerImageList::getImage(const LLUUID &image_id, BOOL usemipmaps, BOOL level_immediate, LLGLint internal_format, LLGLenum primary_format, LLHost request_from_host) { // Return the image with ID image_id // If the image is not found, creates new image and // enqueues a request for transmission if ((&image_id == NULL) || image_id.isNull()) { return (getImage(IMG_DEFAULT, TRUE, TRUE)); } LLPointer<LLViewerImage> imagep = hasImage(image_id); if (imagep.isNull()) { imagep = new LLViewerImage(image_id, request_from_host, usemipmaps); if (internal_format && primary_format) { imagep->setExplicitFormat(internal_format, primary_format); } addImage(imagep); if (level_immediate) { imagep->dontDiscard(); imagep->setBoostLevel(LLViewerImageBoostLevel::BOOST_UI); } else { //by default, the texure can not be removed from memory even if it is not used. //here turn this off //if this texture should be set to NO_DELETE, either pass level_immediate == TRUE here, or call setNoDelete() afterwards. imagep->forceActive() ; } } imagep->setGLTextureCreated(true); return imagep; }
void FrameEditor::updateGridSize() { if (!hasImage()) return; // Update the widget geometry so that it can be resized correctly this->setBaseSize(frameData.size()); // Base the widget size on the window height // cast float to int to save rounded scale QSize frameSize = frameData.size(); // TODO Why? pixelScale = static_cast<int>(float(size().height() - 1)/frameSize.height()*10); pixelScale /= 10; // If the drawing space is large enough, make a grid pattern to superimpose over the image if (pixelScale >= GRID_MIN_Y_SCALE) { gridPattern = QImage(frameSize.width()*pixelScale +.5 + 1, frameSize.height()*pixelScale +.5 + 1, QImage::Format_ARGB32_Premultiplied); gridPattern.fill(COLOR_CLEAR); QPainter painter(&gridPattern); painter.setRenderHint(QPainter::SmoothPixmapTransform, false); painter.setRenderHint(QPainter::Antialiasing, false); // Draw vertical lines painter.setPen(COLOR_GRID_LINES); for (int x = 0; x <= frameSize.width(); x++) { painter.drawLine(x*pixelScale+.5, 0, x*pixelScale+.5, gridPattern.height()); } // Draw horizontal lines for (int y = 0; y <= frameSize.height(); y++) { painter.drawLine(0, y*pixelScale+.5, gridPattern.width(), y*pixelScale+.5); } } }
bool Txtr::createImage(gl_uint w, gl_uint h) { bool hadImage = hasImage(); if (hadImage) removeImage(); if ((w == 0) || (h == 0)) { dAssert((w == 0) && (h == 0)); } else { this->width = w; this->height = h; pixels = new Pixel4[w * h]; } return !hadImage; }
void LLViewerImageList::addImage(LLViewerImage *new_image) { if (!new_image) { llwarning("No image to add to image list", 0); return; } LLUUID image_id = new_image->getID(); LLViewerImage *image = hasImage(image_id); if (image) { llwarns << "Image with ID " << image_id << " already in list" << llendl; } sNumImages++; addImageToList(new_image); mUUIDMap[image_id] = new_image; }
const TexturePtr& UINode::setImage (const std::string& texture) { _texture = loadTexture(texture); if (!hasImage()) return _texture; float w = getWidth(); if (w <= 0.0f) { w = getAutoWidth(); } float h = getHeight(); if (h <= 0.0f) { h = getAutoHeight(); } setSize(w, h); updateAlignment(); return _texture; }
LLViewerImage* LLViewerImageList::getImage(const LLUUID &image_id, BOOL usemipmaps, BOOL level_immediate, LLGLint internal_format, LLGLenum primary_format, LLHost request_from_host) { // Return the image with ID image_id // If the image is not found, creates new image and // enqueues a request for transmission if ((&image_id == NULL) || image_id.isNull()) { return (getImage(IMG_DEFAULT, TRUE, TRUE)); } LLPointer<LLViewerImage> imagep = hasImage(image_id); if (imagep.isNull()) { imagep = new LLViewerImage(image_id, usemipmaps); // Might want to request from host other than where the agent is. JC imagep->setTargetHost(request_from_host); if (internal_format && primary_format) { imagep->setExplicitFormat(internal_format, primary_format); } addImage(imagep); if (level_immediate) { imagep->dontDiscard(); imagep->setBoostLevel(LLViewerImage::BOOST_UI); } } return imagep; }
void CoverWidget::dropEvent(QDropEvent *e) { auto mimeData = e->mimeData(); QImage img; if (mimeData->hasImage()) { img = qvariant_cast<QImage>(mimeData->imageData()); } else { const auto &urls = mimeData->urls(); if (urls.size() == 1) { auto &url = urls.at(0); if (url.isLocalFile()) { img = App::readImage(psConvertFileUrl(url)); } } } if (!_dropArea->hiding()) { _dropArea->hideAnimated(func(this, &CoverWidget::dropAreaHidden)); } e->acceptProposedAction(); showSetPhotoBox(img); }
gl_uint Txtr::add(RenderContext *renderContext, const fschar *name) { dAssert(isConsistent()); fsstring nameStr(name); gl_uint txtrId; // result variable std::map<fsstring, gl_uint>::iterator it = txtrIdPool.find(nameStr); if (it == txtrIdPool.end()) { if (hasImage()) { // Create an enlarged texture if necessary gl_uint width2 = width; gl_uint height2 = height; Txtr *enlargedTxtr = nullptr; Vecd txtrCoordRescale; if ( ! renderContext->hasFeature(RenderContext::FEATURE_TEXTURE_NON_POWER_OF_TWO_AVAILIBLE)) { bool wRes = conformSizeValue(width2); bool hRes = conformSizeValue(height2); if (wRes || hRes) { enlargedTxtr = new Txtr(width2, height2); copyTo(enlargedTxtr, 0, 0, true); //enlargedTxtr->duplicateRectangleEdges(0, 0, width, height); txtrCoordRescale.x = static_cast<double>(width) / static_cast<double>(width2); txtrCoordRescale.y = static_cast<double>(height) / static_cast<double>(height2); } } Txtr *txtrToLoad = enlargedTxtr ? enlargedTxtr : this; txtrId = renderContext->loadTxtr(txtrToLoad->getPixels(), width2, height2); if (enlargedTxtr) { delete enlargedTxtr; txtrRescaleMap[txtrId] = txtrCoordRescale; } } else { txtrId = defaultTxtr; } // add to pool txtrIdPool[nameStr] = txtrId; } else { // get from pool txtrId = it->second; } //if (hasImage()) //{ // std::map<std::wstring, GLuint>::iterator it = txtrIdPool.find(std::wstring(name)); // if (it == txtrIdPool.end()) // { // glGenTextures(1, &txtrId); // glBindTexture(GL_TEXTURE_2D, txtrId); // glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)pixels); // // // Perform these here? // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // // add to pool // txtrIdPool[std::wstring(name)] = txtrId; // } // else // { // // get from pool // txtrId = it->second; // } //} //else //{ // txtrId = defaultTxtr; // // add to pool // txtrIdPool[std::wstring(name)] = txtrId; //} return txtrId; }