ImageType ImageUtils::readBinaryPPM(const char *filename, int &width, int &height)
{

  FILE *imgin = NULL;
  int mval=0, format=0, eret;
  ImageType ret = IMAGE_TYPE_NOIMAGE;

  imgin = fopen(filename, "r");
  if (imgin == NULL) {
    fprintf(stderr, "Error: Filename %s not found\n", filename);
    return ret;
  }

  eret = fscanf(imgin, "P%d\n", &format);
  if (format != 6) {
    fprintf(stderr, "Error: readBinaryPPM only supports PPM format (P6)\n");
    return ret;
  }

  eret = fscanf(imgin, "%d %d\n", &width, &height);
  eret = fscanf(imgin, "%d\n", &mval);
  ret  = allocateImage(width, height, IMAGE_TYPE_NUM_CHANNELS);
  eret = fread(ret, sizeof(ImageTypeBase), IMAGE_TYPE_NUM_CHANNELS*width*height, imgin);

  fclose(imgin);

  return ret;

}
Esempio n. 2
0
File: main.cpp Progetto: ar90n/sdviz
sdviz::Image loadTestImage()
{
    sdviz::Image image = allocateImage( lena_width, lena_height );
    std::copy( lena, lena + lena_len, image.getBuffer() );

    return image;
}
Esempio n. 3
0
	void
	DSVL2Video::open()
	{	
		graphManager = new DSVL_VideoSource();
		
		if(FAILED(graphManager->BuildGraphFromXMLFile((char*)m_videoconfig.deviceconfig.c_str())))
		{
			std::cerr<<"OSGART->ERROR:Failed to build graph manager!!"<<std::endl;
			exit(-1);
		}

		if(FAILED(graphManager->EnableMemoryBuffer())) 
		{
			std::cerr<<"OSGART->ERROR:Failed to get memory buffer!!"<<std::endl;
			exit(-1);
		}
		
		long frame_width;
		long frame_height;

		graphManager->GetCurrentMediaFormat(&frame_width, &frame_height,NULL,NULL);

		allocateImage(frame_width, frame_height, 1, GL_BGRA, GL_UNSIGNED_BYTE, 1);
		
	}
Esempio n. 4
0
File: imageio.c Progetto: M-ike/work
Image *readDATFile(const char *fileName) {
	int  value; //for IO
	int  i, j; //loop counters
	int  width, height; //pgm properties
	Image *image;
	FILE *imageFile;

	imageFile = fopen(fileName, "rb");
	if(!imageFile) {
		printf("***imageio.c/readDATFile: cannot open file %s\n", fileName);
		return NULL;
	}

	/* save width */
	fscanf(imageFile,"%d",&width);
	/* save height */
	fscanf(imageFile,"%d",&height);
	//allocate memory
	image = allocateImage(width, height);

	//read data
	
    readDATFile_loop_17(&i, &image, &j, &imageFile, &value);

		fclose(imageFile);
		return image;
}
Esempio n. 5
0
/// Copy 'grabbed' image into capture buffer and return it.
IplImage * CvCaptureCAM_TYZX::retrieveFrame(int)
{
    if(!isOpened() || !g_tyzx_camera) return 0;

    if(!image && !allocateImage())
        return 0;

    // copy camera image into buffer.
    // tempting to reference TYZX memory directly to avoid copying.
    switch (index)
    {
        case CV_TYZX_RIGHT:
            memcpy(image->imageData, g_tyzx_camera->getRImage(), image->imageSize);
            break;
        case CV_TYZX_Z:
            memcpy(image->imageData, g_tyzx_camera->getZImage(), image->imageSize);
            break;
        case CV_TYZX_LEFT:
        default:
            memcpy(image->imageData, g_tyzx_camera->getLImage(), image->imageSize);
            break;
    }

    return image;
}
Esempio n. 6
0
 /** File has to be in one of the following formats:
     [file://]filename              Plain media file
     http://ip:port/file            HTTP URL
     ftp://ip:port/file             FTP URL
     mms://ip:port/file             MMS URL
     screen://                      Screen capture
     [dvd://][device][@raw_device]  DVD device
     [vcd://][device]               VCD device
     [cdda://][device]              Audio CD device
     udp:[[<source address>]@[<bind address>][:<bind port>]]
 */
 void open( const std::string& file, bool needPlay=true, unsigned int w=512, unsigned int h=512 )
 {
     _vlcMedia = libvlc_media_new_path( _vlc, file.c_str() );
     libvlc_media_player_set_media( _vlcPlayer, _vlcMedia );
     libvlc_video_set_callbacks( _vlcPlayer, &VLCImageStream::lockFunc, &VLCImageStream::unlockFunc,
                                 &VLCImageStream::displayFunc, this );
     libvlc_video_set_format( _vlcPlayer, "RGBA", w, h, w*4 );
     
     allocateImage( w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE );
     if ( needPlay ) play();
 }
