示例#1
0
// Invoke Function
bb::cascades::Image PictureHelper::getImage() {
	// Get random image from list and remove path
	if (m_imageCount == 0)
		initListImage();

	int rnd = rand() % m_imageCount;

	// Get imagedata and generate random width & height
	bb::ImageData img = fromQImage(loadQImage(listImg[rnd]));
	float ratio = (float)img.width() / (float)img.height();
	int max, min;	// max min to random width or height
	max = 700;
	min = 450;
	int rnd2 = (rand() % (max - min)) + min;
	if (ratio > 1) { //if width > height
		setImageWidth(rnd2);
		setImageHeight(rnd2 / ratio);
	} else {	// if width < height
		setImageHeight(rnd2);
		setImageWidth(rnd2 * ratio);
	}

	listImg.removeAt(rnd);
	setImageCount(listImg.count());

	return bb::cascades::Image(img);
}
示例#2
0
TextureQImage::TextureQImage(QImage * image, string name) {
  this->name = name;
  glGenTextures(1, &handle);
  LogDebug << "Creating texture from qimage #" << handle << " " << name;
  bind();
  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
  filterMinMag(GL_LINEAR, GL_LINEAR);
  loadQImage(image);
  unbind();
}
示例#3
0
void doMagicIn(QString path, QString q, QString OPath)
{
    QRegExp isMask = QRegExp("*m.gif");
    isMask.setPatternSyntax(QRegExp::Wildcard);

    QRegExp isBackupDir = QRegExp("*/_backup/");
    isBackupDir.setPatternSyntax(QRegExp::Wildcard);

    if(isBackupDir.exactMatch(path))
        return; //Skip backup directories

    if(isMask.exactMatch(q))
        return;

    QImage target;
    QString imgFileM;
    QStringList tmp = q.split(".", QString::SkipEmptyParts);
    if(tmp.size()==2)
        imgFileM = tmp[0] + "m." + tmp[1];
    else
        return;

    //skip unexists pairs
    if(!QFile(path+q).exists())
        return;

    if(!QFile(path+imgFileM).exists())
    {
        QString saveTo;

        QImage image = loadQImage(path+q);
        if(image.isNull()) return;

        QTextStream(stdout) << QString(path+q+"\n").toUtf8().data();

        saveTo = QString(OPath+(tmp[0].toLower())+".gif");
        //overwrite source image (convert BMP to GIF)
        if(toGif( image, saveTo ) ) //Write gif
        {
            QTextStream(stdout) <<"GIF-1 only\n";
        }
        else
        {
            QTextStream(stdout) <<"BMP-1 only\n";
            image.save(saveTo, "BMP"); //If failed, write BMP
        }
        return;
    }

    if(!noBackUp)
    {
        //create backup dir
        QDir backup(path+"_backup/");
        if(!backup.exists())
        {
            QTextStream(stdout) << QString("Create backup with path %1\n").arg(path+"_backup");
            if(!backup.mkdir("."))
                QTextStream(stderr) << QString("WARNING! Can't create backup directory %1\n").arg(path+"_backup");

        }

        //create Back UP of source images
        if(!QFile(path+"_backup/"+q).exists())
            QFile::copy(path+q, path+"_backup/"+q);
        if(!QFile(path+"_backup/"+imgFileM).exists())
            QFile::copy(path+imgFileM, path+"_backup/"+imgFileM);
    }

    QImage image = loadQImage(path+q);
    QImage mask = loadQImage(path+imgFileM);

    if(mask.isNull()) //Skip null masks
        return;

    target = setAlphaMask(image, mask);

    if(!target.isNull())
    {
        //Save before fix
        //target.save(OPath+tmp[0]+"_before.png");
        //mask.save(OPath+tmp[0]+"_mask_before.png");
        QTextStream(stdout) << QString(path+q+"\n").toUtf8().data();

        //fix
        if(image.size()!= mask.size())
            mask = mask.copy(0,0, image.width(), image.height());

        mask = target.alphaChannel();
        mask.invertPixels();

        //Save after fix
        //target.save(OPath+tmp[0]+"_after.bmp", "BMP");
        QString saveTo;


        saveTo = QString(OPath+(tmp[0].toLower())+".gif");

        //overwrite source image (convert BMP to GIF)
        if(toGif(image, saveTo ) ) //Write gif
        {
            QTextStream(stdout) <<"GIF-1 ";
        }
        else
        {
            QTextStream(stdout) <<"BMP-1 ";
            image.save(saveTo, "BMP"); //If failed, write BMP
        }

        saveTo = QString(OPath+(tmp[0].toLower())+"m.gif");

        //overwrite mask image
        if( toGif(mask, saveTo ) ) //Write gif
        {
            QTextStream(stdout) <<"GIF-2\n";
        }
        else
        {
            mask.save(saveTo, "BMP"); //If failed, write BMP
            QTextStream(stdout) <<"BMP-2\n";
        }
    }
    else
        QTextStream(stderr) << path+q+" - WRONG!\n";
}
int doMagicIn(QString path, QString q, QString OPath)
{
    //skip unexists pairs
    if(!QFile(path+q).exists())
        return CNV_SKIPPED;

    QImage ImgSrc;
    QImage image;
    QImage mask;

    ImgSrc = loadQImage(path+q);

    if(ImgSrc.isNull()) //Skip null images
        return CNV_FAILED;
    QString bname = QFileInfo(path+q).baseName();

    QString saveToImg = QString(OPath+(bname.toLower())+".gif");
    QString saveToMask = QString(OPath+(bname.toLower())+"m.gif");

    QTextStream(stdout) << path+q+"\n";

    mask = ImgSrc.alphaChannel();
    mask.invertPixels();

    //Write mask image
    if( toGif(mask, saveToMask ) ) //Write gif
    {
        QTextStream(stdout) <<"GIF-1\n";
    }
    else
    {
        mask.save(saveToMask, "BMP"); //If failed, write BMP
        QTextStream(stdout) <<"BMP-1\n";
    }



    image = ImgSrc.convertToFormat(QImage::Format_RGB32);
    mask = ImgSrc.alphaChannel();
    mask.invertPixels();
    for(int w=0; w < mask.width(); w++)
        for(int h=0; h < mask.height(); h++)
        {
            if(mask.pixel(w,h)==qRgb(0xFF,0xFF,0xFF)) //Fill white pixel into black on image
            {
                image.setPixel(w,h, qRgb(0,0,0));
            }
            else
            if(mask.pixel(w,h)!=qRgb(0,0,0)) //Fill non-black pixel color into black on mask
            {
                mask.setPixel(w,h, qGray(0,0,0));
            }
        }
    mask.invertPixels();
    image.setAlphaChannel(mask);

    //Write mask image
    if( toGif(image, saveToImg ) ) //Write gif
    {
        QTextStream(stdout) <<"GIF-2\n";
    }
    else
    {
        image.save(saveToImg, "BMP"); //If failed, write BMP
        QTextStream(stdout) <<"BMP-2\n";
    }

    if(removeSource) QFile(path+q).remove();

    return CNV_SUCCESS;
}
示例#5
0
WzMainWindow::WzMainWindow(QSize resolution, const QGLFormat &format, QWidget *parent) : QtGameWidget(resolution, format, parent)
{
	myself = this;
	notReadyToPaint = true;
	tickCount.start();
	std::fill_n(cursors, CURSOR_MAX, nullptr);
	setAutoFillBackground(false);
	setAutoBufferSwap(false);
	setMouseTracking(true);

	// Mac apps typically don't have window icons unless document-based.
#if !defined(WZ_OS_MAC)
	setWindowIcon(QIcon(QPixmap::fromImage(loadQImage("images/warzone2100.png", "PNG"))));
#endif
	setWindowTitle(PACKAGE_NAME);

	loadCursor(CURSOR_EMBARK, "images/intfac/image_cursor_embark.png");
	loadCursor(CURSOR_DEST, "images/intfac/image_cursor_dest.png");
	loadCursor(CURSOR_DEFAULT, "images/intfac/image_cursor_default.png");
	loadCursor(CURSOR_BUILD, "images/intfac/image_cursor_build.png");
	loadCursor(CURSOR_SCOUT, "images/intfac/image_cursor_scout.png");
	loadCursor(CURSOR_DISEMBARK, "images/intfac/image_cursor_disembark.png");
	loadCursor(CURSOR_ATTACK, "images/intfac/image_cursor_attack.png");
	loadCursor(CURSOR_GUARD, "images/intfac/image_cursor_guard.png");
	loadCursor(CURSOR_FIX, "images/intfac/image_cursor_fix.png");
	loadCursor(CURSOR_SELECT, "images/intfac/image_cursor_select.png");
//	loadCursor(CURSOR_REPAIR, 64, 160, buffer);		// FIX ME: This IS in infac.img, but the define is MIA
	loadCursor(CURSOR_SEEKREPAIR, "images/intfac/image_cursor_repair.png");  // FIX ME: This is NOT in infac.img!
	loadCursor(CURSOR_PICKUP, "images/intfac/image_cursor_pickup.png");
	loadCursor(CURSOR_NOTPOSSIBLE, "images/intfac/image_cursor_notpos.png");
	loadCursor(CURSOR_MOVE, "images/intfac/image_cursor_move.png");
	loadCursor(CURSOR_LOCKON, "images/intfac/image_cursor_lockon.png");
//	loadCursor(CURSOR_ECM, 224, 160, buffer);		// FIX ME: Not defined yet!
	loadCursor(CURSOR_JAM, "images/intfac/image_cursor_ecm.png");  // FIX ME: This is NOT in infac.img, and is using IMAGE CURSOR ECM ?
	loadCursor(CURSOR_ATTACH, "images/intfac/image_cursor_attach.png");
	loadCursor(CURSOR_BRIDGE, "images/intfac/image_cursor_bridge.png");
	loadCursor(CURSOR_BOMB, "images/intfac/image_cursor_bomb.png");

	// Reused (unused) cursors
	cursors[CURSOR_ARROW] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_MENU] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_BOMB] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_EDGEOFMAP] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_SIGHT] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_TARGET] = new QCursor(Qt::ArrowCursor);
	cursors[CURSOR_UARROW] = new QCursor(Qt::SizeVerCursor);
	cursors[CURSOR_DARROW] = new QCursor(Qt::SizeVerCursor);
	cursors[CURSOR_LARROW] = new QCursor(Qt::SizeHorCursor);
	cursors[CURSOR_RARROW] = new QCursor(Qt::SizeHorCursor);

	// Fonts
	regularFont.setFamily("DejaVu Sans");
	regularFont.setPixelSize(12);
	boldFont.setFamily("DejaVu Sans");
	boldFont.setPixelSize(21);
	boldFont.setWeight(QFont::DemiBold);
	smallFont.setFamily("DejaVu Sans");
	smallFont.setPixelSize(9);

	// Want focusOutEvent messages.
	setFocusPolicy(Qt::StrongFocus);

	// set radix character (again) to the period (".")
	setlocale(LC_NUMERIC, "C");

#if !defined(WZ_OS_MAC)
	// Want áéíóú inputMethodEvent messages.
	setAttribute(Qt::WA_InputMethodEnabled, true);
#else
	// But not on the Mac (no ALT+H on US Extended Keyboards)
	setAttribute(Qt::WA_InputMethodEnabled, false);
#endif
}
示例#6
0
void WzMainWindow::loadCursor(CURSOR cursor, char const *name)
{
	cursors[cursor] = new QCursor(QPixmap::fromImage(loadQImage(name, "PNG")));
}