DGtal 1.3.0
Loading...
Searching...
No Matches
testSTBWriter.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "ConfigTest.h"
34#include "DGtalCatch.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/io/readers/STBReader.h"
37#include "DGtal/io/writers/STBWriter.h"
38#include "DGtal/images/ImageSelector.h"
39
40#include "DGtal/io/colormaps/GradientColorMap.h"
41#include "DGtal/io/writers/PPMWriter.h"
43
44using namespace std;
45using namespace DGtal;
46
48// Functions for testing class STBReader.
50
51TEST_CASE( "Testing STBWriter" )
52{
53 SECTION("Testing feature io/readers of STBWriter (Grayscale PNG)")
54 {
55 std::string filename = testPath + "samples/contourS.png";
57 Image image = STBReader<Image>::import( filename );
58 CAPTURE(image);
59 PPMWriter<Image>::exportPPM("contourS-export.ppm", image);
60
61 STBWriter<Image>::exportPNG("contourS-export.png", image);
62 CHECK( image.isValid());
63 }
64
65 SECTION("Testing feature io/readers of STBWriter (PNG)")
66 {
67 std::string filename = testPath + "samples/color64.png";
69 Image image = STBReader<Image>::import( filename );
70 CHECK( image.isValid());
71 PPMWriter<Image>::exportPPM("color64-export.ppm", image);
72 STBWriter<Image>::exportTGA("color64-export.tga", image);
73 STBWriter<Image>::exportJPG("color64-export.jpg", image);
74 STBWriter<Image>::exportBMP("color64-export.bmp", image);
75 }
76
77 SECTION("Testing scalar functor (PNG)")
78 {
80 Image image(Z2i::Domain(Z2i::Point(0,0), Z2i::Point(8,8)));
81
82 image.setValue(Z2i::Point(3,3), 10);
83 image.setValue(Z2i::Point(1,1), 1);
84 image.setValue(Z2i::Point(7,7), 20);
85
86 // Creating colormap.
87 GradientColorMap<int> cmap_grad( 0, 30 );
88 cmap_grad.addColor( Color( 50, 50, 255 ) );
89 cmap_grad.addColor( Color( 255, 0, 0 ) );
90 cmap_grad.addColor( Color( 255, 255, 10 ) );
91
92 CHECK( image.isValid());
93 STBWriter<Image,GradientColorMap<int>>::exportPNG("scalar-export.jpg", image, cmap_grad );
94 }
95
96}
97
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
static ImageContainer import(const std::string &filename, const Functor &aFunctor=Functor())
Aim: Image Writer using the stb_image.h header only code.
Definition: STBWriter.h:65
static bool exportTGA(const std::string &filename, const ImageContainer &anImage, const Functor &aFunctor=Functor())
static bool exportPNG(const std::string &filename, const ImageContainer &anImage, const Functor &aFunctor=Functor())
static bool exportBMP(const std::string &filename, const ImageContainer &anImage, const Functor &aFunctor=Functor())
static bool exportJPG(const std::string &filename, const ImageContainer &anImage, const Functor &aFunctor=Functor(), int quality=70)
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
Definition: ImageSelector.h:78
static bool exportPPM(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool topbottomOrder=true)
CAPTURE(thicknessHV)
TEST_CASE("Testing STBWriter")
SECTION("Testing constant forward iterators")