Beispiel #1
0
void atari_ntsc_init( atari_ntsc_t* ntsc, atari_ntsc_setup_t const* setup,
                      atari_ntsc_in_t const* palette )
{
  int entry;
  init_t impl;
  if ( !setup )
    setup = &atari_ntsc_composite;
  init( &impl, setup );

  // Palette stores R/G/B data for 'atari_ntsc_palette_size' entries
  for ( entry = 0; entry < atari_ntsc_palette_size; entry++ )
  {
    float r = impl.to_float [*palette++];
    float g = impl.to_float [*palette++];
    float b = impl.to_float [*palette++];

    float y, i, q = RGB_TO_YIQ( r, g, b, y, i );
      
    // Generate kernel
    int ir, ig, ib = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, ir, ig );
    atari_ntsc_rgb_t rgb = PACK_RGB( ir, ig, ib );

    if ( ntsc )
    {
      atari_ntsc_rgb_t* kernel = ntsc->table [entry];
      gen_kernel( &impl, y, i, q, kernel );
      correct_errors( rgb, kernel );
    }
  }
}
Beispiel #2
0
void atari_ntsc_init( atari_ntsc_t* ntsc, atari_ntsc_setup_t const* setup )
{
	/* Atari change: no alternating burst phases - remove merge_fields variable. */
	int entry;
	init_t impl;
	/* Atari change: NES palette generation and reading removed.
	   Atari palette generation is located in colours_ntsc.c, and colours are read
	   from setup->yiq_palette. */

	if ( !setup )
		setup = &atari_ntsc_composite;

	init( &impl, setup );
	
	/* Atari change: no alternating burst phases - remove code for merge_fields. */

	for ( entry = 0; entry < atari_ntsc_palette_size; entry++ )
	{
		/* Atari change: Instead of palette generation, load colours
		   from setup->yiq_palette. */
		double y;
		double i;
		double q;

		{
			double *yiq_ptr = setup->yiq_palette + 3 * entry;
			y = *yiq_ptr++;
			i = *yiq_ptr++;
			q = *yiq_ptr++;
		}

		i *= rgb_unit;
		q *= rgb_unit;
		y *= rgb_unit;
		y += rgb_offset;

		/* Generate kernel */
		{
			int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g );
			/* blue tends to overflow, so clamp it */
			atari_ntsc_rgb_t rgb = PACK_RGB( r, g, (b < 0x3E0 ? b: 0x3E0) );
			
			if ( setup->palette_out )
				RGB_PALETTE_OUT( rgb, &setup->palette_out [entry * 3] );
			
			if ( ntsc )
			{
				atari_ntsc_rgb_t* kernel = ntsc->table [entry];
				gen_kernel( &impl, y, i, q, kernel );
				/* Atari change: no alternating burst phases - remove code for merge_fields. */
				correct_errors( rgb, kernel );
			}
		}
	}
}
Beispiel #3
0
/**
 * Parse a CSS2 color specifier, return RGB value
 */
