Skip to content

Commit

Permalink
Move namespace from tq to vivid
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Gurdan committed May 17, 2019
1 parent 585c522 commit de9787a
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 148 deletions.
80 changes: 41 additions & 39 deletions examples/qmake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

int main( int, char* argv[] )
{
tq::ColorTable::load( VIVID_ROOT_PATH "/res/colors.json" );
using namespace vivid;

ColorTable::load( VIVID_ROOT_PATH "/res/colors.json" );

QDir dir( argv[ 0 ] );
dir.cdUp();
Expand All @@ -20,32 +22,32 @@ int main( int, char* argv[] )

// introduction

tq::ColorMap hslMap( tq::ColorMap::PresetHsl );
std::cout << tq::ansi::colorize( "vivid", hslMap ) << std::endl;
ColorMap hslMap( ColorMap::PresetHsl );
std::cout << ansi::colorize( "vivid", hslMap ) << std::endl;
std::cout << std::endl;

// colormaps

dir.mkpath( "colormaps/" );
dir.cd( "colormaps/" );

std::vector<tq::ColorMap::Preset> defaults = {
tq::ColorMap::PresetBlueYellow,
tq::ColorMap::PresetCoolWarm,
tq::ColorMap::PresetInferno,
tq::ColorMap::PresetMagma,
tq::ColorMap::PresetPlasma,
tq::ColorMap::PresetRainbow,
tq::ColorMap::PresetHsl,
tq::ColorMap::PresetHslPastel,
tq::ColorMap::PresetViridis,
tq::ColorMap::PresetVivid
std::vector<ColorMap::Preset> defaults = {
ColorMap::PresetBlueYellow,
ColorMap::PresetCoolWarm,
ColorMap::PresetInferno,
ColorMap::PresetMagma,
ColorMap::PresetPlasma,
ColorMap::PresetRainbow,
ColorMap::PresetHsl,
ColorMap::PresetHslPastel,
ColorMap::PresetViridis,
ColorMap::PresetVivid
};

for ( const auto& type : defaults )
{
tq::ColorMap cmap( type );
cmap.interpolation = tq::ColorMap::InterpolationHcl;
ColorMap cmap( type );
cmap.interpolation = ColorMap::InterpolationHcl;
QImage img( 512, 32, QImage::Format_RGB32 );

for ( int c = 0; c < img.width(); c++ )
Expand All @@ -59,7 +61,7 @@ int main( int, char* argv[] )
}
}

img.save( dir.filePath( QString::fromStdString( tq::ColorMap::nameForPreset( type ) + ".png" ) ));
img.save( dir.filePath( QString::fromStdString( ColorMap::nameForPreset( type ) + ".png" ) ));
}

// interpolation
Expand All @@ -68,22 +70,22 @@ int main( int, char* argv[] )
dir.mkdir( "interpolations/" );
dir.cd( "interpolations/" );

