<commit_before>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef WIN32
#include <io.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>

#include "gvplugin_render.h"


#ifdef HAVE_LIBGD
#include "gd.h"

typedef enum { FORMAT_GD, FORMAT_GD2, FORMAT_GIF, FORMAT_JPEG, FORMAT_PNG,
	FORMAT_WBMP, FORMAT_XBM, } format_type;

extern boolean mapbool(char *);
extern char *safefile(char *shapefilename);
extern pointf Bezier(pointf * V, int degree, double t, pointf * Left, pointf * Right);

#define BEZIERSUBDIVISION 10

/* fontsize at which text is omitted entirely */
#define FONTSIZE_MUCH_TOO_SMALL 0.15
/* fontsize at which text is rendered by a simple line */
#define FONTSIZE_TOO_SMALL 1.5

static void gdgen_resolve_color(GVJ_t * job, gvcolor_t * color)
{
    gdImagePtr im = (gdImagePtr) job->surface;

    if (!im)
	return;

    /* seems gd alpha is "transparency" rather than the usual "opacity" */
    color->u.index = gdImageColorResolveAlpha(im,
			  color->u.rgba[0],
			  color->u.rgba[1],
			  color->u.rgba[2],
			  (255 - color->u.rgba[3]) * gdAlphaMax / 255);
    color->type = COLOR_INDEX;
}

static int white, black, transparent, basecolor;

static void gdgen_begin_page(GVJ_t * job)
{
    char *bgcolor_str = NULL, *truecolor_str = NULL;
    boolean truecolor_p = FALSE;	/* try to use cheaper paletted mode */
    boolean bg_transparent_p = FALSE;
    int bgcolor = 0;
    gdImagePtr im = NULL;


/* FIXME - ... */
//    truecolor_str = agget(job->gvc->g, "truecolor");	/* allow user to force truecolor */
//    bgcolor_str = agget(job->gvc->g, "bgcolor");

    if (truecolor_str && truecolor_str[0])
	truecolor_p = mapbool(truecolor_str);

    if (bgcolor_str && strcmp(bgcolor_str, "transparent") == 0) {
	bg_transparent_p = TRUE;
	if (job->render.features->flags & GVRENDER_DOES_TRUECOLOR)
	    truecolor_p = TRUE;	/* force truecolor */
    }

//    if (GD_has_images(job->gvc->g))
//	truecolor_p = TRUE;	/* force truecolor */

    if (job->external_surface) {
	if (job->common->verbose)
	    fprintf(stderr, "%s: using existing GD image\n", job->common->cmdname);
	im = (gdImagePtr) (job->surface);
    } else {
	if (truecolor_p) {
	    if (job->common->verbose)
		fprintf(stderr,
			"%s: allocating a %dK TrueColor GD image\n",
			job->common->cmdname,
			ROUND(job->width * job->height * 4 / 1024.));
	    im = gdImageCreateTrueColor(job->width, job->height);
	} else {
	    if (job->common->verbose)
		fprintf(stderr,
			"%s: allocating a %dK PaletteColor GD image\n",
			job->common->cmdname, ROUND(job->width * job->height / 1024.));
	    im = gdImageCreate(job->width, job->height);
	}<commit_msg>Fixed truecolor for native gd.<commit_after>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef WIN32
#include <io.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>

#include "gvplugin_render.h"
#include "graph.h"	/* for agget  for truecolor test */
#include "gvcint.h"	/* for gvc->g for agget */

#ifdef HAVE_LIBGD
#include "gd.h"

typedef enum { FORMAT_GD, FORMAT_GD2, FORMAT_GIF, FORMAT_JPEG, FORMAT_PNG,
	FORMAT_WBMP, FORMAT_XBM, } format_type;

extern boolean mapbool(char *);
extern char *safefile(char *shapefilename);
extern pointf Bezier(pointf * V, int degree, double t, pointf * Left, pointf * Right);

#define BEZIERSUBDIVISION 10

/* fontsize at which text is omitted entirely */
#define FONTSIZE_MUCH_TOO_SMALL 0.15
/* fontsize at which text is rendered by a simple line */
#define FONTSIZE_TOO_SMALL 1.5

static void gdgen_resolve_color(GVJ_t * job, gvcolor_t * color)
{
    gdImagePtr im = (gdImagePtr) job->surface;

    if (!im)
	return;

    /* seems gd alpha is "transparency" rather than the usual "opacity" */
    color->u.index = gdImageColorResolveAlpha(im,
			  color->u.rgba[0],
			  color->u.rgba[1],
			  color->u.rgba[2],
			  (255 - color->u.rgba[3]) * gdAlphaMax / 255);
    color->type = COLOR_INDEX;
}

static int white, black, transparent, basecolor;

static void gdgen_begin_page(GVJ_t * job)
{
    char *bgcolor_str = NULL, *truecolor_str = NULL;
    boolean truecolor_p = FALSE;	/* try to use cheaper paletted mode */
    boolean bg_transparent_p = FALSE;
    int bgcolor = 0;
    gdImagePtr im = NULL;


    truecolor_str = agget((graph_t*)(job->gvc->g), "truecolor");	/* allow user to force truecolor */
    bgcolor_str = agget((graph_t*)(job->gvc->g), "bgcolor");

    if (truecolor_str && truecolor_str[0])
	truecolor_p = mapbool(truecolor_str);

    if (bgcolor_str && strcmp(bgcolor_str, "transparent") == 0) {
	bg_transparent_p = TRUE;
	if (job->render.features->flags & GVRENDER_DOES_TRUECOLOR)
	    truecolor_p = TRUE;	/* force truecolor */
    }

    if (GD_has_images(job->gvc->g))
	truecolor_p = TRUE;	/* force truecolor */

    if (job->external_surface) {
	if (job->common->verbose)
	    fprintf(stderr, "%s: using existing GD image\n", job->common->cmdname);
	im = (gdImagePtr) (job->surface);
    } else {
	if (truecolor_p) {
	    if (job->common->verbose)
		fprintf(stderr,
			"%s: allocating a %dK TrueColor GD image\n",
			job->common->cmdname,
			ROUND(job->width * job->height * 4 / 1024.));
	    im = gdImageCreateTrueColor(job->width, job->height);
	} else {
	    if (job->common->verbose)
		fprintf(stderr,
			"%s: allocating a %dK PaletteColor GD image\n",
			job->common->cmdname, ROUND(job->width * job->height / 1024.));
	    im = gdImageCreate(job->width, job->height);
	}
{'fraction_non_alphanumeric': 0.16214285714285714, 'fraction_numerical': 0.012571428571428572, 'mean_word_length': 2.640665626625065, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3590317', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2314, 'n_words': 574}