guint32
rsvg_css_parse_color (const char *str, gboolean * inherit)
{
    gint val = 0;

    SETINHERIT ();

    if (str[0] == '#') {
        int i;
        for (i = 1; str[i]; i++) {
            int hexval;
            if (str[i] >= '0' && str[i] <= '9')
                hexval = str[i] - '0';
            else if (str[i] >= 'A' && str[i] <= 'F')
                hexval = str[i] - 'A' + 10;
            else if (str[i] >= 'a' && str[i] <= 'f')
                hexval = str[i] - 'a' + 10;
            else
                break;
            val = (val << 4) + hexval;
        }
        /* handle #rgb case */
        if (i == 4) {
            val = ((val & 0xf00) << 8) | ((val & 0x0f0) << 4) | (val & 0x00f);
            val |= val << 4;
        }
    }
    /* i want to use g_str_has_prefix but it isn't in my gstrfuncs.h?? */
    else if (strstr (str, "rgb") != NULL) {
        gint r, g, b;
        r = g = b = 0;

        if (strstr (str, "%") != 0) {
            guint i, nb_toks;
            char **toks;

            /* assume rgb (9%, 100%, 23%) */
            for (i = 0; str[i] != '('; i++);

            i++;

            toks = rsvg_css_parse_list (str + i, &nb_toks);

            if (toks) {
                if (nb_toks == 3) {
                    r = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[0], NULL));
                    g = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[1], NULL));
                    b = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[2], NULL));
                }

                g_strfreev (toks);
            }
        } else {
            /* assume "rgb (r, g, b)" */
            if (3 == sscanf (str, " rgb ( %d , %d , %d ) ", &r, &g, &b)) {
                r = rsvg_css_clip_rgb (r);
                g = rsvg_css_clip_rgb (g);
                b = rsvg_css_clip_rgb (b);
            } else
                r = g = b = 0;
        }

        val = PACK_RGB (r, g, b);
    } else if (!strcmp (str, "inherit"))
        UNSETINHERIT ();
    else {
        static const ColorPair color_list[] = {
            {"aliceblue", PACK_RGB (240, 248, 255)},
            {"antiquewhite", PACK_RGB (250, 235, 215)},
            {"aqua", PACK_RGB (0, 255, 255)},
            {"aquamarine", PACK_RGB (127, 255, 212)},
            {"azure", PACK_RGB (240, 255, 255)},
            {"beige", PACK_RGB (245, 245, 220)},
            {"bisque", PACK_RGB (255, 228, 196)},
            {"black", PACK_RGB (0, 0, 0)},
            {"blanchedalmond", PACK_RGB (255, 235, 205)},
            {"blue", PACK_RGB (0, 0, 255)},
            {"blueviolet", PACK_RGB (138, 43, 226)},
            {"brown", PACK_RGB (165, 42, 42)},
            {"burlywood", PACK_RGB (222, 184, 135)},
            {"cadetblue", PACK_RGB (95, 158, 160)},
            {"chartreuse", PACK_RGB (127, 255, 0)},
            {"chocolate", PACK_RGB (210, 105, 30)},
            {"coral", PACK_RGB (255, 127, 80)},
            {"cornflowerblue", PACK_RGB (100, 149, 237)},
            {"cornsilk", PACK_RGB (255, 248, 220)},
            {"crimson", PACK_RGB (220, 20, 60)},
            {"cyan", PACK_RGB (0, 255, 255)},
            {"darkblue", PACK_RGB (0, 0, 139)},
            {"darkcyan", PACK_RGB (0, 139, 139)},
            {"darkgoldenrod", PACK_RGB (184, 132, 11)},
            {"darkgray", PACK_RGB (169, 169, 169)},
            {"darkgreen", PACK_RGB (0, 100, 0)},
            {"darkgrey", PACK_RGB (169, 169, 169)},
            {"darkkhaki", PACK_RGB (189, 183, 107)},
            {"darkmagenta", PACK_RGB (139, 0, 139)},
            {"darkolivegreen", PACK_RGB (85, 107, 47)},
            {"darkorange", PACK_RGB (255, 140, 0)},
            {"darkorchid", PACK_RGB (153, 50, 204)},
            {"darkred", PACK_RGB (139, 0, 0)},
            {"darksalmon", PACK_RGB (233, 150, 122)},
            {"darkseagreen", PACK_RGB (143, 188, 143)},
            {"darkslateblue", PACK_RGB (72, 61, 139)},
            {"darkslategray", PACK_RGB (47, 79, 79)},
            {"darkslategrey", PACK_RGB (47, 79, 79)},
            {"darkturquoise", PACK_RGB (0, 206, 209)},
            {"darkviolet", PACK_RGB (148, 0, 211)},
            {"deeppink", PACK_RGB (255, 20, 147)},
            {"deepskyblue", PACK_RGB (0, 191, 255)},
            {"dimgray", PACK_RGB (105, 105, 105)},
            {"dimgrey", PACK_RGB (105, 105, 105)},
            {"dodgerblue", PACK_RGB (30, 144, 255)},
            {"firebrick", PACK_RGB (178, 34, 34)},
            {"floralwhite", PACK_RGB (255, 255, 240)},
            {"forestgreen", PACK_RGB (34, 139, 34)},
            {"fuchsia", PACK_RGB (255, 0, 255)},
            {"gainsboro", PACK_RGB (220, 220, 220)},
            {"ghostwhite", PACK_RGB (248, 248, 255)},
            {"gold", PACK_RGB (255, 215, 0)},
            {"goldenrod", PACK_RGB (218, 165, 32)},
            {"gray", PACK_RGB (128, 128, 128)},
            {"green", PACK_RGB (0, 128, 0)},
            {"greenyellow", PACK_RGB (173, 255, 47)},
            {"grey", PACK_RGB (128, 128, 128)},
            {"honeydew", PACK_RGB (240, 255, 240)},
            {"hotpink", PACK_RGB (255, 105, 180)},
            {"indianred", PACK_RGB (205, 92, 92)},
            {"indigo", PACK_RGB (75, 0, 130)},
            {"ivory", PACK_RGB (255, 255, 240)},
            {"khaki", PACK_RGB (240, 230, 140)},
            {"lavender", PACK_RGB (230, 230, 250)},
            {"lavenderblush", PACK_RGB (255, 240, 245)},
            {"lawngreen", PACK_RGB (124, 252, 0)},
            {"lemonchiffon", PACK_RGB (255, 250, 205)},
            {"lightblue", PACK_RGB (173, 216, 230)},
            {"lightcoral", PACK_RGB (240, 128, 128)},
            {"lightcyan", PACK_RGB (224, 255, 255)},
            {"lightgoldenrodyellow", PACK_RGB (250, 250, 210)},
            {"lightgray", PACK_RGB (211, 211, 211)},
            {"lightgreen", PACK_RGB (144, 238, 144)},
            {"lightgrey", PACK_RGB (211, 211, 211)},
            {"lightpink", PACK_RGB (255, 182, 193)},
            {"lightsalmon", PACK_RGB (255, 160, 122)},
            {"lightseagreen", PACK_RGB (32, 178, 170)},
            {"lightskyblue", PACK_RGB (135, 206, 250)},
            {"lightslategray", PACK_RGB (119, 136, 153)},
            {"lightslategrey", PACK_RGB (119, 136, 153)},
            {"lightsteelblue", PACK_RGB (176, 196, 222)},
            {"lightyellow", PACK_RGB (255, 255, 224)},
            {"lime", PACK_RGB (0, 255, 0)},
            {"limegreen", PACK_RGB (50, 205, 50)},
            {"linen", PACK_RGB (250, 240, 230)},
            {"magenta", PACK_RGB (255, 0, 255)},
            {"maroon", PACK_RGB (128, 0, 0)},
            {"mediumaquamarine", PACK_RGB (102, 205, 170)},
            {"mediumblue", PACK_RGB (0, 0, 205)},
            {"mediumorchid", PACK_RGB (186, 85, 211)},
            {"mediumpurple", PACK_RGB (147, 112, 219)},
            {"mediumseagreen", PACK_RGB (60, 179, 113)},
            {"mediumslateblue", PACK_RGB (123, 104, 238)},
            {"mediumspringgreen", PACK_RGB (0, 250, 154)},
            {"mediumturquoise", PACK_RGB (72, 209, 204)},
            {"mediumvioletred", PACK_RGB (199, 21, 133)},
            {"midnightblue", PACK_RGB (25, 25, 112)},
            {"mintcream", PACK_RGB (245, 255, 250)},
            {"mistyrose", PACK_RGB (255, 228, 225)},
            {"moccasin", PACK_RGB (255, 228, 181)},
            {"navajowhite", PACK_RGB (255, 222, 173)},
            {"navy", PACK_RGB (0, 0, 128)},
            {"oldlace", PACK_RGB (253, 245, 230)},
            {"olive", PACK_RGB (128, 128, 0)},
            {"olivedrab", PACK_RGB (107, 142, 35)},
            {"orange", PACK_RGB (255, 165, 0)},
            {"orangered", PACK_RGB (255, 69, 0)},
            {"orchid", PACK_RGB (218, 112, 214)},
            {"palegoldenrod", PACK_RGB (238, 232, 170)},
            {"palegreen", PACK_RGB (152, 251, 152)},
            {"paleturquoise", PACK_RGB (175, 238, 238)},
            {"palevioletred", PACK_RGB (219, 112, 147)},
            {"papayawhip", PACK_RGB (255, 239, 213)},
            {"peachpuff", PACK_RGB (255, 218, 185)},
            {"peru", PACK_RGB (205, 133, 63)},
            {"pink", PACK_RGB (255, 192, 203)},
            {"plum", PACK_RGB (221, 160, 203)},
            {"powderblue", PACK_RGB (176, 224, 230)},
            {"purple", PACK_RGB (128, 0, 128)},
            {"red", PACK_RGB (255, 0, 0)},
            {"rosybrown", PACK_RGB (188, 143, 143)},
            {"royalblue", PACK_RGB (65, 105, 225)},
            {"saddlebrown", PACK_RGB (139, 69, 19)},
            {"salmon", PACK_RGB (250, 128, 114)},
            {"sandybrown", PACK_RGB (244, 164, 96)},
            {"seagreen", PACK_RGB (46, 139, 87)},
            {"seashell", PACK_RGB (255, 245, 238)},
            {"sienna", PACK_RGB (160, 82, 45)},
            {"silver", PACK_RGB (192, 192, 192)},
            {"skyblue", PACK_RGB (135, 206, 235)},
            {"slateblue", PACK_RGB (106, 90, 205)},
            {"slategray", PACK_RGB (119, 128, 144)},
            {"slategrey", PACK_RGB (119, 128, 144)},
            {"snow", PACK_RGB (255, 255, 250)},
            {"springgreen", PACK_RGB (0, 255, 127)},
            {"steelblue", PACK_RGB (70, 130, 180)},
            {"tan", PACK_RGB (210, 180, 140)},
            {"teal", PACK_RGB (0, 128, 128)},
            {"thistle", PACK_RGB (216, 191, 216)},
            {"tomato", PACK_RGB (255, 99, 71)},
            {"turquoise", PACK_RGB (64, 224, 208)},
            {"violet", PACK_RGB (238, 130, 238)},
            {"wheat", PACK_RGB (245, 222, 179)},
            {"white", PACK_RGB (255, 255, 255)},
            {"whitesmoke", PACK_RGB (245, 245, 245)},
            {"yellow", PACK_RGB (255, 255, 0)},
            {"yellowgreen", PACK_RGB (154, 205, 50)}
        };

        ColorPair *result = bsearch (str, color_list,
                                     sizeof (color_list) / sizeof (color_list[0]),
                                     sizeof (ColorPair),
                                     rsvg_css_color_compare);

        /* default to black on failed lookup */
        if (result == NULL) {
            UNSETINHERIT ();
            val = 0;
        } else
            val = result->rgb;
    }

    return val;
}
Beispiel #4
0
/**
* Read PNG file to RGB24 Buffer
*
* @param    char *path
* @param    int *width
* @param    int *height
* @return   pointer or NULL
**/
uint32_t *rgb24_from_png(const char *path, int *width, int *height)
{
    int x, y;
    uint8_t r, g, b;
    uint32_t *buffer, *out;

    /* libpng stuff */
    png_structp png_ptr;
    png_infop info_ptr;
    png_byte channels;
    png_bytep *row_pointers;

    /* Open file */
    FILE *fp = fopen(path, "rb");
    if (!fp) {
        return NULL;
    }
    
    /* Initialize */
    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return NULL;
    }
    
    /* Error handling */
    if (setjmp(png_jmpbuf(png_ptr))) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        if (fp) {
            fclose(fp);
        }
        
        return NULL;
    }
    
    /* Init PNG stuff */
    png_init_io(png_ptr, fp);
    png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY | PNG_TRANSFORM_EXPAND, NULL);
    fclose(fp); fp = NULL;
    
    /* Get width / height, channels */
    *width = png_get_image_width(png_ptr, info_ptr);
    *height = png_get_image_height(png_ptr, info_ptr);
    channels = png_get_channels(png_ptr, info_ptr);
 
    /* Setup buffers */
    row_pointers = png_get_rows(png_ptr, info_ptr);
    
    buffer = malloc(sizeof(*buffer) * (*width) * (*height));
    if (!buffer) {
        return NULL;
    }
    
    /*printf("Channels: %d\n", channels);*/
    
    /* Copy to buffer, removing alpha */
    out = buffer;
    
    for (y = 0; y < *height; y++) {
        for (x = 0; x < *width; x++) {
            r = row_pointers[y][(x * channels) + 0],
            g = row_pointers[y][(x * channels) + 1],
            b = row_pointers[y][(x * channels) + 2];
            
            PACK_RGB(r, g, b, tvxx_rgb_format_rgb24, *out);
            out++;
        }
    }
 
    png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
    return buffer;

}
Beispiel #5
0
/**
 * rsvg_css_parse_color:
 * @str: string to parse
 * @inherit: whether to inherit
 *
 * Parse a CSS2 color specifier, return RGB value
 *
 * Returns: and RGB value
 */
