Пример #1
0
int
main (int argc, char **argv)
{
  stream *s = (argc > 1) ? New buf_stream (argv[1], strlen (argv[1]))
                         : New file_stream (stdin);
  gob *g = g_read (s);
  if (g)
    g->fwrite (stderr);
  else
    fprintf (stderr, "-- Error reading input");
  fprintf (stderr, "\n");
}
Пример #2
0
void BindingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
      const vector<Blob<Dtype>*>& top) {
	// check and initialization
	BindingParameter binding_param = this->layer_param_.binding_param();
    CHECK(binding_param.has_num_binding_group())<< "num_binding_group should be set!\n";
  	CHECK(binding_param.has_channels_each_group())<< "channels_each_group should be set!\n";
  	CHECK(binding_param.has_binding_rules())<< "binding_rules should be set!\n";
  	this->num_binding_group_ = binding_param.num_binding_group();
  	this->channels_each_group_ = binding_param.channels_each_group();
  	this->binding_rules.clear();
  	this->max_channel_id = 0;
  	CHECK_GT(this->num_binding_group_, 0) <<"num_binding_group  should be positive\n";
  	CHECK_GT(this->channels_each_group_, 0) <<"channels_each_group  should be positive\n";


  	std::istringstream buf_stream(binding_param.binding_rules());

  	const string& rules_string = binding_param.binding_rules();
  	// parse the rules_string into binding rules
  	int count=0;
  	for(int i=0;i<this->num_binding_group_;++i)
  	{
  		vector<int> buf_group;
  		buf_group.clear();
  		for(int j=0; j< this->channels_each_group_;j++)
  		{
  			int buf_int =0;
  			buf_stream >> buf_int;
  			buf_group.push_back(buf_int);
  			if(buf_int > this->max_channel_id)
  			{
  				this->max_channel_id = buf_int;
  			}
  			count++;
  		}
  		this->binding_rules.push_back(buf_group);
  	}

  	CHECK((count ==  this->channels_each_group_* this->num_binding_group_))<<"the binding rule does not matches"
  			<< "the num_binding_group  and  channels_each_group";

}
Пример #3
0
bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
{
    wxUint32  width, height;
    wxUint16  maxval;
    char      c(0);

    image->Destroy();

    /*
     * Read the PNM header
     */

    wxBufferedInputStream buf_stream(stream);
    wxTextInputStream text_stream(buf_stream);

    Skip_Comment(buf_stream);
    if (buf_stream.GetC()==wxT('P')) c=buf_stream.GetC();

    switch (c)
    {
        case wxT('2'): // ASCII Grey
        case wxT('3'): // ASCII RGB
        case wxT('5'): // RAW Grey
        case wxT('6'): break;
        default:
            if (verbose)
            {
                wxLogError(_("PNM: File format is not recognized."));
            }
            return false;
    }

    text_stream.ReadLine(); // for the \n
    Skip_Comment(buf_stream);
    text_stream >> width >> height ;
    Skip_Comment(buf_stream);
    text_stream >> maxval;

    //cout << line << " " << width << " " << height << " " << maxval << endl;
    image->Create( width, height );
    unsigned char *ptr = image->GetData();
    if (!ptr)
    {
        if (verbose)
        {
           wxLogError( _("PNM: Couldn't allocate memory.") );
        }
        return false;
    }


    if (c=='2') // Ascii GREY
    {
        wxUint32 value, size=width*height;
        for (wxUint32 i=0; i<size; ++i)
        {
            value=text_stream.Read32();
            if ( maxval != 255 )
                value = (255 * value)/maxval;
            *ptr++=(unsigned char)value; // R
            *ptr++=(unsigned char)value; // G
            *ptr++=(unsigned char)value; // B
            if ( !buf_stream )
            {
                if (verbose)
                {
                    wxLogError(_("PNM: File seems truncated."));
                }
                return false;
            }
        }
    }
    if (c=='3') // Ascii RBG
    {
        wxUint32 value, size=3*width*height;
        for (wxUint32 i=0; i<size; ++i)
          {
            //this is very slow !!!
            //I wonder how we can make any better ?
            value=text_stream.Read32();
            if ( maxval != 255 )
                value = (255 * value)/maxval;
            *ptr++=(unsigned char)value;

            if ( !buf_stream )
              {
                if (verbose)
                {
                    wxLogError(_("PNM: File seems truncated."));
                }
                return false;
              }
          }
    }
    if (c=='5') // Raw GREY
    {
        wxUint32 size=width*height;
        unsigned char value;
        for (wxUint32 i=0; i<size; ++i)
        {
            buf_stream.Read(&value,1);
            if ( maxval != 255 )
                value = (255 * value)/maxval;
            *ptr++=value; // R
            *ptr++=value; // G
            *ptr++=value; // B
            if ( !buf_stream )
            {
                if (verbose)
                {
                    wxLogError(_("PNM: File seems truncated."));
                }
                return false;
            }
        }
    }

    if ( c=='6' ) // Raw RGB
    {
        buf_stream.Read(ptr, 3*width*height);
        if ( maxval != 255 )
        {
            for ( unsigned i = 0; i < 3*width*height; i++ )
                ptr[i] = (255 * ptr[i])/maxval;
        }
    }

    image->SetMask( false );

    const wxStreamError err = buf_stream.GetLastError();
    return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
}