int main() { gdImagePtr im; int white, black; char *path; im = gdImageCreateTrueColor(6, 6); white = gdImageColorAllocate(im, 255, 255, 255); black = gdImageColorAllocate(im, 0, 0, 0); gdImageFilledRectangle(im, 0,0, 5,5, white); gdImageLine(im, 4,4, 4,4, black); gdImageLine(im, 1,4, 2,4, black); gdImageLine(im, 4,1, 4,2, black); gdImageSetAntiAliased(im, black); gdImageLine(im, 1,1, 1,1, gdAntiAliased); path = gdTestFilePath2("gdimageline", "bug00315_exp.png"); gdAssertImageEqualsToFile(path, im); gdFree(path); gdImageDestroy(im); return gdNumFailures(); }
int main() { gdImagePtr im; int error = 0; char path[2048]; const char *file_exp = "bug00111_exp.png"; im = gdImageCreateTrueColor(10, 10); if (!im) { printf("can't get truecolor image\n"); return 1; } gdImageLine(im, 2, 2, 2, 2, 0xFFFFFF); gdImageLine(im, 5, 5, 5, 5, 0xFFFFFF); gdImageLine(im, 0, 0, 0, 0, 0xFFFFFF); sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, file_exp); if (!gdAssertImageEqualsToFile(path, im)) { error = 1; printf("Reference image and destination differ\n"); } gdImageDestroy(im); return error; }
int main() { gdImagePtr im; const char *exp = "bug00077_exp.png"; const int files_cnt = 4; FILE *fp; int i = 0; int error = 0; char path[1024]; im = gdImageCreateTrueColor(11, 11); gdImageFilledRectangle(im, 0, 0, 10, 10, 0xFFFFFF); gdImageSetThickness(im, 1); gdImageLine(im, 0, 10, 0, 0, 0x0); gdImageLine(im, 5, 10, 5, 0, 0x0); gdImageLine(im, 10, 5, 0, 5, 0x0); gdImageLine(im, 10, 10, 0, 10, 0x0); sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, exp); if (!gdAssertImageEqualsToFile(path, im)) { error = 1; } gdImageDestroy(im); return error; }
/* -------------------------------------------------------------------- */ void init_monthgraph(char *title) { int i = 0; int xsize = 670; int ysize = 160; imgbuf_mon = gdImageCreate(xsize,ysize); /* allocate color maps, background color first (grey) */ grey = gdImageColorAllocate(imgbuf_mon, 204, 204, 204); dkblue = gdImageColorAllocate(imgbuf_mon, 0, 0, 153); white = gdImageColorAllocate(imgbuf_mon, 255, 255, 255); dkgrey = gdImageColorAllocate(imgbuf_mon, 128, 128, 128); black = gdImageColorAllocate(imgbuf_mon, 0, 0, 0); /* makes shadow effect around the image, 2 pixels wide */ for (i=0; i<2 ;i++) { /* do shadow effect around the image, 2 pixels wide */ gdImageLine(imgbuf_mon, i, i, xsize-i, i, white); gdImageLine(imgbuf_mon, i, i, i, ysize-i, white); gdImageLine(imgbuf_mon, i, ysize-i-1, xsize-i-1, ysize-i-1, dkgrey); gdImageLine(imgbuf_mon, xsize-i-1, i, xsize-i-1, ysize-i-1, dkgrey); } /* draw the inner frame around the data, 2 pixels wide */ gdImageRectangle(imgbuf_mon, 19, 20, xsize-19, ysize-27, black); gdImageFilledRectangle(imgbuf_mon, 20, 21, xsize-20, ysize-28, white); /* draw the outermost black frame line around the image, 1 pixel wide */ gdImageRectangle(imgbuf_mon, 0, 0, xsize-1, ysize-1, black); /* display the graph title */ gdImageString(imgbuf_mon, gdFontMediumBold, 26, 5, (unsigned char*) title, dkblue); if(DEBUG>=2) printf("Finished init_monthgraph().\n"); return; }
void GdImageRenderer::drawTimeAxisLabels() const { const int marker_height = 10; // Time interval between axis markers (seconds) const int axis_label_interval_secs = getAxisLabelScale(); // Time of first axis marker (seconds) const int first_axis_label_secs = MathUtil::roundUpToNearest(start_time_, axis_label_interval_secs); // Distance between waveform start time and first axis marker (seconds) const double axis_label_offset_secs = first_axis_label_secs - start_time_; // Distance between waveform start time and first axis marker (samples) const int axis_label_offset_samples = secondsToSamples(axis_label_offset_secs); // Distance between waveform start time and first axis marker (pixels) const int axis_label_offset_pixels = axis_label_offset_samples / samples_per_pixel_; assert(axis_label_offset_pixels >= 0); gdFontPtr font = gdFontGetSmall(); int secs = first_axis_label_secs; for (;;) { const int x = axis_label_offset_pixels + (secs - first_axis_label_secs) * sample_rate_ / samples_per_pixel_; assert(x >= 0); if (x >= image_width_) { break; } gdImageLine(image_, x, 0, x, marker_height, border_color_); gdImageLine(image_, x, image_height_ - 1, x, image_height_ - 1 - marker_height, border_color_); char label[50]; const int label_length = TimeUtil::secondsToString(label, ARRAY_LENGTH(label), secs); const int label_width = font->w * label_length; const int label_x = x - (label_width / 2) + 1; const int label_y = image_height_ - 1 - marker_height - 1 - font->h; if (label_x >= 0) { gdImageString( image_, font, label_x, label_y, reinterpret_cast<unsigned char*>(label), axis_label_color_ ); } secs += axis_label_interval_secs; } }
static void DrawTickLines(gdImagePtr im) { gdImageLine (im, 50, 60, 150, 60, darkgrey); gdImageLine (im, 50, 120, 150, 120, darkgrey); gdImageLine (im, 50, 180, 150, 180, darkgrey); gdImageLine (im, 50, 240, 150, 240, darkgrey); gdImageLine (im, 50, 300, 150, 300, darkgrey); }
int main() { /* Declare the image */ gdImagePtr im; /* Declare output files */ FILE *pngout, *jpegout; /* Declare color indexes */ int black; int white; int cyan; int orange; /* Allocate the image: 64 pixels across by 64 pixels tall */ im = gdImageCreate(64, 64); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); /* Allocate the color cyan and orange. */ cyan = gdImageColorAllocate(im, 0, 192, 255); orange = gdImageColorAllocate(im, 255, 128, 0); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); gdImageLine(im, 15, 0, 15, 63, cyan); gdImageLine(im, 31, 0, 31, 63, orange); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ pngout = fopen("test.png", "wb"); /* Do the same for a JPEG-format file. */ jpegout = fopen("test.jpg", "wb"); /* Output the image to the disk file in PNG format. */ gdImagePng(im, pngout); /* Output the same image in JPEG format, using the default JPEG quality setting. */ gdImageJpeg(im, jpegout, -1); /* Close the files. */ fclose(pngout); fclose(jpegout); /* Destroy the image in memory. */ gdImageDestroy(im); return(0); }
FILE *piechart_init(char *filename) { FILE *pieoutf; int xsize, ysize, b1, b2; if ((pieoutf = FOPENWB(filename)) == NULL) { warn('F', TRUE, "Failed to open pie chart file %s for writing: " "ignoring it", filename); return(pieoutf); } debug('F', "Opening %s as pie chart file", filename); #ifdef RISCOS _swix(OS_File, _INR(0,2), 18, filename, 0xb60); /* set PNG filetype */ #endif xsize = normalchart?XSIZE:SHORTXSIZE; ysize = normalchart?YSIZE:SHORTYSIZE; im = gdImageCreate(xsize, ysize); /* The first colour allocated in a new image is the background colour. */ white = gdImageColorAllocate(im, 255, 255, 255); /* white */ black = gdImageColorAllocate(im, 0, 0, 0); /* black */ grey = gdImageColorAllocate(im, 128, 128, 128); /* grey */ lightgrey = gdImageColorAllocate(im, 217, 217, 217); /* light grey */ col = 0; /* Wedge colours. If these change, so must images/sq*. */ colours[col++] = gdImageColorAllocate(im, 255, 0, 0); /* red */ colours[col++] = gdImageColorAllocate(im, 0, 0, 255); /* mid blue */ colours[col++] = gdImageColorAllocate(im, 0, 128, 0); /* green */ colours[col++] = gdImageColorAllocate(im, 255, 128, 0); /* orange */ colours[col++] = gdImageColorAllocate(im, 0, 0, 128); /* navy blue */ colours[col++] = gdImageColorAllocate(im, 0, 255, 0); /* pale green */ colours[col++] = gdImageColorAllocate(im, 255, 128, 128); /* pink */ colours[col++] = gdImageColorAllocate(im, 0, 255, 255); /* cyan */ colours[col++] = gdImageColorAllocate(im, 128, 0, 128); /* purple */ colours[col++] = gdImageColorAllocate(im, 255, 255, 0); /* yellow */ col = 0; totangle = 0.75; /* starting at the top */ boxesy = BOXESTOP; b1 = xsize - 1 - BORDER; b2 = ysize - 1 - BORDER; /* Plot outline of pie, and border of image */ gdImageArc(im, XCENTRE, YCENTRE, DIAMETER + 2, DIAMETER + 2, 0, 360, black); gdImageRectangle(im, BORDER, BORDER, b1, b2, black); gdImageLine(im, xsize - 1, 0, b1, BORDER, black); gdImageLine(im, 0, ysize - 1, BORDER, b2, black); gdImageFill(im, 0, 0, lightgrey); gdImageFill(im, xsize - 1, ysize - 1, grey); gdImageLine(im, 0, 0, BORDER, BORDER, black); gdImageLine(im, xsize - 1, ysize - 1, b1, b2, black); return(pieoutf); }
void CreateGIF ( const JBoolean incr[], const JCharacter* fileName ) { gdImagePtr image = gdImageCreate(256, kImageHeight); assert( image != NULL ); unsigned long rgb[3] = {0,0,0}; for (JCoordinate x=0; x<256; x++) { const int colorIndex = gdImageColorAllocate(image, rgb[0], rgb[1], rgb[2]); assert( colorIndex != -1 ); gdImageLine(image, x,0, x,kImageHeight-1, colorIndex); for (JIndex i=0; i<3; i++) { if (incr[i]) { rgb[i]++; } } } FILE* output = fopen(fileName, "wb"); assert( output != NULL ); gdImageGif(image, output); assert( ferror(output) == 0 ); fclose(output); gdImageDestroy(image); }
static void drawLines (MULTICHART_ID id) { register int i, j; int x1, x2, y1, y2; gdImageSetThickness (id->im, 2); for (i = 0; i < id->numpoints - 1; i ++) { for (j = 0; j < id->numdatasets; j ++) { if (id->dataset[j].valueset[i] <= ARCHIVE_VALUE_NULL || id->dataset[j].valueset[i+1] <= ARCHIVE_VALUE_NULL) { continue; } x1 = id->imtx + (int)((double)i * id->pointpixels); x2 = id->imtx + (int)((double)(i+1) * id->pointpixels); y1 = id->imby - (int)(id->ypixelconstant * (id->dataset[j].valueset[i] - id->min)); y2 = id->imby - (int)(id->ypixelconstant * (id->dataset[j].valueset[i+1] - id->min)); gdImageLine (id->im, x1, y1, x2, y2, id->dataset[j].lineColor); } } }
//axis aligned circle for setting up brushes for thick lines void rs_gdImageCircleForBrush(gdImagePtr im, int x, int y, int rad, RS_Color& color) { int gdc = ConvertColor(im, color); float rad2 = (float)rad*rad; for (int j = -rad, k = y+j; j <= rad; j++, k++) { float j_offset = j + 0.5f; float hlen = sqrt(rad2 - j_offset*j_offset); int solidwid = (int)hlen; if (solidwid) gdImageLine(im, x-solidwid, k, x+solidwid-1, k, gdc); float aalpha = hlen - solidwid; RS_Color ac = color; ac.alpha() = (int)(ac.alpha() * aalpha); int gdc2 = ConvertColor(im, ac); gdImageSetPixel(im, x-solidwid-1, k, gdc2); gdImageSetPixel(im, x+solidwid, k, gdc2); } }
void GDlineX1Y1X2Y2Color(void) { Proto proto; Proto tmp; Proto blob; gdImagePtr imgPtr; char * p; int x1,y1,x2,y2; int index; proto = (Proto) stackAt(Cpu, 2); objectGetSlot(proto, stringToAtom("_gdp"), &blob); p = (char *) objectPointerValue(blob); memcpy(&imgPtr, p, sizeof(imgPtr)); tmp = (Proto) stackAt(Cpu, 4); x1 = objectIntegerValue(tmp); tmp = (Proto) stackAt(Cpu, 5); y1 = objectIntegerValue(tmp); tmp = (Proto) stackAt(Cpu, 6); x2 = objectIntegerValue(tmp); tmp = (Proto) stackAt(Cpu, 7); y2 = objectIntegerValue(tmp); tmp = (Proto) stackAt(Cpu, 8); index = objectIntegerValue(tmp); gdImageLine(imgPtr, x1, y1, x2, y2, index); VMReturn(Cpu, (unsigned int) objectNewInteger(index), 8); }
void GdImageRenderer::drawWaveform(const WaveformBuffer& buffer) const { // Avoid drawing over the right border const int max_x = render_axis_labels_ ? image_width_ - 1 : image_width_; // Avoid drawing over the top and bottom borders const int wave_bottom_y = render_axis_labels_ ? image_height_ - 2 : image_height_ - 1; const int max_wave_height = render_axis_labels_ ? image_height_ - 2 : image_height_; const int buffer_size = buffer.getSize(); // Avoid drawing over the left border int x = render_axis_labels_ ? 1 : 0; int i = render_axis_labels_ ? start_index_ + 1 : start_index_; for (; x < max_x && i < buffer_size; ++i, ++x) { // convert range [-32768, 32727] to [0, 65535] int low = buffer.getMinSample(i) + 32768; int high = buffer.getMaxSample(i) + 32768; // scale to fit the bitmap int low_y = wave_bottom_y - low * max_wave_height / 65536; int high_y = wave_bottom_y - high * max_wave_height / 65536; gdImageLine(image_, x, low_y, x, high_y, waveform_color_); } }
static void gd_bezier(point* A, int n, int arrow_at_start, int arrow_at_end) { pointf p0, p1, V[4]; int i, j, step; int style[20]; int pen, width; gdImagePtr brush = NULL; if (cstk[SP].pen != P_NONE) { if (cstk[SP].pen == P_DASHED) { for (i = 0; i < 10; i++) style[i] = cstk[SP].pencolor; for (; i < 20; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 20); pen = gdStyled; } else if (cstk[SP].pen == P_DOTTED) { for (i = 0; i < 2; i++) style[i] = cstk[SP].pencolor; for (; i < 12; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 12); pen = gdStyled; } else { pen = cstk[SP].pencolor; } #if 0 if (cstk[SP].penwidth != WIDTH_NORMAL) { width=cstk[SP].penwidth; brush = gdImageCreate(width,width); gdImagePaletteCopy(brush, im); gdImageFilledRectangle(brush, 0,0,width-1, width-1, cstk[SP].pencolor); gdImageSetBrush(im, brush); if (pen == gdStyled) pen = gdStyledBrushed; else pen = gdBrushed; } #else width = cstk[SP].penwidth; gdImageSetThickness(im, width); #endif V[3].x = A[0].x; V[3].y = A[0].y; for (i = 0; i+3 < n; i += 3) { V[0] = V[3]; for (j = 1; j <= 3; j++) { V[j].x = A[i+j].x; V[j].y = A[i+j].y; } p0 = gdpt(V[0]); for (step = 1; step <= BEZIERSUBDIVISION; step++) { p1 = gdpt(Bezier(V, 3, (double)step/BEZIERSUBDIVISION, NULL, NULL)); gdImageLine(im, ROUND(p0.x), ROUND(p0.y), ROUND(p1.x), ROUND(p1.y), pen); p0 = p1; } } if (brush) gdImageDestroy(brush); } }
static void gd_polyline(point* A, int n) { pointf p, p1; int i; int style[20]; int pen, width; gdImagePtr brush = NULL; if (cstk[SP].pen != P_NONE) { if (cstk[SP].pen == P_DASHED) { for (i = 0; i < 10; i++) style[i] = cstk[SP].pencolor; for (; i < 20; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 20); pen = gdStyled; } else if (cstk[SP].pen == P_DOTTED) { for (i = 0; i < 2; i++) style[i] = cstk[SP].pencolor; for (; i < 12; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 12); pen = gdStyled; } else { pen = cstk[SP].pencolor; } #if 0 if (cstk[SP].penwidth != WIDTH_NORMAL) { width = cstk[SP].penwidth; brush = gdImageCreate(width,width); gdImagePaletteCopy(brush, im); gdImageFilledRectangle(brush, 0,0,width-1,width-1,cstk[SP].pencolor); gdImageSetBrush(im, brush); if (pen == gdStyled) pen = gdStyledBrushed; else pen = gdBrushed; } #else width = cstk[SP].penwidth; gdImageSetThickness(im, width); #endif p.x = A[0].x; p.y = A[0].y; p = gdpt(p); for (i = 1; i < n; i++) { p1.x = A[i].x; p1.y = A[i].y; p1 = gdpt(p1); gdImageLine(im, ROUND(p.x), ROUND(p.y), ROUND(p1.x), ROUND(p1.y), pen); p.x = p1.x; p.y = p1.y; } if (brush) gdImageDestroy(brush); } }
result_t Image::line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t color) { if (!m_image) return CHECK_ERROR(CALL_E_INVALID_CALL); gdImageLine(m_image, x1, y1, x2, y2, color); return 0; }
void gdoLine(struct ADrawTag *ctx, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) { gdImageLine(getGdoImg(ctx), x1, y1, x2, y2, getGdoPen(ctx)); }
/* prints the arrow into the image poined to by the pointer with given color*/ void ocin_vis_arrow::print(gdImagePtr im, float scale_val) { int thick = ((int)((float)thickness *scale_val)) + 1; int scaled_a_size = (int) ((float)(a_size - 4) *scale_val) + 4; // create points for arrow head based on scale factor if (dir == S) { points[1].x = x2 - scaled_a_size; points[1].y = y2 - scaled_a_size; points[2].x = x2 + scaled_a_size; points[2].y = y2 - scaled_a_size; } else if (dir == E) { points[1].x = x2 - scaled_a_size; points[1].y = y2 + scaled_a_size; points[2].x = x2 - scaled_a_size; points[2].y = y2 - scaled_a_size; } else if (dir == N) { points[1].x = x2 - scaled_a_size; points[1].y = y2 + scaled_a_size; points[2].x = x2 + scaled_a_size; points[2].y = y2 + scaled_a_size; } else if (dir == W) { points[1].x = x2 + scaled_a_size; points[1].y = y2 + scaled_a_size; points[2].x = x2 + scaled_a_size; points[2].y = y2 - scaled_a_size; } // setup the arrow head points points[0].x = x2; // first point is end of the line points[0].y = y2; // select the color for the arrow head int cnt = 255 - ((int)(250.0*scale_val)); cnt = cnt &0xfffffffe; // make sure we have an even number // (?) int color; color = gdImageColorResolve(im, cnt, cnt, cnt); // if (cnt < 0) { // color = gdImageColorResolve(im, 0, 255+cnt, (cnt*-1)); // } else { // color = gdImageColorResolve(im, cnt, 255-cnt, 0); // } // draw the arrowhead first (why not) gdImageFilledPolygon(im, points, 3, color); // then the line gdImageSetThickness(im, thick); gdImageLine(im, x1, y1, x2, y2, color); }
void gdoDottedLine(struct ADrawTag *ctx, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) { setStyle(ctx); gdImageLine(getGdoImg(ctx), x1, y1, x2, y2, gdStyled); }
void doLine(FILE *stream) { float x1, y1, x2, y2; int c; x1 = getFloat(stream); y1 = getFloat(stream); x2 = getFloat(stream); y2 = getFloat(stream); c = getColor(getNumber(stream)); gdImageLine(image, viewx(x1), viewy(y1), viewx(x2), viewy(y2), c); }
int main (int argc, char *argv[]) { gdImagePtr im = gdImageCreate (WIDTH, HEIGHT); int white = gdImageColorResolve (im, 0xFF, 0xFF, 0xFF), black = gdImageColorResolve (im, 0, 0, 0), red = gdImageColorResolve (im, 0xFF, 0xA0, 0xA0); FILE *out; /* filled arc - circle */ gdImageFilledArc (im, WIDTH / 5, HEIGHT / 4, 200, 200, 45, 90, red, gdPie); gdImageArc (im, WIDTH / 5, HEIGHT / 4, 200, 200, 45, 90, black); /* filled arc - ellipse */ gdImageFilledArc (im, WIDTH / 2, HEIGHT / 4, 200, 150, 45, 90, red, gdPie); gdImageArc (im, WIDTH / 2, HEIGHT / 4, 200, 150, 45, 90, black); /* reference lines */ gdImageLine (im, 0, HEIGHT / 4, WIDTH, HEIGHT / 4, black); gdImageLine (im, WIDTH / 5, 0, WIDTH / 5, HEIGHT, black); gdImageLine (im, WIDTH / 2, 0, WIDTH / 2, HEIGHT, black); gdImageLine (im, WIDTH / 2, HEIGHT / 4, WIDTH / 2 + 300, HEIGHT / 4 + 300, black); gdImageLine (im, WIDTH / 5, HEIGHT / 4, WIDTH / 5 + 300, HEIGHT / 4 + 300, black); /* TBB: Write img to test/arctest.png */ out = fopen ("test/arctest.png", "wb"); if (!out) { fprintf (stderr, "Can't create test/arctest.png\n"); exit (1); } gdImagePng (im, out); fclose (out); fprintf (stderr, "Test image written to test/arctest.png\n"); /* Destroy it */ gdImageDestroy (im); return 0; }
int main() { gdImagePtr im, tile; int im_white, im_black, tile_white, tile_black; int x,y, error = 0; FILE *fp; char path[1024]; fputs("flag 0\n", stdout); im = gdImageCreate(150, 150); tile = gdImageCreateTrueColor(36, 36); tile_white = gdImageColorAllocate(tile,255,255,255); tile_black = gdImageColorAllocate(tile,55,0,0); im_white = gdImageColorAllocate(im,255,255,255); im_black = gdImageColorAllocate(im,0,0,0); gdImageFill(tile, 0,0, tile_white); gdImageColorTransparent(tile, tile_black); gdImageColorTransparent(im, im_black); /* create the dots pattern */ for (x=0; x<36; x+=2) { for (y=0; y<36; y+=2) { gdImageSetPixel(tile,x,y,tile_black); } } gdImageSetTile(im,tile); gdImageRectangle(im, 9,9,139,139, im_black); gdImageLine(im, 9,9,139,139, im_black); gdImageFill(im, 11,12, gdTiled); fputs("flag 1\n", stdout); gdImageFill(im, 0, 0, 0xffffff); fputs("flag 2\n", stdout); gdImageFill(im, 0, 0, 0xffffff); fputs("flag 3\n", stdout); sprintf(path, "%s/gdimagefill/bug00002_3_exp.png", GDTEST_TOP_DIR); if (!gdAssertImageEqualsToFile(path, im)) { error = 1; } /* Destroy it */ gdImageDestroy(im); return error; }
void gridPNG() { int i, j; char buffer[8]; if (g_grid > 0) { i = g_grid; while (i < g_top) i += g_grid; for (; i < g_top + g_size; i += g_grid) gdImageLine(g_image, 92, roundInt((i - g_top + 0.5) * g_dotSpacing) + 92, 484 + 92, roundInt((i - g_top + 0.5) * g_dotSpacing) + 92, g_black); i = g_labels; while (i < g_top) i += g_labels; for (; i < g_top + g_size; i += g_labels) { sprintf(buffer, "%d", i); vertCenterPNG(buffer, i); } j = g_grid; while (j < g_left) j += g_grid; for (; j < g_left + g_size; j += g_grid) gdImageLine(g_image, roundInt((j - g_left + 0.5) * g_dotSpacing) + 92, 92, roundInt((j - g_left + 0.5) * g_dotSpacing) + 92, 484 + 92, g_black); j = g_labels; while (j < g_left) j += g_labels; for (; j < g_left + g_size; j += g_labels) { sprintf(buffer, "%d", j); horzCenterPNG(buffer, j); } } }
int gen_image(const char* filename, int idx, int reverse_x, int width, int height, int bgd) { double gradient = height / (width*2.0); int offset = idx*width; int x1,y1,x2,y2, error = 0; gdImagePtr im = gdImageCreateTrueColor(width,height); if (bgd==1) { gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 255, 0)); } else { gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 0, 0)); } gdImageSetAntiAliased(im, gdTrueColorAlpha(0,0,0,0)); /* test for potential segfault (introduced with AA improvements, fixed with the same patch - but I didn't notice it until later).*/ gdImageLine(im,-1,-1,-1,-1,gdAntiAliased); x1 = floor(reverse_x * -width + 0.5); y1 = (offset-width) * gradient + 0.5; x2 = floor(reverse_x * width*2 + 0.5); y2 = floor((offset+width*2) * gradient + 0.5); // draw an AA line gdImageLine(im, x1, y1, x2, y2, gdAntiAliased); gdImageLine(im, 0, im->sy - 1, im->sx, im->sy - 1, 0x40FF0000); if (!gdAssertImageEqualsToFile(filename, im)) { printf("%s failed\n", filename); error = 1; } gdImageDestroy(im); return error; }
static void imagePolyline(gdImagePtr im, shapeObj *p, int c) { int i, j; for (i=0; i < p->numlines; i++) { lineObj *line = &(p->line[i]); for(j=1; j<line->numpoints; j++) { pointObj *point1 = &line->point[j-1]; pointObj *point2 = &line->point[j]; gdImageLine(im, (int) point1->x, (int) point1->y, (int) point2->x, (int) point2->y, c); } } }
void plD_line_png(PLStream *pls, short x1a, short y1a, short x2a, short y2a) { png_Dev *dev=(png_Dev *)pls->dev; int xx1 = x1a/dev->scale, yy1 = y1a/dev->scale; int xx2 = x2a/dev->scale, yy2 = y2a/dev->scale; yy1 = dev->pngy - yy1; yy2 = dev->pngy - yy2; #if GD2_VERS >= 2 if (dev->smooth==1) { gdImageSetAntiAliased(dev->im_out,dev->colour); gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, gdAntiAliased); } else { gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, dev->colour); } #else gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, dev->colour); #endif }
gdImagePtr graph_dibujar_grid( int w, int h, int cw, int ch, int f, int b ){ int i, j; gdImagePtr gd = gdImageCreateTrueColor( h + 6, w + 6 ); int fondo = gdImageColorAllocate( gd, b >> 16, ( b & 0xFF00 ) >> 8 , b & 0xFF ); int frente = gdImageColorAllocate( gd, f >> 16, ( f & 0xFF00 ) >> 8 , f & 0xFF ); gdImageFilledRectangle( gd, 0, 0, w + 5, h + 5, fondo ); gdImageSetThickness( gd, 1 ); // La linea de cuatro pixel que pienso dibujar por el borde // Dibujo un rectangulo alrededor de todo el tablero. // gdImageRectangle( gd, 0, 0, w + 3 , h + 3 , frente ); gdImageRectangle( gd, 1, 1, w + 4 , h + 4 , frente ); gdImageRectangle( gd, 2, 2, w + 3 , h + 3 , frente ); gdImageRectangle( gd, 3, 3, w + 2 , h + 2 , frente ); gdImageSetThickness( gd, 2 ); // La linea de dos pixel que pienso dibujar for( i = 1; i < cw - 1; i ++ ){ gdImageLine( gd, 3 + cw * i, 3 + 0, 3 + cw * i, 3 + h, frente ); } for( i = 1; i < ch - 1; i ++ ){ gdImageLine( gd, 3 + 0, 3 + ch * i, 3 + w, 3 + ch * i, frente ); } return gd; }
// Prints the error string if in debug, otherwise generates an error image void Error(const char *pcText) { if (g_oCGI.Debug()) { printf("Error: %s\n\n", pcText); printf("Usage: id=<counter_id> [font=<font_name>] [digits=<num_of_digits>]\n"); printf("Note: out.gif will be placed in %s\n", COUNTER_ROOT); } else { gdImagePtr pOutImg = NULL; pOutImg = gdImageCreate(20, 20); if (pOutImg) { int iBlack = gdImageColorAllocate(pOutImg, 0, 0, 0); int iRed = gdImageColorAllocate(pOutImg, 255, 0, 0); gdImageFill(pOutImg, 0, 0, iBlack); gdImageLine(pOutImg, 0, 0, 19, 19, iRed); gdImageLine(pOutImg, 19, 0, 0, 19, iRed); gdImageInterlace(pOutImg, 1); #ifdef WIN32 _setmode(_fileno(stdout), _O_BINARY); #endif printf("Content-type: image/gif\n\n"); gdImageGif(pOutImg, stdout); } } } // Error
int main(void) { // Create IP connection IPConnection ipcon; ipcon_create(&ipcon); // Create device object OLED64x48 oled; oled_64x48_create(&oled, UID, &ipcon); // Connect to brickd if(ipcon_connect(&ipcon, HOST, PORT) < 0) { fprintf(stderr, "Could not connect\n"); return 1; } // Don't use device before ipcon is connected // Clear display oled_64x48_clear_display(&oled); // Draw rotating line gdImagePtr image = gdImageCreate(WIDTH, HEIGHT); int black = gdImageColorAllocate(image, 0, 0, 0); int white = gdImageColorAllocate(image, 255, 255, 255); int origin_x = WIDTH / 2; int origin_y = HEIGHT / 2; int length = HEIGHT / 2 - 2; int angle = 0; printf("Press ctrl+c exit\n"); while (true) { double radians = M_PI * angle / 180.0; int x = (int)(origin_x + length * cos(radians)); int y = (int)(origin_y + length * sin(radians)); gdImageFilledRectangle(image, 0, 0, WIDTH, HEIGHT, black); gdImageLine(image, origin_x, origin_y, x, y, white); draw_image(&oled, image); millisleep(25); angle++; } gdImageDestroy(image); ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally return 0; }
void doGene(FILE *stream) { int i, start, end, rstart, rend, y, strand, nsmall, nlarge, color; int *small, *large; start = getNumber(stream); end = getNumber(stream); y = getNumber(stream); strand = getNumber(stream); /* 0, 1, or -1 */ color = getNumber(stream); rstart = viewx(start); rend = viewx(end); y = viewy(y); // fprintf(stderr, "%d->%d, %d->%d\n", start, rstart, end, rend); gdImageLine(image, rstart, y, rend, y, color); if (strand == 1) { for (i = rstart+2; i < rend-2; i = i+5) { gdImageSetPixel(image, i, y-1, color); gdImageSetPixel(image, i-1, y-2, color); gdImageSetPixel(image, i, y+1, color); gdImageSetPixel(image, i-1, y+2, color); } } else if (strand == -1) { for (i = rstart+2; i < rend-2; i = i+5) { gdImageSetPixel(image, i, y-1, color); gdImageSetPixel(image, i+1, y-2, color); gdImageSetPixel(image, i, y+1, color); gdImageSetPixel(image, i+1, y+2, color); } } nsmall = getNumber(stream); for (i = 0; i < nsmall; i++) { start = getNumber(stream); end = getNumber(stream); gdImageFilledRectangle(image, viewx(start), y-4, viewx(end), y+4, color); } nlarge = getNumber(stream); for (i = 0; i < nlarge; i++) { start = getNumber(stream); end = getNumber(stream); // fprintf(stderr, "%d->%d, %d->%d\n", start, viewx(start), end, viewx(end)); gdImageFilledRectangle(image, viewx(start), y-6, viewx(end), y+6, color); } }