Skip to content

Commit ad07a2d

Browse files
author
pradeep
committed
Added colormap attribute to af::Window
This attribute will affect rendering of images currently.
1 parent 8e3c5a6 commit ad07a2d

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

include/af/defines.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ typedef enum {
272272
AF_MAT_BLOCK_DIAG = 8192 ///< Matrix is block diagonal
273273
} af_mat_prop;
274274

275+
typedef enum {
276+
AF_COLORMAP_DEFAULT = 0, ///< Default grayscale map
277+
AF_COLORMAP_SPECTRUM= 1, ///< Spectrum map
278+
AF_COLORMAP_COLORS = 2, ///< Colors
279+
AF_COLORMAP_RED = 3, ///< Red hue map
280+
AF_COLORMAP_MOOD = 4, ///< Mood map
281+
AF_COLORMAP_HEAT = 5, ///< Heat map
282+
AF_COLORMAP_BLUE = 6 ///< Blue hue map
283+
} af_colormap;
284+
275285
// Below enum is purely added for example purposes
276286
// it doesn't and shoudn't be used anywhere in the
277287
// code. No Guarantee's provided if it is used.
@@ -296,6 +306,7 @@ namespace af
296306
typedef af_conv_mode convMode;
297307
typedef af_conv_domain convDomain;
298308
typedef af_mat_prop matProp;
309+
typedef af_colormap ColorMap;
299310
}
300311

301312
#endif

include/af/graphics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct {
1818
int row;
1919
int col;
2020
const char* title;
21+
af_colormap cmap;
2122
} af_cell;
2223

2324
#ifdef __cplusplus
@@ -32,6 +33,7 @@ class AFAPI Window {
3233
* cell in the grid is being rendered currently */
3334
int _r;
3435
int _c;
36+
ColorMap _cmap;
3537

3638
void initWindow(const int width, const int height, const char* const title);
3739

@@ -45,6 +47,7 @@ class AFAPI Window {
4547
af_window get() const { return wnd; }
4648
void setPos(const unsigned x, const unsigned y);
4749
void setTitle(const char* const title);
50+
void setColorMap(const ColorMap cmap);
4851

4952
void image(const array& in, const char* title=NULL);
5053
void plot(const array& X, const array& Y, const char* const title=NULL);

src/api/c/image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ af_err af_draw_image(const af_window wind, const af_array in, const af_cell* con
8181
default: TYPE_ERROR(1, type);
8282
}
8383

84+
window->setColorMap((fg::ColorMap)props->cmap);
8485
if (props->col>-1 && props->row>-1)
8586
window->draw(props->col, props->row, *image, props->title);
8687
else

src/api/cpp/graphics.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ void Window::initWindow(const int width, const int height, const char* const tit
2020
}
2121

2222
Window::Window()
23-
: wnd(0), _r(-1), _c(-1)
23+
: wnd(0), _r(-1), _c(-1), _cmap(AF_COLORMAP_DEFAULT)
2424
{
2525
initWindow(1280, 720, "ArrayFire");
2626
}
2727

2828
Window::Window(const char* const title)
29-
: wnd(0), _r(-1), _c(-1)
29+
: wnd(0), _r(-1), _c(-1), _cmap(AF_COLORMAP_DEFAULT)
3030
{
3131
initWindow(1280, 720, title);
3232
}
3333

3434
Window::Window(const int width, const int height, const char* const title)
35-
: wnd(0), _r(-1), _c(-1)
35+
: wnd(0), _r(-1), _c(-1), _cmap(AF_COLORMAP_DEFAULT)
3636
{
3737
initWindow(width, height, title);
3838
}
3939

4040
Window::Window(const af_window window)
41-
: wnd(window), _r(-1), _c(-1)
41+
: wnd(window), _r(-1), _c(-1), _cmap(AF_COLORMAP_DEFAULT)
4242
{
4343
}
4444

@@ -57,21 +57,26 @@ void Window::setTitle(const char* const title)
5757
AF_THROW(af_set_title(get(), title));
5858
}
5959

60+
void Window::setColorMap(const ColorMap cmap)
61+
{
62+
_cmap = cmap;
63+
}
64+
6065
void Window::image(const array& in, const char* const title)
6166
{
62-
af_cell temp{_r, _c, title};
67+
af_cell temp{_r, _c, title, _cmap};
6368
AF_THROW(af_draw_image(get(), in.get(), &temp));
6469
}
6570

6671
void Window::plot(const array& X, const array& Y, const char* const title)
6772
{
68-
af_cell temp{_r, _c, title};
73+
af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
6974
AF_THROW(af_draw_plot(get(), X.get(), Y.get(), &temp));
7075
}
7176

7277
void Window::hist(const array& X, const double minval, const double maxval, const char* const title)
7378
{
74-
af_cell temp{_r, _c, title};
79+
af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
7580
AF_THROW(af_draw_hist(get(), X.get(), minval, maxval, &temp));
7681
}
7782

0 commit comments

Comments
 (0)