int FrameLoader::getFrame(int frameNumber, IplImage **dst, _frame_normalization_methodT fnm, double normTarget) {
    _TICTOC_TIC_FUNC;
    message ("getFrame called ", verb_debug);
    if (lastFrameLoaded != frameNumber) {
        if (loadWholeFrame(frameNumber) != 0){
            _TICTOC_TOC_FUNC;
            return -1;
        };
        message ("loadWholeFrame returned ", verb_debug);
        lastFrameLoaded = frameNumber;
    }
    if (loadIm == NULL) {
        stringstream s("failed to load frame ");
        s << frameNumber << "\n";
        message (s.str().c_str(), verb_error);
        _TICTOC_TOC_FUNC;
        return -1;
    }
    checkAr();
    allocateImage(&convertedIm, loadIm);
    if (fnm == _frame_none) {
        message ("calling cloneImage ", verb_debug);
        cloneImage(loadIm, &convertedIm);
    } else {
        if (normTarget <= 0) {
            message("You asked me to normalize an image, but gave me a target <= 0", verb_warning);
            cloneImage(loadIm, &convertedIm);
        } else {
            double nf = getFrameNormFactor(frameNumber, fnm);
            if (nf > 0) {
                stringstream s; s << ("scaling frame: target norm factor = ");
                s << normTarget << " and this frame has nf: " << nf;
                nf = normTarget / nf;
                s << " so I am multiplying by " << nf << "\n";
                cvConvertScale(loadIm, convertedIm, nf, 0);
                message(s.str().c_str(), verb_verbose);
            } else {
                message("Norm factor returned a value <= 0", verb_warning);
                cloneImage(loadIm, &convertedIm);
            }
        }
    }
    message ("calling subImage", verb_debug);
    string msg = "convertedIm info: " + imStrInfo(convertedIm);
    message (msg.c_str(), verb_debug);
    msg = "dst info: " + imStrInfo(*dst);
     message (msg.c_str(), verb_debug);
    subImage (convertedIm, dst, ar);
    _TICTOC_TOC_FUNC;
    message ("getFrame exiting", verb_debug);
    return 0;
}
Esempio n. 8
0
void generate_stl(const char *filenames_format_string, int min_n, int max_n,int step_n, int dimensions[], const char * stl_filename)
{
	vtkSmartPointer<vtkImageData> im=allocateImage(dimensions);

	for(int co=min_n; co<=max_n; co+=step_n)
	{
		for(char ch = 'E'; ch <= 'H'; ch++)
		{
			char buff[1024];
			sprintf(buff, filenames_format_string ,co,ch);
			loadImageFromFile(buff,im,dimensions);
		}
	}

	vtkSmartPointer<vtkPolyDataMapper> mapper;
	vtkSmartPointer<vtkLODActor> actor;
	vtkSmartPointer<vtkMarchingCubes> contourf = vtkSmartPointer<vtkMarchingCubes>::New();
	contourf->SetInputData(im);
	contourf->SetValue(0,127);
	contourf->ComputeNormalsOff();
	contourf->ComputeScalarsOff();
	contourf->ComputeGradientsOff();
//	contourf->SetInputMemoryLimit(500000);
	printf("About to update contourf");
	contourf->Update();
	printf("Contour Generated");
	vtkSmartPointer<vtkSmoothPolyDataFilter> smoothf = vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
	smoothf->SetInputData(contourf->GetOutput());
	smoothf->SetRelaxationFactor(0.1);
	smoothf->SetNumberOfIterations(20);
	smoothf->Update();
	printf("Contour smoothed\n");
    mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputData(smoothf->GetOutput());
	printf("Begin updating mapper\n");
	mapper->Update();
	vtkSmartPointer<vtkPLYWriter> stlwriter = vtkSmartPointer<vtkPLYWriter>::New();
	stlwriter->SetInputData(smoothf->GetOutput());
	stlwriter->SetFileName(stl_filename);
	stlwriter->SetFileTypeToBinary();
	printf("Begin Writing stl file %s\n", stl_filename);
	stlwriter->Write();
	printf("Done writing to stl file");
	//im->Delete();
}
void VideoPlayer::open( const std::string& file, unsigned int w, unsigned int h )
{
    if ( libvlc_media_player_is_playing(_vlcPlayer)==1 )
    {
        libvlc_media_player_stop( _vlcPlayer );
        libvlc_media_release( _vlcMedia );
    }
    
    std::string protocol = osgDB::getServerProtocol( file );
    if ( !protocol.empty() ) _vlcMedia = libvlc_media_new_location( _vlc, file.c_str() );
    else _vlcMedia = libvlc_media_new_path( _vlc, file.c_str() );
    
    libvlc_media_player_set_media( _vlcPlayer, _vlcMedia );
    libvlc_video_set_callbacks( _vlcPlayer, &VideoPlayer::lockFunc, &VideoPlayer::unlockFunc,
                                &VideoPlayer::displayFunc, this );
    libvlc_video_set_format( _vlcPlayer, "RGBA", w, h, w*4 );
    
    allocateImage( w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE );
    setInternalTextureFormat( GL_RGBA );
}
Esempio n. 10
0
bool vtImage::Create(int width, int height, int bitdepth, bool create_palette)
{
	GLenum pixelFormat;
	GLenum dataType = GL_UNSIGNED_BYTE;

	if (bitdepth == 24)
	{
		pixelFormat = GL_RGB;
	}
	else if (bitdepth == 32)
	{
		pixelFormat = GL_RGBA;
	}
	else if (bitdepth == 8)
	{
		pixelFormat = GL_LUMINANCE;
	}
	else
		return false;

	allocateImage(width, height, 1, pixelFormat, dataType);

	return true;
}
Esempio n. 11
0
File: main.cpp Progetto: ar90n/sdviz
int main(int argc, char const* argv[])
{
    sdviz::Config config;
    config.http_port = 8082;
    config.ws_port = 8083;
    sdviz::start( config );

    sdviz::Image org_image = loadTestImage();
    sdviz::Image image = allocateImage( org_image.getWidth(), org_image.getHeight() );
    size_t const image_size = 3 * org_image.getWidth() * org_image.getHeight();
    std::copy( org_image.getBuffer(), org_image.getBuffer() + image_size, image.getBuffer() );

    sdviz::Canvas canvas{ image.getWidth(), image.getHeight() };
    canvas.drawImage( image, std::make_tuple( 0.0, 0.0 ) );
    auto image_element = sdviz::CanvasElement::create( canvas );

    sdviz::ChartElement::value_type chart_data{ calcHistogram( image ) };
    sdviz::ChartElement chart_element = sdviz::ChartElement::create( chart_data );

    double red_slider_value = 0.5;
    sdviz::SliderElementParam red_slider_param;
    red_slider_param.label = "RED";
    red_slider_param.on_value_changed = [&red_slider_value]( double old_value, double new_value ){
        red_slider_value = new_value;
    };
    sdviz::SliderElement red_slider_element = sdviz::SliderElement::create( red_slider_value, red_slider_param );

    double blue_slider_value = 0.5;
    sdviz::SliderElementParam blue_slider_param;
    blue_slider_param.label = "BLUE";
    blue_slider_param.on_value_changed = [&blue_slider_value]( double old_value, double new_value ){
        blue_slider_value = new_value;
    };
    sdviz::SliderElement blue_slider_element = sdviz::SliderElement::create( blue_slider_value, blue_slider_param );

    double green_slider_value = 0.5;
    sdviz::SliderElementParam green_slider_param;
    green_slider_param.label = "GREEN";
    green_slider_param.on_value_changed = [&green_slider_value]( double old_value, double new_value ){
        green_slider_value = new_value;
    };
    sdviz::SliderElement green_slider_element = sdviz::SliderElement::create( green_slider_value, green_slider_param );

    auto slider_container = sdviz::ContainerElement::create( "RGB Sliders", false );
    slider_container << red_slider_element << green_slider_element << blue_slider_element;

    sdviz::ButtonElementParam apply_button_param ;
    apply_button_param.label = "apply";
    apply_button_param.on_value_changed = [&]( bool new_value, bool old_value ){
        shiftColors( org_image, image, red_slider_value, blue_slider_value, green_slider_value );

        sdviz::Canvas canvas{ image.getWidth(), image.getHeight() };
        canvas.drawImage( image, std::make_tuple( 0.0, 0.0 ) );
        image_element.setValue( canvas );

        sdviz::ChartElement::value_type const chart_data{ calcHistogram( image ) };
        chart_element.setValue( chart_data );
    };
    sdviz::ButtonElement apply_button_element = sdviz::ButtonElement::create( false, apply_button_param );

    sdviz::eout << image_element << chart_element << sdviz::endl
                << slider_container << sdviz::Page::endl
                << apply_button_element << sdviz::Page::endl;

    sdviz::wait();
    return 0;
}
Esempio n. 12
0
        bool open(xine_t* xine, const std::string& filename)
        {
            if (filename==getFileName()) return true;

            _xine = xine;

            // create visual
            rgbout_visual_info_t* visual = new rgbout_visual_info_t;
            visual->levels = PXLEVEL_ALL;
            visual->format = PX_RGB32;
            visual->user_data = this;
            visual->callback = my_render_frame;

            // set up video driver
            _vo = xine_open_video_driver(_xine, "rgb", XINE_VISUAL_TYPE_RGBOUT, (void*)visual);

            // set up audio driver
            char* audio_driver = getenv("OSG_XINE_AUDIO_DRIVER");
            _ao = audio_driver ? xine_open_audio_driver(_xine, audio_driver, NULL) : xine_open_audio_driver(_xine, "auto", NULL);

            if (!_vo)
            {
                OSG_NOTICE<<"XineImageStream::open() : Failed to create video driver"<<std::endl;
                return false;
            }


            // set up stream
            _stream = xine_stream_new(_xine, _ao, _vo);

            if (_stream)
            {
                if (_volume < 0.0)
                {
                    _volume = static_cast<float>(xine_get_param(_stream, XINE_PARAM_AUDIO_VOLUME))/100.0f;
                }
                else
                {
                    setVolume(_volume);
                }
            }

            _event_queue = xine_event_new_queue(_stream);
            xine_event_create_listener_thread(_event_queue, event_listener, this);

            int result = xine_open(_stream, filename.c_str());

            if (result==0)
            {
                OSG_INFO<<"XineImageStream::open() : Could not ready movie file."<<std::endl;
                close();
                return false;
            }


            _ready = false;

            int width = xine_get_stream_info(_stream,XINE_STREAM_INFO_VIDEO_WIDTH);
            int height = xine_get_stream_info(_stream,XINE_STREAM_INFO_VIDEO_HEIGHT);
            allocateImage(width,height,1,GL_RGB,GL_UNSIGNED_BYTE,1);

            OSG_INFO<<"XineImageStream::open() size "<<width<<" "<<height<<std::endl;

            // play();

            return true;

        }