guint32
rsvg_css_parse_color (const char *str, gboolean * inherit)
{
    gint val = 0;

    SETINHERIT ();

    if (str[0] == '#') {
        int i;
        for (i = 1; str[i]; i++) {
            int hexval;
            if (str[i] >= '0' && str[i] <= '9')
                hexval = str[i] - '0';
            else if (str[i] >= 'A' && str[i] <= 'F')
                hexval = str[i] - 'A' + 10;
            else if (str[i] >= 'a' && str[i] <= 'f')
                hexval = str[i] - 'a' + 10;
            else
                break;
            val = (val << 4) + hexval;
        }
        /* handle #rgb case */
        if (i == 4) {
            val = ((val & 0xf00) << 8) | ((val & 0x0f0) << 4) | (val & 0x00f);
            val |= val << 4;
        }

        val |= 0xff000000; /* opaque */
    }
    else if (g_str_has_prefix (str, "rgb")) {
        gint r, g, b, a;
        gboolean has_alpha;
        guint nb_toks;
        char **toks;

        r = g = b = 0;
        a = 255;

        if (str[3] == 'a') {
            /* "rgba" */
            has_alpha = TRUE;
            str += 4;
        }
        else {
            /* "rgb" */
            has_alpha = FALSE;
            str += 3;
        }

        str = strchr (str, '(');
        if (str == NULL)
          return val;

        toks = rsvg_css_parse_list (str + 1, &nb_toks);

        if (toks) {
            if (nb_toks == (has_alpha ? 4 : 3)) {
                r = rsvg_css_clip_rgb_percent (toks[0], 255.0);
                g = rsvg_css_clip_rgb_percent (toks[1], 255.0);
                b = rsvg_css_clip_rgb_percent (toks[2], 255.0);
                if (has_alpha)
                    a = rsvg_css_clip_rgb_percent (toks[3], 1.0);
                else
                    a = 255;
            }

            g_strfreev (toks);
        }

        val = PACK_RGBA (r, g, b, a);
    } else if (!strcmp (str, "inherit"))
        UNSETINHERIT ();
    else {
        CRRgb rgb;

        if (cr_rgb_set_from_name (&rgb, (const guchar *) str) == CR_OK) {
            val = PACK_RGB (rgb.red, rgb.green, rgb.blue);
        } else {
            /* default to opaque black on failed lookup */
            UNSETINHERIT ();
            val = PACK_RGB (0, 0, 0);
        }
    }

    return val;
}
Beispiel #6
0
/**
 * Parse a CSS2 color specifier, return RGB value
 */
