Пример #1
0
void IMB_exr_read_channels(void *handle)
{
	ExrHandle *data = (ExrHandle *)handle;
	FrameBuffer frameBuffer;
	ExrChannel *echan;

	/* check if exr was saved with previous versions of blender which flipped images */
	const StringAttribute *ta = data->ifile->header().findTypedAttribute <StringAttribute> ("BlenderMultiChannel");
	short flip = (ta && strncmp(ta->value().c_str(), "Blender V2.43", 13) == 0); /* 'previous multilayer attribute, flipped */

	for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {

		if (echan->rect) {
			if (flip)
				frameBuffer.insert(echan->name, Slice(Imf::FLOAT,  (char *)echan->rect,
				                                      echan->xstride * sizeof(float), echan->ystride * sizeof(float)));
			else
				frameBuffer.insert(echan->name, Slice(Imf::FLOAT,  (char *)(echan->rect + echan->xstride * (data->height - 1) * data->width),
				                                      echan->xstride * sizeof(float), -echan->ystride * sizeof(float)));
		}
		else
			printf("warning, channel with no rect set %s\n", echan->name);
	}

	data->ifile->setFrameBuffer(frameBuffer);

	try {
		data->ifile->readPixels(0, data->height - 1);
	}
	catch (const std::exception &exc) {
		std::cerr << "OpenEXR-readPixels: ERROR: " << exc.what() << std::endl;
	}
}
Пример #2
0
static int imb_save_openexr_float(struct ImBuf *ibuf, const char *name, int flags)
{
	const int channels = ibuf->channels;
	const int is_alpha = (channels >= 4) && (ibuf->planes == 32);
	const int is_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; /* summarize */
	const int width = ibuf->x;
	const int height = ibuf->y;

	try
	{
		Header header(width, height);

		openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
		openexr_header_metadata(&header, ibuf);

		header.channels().insert("R", Channel(Imf::FLOAT));
		header.channels().insert("G", Channel(Imf::FLOAT));
		header.channels().insert("B", Channel(Imf::FLOAT));
		if (is_alpha)
			header.channels().insert("A", Channel(Imf::FLOAT));
		if (is_zbuf)
			header.channels().insert("Z", Channel(Imf::FLOAT));

		FrameBuffer frameBuffer;

		/* manually create ofstream, so we can handle utf-8 filepaths on windows */
		OFileStream file_stream(name);
		OutputFile file(file_stream, header);

		int xstride = sizeof(float) * channels;
		int ystride = -xstride * width;
		float *rect[4] = {NULL, NULL, NULL, NULL};

		/* last scanline, stride negative */
		rect[0] = ibuf->rect_float + channels * (height - 1) * width;
		rect[1] = (channels >= 2) ? rect[0] + 1 : rect[0];
		rect[2] = (channels >= 3) ? rect[0] + 2 : rect[0];
		rect[3] = (channels >= 4) ? rect[0] + 3 : rect[0]; /* red as alpha, is this needed since alpha isn't written? */

		frameBuffer.insert("R", Slice(Imf::FLOAT,  (char *)rect[0], xstride, ystride));
		frameBuffer.insert("G", Slice(Imf::FLOAT,  (char *)rect[1], xstride, ystride));
		frameBuffer.insert("B", Slice(Imf::FLOAT,  (char *)rect[2], xstride, ystride));
		if (is_alpha)
			frameBuffer.insert("A", Slice(Imf::FLOAT,  (char *)rect[3], xstride, ystride));
		if (is_zbuf)
			frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *) (ibuf->zbuf_float + (height - 1) * width),
			                              sizeof(float), sizeof(float) * -width));
		file.setFrameBuffer(frameBuffer);
		file.writePixels(height);
	}
	catch (const std::exception &exc)
	{
		printf("OpenEXR-save: ERROR: %s\n", exc.what());

		return (0);
	}

	return (1);
	//	printf("OpenEXR-save: Done.\n");
}
Пример #3
0
void IMB_exr_write_channels(void *handle)
{
	ExrHandle *data = (ExrHandle *)handle;
	FrameBuffer frameBuffer;
	ExrChannel *echan;

	if (data->channels.first) {
		for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
			/* last scanline, stride negative */
			float *rect = echan->rect + echan->xstride * (data->height - 1) * data->width;

			frameBuffer.insert(echan->name, Slice(Imf::FLOAT,  (char *)rect,
			                                      echan->xstride * sizeof(float), -echan->ystride * sizeof(float)));
		}

		data->ofile->setFrameBuffer(frameBuffer);
		try {
			data->ofile->writePixels(data->height);
		}
		catch (const std::exception &exc) {
			std::cerr << "OpenEXR-writePixels: ERROR: " << exc.what() << std::endl;
		}
	}
	else {
		printf("Error: attempt to save MultiLayer without layers.\n");
	}
}
Пример #4
0
PipeLine::PipeLine(FrameBuffer& fbo,int regsN)
    :fbo_(fbo),registers_(regsN),
     uniforms_((Uniforms*)registers_.regs_.data()),
     worldTransform_(),
     viewfrustum_(),
     cam_(viewfrustum_,0.1,0.01)
{

    setCullState(FT_CCW,CT_BACK);
    viewfrustum_.setFrustum(90.0f,fbo.width(),fbo.height(),5,500);

    //viewfrustum_.setFrustum(-400,400,-300,300,50,500);
    setViewPort(fbo.width(),fbo.height(),0,0);
    uniforms_->wpvMatrix_ = viewfrustum_.getProjectionViewMatrix();
    using PT = Mesh::PrimitiveT;

    // FIXME
    //drawFunction_[PT::POLYPOINT] = &PipeLine::drawPolypoint;
    //drawFunction_[PT::POLYSEGMENT_DISJOINT] = &PipeLine::drawPolylineDisjoint;
    //drawFunction_[PT::POLYSEGMENT_CONTIGUOUS] = &PipeLine::drawPolylineContiguous;
    //drawFunction_[PT::TRISTRIP]=

    drawFunction_[PT::TRIMESH] = &PipeLine::drawTriMesh;
    rasterAlgo_[RasAlgo::SCANLINE_ALGO] = &PipeLine::scanlineAlgo;
}
Пример #5
0
void SSAOShader::generateRandomTexture(){
	// Genero un request para la nueva textura de random a crear
	GraphicDeviceConstantCatalog* catalog = GraphicDevice::getInstance()->getConstantCatalog();
	FrameBufferRequest* request = new FrameBufferRequest();
	TextureRequest* textureRequest = new TextureRequest(4, 4, catalog->getFormatRGB(), catalog->getFormatRGB());
	textureRequest->addFilterRequest(new TextureFilterRequest(catalog->getTextureMagFilterFlag(), catalog->getTextureNearestFilterFlag()));
	textureRequest->addFilterRequest(new TextureFilterRequest(catalog->getTextureMinFilterFlag(), catalog->getTextureNearestFilterFlag()));
	textureRequest->addFilterRequest(new TextureFilterRequest(catalog->getTextureWrapSFlag(), catalog->getTextureRepeatFlag()));
	textureRequest->addFilterRequest(new TextureFilterRequest(catalog->getTextureWrapTFlag(), catalog->getTextureRepeatFlag()));
	request->addTextureRequest(textureRequest);

	// Consigo un fbo, dibujo en el, y vuelvo al fbo anterior
	FrameBuffer* currentFbo = FrameBufferManager::getInstance()->getActiveFrameBuffer();
	static FrameBuffer* randomTextureFbo = NULL; 
	if(randomTextureFbo != NULL){
		randomTextureFbo->getOutputTextures()->at(0)->setWriteLock(false);
	}
	randomTextureFbo = FrameBufferManager::getInstance()->getFrameBufferAndBind(request, randomTextureFbo);	
	GraphicDevice::getInstance()->setViewport(0, 0, 4, 4);
	RandomTextureGeneratorShader::getInstance()->draw(vec2(4, 4), 0.0f, 1.0f);
	currentFbo->bind();
	vec2 size = currentFbo->getOutputTextures()->at(0)->getSize();
	GraphicDevice::getInstance()->setViewport(0, 0, size.x, size.y);

	// Me guardo la textura (no libero el writelock del fbo, porque sino se me borra la textura)
	this->randomTexture = randomTextureFbo->getOutputTextures()->at(0);
	delete request;
}
Пример #6
0
void
TiledRgbaOutputFile::setFrameBuffer (const Rgba *base,
				     size_t xStride,
				     size_t yStride)
{
    if (_toYa)
    {
	Lock lock (*_toYa);
	_toYa->setFrameBuffer (base, xStride, yStride);
    }
    else
    {
	size_t xs = xStride * sizeof (Rgba);
	size_t ys = yStride * sizeof (Rgba);

	FrameBuffer fb;

	fb.insert ("R", Slice (HALF, (char *) &base[0].r, xs, ys));
	fb.insert ("G", Slice (HALF, (char *) &base[0].g, xs, ys));
	fb.insert ("B", Slice (HALF, (char *) &base[0].b, xs, ys));
	fb.insert ("A", Slice (HALF, (char *) &base[0].a, xs, ys));

	_outputFile->setFrameBuffer (fb);
    }
}
Пример #7
0
bool ProtocolDHCP::parseOption(const FrameBuffer& buffer, size_t& offset)
{
    if (buffer.sizeBytes() <= offset) {
        return false;
    }
    Poco::UInt8 type = buffer[offset];
	if (type == 0xff)
	{
		return false;
	}
	if (buffer.sizeBytes() <= offset) {
		return false;
	}
	offset++;
    Poco::UInt8 length = buffer[offset];
	offset++;
    if (!enoughFor(buffer, offset, length)) {
        return false;
    }	
	
    std::string data((const char*)(buffer.begin()+offset), length);
    offset += length;
    _options[type] = data;
    return true;
}
void
CompositeDeepScanLine::setFrameBuffer(const FrameBuffer& fr)
{
    
    //
    // count channels; build map between channels in frame buffer
    // and channels in internal buffers
    //
    
    _Data->_channels.resize(3);
    _Data->_channels[0]="Z";
    _Data->_channels[1]=_Data->_zback ? "ZBack" : "Z";
    _Data->_channels[2]="A";
    _Data->_bufferMap.resize(0);
    
    for(FrameBuffer::ConstIterator q=fr.begin();q!=fr.end();q++)
    {
        string name(q.name());
        if(name=="ZBack")
        {
            _Data->_bufferMap.push_back(1);
        }else if(name=="Z")
        {
            _Data->_bufferMap.push_back(0);
        }else if(name=="A")
        {
            _Data->_bufferMap.push_back(2);
        }else{
            _Data->_bufferMap.push_back(_Data->_channels.size());
            _Data->_channels.push_back(name);
        }
    }
    
  _Data->_outputFrameBuffer=fr;
}
static bool ReadEXR(const char *name, float *&rgba, int &xRes, int &yRes, bool &hasAlpha)
{
    InputFile file(name);
    Box2i dw = file.header().dataWindow();
    xRes = dw.max.x - dw.min.x + 1;
    yRes = dw.max.y - dw.min.y + 1;

    half *hrgba = new half[4 * xRes * yRes];

    // for now...
    hasAlpha = true;
    int nChannels = 4;

    half *hp = hrgba - nChannels * (dw.min.x + dw.min.y * xRes);

    FrameBuffer frameBuffer;
    frameBuffer.insert("R", Slice(HALF, (char *)hp,
				  4*sizeof(half), xRes * 4 * sizeof(half), 1, 1, 0.0));
    frameBuffer.insert("G", Slice(HALF, (char *)hp+sizeof(half),
				  4*sizeof(half), xRes * 4 * sizeof(half), 1, 1, 0.0));
    frameBuffer.insert("B", Slice(HALF, (char *)hp+2*sizeof(half),
				  4*sizeof(half), xRes * 4 * sizeof(half), 1, 1, 0.0));
    frameBuffer.insert("A", Slice(HALF, (char *)hp+3*sizeof(half),
				  4*sizeof(half), xRes * 4 * sizeof(half), 1, 1, 1.0));

    file.setFrameBuffer(frameBuffer);
    file.readPixels(dw.min.y, dw.max.y);

    rgba = new float[nChannels * xRes * yRes];
    for (int i = 0; i < nChannels * xRes * yRes; ++i)
	rgba[i] = hrgba[i];
    delete[] hrgba;

    return rgba;
}
Пример #10
0
void readEXRRED(const char* filename, int width, int height, float* data)
{
	InputFile file(filename); 
	Box2i dw = file.header().dataWindow();
	
	int size = (width)*(height);
	
	half *rPixels = new half[size];
	
	FrameBuffer frameBuffer; 
	frameBuffer.insert ("R",                                  // name 
						Slice (HALF,                          // type 
							   (char *) rPixels, 
							   sizeof (*rPixels) * 1,    // xStride 
							   sizeof (*rPixels) * (width),// yStride 
							   1, 1,                          // x/y sampling 
							   0.0));                         // fillValue 
							   
	file.setFrameBuffer (frameBuffer); 
	file.readPixels (dw.min.y, dw.max.y); 
	
	for(int j=0; j<height; j++)
	for(int i=0; i<width; i++) {
		
		data[j*width+i] = rPixels[(height-1-j)*width+i];
		
	}
	
	delete[] rPixels;
}
Пример #11
0
int main() {
	printf("start of program\n");

	FrameBuffer FB;
	FB.initAvailable();

	Polygon pmouth(0, 0, 0, mouth, 18);
	pmouth.setPosition(0, 0, 0);
	pmouth.setMultiplication(10);
	pmouth.setCenter(0, 0, 0);
	pmouth.setFillColor(135, 206, 250);


	static Polygon* arrStar[] = {
		&pmouth
	};
	vector<Polygon*> star(arrStar, arrStar + sizeof(arrStar) / sizeof(arrStar[0]) );


	FB.canvas();
	FB.draw(star);
	//FB.drawBeizer(star);

	FB.render();


	return 0;
}
Пример #12
0
void WriteEXR(const char *name, float *frgba, int xRes, int yRes, bool hasAlpha) 
{
    Header header(xRes, yRes);
    header.channels().insert("R", Channel (HALF));
    header.channels().insert("G", Channel (HALF));
    header.channels().insert("B", Channel (HALF));
    if (hasAlpha)
	header.channels().insert("A", Channel (HALF));
    int stride = hasAlpha ? 4 : 3;

    half *rgba = new half[xRes*yRes * stride];
    for (int i = 0; i < xRes*yRes * stride; ++i)
	rgba[i] = frgba[i];

    FrameBuffer fb;
    fb.insert("R", Slice(HALF, (char *)rgba, stride*sizeof(half),
			 stride*xRes*sizeof(half)));
    fb.insert("G", Slice(HALF, (char *)rgba+sizeof(half), stride*sizeof(half),
			 stride*xRes*sizeof(half)));
    fb.insert("B", Slice(HALF, (char *)rgba+2*sizeof(half), stride*sizeof(half),
			 stride*xRes*sizeof(half)));
    if (hasAlpha)
	fb.insert("A", Slice(HALF, (char *)rgba+3*sizeof(half), stride*sizeof(half),
			     stride*xRes*sizeof(half)));

    OutputFile file(name, header);
    file.setFrameBuffer(fb);
    file.writePixels(yRes);
}
Пример #13
0
Result_t
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::ReadAncillaryResource(const byte_t* uuid, FrameBuffer& FrameBuf,
									     const IResourceResolver& Resolver) const
{
  FrameBuf.AssetID(uuid);
  UUID TmpID(uuid);
  char buf[64];

  ResourceTypeMap_t::const_iterator rmi = m_ResourceTypes.find(TmpID);

  if ( rmi == m_ResourceTypes.end() )
    {
      DefaultLogSink().Error("Unknown ancillary resource id: %s\n", TmpID.EncodeHex(buf, 64));
      return RESULT_RANGE;
    }

  Result_t result = Resolver.ResolveRID(uuid, FrameBuf);

  if ( KM_SUCCESS(result) )
    {
      if ( (*rmi).second == MT_PNG )
	FrameBuf.MIMEType("image/png");
	      
      else if ( (*rmi).second == MT_OPENTYPE )
	FrameBuf.MIMEType("application/x-font-opentype");

      else
	FrameBuf.MIMEType("application/octet-stream");
    }

  return result;
}
Пример #14
0
void PostProcessing::renderMotionBlur(unsigned , FrameBuffer &in_fbo, FrameBuffer &out_fbo)
{
    MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver->
        getCallback(ES_MOTIONBLUR);
    Camera *cam = Camera::getActiveCamera();
    unsigned camID = cam->getIndex();

    scene::ICameraSceneNode * const camnode = cam->getCameraSceneNode();

    // Calculate the kart's Y position on screen
    if (cam->getKart())
    {
        const core::vector3df pos = cam->getKart()->getNode()->getPosition();
        float ndc[4];
        core::matrix4 trans = camnode->getProjectionMatrix();
        trans *= camnode->getViewMatrix();

        trans.transformVect(ndc, pos);
        const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f;
        setMotionBlurCenterY(camID, karty);
    }
    else
        setMotionBlurCenterY(camID, 0.5f);

    out_fbo.Bind();
    glClear(GL_COLOR_BUFFER_BIT);

    FullScreenShader::MotionBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0], irr_driver->getDepthStencilTexture());
    DrawFullScreenEffect<FullScreenShader::MotionBlurShader>(
                                  // Todo : use a previousPVMatrix per cam, not global
                                  cam->getPreviousPVMatrix(),
                                  core::vector2df(0.5, 0.5),
                                  cb->getBoostTime(cam->getIndex()) * 10, // Todo : should be framerate dependent
                                  0.15f);
}
Пример #15
0
// EXR Function Definitions
COREDLL Spectrum *ReadImage(const string &name, int *width, int *height) {
    try {
        InputFile file(name.c_str());
        Box2i dw = file.header().dataWindow();
        *width  = dw.max.x - dw.min.x + 1;
        *height = dw.max.y - dw.min.y + 1;

        half *rgb = new half[3 * *width * *height];

        FrameBuffer frameBuffer;
        frameBuffer.insert("R", Slice(HALF, (char *)rgb,
                                      3*sizeof(half), *width * 3 * sizeof(half), 1, 1, 0.0));
        frameBuffer.insert("G", Slice(HALF, (char *)rgb+sizeof(half),
                                      3*sizeof(half), *width * 3 * sizeof(half), 1, 1, 0.0));
        frameBuffer.insert("B", Slice(HALF, (char *)rgb+2*sizeof(half),
                                      3*sizeof(half), *width * 3 * sizeof(half), 1, 1, 0.0));

        file.setFrameBuffer(frameBuffer);
        file.readPixels(dw.min.y, dw.max.y);

        Spectrum *ret = new Spectrum[*width * *height];
        // XXX should do real RGB -> Spectrum conversion here
        for (int i = 0; i < *width * *height; ++i) {
            float c[3] = { rgb[3*i], rgb[3*i+1], rgb[3*i+2] };
            ret[i] = Spectrum(c);
        }
        delete[] rgb;
        return ret;
    } catch (const std::exception &e) {
        Error("Unable to read image file \"%s\": %s", name.c_str(),
              e.what());
        return NULL;
    }
}
Пример #16
0
void drawImage(Texture &_texture, ShaderProgram _program) {
	glViewport(0, 0, 640, 480);

	DriverGPU *driver = DriverGPU::get();
	
	// create a RGBA color texture
	Texture colorTex(640, 480, eTexType::eRGB8);

	// create the framebuffer object
	FrameBuffer fbo;
	fbo.attachTexture(colorTex);
	fbo.linkAttachments();
	
	_program.use();

	_texture.attachToUniform(_program, "texture");

	driver->drawQuadTextured2f(	std::array < vec2f, 4 > {{vec2f(-1.0f, -1.0f), vec2f(1.0f, -1.0f), vec2f(1.0f, 1.0f), vec2f(-1.0f, 1.0f)}},
								std::array < vec2f, 4 > {{vec2f(1.0f, 0.0f), vec2f(1.0f, 1.0f), vec2f(0.0f, 1.0f), vec2f(0.0f, 0.0f)}});

	glFlush();
	
	//fbo.detachTexture(colorTex);
	colorTex.saveTexture("./result.bmp");
 
	glFinish();

	std::cout << "finished" << std::endl;
}
void setPostCallback(OnPostFn onPost, void* onPostContext)
{
    FrameBuffer* fb = FrameBuffer::getFB();
    if (fb) {
        fb->setPostCallback(onPost, onPostContext);
    }
}
void
writeTiled1 (const char fileName[],
             Array2D<GZ> &pixels,
             int width, int height,
             int tileWidth, int tileHeight)
{
    Header header (width, height);
    header.channels().insert ("G", Channel (IMF::HALF));
    header.channels().insert ("Z", Channel (IMF::FLOAT));

    header.setTileDescription
	(TileDescription (tileWidth, tileHeight, ONE_LEVEL));
    
    TiledOutputFile out (fileName, header);

    FrameBuffer frameBuffer;

    frameBuffer.insert ("G",					 // name
                        Slice (IMF::HALF,			 // type
			       (char *) &pixels[0][0].g,	 // base
				sizeof (pixels[0][0]) * 1,	 // xStride
				sizeof (pixels[0][0]) * width)); // yStride

    frameBuffer.insert ("Z",					 // name
                        Slice (IMF::FLOAT,			 // type
			       (char *) &pixels[0][0].z,	 // base
				sizeof (pixels[0][0]) * 1,	 // xStride
				sizeof (pixels[0][0]) * width)); // yStride

    out.setFrameBuffer (frameBuffer);
    out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
}
Пример #19
0
int main(int argc, char **argv)
{
	Configuration *config = Configuration::instance("frconfig.cfg");
	config->parse();

	FrameBuffer *fb = FrameBuffer::instance(
			config->get("framebuffer", "device"),
			config->get("console", "device"));

	if (!fb->open())
	{
		fprintf(stderr, "open frame buffer failed\n");
		return 1;
	}

	char msg[] = "Frame Buffer test program";

	fb->create_window("main");

	fb->window().set_color(0, 0x000000);
	fb->window().set_color(1, 0xffe080);
	fb->window().fill_rect(0, 0, fb->get_xres() - 1, fb->get_yres() - 1, 0);
	fb->window().put_string_center(fb->get_xres()/2, fb->get_yres()/2, msg, 1);

	fb->close();

	return 0;
}
ASDCP::Result_t
ASDCP::TimedText::MXFReader::h__Reader::ReadAncillaryResource(const byte_t* uuid, FrameBuffer& frame_buf,
							      AESDecContext* Ctx, HMACContext* HMAC)
{
  KM_TEST_NULL_L(uuid);
  UUID RID(uuid);

  ResourceMap_t::const_iterator ri = m_ResourceMap.find(RID);
  if ( ri == m_ResourceMap.end() )
    {
      char buf[64];
      DefaultLogSink().Error("No such resource: %s\n", RID.EncodeHex(buf, 64));
      return RESULT_RANGE;
    }

  // get the subdescriptor
  InterchangeObject* tmp_iobj = 0;
  Result_t result = m_HeaderPart.GetMDObjectByID((*ri).second, &tmp_iobj);
  TimedTextResourceSubDescriptor* desc_object = dynamic_cast<TimedTextResourceSubDescriptor*>(tmp_iobj);

  if ( KM_SUCCESS(result) )
    {
      assert(desc_object);
      result = ReadGenericStreamPartitionPayload(desc_object->EssenceStreamID, frame_buf, Ctx, HMAC);
    }

  if ( KM_SUCCESS(result) )
    {
      frame_buf.AssetID(uuid);
      frame_buf.MIMEType(desc_object->MIMEMediaType);
    }

  return result;
}
bool WindowSurface::blitToColorBuffer()
{
    if (!m_width && !m_height) return false;

    if (m_attachedColorBuffer->getWidth() != m_width ||
        m_attachedColorBuffer->getHeight() != m_height) {
        // XXX: should never happen - how this needs to be handled?
        fprintf(stderr, "Dimensions do not match\n");
        return false;
    }

    //
    // Make the surface current
    //
    EGLContext prevContext = s_egl.eglGetCurrentContext();
    EGLSurface prevReadSurf = s_egl.eglGetCurrentSurface(EGL_READ);
    EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW);
    FrameBuffer *fb = FrameBuffer::getFB();
    if (!m_drawContext.Ptr()) {
        fprintf(stderr, "Draw context is NULL\n");
        return false;
    }
    if (!s_egl.eglMakeCurrent(fb->getDisplay(), m_eglSurface,
                              m_eglSurface, m_drawContext->getEGLContext())) {
        fprintf(stderr, "Error making draw context current\n");
        return false;
    }

    m_attachedColorBuffer->blitFromCurrentReadBuffer();

    // restore current context/surface
    s_egl.eglMakeCurrent(fb->getDisplay(), prevDrawSurf,
                         prevReadSurf, prevContext);
    return true;
}
  Result_t OpenReadFrame(const char* filename, FrameBuffer& FB)
  {
    ASDCP_TEST_NULL_STR(filename);
    m_File.Close();
    Result_t result = m_File.OpenRead(filename);

    if ( ASDCP_SUCCESS(result) )
    {
        Kumu::fsize_t file_size = m_File.Size();

        if ( FB.Capacity() < file_size )
        {
            DefaultLogSink().Error("FrameBuf.Capacity: %u frame length: %u\n", FB.Capacity(), (ui32_t)file_size);
            return RESULT_SMALLBUF;
        }
    }

    ui32_t read_count;

    if ( ASDCP_SUCCESS(result) )
        result = m_File.Read(FB.Data(), FB.Capacity(), &read_count);

    if ( ASDCP_SUCCESS(result) )
        FB.Size(read_count);

    return result;
  }
