void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief)
{
	image_interface_iterator iter(device().mconfig().root_device());
	int count = 0;
	int index = -1;
	for (const device_image_interface *image = iter.first(); image != NULL; image = iter.next())
	{
		if (this == image)
			index = count;
		if ((image->image_type() == image_type() && device_type==NULL) || (device_type==image->device().type()))
			count++;
	}
	const char *inst_name = (device_type!=NULL) ? inst : device_typename(image_type());
	const char *brief_name = (device_type!=NULL) ? brief : device_brieftypename(image_type());
	if (count > 1)
	{
		m_instance_name.printf("%s%d", inst_name , index + 1);
		m_brief_instance_name.printf("%s%d", brief_name, index + 1);
	}
	else
	{
		m_instance_name = inst_name;
		m_brief_instance_name = brief_name;
	}
}
image_type load_file( const std::string& filename ) {
	fitsfile* f;
	int status = 0, naxis;

	fits_open_file( &f, filename.c_str(), READONLY, &status );
	fits_get_img_dim( f, &naxis, &status );
	if( naxis != 2 && naxis != 3 ) {
		std::cout << "Could not read image" << std::endl;
		fits_close_file( f, &status );
		return image_type();
	}

	long dim[3];
	dim[0] = dim[1] = dim[2] = 0;
	fits_get_img_size( f, 3, dim, &status );

	image_type data( image_type::extents_type( dim[0], dim[1] ) );
	typedef CFitsIOTypeMap< image_type::element > map;

	int any_null;
	unsigned short null = 0;
	fits_read_img( f, map::type, 1, data.num_elements(), &null, data.ptr(),
		&any_null, &status );

	fits_close_file( f, &status );
	if( status ) {
		fits_report_error( stderr, status );
		return image_type();
	}		

	return data;
}
Esempio n. 3
0
static void gretl_clipboard_get (GtkClipboard *clip,
				 GtkSelectionData *selection_data,
				 guint info,
				 gpointer p)
{
#if 1 || CLIPDEBUG
    fprintf(stderr, "gretl_clipboard_get: info = %d (%s)\n", 
	    (int) info, fmt_label(info));
#endif

    if (image_type(info)) {
	write_plot_for_copy(info);
	if (clipboard_buf == NULL) {
	    return;
	}
    } else {
	if (clipboard_buf == NULL || *clipboard_buf == '\0') {
	    return;
	} else if (info != TARGET_UTF8_STRING) {
	    /* remove any Unicode minuses (??) */
	    strip_unicode_minus(clipboard_buf);
	}	
    }

    if (info == TARGET_RTF) {
	gtk_selection_data_set(selection_data,
			       GDK_SELECTION_TYPE_STRING,
			       8, (guchar *) clipboard_buf, 
			       strlen(clipboard_buf));
    } else if (image_type(info)) {
	gtk_selection_data_set(selection_data,
			       GDK_SELECTION_TYPE_STRING,
			       8, (guchar *) clipboard_buf, 
			       clipboard_bytes);
    } else {
	gtk_selection_data_set_text(selection_data, clipboard_buf, -1);
    }
}
Esempio n. 4
0
void device_image_interface::update_names()
{
	image_interface_iterator iter(device().mconfig().root_device());
	int count = 0;
	int index = -1;
	for (const device_image_interface *image = iter.first(); image != NULL; image = iter.next())
	{
		if (this == image)
			index = count;
		if (image->image_type() == image_type())
			count++;
	}
	if (count > 1)
	{
		m_instance_name.printf("%s%d", device_typename(image_type()), index + 1);
		m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1);
	}
	else
	{
		m_instance_name = device_typename(image_type());
		m_brief_instance_name = device_brieftypename(image_type());
	}
}
Esempio n. 5
0
void device_image_interface::update_names()
{
	const device_image_interface *image = NULL;
	int count = 0;
	int index = -1;

	for (bool gotone = device().mconfig().devicelist().first(image); gotone; gotone = image->next(image))
	{
		if (this == image)
			index = count;
		if (image->image_type() == image_type())
			count++;
	}
	if (count > 1) {
		m_instance_name.printf("%s%d", device_typename(image_type()), index + 1);
		m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1);
	}
	else
	{
		m_instance_name = device_typename(image_type());
		m_brief_instance_name = device_brieftypename(image_type());
	}
}
Esempio n. 6
0
void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief)
{
	int count = 0;
	int index = -1;
	for (const device_image_interface &image : image_interface_iterator(device().mconfig().root_device()))
	{
		if (this == &image)
			index = count;
		if ((image.image_type() == image_type() && device_type == nullptr) || (device_type == image.device().type()))
			count++;
	}
	const char *inst_name = (device_type!=nullptr) ? inst : device_typename(image_type());
	const char *brief_name = (device_type!=nullptr) ? brief : device_brieftypename(image_type());
	if (count > 1)
	{
		m_instance_name = string_format("%s%d", inst_name, index + 1);
		m_brief_instance_name = string_format("%s%d", brief_name, index + 1);
	}
	else
	{
		m_instance_name = inst_name;
		m_brief_instance_name = brief_name;
	}
}
Esempio n. 7
0
bool device_image_interface::support_command_line_image_creation() const
{
	bool result;
	switch (image_type())
	{
	case IO_PRINTER:
	case IO_SERIAL:
	case IO_PARALLEL:
		// going by the assumption that these device image types should support this
		// behavior; ideally we'd get rid of IO_* and just push this to the specific
		// devices
		result = true;
		break;
	default:
		result = false;
		break;
	}
	return result;
}
Esempio n. 8
0
void device_image_interface::image_checkhash()
{
    device_image_partialhash_func partialhash;

    /* only calculate CRC if it hasn't been calculated, and the open_mode is read only */
    if (m_hash.first() == NULL && m_readonly && !m_created)
    {
        /* do not cause a linear read of 600 megs please */
        /* TODO: use SHA1 in the CHD header as the hash */
        if (image_type() == IO_CDROM)
            return;

		/* Skip calculating the hash when we have an image mounted through a software list */
		if ( m_software_info_ptr )
			return;

        /* retrieve the partial hash func */
        partialhash = get_partial_hash();

        run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL);
    }
    return;
}
Esempio n. 9
0
void device_image_interface::image_checkhash()
{
	device_image_partialhash_func partialhash;

	// only calculate CRC if it hasn't been calculated, and the open_mode is read only
	UINT32 crcval;
	if (!m_hash.crc(crcval) && is_readonly() && !m_created)
	{
		// do not cause a linear read of 600 megs please
		// TODO: use SHA1 in the CHD header as the hash
		if (image_type() == IO_CDROM)
			return;

		// Skip calculating the hash when we have an image mounted through a software list
		if ( m_software_info_ptr )
			return;

		// retrieve the partial hash func
		partialhash = get_partial_hash();

		run_hash(partialhash, m_hash, util::hash_collection::HASH_TYPES_ALL);
	}
	return;
}
Esempio n. 10
0
//----------------------------------------
void Image::loadPGM(const char* aFileName)
//----------------------------------------
{
	// Open the file
	std::ifstream input_file(aFileName);

	// The file does not exist
	if (!input_file.is_open())
	{
		// Build the error message
		std::stringstream error_message;
		error_message << "Cannot open the file \"" << aFileName << "\". It does not exist";

		// Throw an error
		throw (error_message.str());
	}
	// The file is open
	else
	{
		// Release the memory if necessary
		destroy();

		// Variable to store a line
		char p_line_data[LINE_SIZE];

		// Get the first line
		input_file.getline(p_line_data, LINE_SIZE);

		// Get the image type
		std::string image_type(p_line_data);

		// Invalid format
		if (image_type != "P2")
		{
			//Build the error message
			std::stringstream error_message;
			error_message << "Invalid file (\"" << aFileName << "\")";

			//Throw an error
			throw (error_message.str());
		}
		// Valid format
		else
		{
			// Variable to save the max value
			int max_value(-1);

			// There is data to read
			unsigned int pixel_count(0);
			while (input_file.good())
			{
				// Get the new line
				input_file.getline(p_line_data, LINE_SIZE);

				// It is not a comment
				if (p_line_data[0] != '#')
				{
					// Store the line in a stream
					std::stringstream stream_line;
					stream_line << std::string(p_line_data);

					// The memory is not allocated
					if (!m_p_image && !m_width && !m_height)
					{
						// Load the image size
						stream_line >> m_width >> m_height;

						// Alocate the memory
						m_p_image = new float[m_width * m_height];

						// Out of memory
						if (!m_p_image)
						{
							throw ("Out of memory");
						}
					}
					// The max value is not set
					else if (max_value < 0)
					{
						// Get the max value;
						stream_line >> max_value;
					}
					// Read the pixel data
					else
					{
						// Process all the pixels of the line
						while (stream_line.good())
Esempio n. 11
0
int main(int argc, char *argv[])
{
   int ret, rawflag, img_type;
   unsigned char *idata, *odata;
   int ilen, width, height, depth, ppi, lossyflag;
   IHEAD *ihead;
   FILE *fp;
   char *outext, *ifile, ofile[MAXPATHLEN];
   NISTCOM *nistcom;


   procargs(argc, argv, &outext, &ifile, &rawflag);
   /* Set ppi to unknown */
   ppi = -1;
   nistcom = (NISTCOM *)NULL;

   /* Check image type */
   ret = read_raw_from_filesize(ifile, &idata, &ilen);
   if(ret)
      exit(ret);

   ret = image_type(&img_type, idata, ilen);
   if(ret) {
      free(idata);
      exit(ret);
   }
   free(idata);

   /* Open image file for reading based on image type */
   if((fp = fopen(ifile,"rb")) == NULL) {
      fprintf(stderr, "ERROR: main : fopen : %s\n",ifile);
      exit(-1);
   }
   /* If img_type is ihead ... */
   if(img_type == IHEAD_IMG){
      /* Read ihead header and check for WSQ_SD14 compression */
      ihead = readihdr(fp);
      if(atoi(ihead->compress) != WSQ_SD14){
         fprintf(stderr, "ERROR : main : input image not WSQ_SD14 compressed\n");
         fprintf(stderr, "        compression = %d, WSQ_SD14 = %d\n",
                 atoi(ihead->compress), WSQ_SD14);
         fclose(fp);
         free(ihead);
         exit(-1);
      }

      /* Get ppi from ihead header */
      sscanf(ihead->density,"%d", &ppi);

      /* Create a nistcom for the image attributes */
      ret = sd_ihead_to_nistcom(&nistcom, ihead, 14);
      if(ret) {
         fclose(fp);
         free(ihead);
         exit(ret);
      }
      free(ihead);
   }
   /* If image not WSQ_IMG or IHEAD_IMG, ERROR!!! */
   else if(img_type != WSQ_IMG) {
      fprintf(stderr, "ERROR : main : Invalid image\n");
      fprintf(stderr, "Expected a WSQ_SD14 compressed image in\n");
      fprintf(stderr, "either raw or ihead format.\n");
      fclose(fp);
      exit(-1);
   }

   /* Decode compressed image */
   ret = wsq14_decode_file(&odata, &width, &height, &depth, &lossyflag, fp);
   if(ret){
      fclose(fp);
      if(img_type == IHEAD_IMG)
         freefet(nistcom);
      exit(ret);
   }
   fclose(fp);

   if(debug > 1)
      fprintf(stderr, "Image pixmap constructed\n");

   /* Combine image attributes into current nistcom */
   ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi, lossyflag, -1.0);
   if(ret){
     if(img_type == IHEAD_IMG)
        freefet(nistcom);
     free(odata);
     exit(ret);
   }
   ret = del_wsq_nistcom(nistcom);
   if(ret){
      free(odata);
      freefet(nistcom);
      exit(ret);
   }

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, NCM_EXT);
   /* Write NISTCOM */
   ret = writefetfile_ret(ofile, nistcom);
   if(ret){
     freefet(nistcom);
     free(odata);
     exit(ret);
   }
   freefet(nistcom);

   /* Write decompressed image */
   sprintf(ofile, "%s.%s", ifile, outext);
   ret = write_raw_or_ihead(!rawflag, ofile, odata, width, height, depth, ppi);
   if(ret){
      free(odata);
      exit(ret);
   }
   free(odata);

   if(debug > 1)
      fprintf(stderr, "Image pixmap written to %s\n", ofile);

   exit(0);
}
edge_image_type IonDetector::canny_edge( const image_type& img ) {
	image_type::extents_type three( 3, 3 );
	Kernel gaussian( image_type( three, boost::assign::list_of
		( 1./16 )( 2./16 )( 1./16 )
		( 2./16 )( 4./16 )( 2./16 )
		( 1./16 )( 2./16 )( 1./16 ) ) );
	Kernel sobelx( image_type( three, boost::assign::list_of
		(1)(0)(-1)(2)(0)(-2)(1)(0)(-1) ) );
	Kernel sobely( image_type( three, boost::assign::list_of
		(1)(2)(1)(0)(0)(0)(-1)(-2)(-1) ) );

	image_type img_gauss( img.extents ), img_sobelx( img.extents ),
		img_sobely( img.extents );

	//gaussian.apply_kernel( img, img_gauss );
	sobelx.apply_kernel( img, img_sobelx );
	sobely.apply_kernel( img, img_sobely );

	save_file( "orig.fits", img );
	//save_file( "gauss.fits", img_gauss );
	//save_file( "sobelx.fits", img_sobelx );
	//save_file( "sobely.fits", img_sobely );

	image_type img_sobel( img_sobelx.extents );
	edge_image_type edges( img_sobelx.extents );

	image_type::element mean = 0, std_dev = 0;
	for( image_type::index i = 2; i < img_sobelx.extents.first-2; ++i ) 
	for( image_type::index j = 2; j < img_sobelx.extents.second-2; ++j ) {
		image_type::element val = img_sobelx( i, j )*img_sobelx( i, j ) +
			img_sobely( i, j )*img_sobely( i, j );
		img_sobel( i, j ) = val;
		mean += val;
	}

	save_file( "sobel.fits", img_sobel );
	
	mean /= img_sobel.num_elements();	
	for( image_type::index i = 2; i<img_sobelx.extents.first-2; ++i ) 
	for( image_type::index j = 2; j<img_sobelx.extents.second-2; ++j ) {
		std_dev += ( img_sobel( i, j ) - mean )*
			( img_sobel( i, j ) - mean );
	}
			
	std_dev = sqrt(std_dev / img_sobel.num_elements());
	image_type::element thresh = mean + canny_threshold * std_dev;
	image_type::element continue_thresh = mean + 
		canny_continue_threshold * std_dev;

	// First mark off edges with a high threshold
	for( image_type::index i = 2; i<img_sobelx.extents.first-2; ++i ) 
	for( image_type::index j = 2; j<img_sobelx.extents.second-2; ++j ) {
		edge_image_type::position pos( i, j );
		if( edges( pos ) ) continue;
		if(	canny_check( img_sobel, img_sobelx, img_sobely, 
				pos, thresh ) ) {
			std::stack< image_type::position > checks;
			checks.push( pos );

			while( !checks.empty() ) {
				pos = checks.top();
				checks.pop();

				if( edges( pos ) ) continue;
				if( !canny_check( img_sobel, img_sobelx, img_sobely, 
						pos, continue_thresh ) ) 
					continue;

				edges( pos ) = 1.0f;
				pos.first++;	checks.push( pos );
				pos.second++;	checks.push( pos );
				pos.second-=2;	checks.push( pos );
				pos.first--;	checks.push( pos );
				pos.second+=2;	checks.push( pos );
				pos.first--;	checks.push( pos );
				pos.second--;	checks.push( pos );
				pos.second--;	checks.push( pos );
			}
		}
	}

		
	save_file( "edges.fits", edges );
	return edges;
}