Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}