guint32
rsvg_css_parse_color (const char *str, gboolean * inherit)
{
    gint val = 0;

    SETINHERIT ();

    if (str[0] == '#') {
        int i;
        for (i = 1; str[i]; i++) {
            int hexval;
            if (str[i] >= '0' && str[i] <= '9')
                hexval = str[i] - '0';
            else if (str[i] >= 'A' && str[i] <= 'F')
                hexval = str[i] - 'A' + 10;
            else if (str[i] >= 'a' && str[i] <= 'f')
                hexval = str[i] - 'a' + 10;
            else
                break;
            val = (val << 4) + hexval;
        }
        /* handle #rgb case */
        if (i == 4) {
            val = ((val & 0xf00) << 8) | ((val & 0x0f0) << 4) | (val & 0x00f);
            val |= val << 4;
        }
    }
    /* i want to use g_str_has_prefix but it isn't in my gstrfuncs.h?? */
    else if (strstr (str, "rgb") != NULL) {
        gint r, g, b;
        r = g = b = 0;

        if (strstr (str, "%") != 0) {
            guint i, nb_toks;
            char **toks;

            /* assume rgb (9%, 100%, 23%) */
            for (i = 0; str[i] != '('; i++);

            i++;

            toks = rsvg_css_parse_list (str + i, &nb_toks);

            if (toks) {
                if (nb_toks == 3) {
                    r = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[0], NULL));
                    g = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[1], NULL));
                    b = rsvg_css_clip_rgb_percent (g_ascii_strtod (toks[2], NULL));
                }

                g_strfreev (toks);
            }
        } else {
            /* assume "rgb (r, g, b)" */
            if (3 == sscanf (str, " rgb ( %d , %d , %d ) ", &r, &g, &b)) {
                r = rsvg_css_clip_rgb (r);
                g = rsvg_css_clip_rgb (g);
                b = rsvg_css_clip_rgb (b);
            } else
                r = g = b = 0;
        }

        val = PACK_RGB (r, g, b);
    } else if (!strcmp (str, "inherit"))
        UNSETINHERIT ();
    else {
        CRRgb rgb;

        if (cr_rgb_set_from_name (&rgb, (const guchar *) str) == CR_OK) {
            val = PACK_RGB (rgb.red, rgb.green, rgb.blue);
        } else {
            /* default to black on failed lookup */
            UNSETINHERIT ();
            val = 0;
        }
    }

    return val;
}
static unsigned int
_svg_color_get_two_hex_digits (const char *str);

