Exemple #1
0
int main(int argc, char **argv)
{
    gdImagePtr A, B, C;
    unsigned char black, white;
    unsigned int minSX, minSY, maxSX, maxSY;
    bool rc;
#ifdef HAVE_GD_PNG
    FILE *f;
#endif

    if (argc < 3) {
        fprintf(stderr, "Usage: diffimg image1 image2 [outimage]\n");
        exit(EX_USAGE);
    }
    A = imageLoad(argv[1]);
    B = imageLoad(argv[2]);

    minSX = (gdImageSX(A) < gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B);
    minSY = (gdImageSY(A) < gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B);
    maxSX = (gdImageSX(A) > gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B);
    maxSY = (gdImageSY(A) > gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B);
    
    C = gdImageCreatePalette (maxSX, maxSY);

    white = gdImageColorAllocate(C, gdRedMax, gdGreenMax, gdBlueMax);
    black = gdImageColorAllocate(C, 0, 0, 0);

    if (maxSX > minSX && maxSY > minSY)
	gdImageFilledRectangle(C, minSX, minSY, maxSX-1, maxSY-1, black);

    rc = imageDiff (A, B, C, minSX, minSY, black, white);

#ifdef HAVE_GD_PNG
    if ((argc > 3) && ((f = fopen(argv[3], "wb")))) {
	gdImagePng (C, f);
	fclose(f);
    }
    else
        gdImagePng (C, stdout);
#else

    fprintf(stderr, "PNG output support is not available\n");
#endif

    gdImageDestroy(A);
    gdImageDestroy(B);
    gdImageDestroy(C);

    return (rc ? EXIT_FAILURE : EXIT_SUCCESS);
}
Exemple #2
0
int main(int argc __attribute__((unused)), char *argv[])
{
	int status = 0;

	setlocale(LC_ALL, getenv(ENV_LANG));
	textdomain("mines");

	// Only work in graphics mode
	if (!graphicsAreEnabled())
	{
		printf(_("\nThe \"%s\" command only works in graphics mode\n"),
			argv[0]);
		return (errno = ERR_NOTINITIALIZED);
	}

	// Load our images
	status = imageLoad(MINE_IMAGE, 0, 0, &mineImage);
	if (status < 0)
	{
		printf(_("\nCan't load %s\n"), MINE_IMAGE);
		return (errno = status);
	}
	mineImage.transColor.green = 255;

	// Create a new window
	window = windowNew(multitaskerGetCurrentProcessId(), WINDOW_TITLE);

	// Register an event handler to catch window events.
	windowRegisterEventHandler(window, &eventHandler);

	// Generate mine field
	initialize();

	// Go live.
	windowSetVisible(window, 1);

	// Run the GUI
	windowGuiRun();

	// Destroy the window
	windowDestroy(window);

	imageFree(&mineImage);

	// Done
	return (0);
}
int loadTextureImage(Image * image, char * name, GLuint * tex) {

    if (!imageLoad(name, image))
    {
        printf("Error reading image file");
        exit(1);
    }

    glGenTextures(1, tex);
    glBindTexture(GL_TEXTURE_2D, *tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
}
Exemple #4
0
void Ammo::LoadGLTextures()
{
    int w, h, c;
    glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
    #if RAYGL == 1
    Image *image[1];
    for (c = 0; c < 1; c++) {
        image[c] = (Image *) malloc(sizeof(Image));
        if (image[c] == NULL) exit(0);
    }
    #else
    uchar*data;

    #endif

    #if RAYGL == 1
    if (!imageLoad("Data/red.ppm", image[0])) exit(0);
    #else
    data = PGM_FILE_READ("Data/red.ppm", &w, &h, &c); 
    #endif 
    
    // Load texture map for sphere.
    //data = PGM_FILE_READ("Data/image-1.ppm", &w, &h, &c); 
    /*BITMAPINFO *BitmapInfo; 
     * data = LoadDIBitmap("Data/perf_white.bmp",&BitmapInfo);
     * w = BitmapInfo->bmiHeader.biWidth; 
     * h = BitmapInfo->bmiHeader.biHeight;
     */
    glGenTextures(1, &EarthMap);
    glBindTexture(GL_TEXTURE_2D, EarthMap);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );   
    #if RAYGL == 1
    gluBuild2DMipmaps(GL_TEXTURE_2D,3, image[0]->sizeX, image[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,image[0]->data);
    #else
    
    gluBuild2DMipmaps( GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, data );
    free(data);
    #endif
    

}
bool Graphic::_imageLoadSprites()
{
    this->pBuffer = imageCreate(m_resX, m_resY, COLOR_WHITE);
    if (!this->pBuffer)
    {
        std::cerr << "Cannot allocate buffer..." << std::endl;
        return 0;
    }

    // chargement des bitmaps du jeu
    this->pSprites[0] = imageCreate(TX, TY, COLOR_WHITE);
    this->pSprites[1] = imageLoad("images/mur.bmp");
    this->pSprites[2] = imageLoad("images/caisse.bmp");
    this->pSprites[3] = imageLoad("images/caisse_ok.bmp");
    this->pSprites[4] = imageLoad("images/objectif.bmp");
    this->pSprites[5] = imageCreate(TX, TY, COLOR_ROSE);
    this->pSprites[6] = imageCreate(TX, TY, COLOR_BLUE);
    this->pSprites[7] = imageCreate(TX, TY, COLOR_YELLOW);
    this->pSprites[8] = imageCreate(TX, TY, COLOR_GREEN);
    this->pSprites[9] = imageCreate(TX, TY, COLOR_CYAN);

    this->pSpritesPlayer[0] = imageLoad("images/mario_haut.bmp");
    this->pSpritesPlayer[1] = imageLoad("images/mario_bas.bmp");
    this->pSpritesPlayer[2] = imageLoad("images/mario_gauche.bmp");
    this->pSpritesPlayer[3] = imageLoad("images/mario_droite.bmp");

    for (int i=0; i<MAX_SPRITE; i++)
    {
        if (this->pSprites[i] == NULL)
        {
            return false;
        }
    }
    for (int i=0; i<MAX_SPRITE_PLAYER; i++)
    {
        if (this->pSpritesPlayer[i] == NULL)
        {
            return false;
        }
    }

    return true;
}
Exemple #6
0
void ProjectHandle::changeCurrent(QModelIndex index){

    emit cleanGl();
    map=NULL;
    delete colorMap;

    map=projObjects[index.data().toString()].map;
    colorMap = new QImage(projObjects[index.data().toString()].path);

    if(map==NULL){
        PObject object = projObjects[index.data().toString()];
        object.map = new Image;
        object.map->data = new uchar[colorMap->width()*colorMap->height()];
        object.map->sizeX =colorMap->width() ;
        object.map->sizeY =colorMap->height() ;
        int k=0;
        for(int i=0;i<(colorMap->height());i++){
            for(int j=0;j<colorMap->width();j++){
                QRgb tmp=colorMap->pixel(j,i);
                uchar t=static_cast<uchar>(qBlue(tmp));
                object.map->data[k]=t;
                k++;
            }
        }
        calculate(&object);
        QFileInfo inf(object.path);
        projObjects.insert(inf.fileName(),object);
        map=object.map;
    }



    emit set_glwMap(map);
    emit imageLoad(map->sizeX,map->sizeY);

    return;
}
int loadTextureImage(Image * image, char * name, GLuint * tex) {

    /**
     * Load image-file
     */
    if (!imageLoad(name, image))
    {
        printf("Error reading image file");
        exit(1);
    }

    /**
     * Create Texture-object with the given identifier
     */
    glGenTextures(1, tex);
    glBindTexture(GL_TEXTURE_2D, *tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    /** Create texture with the data from the image */
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
}
Exemple #8
0
// Function allocates and init a Game
static game_p gameNew(engine_p engine,
                      board_p board)
{
    game_p game = NULL;
    context_p screen = NULL;
    int hd = 0;

    ASSERT(NULL != board, "gameNew");

    game = (game_p)objectCreate(
        sizeof(game_t),
        (destructor_f)gameDestroy);

    game->board = boardRetain(board);

    screen = engineScreen(engine);

    game->width = contextWidth(screen);
    game->height = contextHeight(screen);
    game->padding = (game->width < game->height
                         ? game->width
                         : game->height) / 64;

    hd = engineHDSupported(engine);

    game->regular = fontRetain(
        fontLoad(hd ? fontNameRegularHD
                    : fontNameRegularSD));
    game->bold = fontRetain(fontLoad(
        hd ? fontNameBoldHD : fontNameBoldSD));

    game->status_line
        = MAX(fontLine(game->regular),
              fontLine(game->bold));

    game->images[0] = imageRetain(
        imageLoad(hd ? imageNameEmptyHD
                     : imageNameEmptySD));
    game->images[1] = imageRetain(imageLoad(
        hd ? imageName2HD : imageName2SD));
    game->images[2] = imageRetain(imageLoad(
        hd ? imageName4HD : imageName4SD));
    game->images[3] = imageRetain(imageLoad(
        hd ? imageName8HD : imageName8SD));
    game->images[4] = imageRetain(imageLoad(
        hd ? imageName16HD : imageName16SD));
    game->images[5] = imageRetain(imageLoad(
        hd ? imageName32HD : imageName32SD));
    game->images[6] = imageRetain(imageLoad(
        hd ? imageName64HD : imageName64SD));
    game->images[7] = imageRetain(imageLoad(
        hd ? imageName128HD : imageName128SD));
    game->images[8] = imageRetain(imageLoad(
        hd ? imageName256HD : imageName256SD));
    game->images[9] = imageRetain(imageLoad(
        hd ? imageName512HD : imageName512SD));
    game->images[10] = imageRetain(imageLoad(
        hd ? imageName1024HD : imageName1024SD));
    game->images[11] = imageRetain(imageLoad(
        hd ? imageName2048HD : imageName2048SD));
    game->images[12] = imageRetain(imageLoad(
        hd ? imageName4096HD : imageName4096SD));
    game->images[13] = imageRetain(imageLoad(
        hd ? imageName8192HD : imageName8192SD));
    game->images[14] = imageRetain(
        imageLoad(hd ? imageName16384HD
                     : imageName16384SD));
    game->images[15] = imageRetain(
        imageLoad(hd ? imageName32768HD
                     : imageName32768SD));
    game->images[16] = imageRetain(
        imageLoad(hd ? imageName65536HD
                     : imageName65536SD));
    game->images[17] = imageRetain(
        imageLoad(hd ? imageName131072HD
                     : imageName131072SD));

    game->cell
        = MIN(imageWidth(game->images[0]),
              imageHeight(game->images[0]));

    game->board_back = rgbColor(0xBB, 0xAD, 0xA0);

    return game;
};
static int getImage(const char *fileName, image *imageData, unsigned maxWidth,
	unsigned maxHeight, int stretch, color *background)
{
	int status = 0;
	image loadImage;
	float scale = 0;
	unsigned thumbWidth = 0;
	unsigned thumbHeight = 0;

	memset(&loadImage, 0, sizeof(image));

	status = imageNew(imageData, maxWidth, maxHeight);
	if (status < 0)
		return (status);

	if (!stretch && background)
	{
		status = imageFill(imageData, background);
		if (status < 0)
			goto out;
	}

	if (fileName)
	{
		status = imageLoad(fileName, 0, 0, &loadImage);
		if (status < 0)
			goto out;

		// Scale the image
		thumbWidth = loadImage.width;
		thumbHeight = loadImage.height;

		// Presumably we need to shrink it?
		if (stretch)
		{
			thumbWidth = maxWidth;
			thumbHeight = maxHeight;
		}
		else
		{
			if (thumbWidth > maxWidth)
			{
				scale = ((float) maxWidth / (float) thumbWidth);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}

			if (thumbHeight > maxHeight)
			{
				scale = ((float) maxHeight / (float) thumbHeight);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}
		}

		if ((thumbWidth != loadImage.width) ||
			(thumbHeight != loadImage.height))
		{
			status = imageResize(&loadImage, thumbWidth, thumbHeight);
			if (status < 0)
				goto out;
		}

		status = imagePaste(&loadImage, imageData,
			((maxWidth - loadImage.width) / 2),
			((maxHeight - loadImage.height) / 2));
		if (status < 0)
			goto out;
	}

	status = 0;

out:
	if (loadImage.data)
		imageFree(&loadImage);

	if ((status < 0) && imageData->data)
		imageFree(imageData);

	return (status);
}
Exemple #10
0
/** Main function **/
int main(int argc, char* args[])
{
	//
	// Initialize program

	// Init SDL
	SDL_Init(SDL_INIT_EVERYTHING);

	// Open window
	gbl::S_screen = SDL_SetVideoMode((int)cnst::WINDOW_WIDTH,(int)cnst::WINDOW_HEIGHT,32,SDL_SWSURFACE);

	// Set caption
	SDL_WM_SetCaption(cnst::WINDOW_CAPTION.c_str(), NULL);

	// Initialize fps regulator
	fpsCalc::GetInstance()->Init((double)cnst::TARGET_FPS);





	//
	// Load resources

	// Graphics
	res::S_title = imageLoad("resources/graphics/title.png");
	res::S_message = imageLoad("resources/graphics/message.png");

	// Sounds
	//





	//
	// Initialize game

	// Set state to title screen
	gbl::state = 2;

	// Initialize title screen
	scr_title_start();





	//
	// Main loop

	while(gbl::loop)
	{

		/*Events*/
		keystates = SDL_GetKeyState(NULL);
		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
				gbl::loop = false;

			// event
			if(event.type == SDL_KEYDOWN)
			{
				switch(event.key.keysym.sym)
				{
					case SDLK_SPACE:
						gbl::spacePressed = true;
					break;
				}
			}

		}

		// keystates
		doKeys();

		 switch(gbl::state)
		 {



			case 2: // title

				scr_title_step();
				scr_title_render_graphics();
				if(gbl::state == 3)
					scr_lvl_start();

			break;

			case 3: // level select

				scr_lvl_step();
				scr_lvl_render_graphics();
				if(gbl::state == 4)
					playLevel("resources/levels/lvl_01.pkm");


			break;

			case 4: // play

				//scr_title_step();
				//scr_title_render_graphics();

			break;



		 }//switch


	}//while




	//
	// Shutdown

	// SDL
	SDL_Quit();

	// Free images
	imageFree(res::S_title);
	imageFree(res::S_message);

	// Bye
	return 0;
}
Exemple #11
0
void ProjectHandle::loadData(){

    QString Name = QFileDialog::getOpenFileName(NULL,tr("Open picture"), ".",tr("Project files (*.bmp *.jpg *.jpeg *.png)"));
    if (Name.isEmpty()){
        return;
    }


    QImage* load_image = new QImage(Name);

    New_dlg dlg(libPath);
    QPixmap pic =QPixmap::fromImage(load_image->scaled(dlg.pic_label->size())) ;
    dlg.pic_label->setPixmap(pic);

    QFile libFile(libPath);
    if(!libFile.open(QFile::ReadOnly | QFile::WriteOnly)){
        emit addToLog("Не найден файл библиотек");
        QDir dir;
        QFileInfo inf(libPath);
        dir=inf.dir();
        dir.mkdir(dir.absolutePath());
        QTextStream s(&libFile);
        s << "";
    }else{

        QTextStream readS(&libFile);
        while(!readS.atEnd()){
            QString inp;
            readS >> inp;
            dlg.material_Box->addItem(inp);
        }
    }


    if(!dlg.exec()){
        delete load_image;
        return;
    }

    colorMap = load_image;

    PObject object;
    if(dlg.width_sizeBox->currentText()=="um"){
        object.width = dlg.width_SpinBox->value();
    }else{
        object.width = dlg.width_SpinBox->value()*1000;
    }

    if(dlg.height_sizeBox->currentText()=="um"){
        object.height = dlg.height_SpinBox->value();
    }else{
        object.height = dlg.height_SpinBox->value()*1000;
    }

    object.map = new Image;
    object.map->data = new uchar[colorMap->width()*colorMap->height()];
    object.material     =   dlg.material_Box->currentText();
    object.map->sizeX   =   colorMap->width() ;
    object.map->sizeY   =   colorMap->height() ;


    calculate(&object);

    map=object.map;
    object.path=Name;

    QFileInfo inf(Name);
    projObjects.insert(inf.fileName(),object);

    curName=inf.fileName();
    emit addToList(inf.fileName());
    emit cleanGl();
    emit set_glwMap(map);
    emit imageLoad(map->sizeX,map->sizeY);
}