using colorlerp_t = std::function< tq::col_t( const tq::col_t&, const tq::col_t&, const float ) >;
using colorlerp_t = std::function< col_t( const col_t&, const col_t&, const float ) >;
using annotated_colorlerp_t = std::pair<colorlerp_t, std::string>;
auto lerpHslClamp = []( const tq::col_t& c1, const tq::col_t& c2, const float t ) {
return tq::rgb::clamp( tq::rgb::lerpHsl( c1, c2, t ) );
auto lerpHslClamp = []( const col_t& c1, const col_t& c2, const float t ) {
return rgb::clamp( rgb::lerpHsl( c1, c2, t ) );
};

const std::vector<annotated_colorlerp_t> lerps = {
{ tq::rgb::lerp, "lerpRgb" },
{ tq::rgb::lerpHsv, "lerpHsv" },
{ tq::rgb::lerpHsl, "lerpHsl" },
{ tq::rgb::lerpHcl, "lerpHcl" },
{ rgb::lerp, "lerpRgb" },
{ rgb::lerpHsv, "lerpHsv" },
{ rgb::lerpHsl, "lerpHsl" },
{ rgb::lerpHcl, "lerpHcl" },
{ lerpHslClamp, "lerpHslClamped" }
};

static const tq::col_t c1( 0.7f, 0.3f, 0.3f );
static const tq::col_t c2( 0.1f, 0.6f, 0.4f );
static const col_t c1( 0.7f, 0.3f, 0.3f );
static const col_t c2( 0.1f, 0.6f, 0.4f );

for ( const auto& lerp: lerps )
{
Expand All @@ -105,37 +107,37 @@ int main( int, char* argv[] )

// low-level conversions

static const tq::col_t col( 1.f, 0.7f, 0.5f );
const auto hsl = tq::hsl::fromRgb( col );
const auto rgb_2 = tq::rgb::fromHsl( hsl );
static const col_t col( 1.f, 0.7f, 0.5f );
const auto hsl = hsl::fromRgb( col );
const auto rgb_2 = rgb::fromHsl( hsl );

std::cout << col << " -> " << hsl << " -> " << rgb_2 << std::endl;

// high-level conversions

tq::Color color1, color2;
color1 = tq::Color( c1 );
color2 = tq::Color( c2 );
Color color1, color2;
color1 = Color( c1 );
color2 = Color( c2 );

std::cout << color1.hsl() << std::endl;
std::cout << tq::lerp( color1.hsl(), color2.hsl(), 0.5f ) << std::endl;
std::cout << lerp( color1.hsl(), color2.hsl(), 0.5f ) << std::endl;

// encoding

std::cout << tq::ansi::fg( 3 ) << "yay colors" << tq::ansi::reset << std::endl;
std::cout << tq::html::fg( "#abc123" ) << "hex hex!" << tq::html::close << std::endl;
std::cout << tq::html::fg( tq::col8_t( 100, 144, 159 ) ) << "html, aw yes" << tq::html::close << std::endl;
std::cout << ansi::fg( 3 ) << "yay colors" << ansi::reset << std::endl;
std::cout << html::fg( "#abc123" ) << "hex hex!" << html::close << std::endl;
std::cout << html::fg( col8_t( 100, 144, 159 ) ) << "html, aw yes" << html::close << std::endl;
std::cout << std::endl;

// escape codes

tq::printColorTable();
printColorTable();

// rainbow text

tq::ColorMap rainbowMap( tq::ColorMap::PresetRainbow );
ColorMap rainbowMap( ColorMap::PresetRainbow );
const std::string text = "How can you tell? - Raaaaaaiiiinbooooooowwws.";
std::cout << tq::ansi::colorize( text, rainbowMap ) << std::endl;
std::cout << ansi::colorize( text, rainbowMap ) << std::endl;

return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions include/vivid/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "vivid/types.h"
#include <string>

namespace tq {
namespace vivid {


class Color
Expand Down Expand Up @@ -50,4 +50,4 @@ class Color
Color lerp( const Color&, const Color&, const float );


} // ::tq
} // ::vivid
4 changes: 2 additions & 2 deletions include/vivid/colormap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <glm/vec3.hpp>
#include <vector>

namespace tq {
namespace vivid {


class ColorMap
Expand Down Expand Up @@ -66,4 +66,4 @@ class ColorMap
};


} // ::tq
} // ::vivid
4 changes: 2 additions & 2 deletions include/vivid/colortable.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// [8] https://jonasjacek.github.io/colors/


namespace tq {
namespace vivid {


// 256 indexed ansi colors including names and various representations
Expand Down Expand Up @@ -48,4 +48,4 @@ void printColorTable(
);


} // ::tq
} // ::vivid
4 changes: 2 additions & 2 deletions include/vivid/conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "vivid/types.h"
#include <string>

namespace tq {
namespace vivid {


// xyz \in [ ( 0, 0, 0 ), ( 1, 1, 1 ) ]
Expand Down Expand Up @@ -105,4 +105,4 @@ namespace name {
}


} // ::tq
} // ::vivid
4 changes: 2 additions & 2 deletions include/vivid/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>


namespace tq::ansi
namespace vivid::ansi
{
inline std::string fg( const uint8_t index ) {
return "\x1b[38;5;" + std::to_string( index ) + "m";
Expand All @@ -27,7 +27,7 @@ namespace tq::ansi
}


namespace tq::html
namespace vivid::html
{
inline std::string fg( const std::string& hex ) {
return "<span style='color:" + hex + "'>";
Expand Down
13 changes: 6 additions & 7 deletions include/vivid/functions.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include "vivid/types.h"
#include "vivid/colormap.h"
#include <string>

class ColorMap;


namespace tq::rgb
namespace vivid::rgb
{
col_t lerp( const col_t&, const col_t&, const float );
col_t lerpHsv( const col_t&, const col_t&, const float );
Expand All @@ -18,15 +17,15 @@ namespace tq::rgb
col_t rainbow( const uint8_t k );
}

namespace tq::hsv {
namespace vivid::hsv {
col_t lerp( const col_t&, const col_t&, const float );
}

namespace tq::hcl {
namespace vivid::hcl {
col_t lerp( const col_t&, const col_t&, const float );
}

namespace tq::hsl
namespace vivid::hsl
{
col_t lerp( const col_t&, const col_t&, const float );

Expand All @@ -37,6 +36,6 @@ namespace tq::hsl
);
}

namespace tq::ansi {
namespace vivid::ansi {
std::string colorize( const std::string& text, const ColorMap& cmap );
}
6 changes: 3 additions & 3 deletions include/vivid/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@


////////////////////////////////////////////////////////////////////////////////
inline std::ostream& operator << ( std::ostream& out, const tq::col_t& col ) {
inline std::ostream& operator << ( std::ostream& out, const vivid::col_t& col ) {
out << "col(" << std::setprecision( 3 ) << col.x << ", " << col.y << ", " << col.z << ")";
return out;
}


////////////////////////////////////////////////////////////////////////////////
inline std::ostream& operator << ( std::ostream& out, const tq::col8_t& col ) {
inline std::ostream& operator << ( std::ostream& out, const vivid::col8_t& col ) {
out << "rgb(" << int( col.x ) << ", " << int( col.y ) << ", " << int( col.z ) << ")";
return out;
}


////////////////////////////////////////////////////////////////////////////////
inline std::ostream& operator << ( std::ostream& out, const tq::Color& col )
inline std::ostream& operator << ( std::ostream& out, const vivid::Color& col )
{
out << col.spaceInfo() << "(";
out << std::setprecision( 3 ) << col.value().x << ", " << col.value().y << ", " << col.value().z;
Expand Down
4 changes: 2 additions & 2 deletions include/vivid/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <glm/glm.hpp>
#include <glm/gtx/component_wise.hpp>

namespace tq {
namespace vivid {


using col_t = glm::vec<3, float>;
Expand All @@ -31,4 +31,4 @@ inline bool fuzzyHueEqual( const col_t& c1, const col_t& c2 )
}


} // ::tq
} // ::vivid
4 changes: 2 additions & 2 deletions src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "vivid/functions.h"
#include "vivid/stream.h"

namespace tq {
namespace vivid {


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -215,4 +215,4 @@ Color lerp( const Color& c1, const Color& c2, const float t )
}


} // ::tq
} // ::vivid
12 changes: 6 additions & 6 deletions src/colormap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <fstream>
#include <iostream>

namespace tq {
namespace vivid {


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -44,10 +44,10 @@ glm::vec3 ColorMap::at( const float t ) const
switch ( interpolation )
{
case InterpolationNearest: return stops_[ k ];
case InterpolationLinear: return tq::rgb::lerp( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHsv: return tq::rgb::lerpHsv( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHsl: return tq::rgb::lerpHsl( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHcl: return tq::rgb::lerpHcl( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationLinear: return vivid::rgb::lerp( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHsv: return vivid::rgb::lerpHsv( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHsl: return vivid::rgb::lerpHsl( stops_[ k ], stops_[ k + 1 ], u );
case InterpolationHcl: return vivid::rgb::lerpHcl( stops_[ k ], stops_[ k + 1 ], u );
}

return {};
Expand Down Expand Up @@ -105,4 +105,4 @@ std::vector<glm::vec3> ColorMap::loadFromFile( const std::string& filename )
}


} // ::tq
} // ::vivid
8 changes: 4 additions & 4 deletions src/colortable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cctype> // std::tolower


namespace tq {
namespace vivid {


nlohmann::json ColorTable::table_ = {};
Expand Down Expand Up @@ -137,8 +137,8 @@ void printColorTable( const bool foreground, const bool background )
char idstr[ 4 ];
std::sprintf( idstr, "%03d", id );

const std::string bgstr = tq::ansi::bg( id ) + " " + idstr + " " + tq::ansi::reset;
const std::string fgstr = tq::ansi::fg( id ) + " " + idstr + " " + tq::ansi::reset;
const std::string bgstr = vivid::ansi::bg( id ) + " " + idstr + " " + vivid::ansi::reset;
const std::string fgstr = vivid::ansi::fg( id ) + " " + idstr + " " + vivid::ansi::reset;

if ( ! background ) {
return fgstr;
Expand Down Expand Up @@ -203,4 +203,4 @@ void printColorTable( const bool foreground, const bool background )
}


} // ::tq
} // ::vivid
Loading

0 comments on commit de9787a

Please sign in to comment.