diff --git a/src/bin/col.c b/src/bin/col.c index 2f98e53f..c4975a5c 100644 --- a/src/bin/col.c +++ b/src/bin/col.c @@ -7,11 +7,14 @@ typedef struct _Color Color; struct _Color { - unsigned char r, g, b, a; + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; }; - -static const Color colors[2][2][12] = +static Color colors[2][2][12]; +static const Color default_colors[2][2][12] = { { // normal { // normal @@ -75,7 +78,8 @@ static const Color colors[2][2][12] = } }; -static const Color colors256[256] = +static Color colors256[256]; +static const Color default_colors256[256] = { // basic 16 repeated { 0x00, 0x00, 0x00, 0xff }, // COL_BLACK @@ -381,84 +385,62 @@ void colors_term_init(Evas_Object *textgrid, Evas_Object *bg, Config *config) { int c, n; - int r, g, b, a; char buf[32]; + Color *color; for (c = 0; c < 4 * 12; c++) { + n = c + (24 * (c / 24)); + color = &colors[c / 24][(c % 24) / 12][c % 12]; if (config->colors_use) { - n = c + (24 * (c / 24)); - - r = config->colors[c].r; - g = config->colors[c].g; - b = config->colors[c].b; - a = config->colors[c].a; - /* normal */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n, - r, g, b, a); - /* faint */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24, - r / 2, g / 2, b / 2, a / 2); + color->r = config->colors[c].r; + color->g = config->colors[c].g; + color->b = config->colors[c].b; + color->a = config->colors[c].a; } else { snprintf(buf, sizeof(buf) - 1, "c%i", c); - - n = c + (24 * (c / 24)); - - if (edje_object_color_class_get(bg, buf, - &r, &g, &b, &a, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL)) + if (!edje_object_color_class_get(bg, buf, + (int*)&color->r, + (int*)&color->g, + (int*)&color->b, + (int*)&color->a, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL)) { - /* normal */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n, - r, g, b, a); - /* faint */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24, - r / 2, g / 2, b / 2, a / 2); - } - else - { - Color color = colors[c / 24][(c % 24) / 12][c % 12]; - - /* normal */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n, - color.r, color.g, color.b, color.a); - /* faint */ - evas_object_textgrid_palette_set - (textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24, - color.r / 2, color.g / 2, color.b / 2, color.a / 2); + *color = default_colors[c / 24][(c % 24) / 12][c % 12]; } } + /* normal */ + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n, + color->r, color->g, color->b, color->a); + + /* faint */ + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24, + color->r / 2, color->g / 2, color->b / 2, color->a / 2); } for (c = 0; c < 256; c++) { snprintf(buf, sizeof(buf) - 1, "C%i", c); + color = &colors256[c]; - if (edje_object_color_class_get(bg, buf, - &r, &g, &b, &a, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL)) + if (!edje_object_color_class_get(bg, buf, + (int*)&colors256[c].r, + (int*)&colors256[c].g, + (int*)&colors256[c].b, + (int*)&colors256[c].a, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL)) { - evas_object_textgrid_palette_set( - textgrid, EVAS_TEXTGRID_PALETTE_EXTENDED, c, - r, g, b, a); - } - else - { - Color color = colors256[c]; - - evas_object_textgrid_palette_set( - textgrid, EVAS_TEXTGRID_PALETTE_EXTENDED, c, - color.r, color.g, color.b, color.a); + *color = default_colors256[c]; } + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_EXTENDED, c, + color->r, color->g, color->b, color->a); } } @@ -468,13 +450,13 @@ colors_standard_get(int set, int col, unsigned char *r, unsigned char *g, unsign if ((set >= 0) && (set < 4)) { int s1, s2; - + s1 = set / 2; s2 = set % 2; - *r = colors[s1][s2][col].r; - *g = colors[s1][s2][col].g; - *b = colors[s1][s2][col].b; - *a = colors[s1][s2][col].a; + *r = default_colors[s1][s2][col].r; + *g = default_colors[s1][s2][col].g; + *b = default_colors[s1][s2][col].b; + *a = default_colors[s1][s2][col].a; return; } *r = 0; @@ -482,3 +464,34 @@ colors_standard_get(int set, int col, unsigned char *r, unsigned char *g, unsign *b = 0; *a = 0; } + +/* if pos >= 256, it's in the 256 colors set */ +unsigned int color_get(unsigned int pos) +{ + Color *c; + + if (pos >= 256) + { + pos -= 256; + if (pos >= sizeof(colors256)/sizeof(Color)) + { + ERR("AAAAAA"); + return 0; + } + c = &colors256[pos]; + } + else + { + if (pos >= sizeof(colors)/sizeof(Color)) + { + ERR("AAAAAA"); + return 0; + } + c = ((Color *)colors) + pos; + } + + return (c->a << 24) | + (c->r << 16) | + (c->g << 8) | + (c->b); +} diff --git a/src/bin/col.h b/src/bin/col.h index c2772876..4add7f9f 100644 --- a/src/bin/col.h +++ b/src/bin/col.h @@ -6,5 +6,6 @@ void colors_term_init(Evas_Object *textgrid, Evas_Object *bg, Config *config); void colors_standard_get(int set, int col, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a); +unsigned int color_get(unsigned int pos); #endif diff --git a/src/bin/miniview.c b/src/bin/miniview.c index d8a3c474..cf86eeb0 100644 --- a/src/bin/miniview.c +++ b/src/bin/miniview.c @@ -63,50 +63,73 @@ struct _Miniview static Evas_Smart *_smart = NULL; +static void +_draw_cell(const Termpty *ty, unsigned int *pixel, const Termcell *cell) +{ + int fg, bg, fgext, bgext; + int inv = ty->state.reverse; + if (cell->codepoint == 0 || + cell->att.newline || + cell->att.invisible) + { + *pixel = 0; + return; + } + // colors + fg = cell->att.fg; + bg = cell->att.bg; + fgext = cell->att.fg256; + bgext = cell->att.bg256; + + if ((fg == COL_DEF) && (cell->att.inverse ^ inv)) + fg = COL_INVERSEBG; + if (bg == COL_DEF) + { + if (cell->att.inverse ^ inv) + bg = COL_INVERSE; + else if (!bgext) + bg = COL_INVIS; + } + if ((cell->att.fgintense) && (!fgext)) + fg += 48; + if ((cell->att.bgintense) && (!bgext)) + bg += 48; + if (cell->att.inverse ^ inv) + { + int t; + t = fgext; fgext = bgext; bgext = t; + t = fg; fg = bg; bg = t; + } + if ((cell->att.bold) && (!fgext)) + fg += 12; + if ((cell->att.faint) && (!fgext)) + fg += 24; + + if (bgext) + *pixel = color_get(bg + 256); + else if (bg && (bg % 12) != COL_INVIS) + *pixel = color_get(bg); + else if (!isspace(cell->codepoint)) + { + if (fgext) + *pixel = color_get(fg + 256); + else + *pixel = color_get(fg); + } + else + *pixel = 0; +} static void -_draw_line(unsigned int *pixels, Termcell *cells, int length) +_draw_line(const Termpty *ty, unsigned int *pixels, + const Termcell *cells, int length) { int x; for (x = 0 ; x < length; x++) { - int r, g, b; - - if (cells[x].codepoint > 0 && !isspace(cells[x].codepoint) && - !cells[x].att.newline && !cells[x].att.tab && - !cells[x].att.invisible && cells[x].att.bg != COL_INVIS) - { - switch (cells[x].att.fg) - { - // TODO: get pixel colors from current theme... - case 0: - r = 180; g = 180; b = 180; - break; - case 2: - r = 204; g = 51; b = 51; - break; - case 3: - r = 51; g = 204; b = 51; - break; - case 4: - r = 204; g = 136; b = 51; - break; - case 5: - r = 51; g = 51; b = 204; - break; - case 6: - r = 204; g = 51; b = 204; - break; - case 7: - r = 51; g = 204; b = 204; - break; - default: - r = 180; g = 180; b = 180; - } - pixels[x] = (0xff << 24) | (r << 16) | (g << 8) | b; - } + _draw_cell(ty, pixels + x, cells + x); } } @@ -301,7 +324,6 @@ _deferred_renderer(void *data) return EINA_TRUE; - DBG("ow:%d oh:%d cols:%d img_h:%d", ow, oh, mv->cols, mv->img_h); pixels = evas_object_image_data_get(mv->img, EINA_TRUE); memset(pixels, 0, sizeof(*pixels) * ow * oh); mv->img_h = oh; @@ -318,15 +340,10 @@ _deferred_renderer(void *data) { cells = termpty_cellrow_get(ty, mv->img_hist + y, &wret); if (cells == NULL) - { - DBG("y:%d get:%d", y, mv->img_hist + y); break; - } - _draw_line(&pixels[y * mv->cols], cells, wret); + _draw_line(ty, &pixels[y * mv->cols], cells, wret); } - DBG("history_len:%d hist:%d img_h:%d rows:%d cols:%d", - history_len, mv->img_hist, mv->img_h, mv->rows, mv->cols); evas_object_image_data_set(mv->img, pixels); evas_object_image_pixels_dirty_set(mv->img, EINA_FALSE); evas_object_image_data_update_add(mv->img, 0, 0, ow, oh);