2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2016-08-26 19:30:52 +00:00
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
//
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2016-08-26 19:30:52 +00:00
|
|
|
|
2020-04-28 11:13:27 +00:00
|
|
|
#include <vtkm/io/DecodePNG.h>
|
2016-08-26 19:30:52 +00:00
|
|
|
|
2019-06-18 19:19:05 +00:00
|
|
|
#include <vtkm/cont/Logging.h>
|
|
|
|
#include <vtkm/internal/Configure.h>
|
|
|
|
|
|
|
|
VTKM_THIRDPARTY_PRE_INCLUDE
|
2020-04-08 20:29:40 +00:00
|
|
|
#include <vtkm/thirdparty/lodepng/vtkmlodepng/lodepng.h>
|
|
|
|
VTKM_THIRDPARTY_POST_INCLUDE
|
2019-06-18 19:19:05 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2020-04-28 11:13:27 +00:00
|
|
|
namespace io
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2016-08-26 19:30:52 +00:00
|
|
|
|
2019-06-18 19:19:05 +00:00
|
|
|
vtkm::UInt32 DecodePNG(std::vector<unsigned char>& out_image,
|
|
|
|
unsigned long& image_width,
|
|
|
|
unsigned long& image_height,
|
|
|
|
const unsigned char* in_png,
|
|
|
|
std::size_t in_size)
|
2016-08-26 19:30:52 +00:00
|
|
|
{
|
2019-07-17 18:21:33 +00:00
|
|
|
using namespace vtkm::png;
|
2019-06-18 19:19:05 +00:00
|
|
|
constexpr std::size_t bitdepth = 8;
|
|
|
|
vtkm::UInt32 iw = 0;
|
|
|
|
vtkm::UInt32 ih = 0;
|
|
|
|
|
|
|
|
auto retcode = lodepng::decode(out_image, iw, ih, in_png, in_size, LCT_RGBA, bitdepth);
|
|
|
|
image_width = iw;
|
|
|
|
image_height = ih;
|
|
|
|
return retcode;
|
2016-08-26 19:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-28 11:13:27 +00:00
|
|
|
} // namespace vtkm::io
|