Пример #23
0
Texture2D Texture2D::createLinkedWith(FrameBuffer &buffer)
{
    Texture2D ret;
    ret.m_id = ResourceHeap::instance().create(textureConstructor,
                                               textureDestructor,
                                               ResourceHeap::Texture2D);
    ret.bind();

    // Set filtering parameters
    useParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    useParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    if (GLEW_EXT_texture_filter_anisotropic)
    {
        int maxAnisotropy = 0;
        glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
        useParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
    }

    // Link texture with framebuffer
    glTexImage2D(GL_TEXTURE_2D, /*level*/0,
                 GL_RGBA, buffer.width(), buffer.height(), /*border*/ 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, /*pixels from FB*/ nullptr);
    glGenerateMipmapEXT(GL_TEXTURE_2D);

    // Link framebuffer with texture
    glFramebufferTexture2DEXT(
                buffer.type(),
                GL_COLOR_ATTACHMENT0_EXT, // attachment point
                GL_TEXTURE_2D,
                ret.m_id,
                0 // initial mip-level
                );
    return ret;
}
Пример #24
0
void printLetterCounter(int font1[][2], int col1, int font2[][2], int col2, float size, int x, int y) {
	if(y > 0 && y < 512-size*y) {
		vector<Point> points;
		vector<Point> points2;

		points.clear();
		for(int i=0;i<col1-1;i++) {
			points.push_back(Point(font1[i][0]*size+size*x,font1[i][1]*size+size*y));
		}
		Polygon Poly1(points);
		FB.drawPolygon(Poly1.e,25,25,122,0);
	
		points2.clear();
		for(int i=0;i<col2-1;i++) {
			points2.push_back(Point(font2[i][0]*size+size*x,font2[i][1]*size+size*y));
		}
		Polygon Poly2(points2);

		FB.drawPolygon(Poly2.e,25,25,122,0);
	
		Poly1.firePoint = Point(font1[col1-1][0]*size+size*x,font1[col1-1][1]*size+size*y);
	
		FB.floodFill(Poly1.firePoint.x, Poly1.firePoint.y, 255, 182, 193, 100, 149, 237);
	}
	else {
		//gausah digambar
	}	
}
Пример #25
0
ASDCP::Result_t
ASDCP::DCData::SequenceParser::h__SequenceParser::OpenRead()
{
  if ( m_FileList.empty() )
    return RESULT_ENDOFFILE;

  m_CurrentFile = m_FileList.begin();
  BytestreamParser Parser;
  FrameBuffer TmpBuffer;

  Kumu::fsize_t file_size = Kumu::FileSize((*m_CurrentFile).c_str());

  if ( file_size == 0 )
    return RESULT_NOT_FOUND;

  assert(file_size <= 0xFFFFFFFFL);
  Result_t result = TmpBuffer.Capacity((ui32_t) file_size);

  if ( ASDCP_SUCCESS(result) )
    result = Parser.OpenReadFrame((*m_CurrentFile).c_str(), TmpBuffer);

  if ( ASDCP_SUCCESS(result) )
    result = Parser.FillDCDataDescriptor(m_DDesc);

  // how big is it?
  if ( ASDCP_SUCCESS(result) )
    m_DDesc.ContainerDuration = m_FileList.size();

  return result;
}
void
readTiled1 (const char fileName[],
            Array2D<GZ> &pixels,
            int &width, int &height)
{
    TiledInputFile in (fileName);

    Box2i dw = in.header().dataWindow();
    width  = dw.max.x - dw.min.x + 1;
    height = dw.max.y - dw.min.y + 1;
    int dx = dw.min.x;
    int dy = dw.min.y;

    pixels.resizeErase (height, width);

    FrameBuffer frameBuffer;

    frameBuffer.insert ("G",					 // name
                        Slice (IMF::HALF,			 // type
			       (char *) &pixels[-dy][-dx].g,	 // base
				sizeof (pixels[0][0]) * 1,	 // xStride
				sizeof (pixels[0][0]) * width)); // yStride

    frameBuffer.insert ("Z",					 // name
                        Slice (IMF::FLOAT,			 // type
			       (char *) &pixels[-dy][-dx].z,	 // base
				sizeof (pixels[0][0]) * 1,	 // xStride
				sizeof (pixels[0][0]) * width)); // yStride

    in.setFrameBuffer (frameBuffer);
    in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1);
}
Пример #27
0
void	
RgbaInputFile::setFrameBuffer (Rgba *base, size_t xStride, size_t yStride)
{
    size_t xs = xStride * sizeof (Rgba);
    size_t ys = yStride * sizeof (Rgba);

    FrameBuffer fb;

    fb.insert ("R", Slice (HALF,
			   (char *) base + offsetof (Rgba, r),
			   xs, ys,
			   1, 1,	// xSampling, ySampling
			   0.0));	// fillValue

    fb.insert ("G", Slice (HALF,
			   (char *) base + offsetof (Rgba, g),
			   xs, ys,
			   1, 1,	// xSampling, ySampling
			   0.0));	// fillValue

    fb.insert ("B", Slice (HALF,
			   (char *) base + offsetof (Rgba, b),
			   xs, ys,
			   1, 1,	// xSampling, ySampling
			   0.0));	// fillValue

    fb.insert ("A", Slice (HALF,
			   (char *) base + offsetof (Rgba, a),
			   xs, ys,
			   1, 1,	// xSampling, ySampling
			   1.0));	// fillValue

    _inputFile->setFrameBuffer (fb);
}
Пример #28
0
void ShowRenderer::Render( double i_dt)
{
    std::chrono::high_resolution_clock::duration pShowTime = std::chrono::high_resolution_clock::now() - m_startTime;
    float pShowSeconds = ((float) pShowTime.count()) / ((float) std::chrono::high_resolution_clock::period::den);
    
    if ( m_events.size() > 0 )
    {
        while ( m_events[0].m_time <= pShowSeconds )
        {
            if ( m_events.size() <= 0 )
                break;
            
            float pTime = m_events[0].m_time;
            if ( strcmp( m_events[0].m_command.substr( 0, 5 ).c_str(), "mode " ) == 0 )
                ChangeMode( m_events[0].m_command.substr( 5 ) );
            cout << m_events[0].m_command << endl;
            
            m_events.erase ( m_events.begin(), m_events.begin()+1 );
        }
    }
    
    if ( m_beats.size() > 0 )
    {
        while ( m_beats[0] <= pShowSeconds )
        {
            if ( m_beats.size() <= 0 )
                break;
            
            float beat = m_beats[0];
            float pNextBeat = beat + 1.0f;
            if ( m_beats.size() > 1 )
                pNextBeat = m_beats[1];
            float pTimeToNextBeat = pNextBeat - beat;
            if ( pTimeToNextBeat > 0.0f )
            {
                if ( m_impulseFX )
                {
                    m_impulseFX->Impulse( RGBA( 255, 0, 0, 255 ), pTimeToNextBeat * 0.5f );
                }
            }
            
            m_beats.erase ( m_beats.begin(), m_beats.begin()+1 );
        }
    }
    
    FrameBuffer* pFrameBuffer = FrameBuffer::Instance();
    
    for ( int i = 0; i < m_activeFX.size(); i++ )
    {
        if ( m_activeFX[i]->IsActive() )
        {
            m_activeFX[i]->Update( i_dt );
        } else {
            RemoveFX( m_activeFX[i] );
        }
    }
    
    pFrameBuffer->Update( i_dt );
}
static void rcCloseColorBuffer(uint32_t colorbuffer)
{
    FrameBuffer *fb = FrameBuffer::getFB();
    if (!fb) {
        return;
    }
    fb->closeColorBuffer( colorbuffer );
}
static int rcOpenColorBuffer2(uint32_t colorbuffer)
{
    FrameBuffer *fb = FrameBuffer::getFB();
    if (!fb) {
        return -1;
    }
    return fb->openColorBuffer( colorbuffer );
}