"gemischte" Konsole-Farben nach RGB umrechnen?



  • Hallo,
    Gibt es Möglichkeiten, einem CHAR_INFO einen RGB-Wert zuzuweisen? Das ist ja ein Zeichen und zwei Farben? Wie vermengt man die zu einem Wert?
    Vielleicht in einem int, wo die jeweiligen Bits Zeichen, Farbe, Farbe sind? Aber erst mal, ob das überhaupt hier geht.

    Ich habe zB solche Matrizen:
    "Farb-Matrizen"

    Kann man da irgendwie was umrechen?

    Grüße



  • Joh, und jetzt bin ich betrunken.

    Schönen Feierabend, wir sehen uns frühestens Montag



  • Bei dir ist Hopfen und Malz verloren.



  • Erstellt werden die Farben so:

    console::Dot::Dot(const float luminance, const int darkColor, const int lightColor)
    {
    	// luminance must be a value between 0.f and 1.f 
    	// lum 0.f = black, lum 1.f = white
    	int pixel_bw = static_cast<int>(13.0f * luminance);
    
    	switch (pixel_bw)
    	{
    	case 0: *this = { SOLID, BLACK, BLACK }; break;
    	case 1: *this = { LIGHT, darkColor, BLACK }; break;
    	case 2: *this = { MED, darkColor, BLACK }; break;
    	case 3: *this = { DARK, darkColor, BLACK }; break;
    	case 4: *this = { SOLID, darkColor, BLACK }; break;
    	case 5: *this = { LIGHT, lightColor, darkColor }; break;
    	case 6: *this = { MED, lightColor, darkColor }; break;
    	case 7: *this = { DARK, lightColor, darkColor }; break;
    	case 8: *this = { SOLID, lightColor, darkColor }; break;
    	case 9: *this = { LIGHT, WHITE, lightColor }; break;
    	case 10: *this = { MED, WHITE, lightColor }; break;
    	case 11: *this = { DARK, WHITE, lightColor }; break;
    	case 12: *this = { SOLID, WHITE, lightColor }; break;
    	default: *this = { SOLID, WHITE, WHITE };
    	}
    }
    


  • Habe ich wohl wieder ziemlichen Mist geschrieben, was? 😉



  • Methoden, wie die Farben oben so gezeigt werden, sehen so aus:

    void Colors::plotColorMatrix(const ColorMatrix& matrix, const int x, const int y, const int color)
    {
    	int py = y;
    	const int size = infoFont[DIGITS].getStringLength("00");
    
    	//plot::string(*this, infoFont[LETTERS], x, py, matrix.name, DGREY);
    	//py += infoFont[LETTERS].info().baseLine + 2;
    
    	plotColors(matrix, x, py, size);
    	plotIndex(matrix, x, py, size, color);
    }
    
    void Colors::plotColors(const ColorMatrix& matrix, const int x, const int y, const int size)
    {
    	int cy = y + size;
    	std::size_t n = 0;
    	for (std::size_t i = 0; i < matrix.rows; ++i)
    	{
    		int cx = x + size + 2;
    		for (std::size_t j = 0; j < matrix.columns; ++j)
    		{
    			plot::filledRect(*this, cx, cy, cx + size, cy + size, matrix.colors[n++]);
    			cx += size + 2;
    		}
    		cy += size + 2;
    	}
    }
    
    void Colors::plotIndex(const ColorMatrix& matrix, const int x, const int y, const int size, const int color)
    {
    	int cy = y + size + 2;
    	for (std::size_t i = 0; i < matrix.rows; ++i)
    	{
    		int cx = x + size + 2;
    		for (std::size_t j = 0; j < matrix.columns; ++j)
    		{
    			plot::string(*this, infoFont[DIGITS], cx, y, std::to_string(j), color);
    			cx += size + 2;
    		}
    		plot::string(*this, infoFont[DIGITS], x, cy, std::to_string(i), color);
    		cy += size + 2;
    	}
    }
    


  • Dieser Beitrag wurde gelöscht!


  • Dieser Beitrag wurde gelöscht!


  • Ich wollte diesen Code zwar noch etwas ausarbeiten, aber ich komme nicht wirklich weiter, wenn ich ihn hier nicht für meine Augen zeige.

    Also es kommt jetzt die cpp für "ColorPalette", aber schnell noch die ColorMatrix

    struct ColorMatrix
    {
    	std::size_t rows = 0;
    	std::size_t columns = 0;
    	std::vector<console::Dot> colors;
    };
    

    jetzt die cpp

    #define _CRT_SECURE_NO_WARNINGS
    #include "ColorPalette.h"
    #include <fstream>
    
    ColorPalette::ColorPalette() = default;
    
    const ErrorState& ColorPalette::errorState() const { return err; }
    const Directory& ColorPalette::directory() const { return colDirectory; }
    Directory& ColorPalette::directory() { return colDirectory; }
    const ColorMatrix& ColorPalette::matrix() const { return colorMatrix; }
    const std::string& ColorPalette::name() const { return colorsName; }
    
    bool ColorPalette::loadFromFile(const std::string& dataFile)
    {
    	if (colDirectory.path().empty())
    		return error("no path to colors set");
    
    	if (dataFile.length() < 5)
    		return error(dataFile + ": invalid file name");
    
    	if (dataFile.substr(dataFile.length() - 4, dataFile.length()) != ".mat")
    		return error(dataFile + ": no mat file");
    
    	std::string file = colDirectory.path() + dataFile;
    	std::ifstream fstream(file);
    	if (!fstream)
    		return error(file + ": " + strerror(errno));
    
    	clear();
    	fstream >> colorsName;
    	fstream >> colorMatrix.rows >> colorMatrix.columns;
    	for (std::size_t i = 0; i < colorMatrix.rows * colorMatrix.columns; ++i)
    	{
    		int c, fg, bg;
    		fstream >> c >> fg >> bg;
    		colorMatrix.colors.push_back({ wchar_t(c), fg, bg });
    	}
    	return true;
    }
    
    void ColorPalette::createOrigColors()
    {
    	clear();
    	std::size_t column = 0;
    	for (std::size_t c = 0; c < std::size(console::COLORS) - 1; c += 2)
    	{
    		//float step = 1.f / 13.0f;
    		//for (float i = 0.f; i <= 13.0f * step; i += step)
    		float step = 1.f / console::Dot::shadeNumber();
    		for (float i = step; i < console::Dot::shadeNumber() * step; i += step)
    		{
    			colorMatrix.colors.push_back({ i, console::COLORS[c], console::COLORS[c + 1] });
    			column++;
    		}
    		colorMatrix.columns = column;
    		column = 0;
    		colorMatrix.rows++;
    	}
    	colorsName = "moreGradation";
    }
    
    void ColorPalette::createSortedColors()
    {
    	clear();
    	std::size_t column = 0;
    	for (std::size_t c = 0; c < std::size(console::COLORS_SORTED); ++c)
    	{
    		//float step = 1.f / 13.0f;
    		//for (float i = 0.f; i <= 13.0f * step; i += step)
    		float step = 1.f / console::Dot::shadeNumber();
    		for (float i = 0.f; i <= console::Dot::shadeNumber() * step; i += step)
    		{
    
    			if (i > 0.3f && i < 0.6f)
    				continue;
    			else
    			{
    				colorMatrix.colors.push_back({ i, console::COLORS_SORTED[c], console::COLORS_SORTED[c] });
    				column++;
    			}
    		}
    		colorMatrix.columns = column;
    		column = 0;
    		colorMatrix.rows++;
    	}
    	colorsName = "moreColors";
    }
    
    bool ColorPalette::saveColorSet() const
    {
    	return true;
    }
    
    void ColorPalette::convertToMatrix()
    {
    
    }
    
    void ColorPalette::clear()
    {
    	colorsName.clear();
    	colorMatrix.rows = 0;
    	colorMatrix.columns = 0;
    	colorMatrix.colors.clear();
    }
    
    bool ColorPalette::error(const std::string& errType)
    {
    	err.setError(errType);
    	return false;
    }
    


  • Wenns nicht allzu vernichtend ist, könnt Ihr ruhig was dazu schreiben, während ich überlege.
    Ist aber wirklich unverbindlich 😉



  • Stell halt Fragen 😉 Hier einfach so kostenlos ein Review zu machen, von Code, den ich nur äußert unzureichend kenne und dessen Sinn sich mir nur unzureichend erschließt ... naja, sagen, wir, da verbringe ich meine Zeit lieber anders.

    Nehmen wir zum Beispiel loadFromFile
    Erstmal, ich hätte das wahrscheinlicht nicht in die Klasse ColorPalette gepackt. Das verstößt gegen dasa Single Responsibility Principle. Ich würde das Auslagern in eine Funktion, die eine ColorPalette zurück gibt.

    Dann machst du in der Funktion erstmal error Handling, das würde ich für die Lesbarkeit der Funktion auslagern, damit das nur noch eine Zeile ist.
    Einen std::ifstream fstream zu nennen, finde ich auch nicht so schön, da es ja auch std::fstreamgibt.



  • Naja, eigentlich zeige ich den Code nur für mich. Ist ein persönliches review. Schon, wenn ich mein Code in notepad sehe, denke ich schon anders darüber. Hier habe ich dann noch eine Sichtweise.

    Dies zu meiner Motivation.

    Ich erkenne aber, das ich triggere. Versuche vorsichtiger zu werden.

    Rest ist dito. Nehme die Hinweise ernst.



  • OK, dann verstehe ich den Post nicht, aber egal 😉

    @zeropage sagte in "gemischte" Konsole-Farben nach RGB umrechnen?:

    Wenns nicht allzu vernichtend ist, könnt Ihr ruhig was dazu schreiben, während ich überlege.
    Ist aber wirklich unverbindlich 😉



  • Wenn es unverbindlich ist, ist es nicht verbindlich 😉



  • Ich weiß ja nicht was das werden soll, aber Console Virtual Terminal Sequences
    .



  • Dieser Beitrag wurde gelöscht!

Anmelden zum Antworten