Пример #1
0
  static void RGB24ToMatlabString(ChunkedBuffer& target,
                                  const ImageAccessor& source)
  {
    assert(source.GetFormat() == PixelFormat_RGB24);

    target.AddChunk("double(permute(reshape([ ");

    for (unsigned int y = 0; y < source.GetHeight(); y++)
    {
      const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
      
      std::string s;
      s.reserve(source.GetWidth() * 3 * 8);
      
      for (unsigned int x = 0; x < 3 * source.GetWidth(); x++, p++)
      {
        s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " ";
      }
      
      target.AddChunk(s);
    }

    target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) +
                    " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))");
  }
Пример #2
0
 static void MemoryCallback(png_structp png_ptr, 
                            png_bytep data, 
                            png_size_t size)
 {
   ChunkedBuffer* buffer = reinterpret_cast<ChunkedBuffer*>(png_get_io_ptr(png_ptr));
   buffer->AddChunk(reinterpret_cast<const char*>(data), size);
 }
Пример #3
0
  static void ToMatlabStringInternal(ChunkedBuffer& target,
                                     const ImageAccessor& source)
  {
    target.AddChunk("double([ ");

    for (unsigned int y = 0; y < source.GetHeight(); y++)
    {
      const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));

      std::string s;
      if (y > 0)
      {
        s = "; ";
      }

      s.reserve(source.GetWidth() * 8);

      for (unsigned int x = 0; x < source.GetWidth(); x++, p++)
      {
        s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " ";
      }

      target.AddChunk(s);
    }

    target.AddChunk("])");
  }
Пример #4
0
  void ImageAccessor::ToMatlabString(std::string& target) const
  {
    ChunkedBuffer buffer;

    switch (GetFormat())
    {
      case PixelFormat_Grayscale8:
        ToMatlabStringInternal<uint8_t>(buffer, *this);
        break;

      case PixelFormat_Grayscale16:
        ToMatlabStringInternal<uint16_t>(buffer, *this);
        break;

      case PixelFormat_SignedGrayscale16:
        ToMatlabStringInternal<int16_t>(buffer, *this);
        break;

      case PixelFormat_Float32:
        ToMatlabStringInternal<float>(buffer, *this);
        break;

      case PixelFormat_RGB24:
        RGB24ToMatlabString(buffer, *this);
        break;

      default:
        throw OrthancException(ErrorCode_NotImplemented);
    }   

    buffer.Flatten(target);
  }
Пример #5
0
 virtual void write(const void *data, size_t size)
 {
   if (size > 0)
   {
     buffer_.AddChunk(reinterpret_cast<const char*>(data), size);
   }
 }
Пример #6
0
  void PngWriter::WriteToMemory(std::string& png,
                                unsigned int width,
                                unsigned int height,
                                unsigned int pitch,
                                PixelFormat format,
                                const void* buffer)
  {
    ChunkedBuffer chunks;

    Prepare(width, height, pitch, format, buffer);

    if (setjmp(png_jmpbuf(pimpl_->png_)))
    {
      // Error during writing PNG
      throw OrthancException(ErrorCode_InternalError);      
    }

    png_set_write_fn(pimpl_->png_, &chunks, MemoryCallback, NULL);

    Compress(width, height, pitch, format);

    chunks.Flatten(png);
  }
Пример #7
0
TEST(RestApi, ChunkedBuffer)
{
  ChunkedBuffer b;
  ASSERT_EQ(0u, b.GetNumBytes());

  b.AddChunk("hello", 5);
  ASSERT_EQ(5u, b.GetNumBytes());

  b.AddChunk("world", 5);
  ASSERT_EQ(10u, b.GetNumBytes());

  std::string s;
  b.Flatten(s);
  ASSERT_EQ("helloworld", s);
}
Пример #8
0
 void Flatten(std::string& s)
 {
   buffer_.Flatten(s);
 }