bool RGLView::snapshot(PixmapFileFormatID formatID, const char* filename) { bool success = false; if ( (formatID < PIXMAP_FILEFORMAT_LAST) && (pixmapFormat[formatID]) && windowImpl->beginGL() ) { // alloc pixmap memory Pixmap snapshot; snapshot.init(RGB24, width, height, 8); // read front buffer glPushAttrib(GL_PIXEL_MODE_BIT); glReadBuffer(GL_FRONT); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0,width,height,GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) snapshot.data); glPopAttrib(); success = snapshot.save( pixmapFormat[formatID], filename ); windowImpl->endGL(); } return success; }
void gtprintf(const Font& fnt, const Pixmap& texture, char *fmt, ...) { va_list ap; uint32 x, y; int len; char ch; Pixmap *glyph; va_start(ap, fmt); vsprintf(gtBuffer, fmt, ap); va_end(ap); len = strlen(gtBuffer); for(int i = 0; i < len; i++) { ch = gtBuffer[i]; if(ch == '\n') gtY += fnt.nl_height; else if(ch == '\r') gtX = 0; else { glyph = fnt.find_glyph(ch); glyph->draw(gtX, gtY); gtX += glyph->width(); if(gtX > 799) { gtX = 0; gtY += fnt.nl_height; } } } }
Pixmap::Pixmap(const Pixmap& other) { m_width= other.width(); m_height = other.height(); m_depth = other.depth(); m_bitmap = new U8[m_width * m_height * m_depth]; memcpy(m_bitmap, other.const_data(), m_width * m_height * m_depth); }
void Texture::draw (Pixmap& pixmap,int x,int y) { if (data->isManaged()) { gdx_cpp::Gdx::app->error(__FILE__ , "can't draw to a managed texture"); } Gdx::gl->glBindTexture(GL_TEXTURE_2D, glHandle); Gdx::gl->glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), pixmap.getGLType(), (const unsigned char*) pixmap.getPixels()); }
void Sprite::sp_draw() { Pixmap *pix = this->_sprite_pixmap; if (pix) { int sx, sy; pix->getframe(this->_sprite_frame, sx, sy); pix->blit(this->_sprite_x, this->_sprite_y, this->_sprite_w, this->_sprite_h, sx, sy); } }
void Pixmap::copy_rect_to( const Rect& p_src_rect,Pixmap &p_pixmap,const Point& p_dst_pos ) const { if (!_pp || !_pp->pixmap->is_valid()) return; if (!p_pixmap._pp || !p_pixmap._pp->pixmap->is_valid()) return; p_pixmap.copy_on_write(); _pp->pixmap->copy_rect_to( p_src_rect, p_pixmap.get_platform_pixmap(), p_dst_pos ); }
void ImageLoader::loadImage(Texture *texture, Pixmap &image) { std::string ext = texture->getFile()->getExt(); ByteBufferPtr buf = texture->getFile()->read(); if (ext == "png") { image.loadPNG(buf->getData(), buf->getSize()); } else { image.loadJPEG(buf->getData(), buf->getSize()); } }
slideShowEngine::AnimationState slideShowEngine::applyAnimation() { effect e; QEasingCurve curve; qreal currentValue; Pixmap *item; if(m_currentStep==EnterAnimation) e=m_currentNode.enterEffect(); else if(m_currentStep==DisplayAnimation) e=m_currentNode.displayEffect(); else if(m_currentStep==ExitAnimation) e=m_currentNode.exitEffect(); int duration=e.duration(); //int elapsed=m_stepCurrentTime; curve.setPeriod(duration); qreal startVal=qreal(e.startValue()); qreal endVal=qreal(e.endValue()); curve.setType(e.easingCurve()); //qreal valore=qreal(m_stepCurrentTime*TIMER_ANIMATION); qreal valore=qreal(m_stepCurrentTime); //qreal valore=qreal(m_stepCurrentTime*10); valore=valore/(qreal(duration)); //valore=valore/10; //currentValue=curve.valueForProgress(valore); currentValue=endVal+(1.0-curve.valueForProgress(valore))*(startVal-endVal); item=m_PixmapList[m_currentSlideIndex]; if(e.effectType()=="pos") item->setProperty(e.effectType().toLatin1(),QVariant(QPointF(currentValue,0))); else item->setProperty(e.effectType().toLatin1(),QVariant(currentValue)); //if(m_stepCurrentTime*TIMER_ANIMATION < e.duration()/**10*/) if(m_stepCurrentTime < duration) //if(m_stepCurrentTime*10 < e.duration()/**10*/) return RunningAnimation; else return EndAnimation; }
void TextureManager::loadTextures() { for (auto pair : this->registeredTextures) { Texture::ptr& texture = pair.second; if (texture->getGlID() != 0) { continue; } Pixmap image; this->loader->loadImage(texture.get(), image); texture->setSize(image.getWidth(), image.getHeight()); textureUtil.UploadTextureToHardware(image, *texture); } }
Pixmap* FileTextureData::ensurePot(Pixmap* pixmap) { if(!Gdx.isGL20Available() && copyToPOT) { int pixmapWidth = pixmap->getWidth(); int pixmapHeight = pixmap->getHeight(); int potWidth = MathUtils::nextPowerOfTwo(pixmapWidth); int potHeight = MathUtils::nextPowerOfTwo(pixmapHeight); if(pixmapWidth != potWidth || pixmapHeight != potHeight) { Pixmap* tmp = new Pixmap(potWidth, potHeight, pixmap->getFormat()); tmp->drawPixmap(pixmap, 0, 0, 0, 0, pixmapWidth, pixmapHeight); pixmap->dispose(); delete pixmap; return tmp; } } return pixmap; }
int xortex(Pixmap &map, const unsigned int width, const unsigned int height) { if (!width || !height) return 1; if(map.init(width, height)) return 2; for(unsigned int j = 0; j < map.height(); j++) { for(unsigned int i = 0; i < map.width(); i++) { scalar_t val = (scalar_t)(i ^ j) / 255.0f; ColorRGBAf &pixel = map.pixel(i, j); pixel.r(val); pixel.g(val); pixel.b(val); pixel.a(1.0f); } } return 0; }
int ppm_raw(const char *filename, const Pixmap &fb) { if (!filename) return 1; if (!fb.width() || !fb.height()) return 3; FILE *fp = fopen(filename, "wb"); if (fp == NULL) return 2; // Write the header. fprintf(fp, "P6\n%d %d\n255\n", fb.width(), fb.height()); // Write the pixel data. for (unsigned int j = 0; j < fb.height(); j++) { for (unsigned int i = 0; i < fb.width(); i++) { const ColorRGBAf &pixel = fb.pixel_ro(i, j); // Do some basic tone mapping. scalar_t fmax = 0.0f; fmax = pixel.r() > fmax ? pixel.r() : fmax; fmax = pixel.g() > fmax ? pixel.g() : fmax; fmax = pixel.b() > fmax ? pixel.b() : fmax; scalar_t scale = 1.f; if (fmax > 1.f) { scale = 1.f / fmax; } // Write the pixel. fputc((char)(pixel.r() * scale * 255.0f), fp); fputc((char)(pixel.g() * scale * 255.0f), fp); fputc((char)(pixel.b() * scale * 255.0f), fp); // Check for errors if (ferror(fp)) { fclose(fp); return 2; } } } fclose(fp); return 0; }
void CompressedPixmap::applyIFS(Pixmap& pixmap, float ratio) { std::vector<Pixmap*> domainRegions; for (unsigned int i = 0; i < m_domainRegions.size(); ++i) domainRegions.push_back(pixmap.extract((int)(m_domainRegions[i].x * ratio), (int)(m_domainRegions[i].y * ratio), (int)(m_domainRegions[i].size * ratio))); //We store each transformation std::map<unsigned short, std::map<unsigned char, Pixmap*>> transformations; for (const RangeRegionDescriptor& rangeRegion : m_rangeRegions) { int newSize = (int)(rangeRegion.size * ratio); int newX = (int)(rangeRegion.x * ratio); int newY = (int)(rangeRegion.y * ratio); Pixmap* domainInUse; //If this domainRegion has not been used already if (!transformations.count(rangeRegion.domainRegionIndex)) { domainInUse = domainRegions[rangeRegion.domainRegionIndex]->downscale(newSize); transformations[rangeRegion.domainRegionIndex][0] = domainInUse; } else domainInUse = transformations[rangeRegion.domainRegionIndex][0]; //If it is a true transformation if (rangeRegion.transformation != NO_ROTATION) { //If it hasn't already been done if (!transformations[rangeRegion.domainRegionIndex].count(rangeRegion.transformation)) { domainInUse = domainInUse->applyTransformation(rangeRegion.transformation); transformations[rangeRegion.domainRegionIndex][rangeRegion.transformation] = domainInUse; } else domainInUse = transformations[rangeRegion.domainRegionIndex][rangeRegion.transformation]; } //Then copy to range region for (int x = 0; x < newSize; ++x) { for (int y = 0; y < newSize; ++y) { pixmap.set(newX + x, newY + y, domainInUse->get(x, y)); } } //Set first pixel value if (rangeRegion.x % 4 == 0 && rangeRegion.y % 4 == 0) pixmap.set(newX, newY, rangeRegion.firstPixelValue); } std::cout << transformations.size() * 100 / domainRegions.size() << std::endl; for (const Pixmap* domainRegion : domainRegions) delete domainRegion; for (const std::pair<unsigned short, std::map<unsigned char, Pixmap*>>& transformedDomain : transformations) { for (const std::pair<unsigned char, Pixmap*>& transformationResult : transformedDomain.second) delete transformationResult.second; } }
static HCURSOR pixmapToCursor( const Pixmap& pinput, int hotSpotX, int hotSpotY ) { if( pinput.isEmpty() ) { return 0; } Pixmap pm = pinput; pm.setFormat( Pixmap::Format_RGBA ); ICONINFO iconInfo; ZeroMemory(&iconInfo, sizeof(iconInfo)); iconInfo.fIcon = false; iconInfo.xHotspot = hotSpotX; iconInfo.yHotspot = hotSpotY; HBITMAP hBitmap = 0; HBITMAP hMonoBitmap = CreateBitmap( pm.width(), pm.height(), 1,1, NULL); iconInfo.hbmMask = hMonoBitmap; { BITMAPV5HEADER bi; ZeroMemory(&bi,sizeof(BITMAPV5HEADER)); bi.bV5Size = sizeof(BITMAPV5HEADER); bi.bV5Width = pm.width(); bi.bV5Height = pm.height(); bi.bV5Planes = 1; bi.bV5BitCount = 32; bi.bV5Compression = BI_BITFIELDS; // The following mask specification specifies a supported 32 BPP // alpha format for Windows XP. bi.bV5RedMask = 0x00FF0000; bi.bV5GreenMask = 0x0000FF00; bi.bV5BlueMask = 0x000000FF; bi.bV5AlphaMask = 0xFF000000; HDC hdc = GetDC(NULL); uint8_t *lpBits; const uint8_t* input = pm.const_data(); hBitmap = CreateDIBSection( hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD)0 ); size_t bperRow = pm.width()*4; for( int i=0; i<pm.height(); ++i ){ memcpy( lpBits + bperRow*i, input + bperRow*(pm.height()-i-1), bperRow ); } size_t bsz = pm.width()*pm.height()*4; for( size_t i=0; i<bsz; i+=4 ){ uint8_t a = *(lpBits+i); *(lpBits+i) = *(lpBits+i+2); *(lpBits+i+2) = a; } iconInfo.hbmColor = hBitmap; } HICON hicon = CreateIconIndirect(&iconInfo); DeleteObject(hBitmap); DeleteObject(hMonoBitmap); return (HCURSOR)hicon; }
Texture2D::Texture2D(const Pixmap &pixmap) : Texture2D(pixmap.getData().data(), pixmap.getInformation()) {}
int ppm_raw(const char *filename, Pixmap &fb) { if (!filename) return 1; FILE* fp = fopen(filename, "rb"); if (fp == NULL) { fb.init(0, 0); return 5; } // Read the header. int c = 0; std::string header_token[4]; for (unsigned int tcount = 0; tcount < 4; tcount++) { for (;;) { while (isspace(c = getc(fp))); if (c != '#') break; do { c = getc(fp); } while (c != '\n' && c != EOF); if (c == EOF) break; } if (c != EOF) { do { header_token[tcount].append(1, c); c = getc(fp); } while (!isspace(c) && c != '#' && c != EOF); if (c == '#') ungetc(c, fp); } } if (header_token[0].compare("P6")) { fclose(fp); return 3; } int nx, ny, pm; if (sscanf(header_token[1].c_str(), "%d", &nx) != 1 || sscanf(header_token[2].c_str(), "%d", &ny) != 1 || sscanf(header_token[3].c_str(), "%d", &pm) != 1) { fclose(fp); return 3; } if (pm != 255) { fclose(fp); return 3; } if (fb.init(nx, ny)) { fclose(fp); return 5; } // Read the pixel data. for (unsigned int j = 0; j < fb.height(); j++) { for (unsigned int i = 0; i < fb.width(); i++) { unsigned char p[3]; if (fread(p, 1, 3, fp) != 3) { fclose(fp); return 4; } ColorRGBAf &pixel = fb.pixel(i, j); pixel.r((scalar_t)p[0] / 255.0f); pixel.g((scalar_t)p[1] / 255.0f); pixel.b((scalar_t)p[2] / 255.0f); pixel.a(1.0f); } } fclose(fp); return 0; }
slideShowEngine::State slideShowEngine::runEngine() { int ret,x,y; QPixmap pix; QModelIndex index; QVariant val; node itemNode; Pixmap *item; effect e; if(m_currentState!=Running) return m_currentState; ret=applyAnimation(); if(ret==EndAnimation) { //m_stepCurrentTime=0; if(step()==EnterAnimation) { setStep(DisplayAnimation); //m_timerAnimation.restart(); m_stepCurrentTime=0; //qDebug() << "enter->display"; } else { if(step()==DisplayAnimation) { setStep(ExitAnimation); //m_timerAnimation.restart(); m_stepCurrentTime=0; //qDebug() << "display->exit"; // if(m_showType==IN) // remove_old_items... if(m_currentSlideIndex+1<m_sequence->rowCount()) { index=m_sequence->index(m_currentSlideIndex+1); if(index.isValid()) { //if(m_showType==OUT) val=index.data(Qt::UserRole); itemNode=val.value<node>(); if(m_exportToMovie) { pix.load(itemNode.nodePath()); } else { pix=itemNode.nodePixmap(); } m_currentNode=itemNode; if(pix.width()>m_size.width() || pix.height()>m_size.height()) pix=pix.scaled(m_size,Qt::KeepAspectRatio,Qt::SmoothTransformation); item = new Pixmap(pix); if(m_exportToMovie) item->setTransformationMode(Qt::SmoothTransformation); m_PixmapList.append(item); // serve questa lista? if(m_size.width()>pix.width()) { x=(m_size.width()-pix.width())/2; } else { x=0; } if(m_size.height()>pix.height()) { y=(m_size.height()-pix.height())/2; } else { y=0; } item->setPos(qreal(x), qreal(y)); item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex-1)); m_scene->addItem(item); //applyAnimation(); } } else { qDebug()<<"index out of range"; } } else { if(step()==ExitAnimation) { item=m_PixmapList[m_currentSlideIndex]; m_scene->removeItem(item); m_currentSlideIndex++; if(m_currentSlideIndex<m_sequence->rowCount()) { /* index=m_sequence->index(m_currentSlideIndex); if(index.isValid()) { //if(m_showType==OUT) val=index.data(Qt::UserRole); itemNode=val.value<node>(); pix=itemNode.nodePixmap(); item = new Pixmap(pix); m_PixmapList.append(item); // serve questa lista? item->setPos(0.0, 0.0); //item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex)); m_scene->addItem(item); applyAnimation(); }*/ setStep(EnterAnimation); //m_timerAnimation.restart(); m_stepCurrentTime=0; } else { // end //endOfSlideShow(); return Finished; } } // if(step()==ExitAnimation) else { } // else if(step()==ExitAnimation) } // else if(step()==DisplayAnimation) } // else if(step()==EnterAnimation) } // if(ret==EndAnimation) //m_stepCurrentTime++; //m_totalCurrentTime++; if(m_exportToMovie) { QImage frame(m_size,QImage::Format_RGB32); QPainter p(&frame); m_scene->render(&p); p.end(); //QString frameName=QString("./tmp/f%1").arg(m_frame_number++); //frameName.append(".jpg"); //frame.save(frameName); //encoder.encodeImage(frame); QByteArray dati; QBuffer buffer(&dati); buffer.open(QIODevice::WriteOnly); frame.save(&buffer, "JPG"); m_ffmpegProcess.write(buffer.buffer()); m_ffmpegProcess.waitForBytesWritten(); //QString command; ////m_ffmpegProcess.start("/usr/bin/ffmpeg", QStringList() << "-y -f image2pipe -i pipe:.jpg -target ntsc-dvd my.mpg"); //command=QString("/usr/bin/ppmtoy4m -v 0 -n 1 -F 25:1 -S 420jpeg"); //m_ffmpegProcess.write(EOF); //command.append(" -F 25:1 -S 420jpeg "); //command.append(buffer.buffer()); //qDebug() << command; //dati=m_ffmpegProcess.readAllStandardOutput(); //m_ffmpegProcess.write(buffer.buffer()); //frame.save(m_ffmpegProcess); //m_ffmpegProcess << frameName; //ffmpeg -y -f image2pipe -i pipe:.jpg -target ntsc-dvd my.mpg } return Running; }
void PixmapCompressor::searchJob(const std::vector<SubPixmap>& rangeRegions, const std::vector<SubPixmap>& domainRegions, unsigned short start, unsigned short end, std::map<unsigned short, Result>& results, unsigned short& status) { status = 0; //For each domain region this thread must handle for (int i = start; i < end; ++i) { //Store every transformations for this domain region to avoid computing them several times Pixmap* transformationsResults[16]; transformationsResults[0] = domainRegions[i].pixmap->downscale(m_rangeRegionSize); transformationsResults[1] = transformationsResults[0]->applyTransformation(ROTATION_90); //ROTATION_90 = 1 transformationsResults[2] = transformationsResults[0]->applyTransformation(ROTATION_180); //ROTATION_180 = 2 transformationsResults[3] = transformationsResults[0]->applyTransformation(ROTATION_270); //ROTATION_270 = 3 transformationsResults[4] = transformationsResults[0]->applyTransformation(FLIP); //FLIP = 4 transformationsResults[5] = transformationsResults[4]->applyTransformation(ROTATION_90); //ROTATION_90 | FLIP = 5 transformationsResults[6] = transformationsResults[4]->applyTransformation(ROTATION_180); //ROTATION_90 | FLIP = 6 transformationsResults[7] = transformationsResults[4]->applyTransformation(ROTATION_270); //ROTATION_90 | FLIP = 7 transformationsResults[8] = transformationsResults[0]->applyTransformation(INVERT); //INVERT = 8 transformationsResults[9] = transformationsResults[8]->applyTransformation(ROTATION_90); //ROTATION_90 | INVERT = 9 transformationsResults[10] = transformationsResults[8]->applyTransformation(ROTATION_180); //ROTATION_180 | INVERT = 10 transformationsResults[11] = transformationsResults[8]->applyTransformation(ROTATION_270); //ROTATION_270 | INVERT = 11 transformationsResults[12] = transformationsResults[8]->applyTransformation(FLIP); //FLIP | INVERT = 12 transformationsResults[13] = transformationsResults[12]->applyTransformation(ROTATION_90); //ROTATION_90 | FLIP | INVERT = 13 transformationsResults[14] = transformationsResults[12]->applyTransformation(ROTATION_180); //ROTATION_180 | FLIP | INVERT = 14 transformationsResults[15] = transformationsResults[12]->applyTransformation(ROTATION_270); //ROTATION_270 | FLIP | INVERT = 15 //For each range region for (unsigned int r = 0; r < rangeRegions.size(); ++r) { auto& currentResult = results[r]; Pixmap* currentRegion = rangeRegions[r].pixmap; //For each transformation //If we already got a perfect match, skip for (int j = 0; currentResult.variance > 0 && j < 16; ++j) { unsigned short variance = currentRegion->computeVariance(*transformationsResults[j]); //We're looking for the minimum variance (best match) if (variance < currentResult.variance) { currentResult.variance = variance; currentResult.transformationId = j; currentResult.domainId = i; } } } //Clean stored transformations for (int j = 0; j < 16; ++j) delete transformationsResults[j]; ++status; } status = STATUS_DONE; }
void slideShowEngine::start() { int x,y; QPixmap pix; QModelIndex index; QVariant val; node itemNode; QPropertyAnimation *enterAnimation,*displayAnimation,*exitAnimation; Pixmap *item; effect e; QParallelAnimationGroup *parallelAnim; QSequentialAnimationGroup *seqAnim; if(m_groupAnimation->state()==QAbstractAnimation::Paused) resume(); if(m_groupAnimation->state()==QAbstractAnimation::Running) return; QList <QGraphicsView *> views=m_scene->views(); m_size=views.at(0)->size(); m_scene->clear(); for(int i=0;i<m_sequence->rowCount();i++) { index=m_sequence->index(i); if(index.isValid()) { m_scene->setSceneRect(0.0,0.0,qreal(m_size.width()),qreal(m_size.height())); // come fare per full screen size? qDebug() << "index valid"; val=index.data(Qt::UserRole); itemNode=val.value<node>(); qDebug() << "pix:" << itemNode.nodeName(); pix=itemNode.nodePixmap(); if(pix.width()>m_size.width() || pix.height()>m_size.height()) pix=pix.scaled(m_size,Qt::KeepAspectRatio,Qt::SmoothTransformation); item = new Pixmap(pix); m_PixmapList.append(item); // serve questa lista? if(m_size.width()>pix.width()) { x=(m_size.width()-pix.width())/2; } else { x=0; } if(m_size.height()>pix.height()) { y=(m_size.height()-pix.height())/2; } else { y=0; } item->setPos(qreal(x), qreal(y)); qDebug() <<qreal(m_sequence->rowCount()-i); item->setZValue(qreal(m_sequence->rowCount()-i)); //m_scene->addItem(item); e=itemNode.enterEffect(); enterAnimation = new QPropertyAnimation(item, e.effectType().toAscii()); itemNode.setEnterAnimation(enterAnimation,item); connect(enterAnimation,SIGNAL(finished()),this,SLOT(animEnterFinished())); e=itemNode.displayEffect(); displayAnimation = new QPropertyAnimation(item, e.effectType().toAscii()); itemNode.setDisplayAnimation(displayAnimation,item); connect(displayAnimation,SIGNAL(finished()),this,SLOT(animDisplayFinished())); e=itemNode.exitEffect(); exitAnimation = new QPropertyAnimation(item, e.effectType().toAscii()); itemNode.setExitAnimation(exitAnimation,item); connect(exitAnimation,SIGNAL(finished()),this,SLOT(animExitFinished())); //parallelAnim= new QParallelAnimationGroup; //parallelAnim->addAnimation(exitAnimation); seqAnim = new QSequentialAnimationGroup; seqAnim->addAnimation(enterAnimation); seqAnim->addAnimation(displayAnimation); seqAnim->addAnimation(exitAnimation); qDebug() << "add all animation"; m_groupAnimation->addAnimation(seqAnim); connect(m_groupAnimation,SIGNAL(finished()),this,SLOT(endOfSlideShow())); //group->addAnimation(animation4); } // end index is valid } // end for qDebug() << "start group"; m_currentSlideIndex=0; m_scene->addItem(m_PixmapList.at(m_currentSlideIndex)); m_groupAnimation->start(); //m_timerId=startTimer(2); //m_slideShowClock.restart(); int width=640; int height=480; int bitrate=1000000; int gop = 20; // Create the encoder //QVideoEncoder encoder; //encoder.createFile("test.avi",width,height,bitrate,gop); }
void slideShowEngine::start() { int x,y; QPixmap pix; QModelIndex index; QVariant val; node itemNode; //QPropertyAnimation *enterAnimation,*displayAnimation,*exitAnimation; Pixmap *item; effect e; //QParallelAnimationGroup *parallelAnim; //QSequentialAnimationGroup *seqAnim; if(state()==Paused) resume(); if(state()==Running) return; //QList <QGraphicsView *> views=m_scene->views(); //m_size=views.at(0)->size(); //int s=views.size(); m_frame_number=0; m_scene->clear(); m_scene->setSceneRect(0.0,0.0,qreal(m_size.width()),qreal(m_size.height())); m_currentSlideIndex=0; index=m_sequence->index(m_currentSlideIndex); if(index.isValid()) { m_currentState=Running; m_currentStep=EnterAnimation; //m_totalCurrentTime=0; //m_stepCurrentTime=0; val=index.data(Qt::UserRole); itemNode=val.value<node>(); if(m_exportToMovie) { pix.load(itemNode.nodePath()); } else { pix=itemNode.nodePixmap(); } m_currentNode=itemNode; if(pix.width()>m_size.width() || pix.height()>m_size.height()) pix=pix.scaled(m_size,Qt::KeepAspectRatio,Qt::SmoothTransformation); item = new Pixmap(pix); if(m_exportToMovie) item->setTransformationMode(Qt::SmoothTransformation); m_PixmapList.append(item); // serve questa lista? if(m_size.width()>pix.width()) { x=(m_size.width()-pix.width())/2; } else { x=0; } if(m_size.height()>pix.height()) { y=(m_size.height()-pix.height())/2; } else { y=0; } item->setPos(qreal(x), qreal(y)); item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex)); m_scene->addItem(item); applyAnimation(); //m_timerId=startTimer(TIMER_ANIMATION); } m_totalCurrentTime=0; m_stepCurrentTime=0; /*int width=m_sequence->movieResolution().width(); int height=m_sequence->movieResolution().height(); int bitrate=m_sequence->movieBitRate();*/ int frameRate=m_sequence->movieFrameRate(); //int gop = 20; if(m_exportToMovie) { //encoder.createFile(m_movieName,width,height,bitrate,gop,frameRate); QEventLoop evt; int frames=0; while(m_currentState!=Finished && m_currentState!=Stopped) { m_currentState=runEngine(); if(m_currentState==Running) emit refresh(m_totalCurrentTime); evt.processEvents(); if(m_currentState==Running) { //int elapsed=m_timerAnimation.elapsed(); //qDebug() << elapsed; int period=1000/frameRate; m_totalCurrentTime+=period; m_stepCurrentTime+=period; m_timerAnimation.start(); } frames++; } qDebug() << "frames:" << frames; endOfSlideShow(); } else { startSound(); m_timerId=startTimer(25); // TIMER_ANIMATION m_timerAnimation.start(); } //State state=Running; //m_timerAnimation.start(); //m_totalTime.start(); //qDebug("Time elapsed: %d ms", t.elapsed()); }
Icon::Icon(const Pixmap &pm, SpritesHolder &h) : normal(h.load(pm)) { Pixmap d = Pixmap(pm.width(),pm.height(),pm.hasAlpha()); const uint8_t* p = pm.const_data(); if(pm.hasAlpha()){ for(int r=0; r<pm.height(); ++r) for(int i=0; i<pm.width(); ++i){ //0.299, 0.587, 0.114 uint8_t cl = uint8_t(p[0]*0.299 + p[1]*0.587 + p[2]*0.114); d.set(i,r,Pixmap::Pixel{cl,cl,cl,p[3]}); p += 4; } } else { for(int r=0; r<pm.height(); ++r) for(int i=0; i<pm.width(); ++i){ //0.299, 0.587, 0.114 uint8_t cl = uint8_t(p[0]*0.299 + p[1]*0.587 + p[2]*0.114); d.set(i,r,Pixmap::Pixel{cl,cl,cl,255}); p += 3; } } disabled = h.load(d); }