Esempio n. 13
0
File: imageio.c Progetto: M-ike/work
Image *readPGMFile(const char *fileName) {

	int  c, value; //for IO
	int  i, j; //loop counters
	int  width, height, maxval; //pgm properties
	char number[6]; //should not have more than 5 digits
	Image *image;
	FILE *imageFile;

	imageFile = fopen(fileName, "rb");
	if(!imageFile) {
		printf("***imageio.c/readPGMFile: cannot open file %s\n", fileName);
		return NULL;
	}
	
	c = getc(imageFile);
	if(!(c == 'P' && getc(imageFile) == '5')) {
		printf("***imageio.c/readPGMFile: input file is not in PGM file format.\n");
		return NULL;
	}

	while(isspace((c = getc(imageFile)))) /* skip whitespace */
		;
	while(c == '#') { /* skip comments */
		while((c = getc(imageFile)) != '\n')
			;
		c = getc(imageFile);
	}
	/* save width */
	
    readPGMFile_loop_1(&i, number, &c, &imageFile);

	number[i] = '\0';
	width = atoi(number);

	while(isspace((c = getc(imageFile)))) /* skip whitespace */
		;
	while(c == '#') { /* skip comments */
		while((c = getc(imageFile)) != '\n')
			;
		c = getc(imageFile);
	}
	/* save height */
	
    readPGMFile_loop_2(&i, number, &c, &imageFile);

	number[i] = '\0';
	height = atoi(number);

	while(isspace((c = getc(imageFile))))
		;
	
    readPGMFile_loop_3(&i, number, &c, &imageFile);

	number[i] = '\0';
	maxval = atoi(number);

	if(maxval > 255) {
		printf("***imageio.c/readPGMFile: The maximum grey value is greater than 255.\n");
		return NULL;
	}

	//allocate memory
	image = allocateImage(width, height);

	//read data
	
    readPGMFile_loop_4(&i, &image, &j, &value, &imageFile);

	fclose(imageFile);
	return image;
}
Esempio n. 14
0
bool Image::allocateSurface(
	unsigned int         width,
	unsigned int         height,
	cairo_format_t       format,
	const unsigned char* data
) {
	// The default is for CAIRO_FORMAT_ARGB32.
	GLenum pf1 = GL_RGBA;
	GLenum pf2 = GL_UNSIGNED_INT_8_8_8_8_REV;

	if(format == CAIRO_FORMAT_A8) {
		pf1 = GL_ALPHA;
		pf2 = GL_UNSIGNED_BYTE;

		// In A8 surfaces, the width must be evenly divisible by 4; if not,
		// this will catch that failure and resize the image appropriately.
		width = cairo_format_stride_for_width(format, width);
	}

	else if(format != CAIRO_FORMAT_ARGB32) {
		OSGCAIRO_WARN 
			<< "The format you've chosen is not supported in osgCairo; there is no "
			"compelling reason (speed or otherwise) to use a format other than "
			"ARGB32 or A8 in an OpenGL setting."
			<< std::endl
		;

		return false;
	}

	// Call the osg::Image allocation method.
	allocateImage(width, height, 1, pf1, pf2);

	if(!osg::Image::valid()) return false;

	unsigned int i = 4;

	// This will have to do for now. :)
	if(format == CAIRO_FORMAT_A8) i = 1;

	if(data) std::memcpy(_data, data, (width * height) * i);

	else std::memset(_data, 0, (width * height) * i);

	if(format == CAIRO_FORMAT_A8) _pixelFormat = GL_ALPHA;

	else _pixelFormat = GL_BGRA;

	// Remove any previous surface allocation.
	if(_surface) cairo_surface_destroy(_surface);

	_surface = cairo_image_surface_create_for_data(
		_data,
		format,
		width,
		height,
		cairo_format_stride_for_width(format, width)
	);

	if(!valid()) return false;

	dirty();

	return true;
}
Esempio n. 15
0
bool Image::allocateSurface(const osg::Image* image) {
	if(!image) return false;

	if(_surface) return false;

	const osgCairo::Image* test = dynamic_cast<const osgCairo::Image*>(image);

	if(test) {
		OSGCAIRO_WARN
			<< "Cannot allocate from an existing osgCairo::Image; "
			"use copy construction instead; this method is only intended "
			"for allocating from a traditional osg::Image."
			<< std::endl
		;

		return false;
	}

	GLenum format = image->getPixelFormat();

	if(format == GL_ALPHA || format == GL_LUMINANCE) return allocateSurface(
		image->s(),
		image->t(),
		CAIRO_FORMAT_A8,
		static_cast<const unsigned char*>(image->getDataPointer())
	);

	else if(format != GL_RGB && format != GL_RGBA) {
		OSGCAIRO_WARN
			<< "Can only allocate ARGB32 surfaces from GL_RGB/GL_RGBA Image sources."
			<< std::endl
		;

		return false;
	}

	allocateImage(image->s(), image->t(), 1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV);

	if(!osg::Image::valid()) return false;

	_pixelFormat = GL_BGRA;

	const unsigned char* data      = image->data();
	unsigned int         numPixels = image->s() * image->t();
	unsigned int         offset    = 4;

	if(format == GL_RGB) offset = 3;

	for(unsigned int i = 0; i < numPixels; i++) {
		unsigned char a = data[i * offset + 3];
		unsigned char r = data[i * offset + 2];
		unsigned char g = data[i * offset + 1];
		unsigned char b = data[i * offset];

		// We want ARGB32 from a _SOURCE_ that _DOES_ have an alpha
		// channel; therefore, we need to premultiply.
		if(format == GL_RGBA) {			
			_data[i * 4]     = (r * a) / 255;
			_data[i * 4 + 1] = (g * a) / 255;
			_data[i * 4 + 2] = (b * a) / 255;
			_data[i * 4 + 3] = a;
		}

		// Otherwise, we're loading from a source with no alpha
		// channel. This doesn't make a lot of sense to do, unless
		// the user is planning on using CAIRO_OPERATOR_CLEAR at
		// some point during their drawing.
		else {
			_data[i * 4]     = r;
			_data[i * 4 + 1] = g;
			_data[i * 4 + 2] = b;
			_data[i * 4 + 3] = 255;
		}
	}

	// Remove any previous surface allocation.
	if(_surface) cairo_surface_destroy(_surface);

	_surface = cairo_image_surface_create_for_data(
		_data,
		CAIRO_FORMAT_ARGB32,
		image->s(),
		image->t(),
		cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, image->s())
	);

	if(!valid()) return false;

	dirty();

	return true;
}
Esempio n. 16
0
File: main.cpp Progetto: ar90n/sdviz
sdviz::Image loadTestImage()
{
    sdviz::Image image = allocateImage( rad_image_width, rad_image_height );
    std::copy( rad_image, rad_image + rad_image_len, image.getBuffer() );
    return image;
}