static svg_status_t
_svg_color_parse_component (const char **str, unsigned int *component);

typedef struct svg_color_map {
    const char *name;
    svg_color_t color;
} svg_color_map_t;

/* pack 3 [0,255] ints into one 32 bit one */
#define PACK_RGB(r,g,b) (((r) << 16) | ((g) << 8) | (b))

static const svg_color_map_t SVG_COLOR_MAP[] = {
    { "aliceblue",            { 0, PACK_RGB (240,248,255) }},
    { "antiquewhite",         { 0, PACK_RGB (250,235,215) }},
    { "aqua",                 { 0, PACK_RGB (  0,255,255) }},
    { "aquamarine",           { 0, PACK_RGB (127,255,212) }},
    { "azure",                { 0, PACK_RGB (240,255,255) }},
    { "beige",                { 0, PACK_RGB (245,245,220) }},
    { "bisque",               { 0, PACK_RGB (255,228,196) }},
    { "black",                { 0, PACK_RGB (  0,  0,  0) }},
    { "blanchedalmond",       { 0, PACK_RGB (255,235,205) }},
    { "blue",                 { 0, PACK_RGB (  0,  0,255) }},
    { "blueviolet",           { 0, PACK_RGB (138, 43,226) }},
    { "brown",                { 0, PACK_RGB (165, 42, 42) }},
    { "burlywood",            { 0, PACK_RGB (222,184,135) }},
    { "cadetblue",            { 0, PACK_RGB ( 95,158,160) }},
    { "chartreuse",           { 0, PACK_RGB (127,255,  0) }},
    { "chocolate",            { 0, PACK_RGB (210,105, 30) }},