mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-23 23:42:32 +00:00
Nitpicker: move 'asci_to<Color>' to public header
This function is worth reusing outside of nitpicker.
This commit is contained in:
parent
4d8cd2b5c5
commit
7b11075264
52
os/include/nitpicker_gfx/string.h
Normal file
52
os/include/nitpicker_gfx/string.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* \brief Convert string to color
|
||||
* \author Norman Feske
|
||||
* \date 2013-01-04
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__NITPICKER_GFX__STRING_H_
|
||||
#define _INCLUDE__NITPICKER_GFX__STRING_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <util/string.h>
|
||||
|
||||
#include "nitpicker_gfx/color.h"
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
* Convert ASCII string to Color
|
||||
*
|
||||
* The ASCII string must have the format '#rrggbb'
|
||||
*
|
||||
* \return number of consumed characters, or 0 if the string contains
|
||||
* no valid color
|
||||
*/
|
||||
template <>
|
||||
inline size_t ascii_to<Color>(const char *s, Color *result, unsigned)
|
||||
{
|
||||
/* validate string */
|
||||
if (strlen(s) < 7 || *s != '#') return 0;
|
||||
|
||||
enum { HEX = true };
|
||||
|
||||
for (unsigned i = 0; i < 6; i++)
|
||||
if (!is_digit(s[i + 1], HEX)) return 0;
|
||||
|
||||
int red = 16*digit(s[1], HEX) + digit(s[2], HEX),
|
||||
green = 16*digit(s[3], HEX) + digit(s[4], HEX),
|
||||
blue = 16*digit(s[5], HEX) + digit(s[6], HEX);
|
||||
|
||||
*result = Color(red, green, blue);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__NITPICKER_GFX__STRING_H_ */
|
@ -29,6 +29,7 @@
|
||||
#include <nitpicker_session/nitpicker_session.h>
|
||||
#include <framebuffer_session/connection.h>
|
||||
#include <nitpicker_gfx/pixel_rgb565.h>
|
||||
#include <nitpicker_gfx/string.h>
|
||||
#include <os/session_policy.h>
|
||||
|
||||
/* local includes */
|
||||
@ -44,37 +45,6 @@
|
||||
** Utilities **
|
||||
***************/
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
* Convert ASCII string to Color
|
||||
*
|
||||
* The ASCII string must have the format '#rrggbb'
|
||||
*
|
||||
* \return number of consumed characters, or 0 if the string contains
|
||||
* no valid color
|
||||
*/
|
||||
template <>
|
||||
inline size_t ascii_to<Color>(const char *s, Color *result, unsigned)
|
||||
{
|
||||
/* validate string */
|
||||
if (strlen(s) != 7 || *s != '#') return 0;
|
||||
|
||||
enum { HEX = true };
|
||||
|
||||
for (unsigned i = 0; i < 6; i++)
|
||||
if (!is_digit(s[i + 1], HEX)) return 0;
|
||||
|
||||
int red = 16*digit(s[1], HEX) + digit(s[2], HEX),
|
||||
green = 16*digit(s[3], HEX) + digit(s[4], HEX),
|
||||
blue = 16*digit(s[5], HEX) + digit(s[6], HEX);
|
||||
|
||||
*result = Color(red, green, blue);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine session color according to the list of configured policies
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user