1 /* 2 # This file is part of the Astrometry.net suite. 3 # Licensed under a 3-clause BSD style license - see LICENSE 4 */ 5 6 #ifndef CAIRO_UTILS_H 7 #define CAIRO_UTILS_H 8 9 #include <stdio.h> 10 11 #include <cairo.h> 12 13 /** 14 A cairo_write_func_t for use with, eg, cairo_pdf_surface_create_for_stream. 15 The "closure" arg must be a FILE*. 16 */ 17 cairo_status_t cairoutils_file_write_func(void *closure, 18 const unsigned char *data, 19 unsigned int length); 20 21 /** 22 Reports any cairo error for the given surface. Returns 0 for ok, -1 on error. 23 */ 24 int cairoutils_surface_status_errors(cairo_surface_t* surf); 25 26 int cairoutils_cairo_status_errors(cairo_t* c); 27 28 void cairoutils_draw_path(cairo_t* c, const double* xy, int N); 29 30 void cairoutils_argb32_to_rgba(unsigned char* img, int W, int H); 31 32 void cairoutils_argb32_to_rgba_2(const unsigned char* inimg, 33 unsigned char* outimg, int W, int H); 34 35 void cairoutils_argb32_to_rgba_flip(const unsigned char* inimg, 36 unsigned char* outimg, int W, int H); 37 38 void cairoutils_rgba_to_argb32(unsigned char* img, int W, int H); 39 40 void cairoutils_rgba_to_argb32_2(const unsigned char* inimg, 41 unsigned char* outimg, int W, int H); 42 43 void cairoutils_rgba_to_argb32_flip(const unsigned char* inimg, 44 unsigned char* outimg, int W, int H); 45 46 void cairoutils_premultiply_alpha_rgba(unsigned char* img, int W, int H); 47 48 /** 49 All the following cairoutils_read_* function return a newly-allocated image buffer 50 of size W * H * 4, containing R,G,B, and alpha. 51 */ 52 unsigned char* cairoutils_read_png_stream(FILE* fid, int* pW, int *pH); 53 54 unsigned char* cairoutils_read_jpeg_stream(FILE* fid, int* pW, int* pH); 55 56 unsigned char* cairoutils_read_png(const char* fn, int* pW, int *pH); 57 58 unsigned char* cairoutils_read_jpeg(const char* fn, int* pW, int* pH); 59 60 void cairoutils_fake_ppm_init(void); 61 62 // You must call ppm_init() or (preferably) cairoutils_fake_ppm_init() 63 unsigned char* cairoutils_read_ppm(const char* infn, int* pW, int* pH); 64 65 unsigned char* cairoutils_read_ppm_stream(FILE* fid, int* pW, int* pH); 66 67 int cairoutils_write_ppm(const char* outfn, unsigned char* img, int W, int H); 68 69 int cairoutils_write_png(const char* outfn, unsigned char* img, int W, int H); 70 71 int cairoutils_write_jpeg(const char* outfn, unsigned char* img, int W, int H); 72 73 int cairoutils_stream_ppm(FILE* fout, unsigned char* img, int W, int H); 74 75 int cairoutils_stream_png(FILE* fout, unsigned char* img, int W, int H); 76 77 int cairoutils_stream_jpeg(FILE* fout, unsigned char* img, int W, int H); 78 79 int cairoutils_parse_color(const char* color, float* r, float* g, float* b); 80 81 // Parses a space-separated list of floating-point rgb(a) values. 82 // Parses alpha if "a" is non-null and str contains four terms. 83 int cairoutils_parse_rgba(const char* str, float* r, float* g, float* b, float* a); 84 85 const char* cairoutils_get_color_name(int i); 86 87 int cairoutils_parse_marker(const char* name); 88 89 #define CAIROUTIL_MARKER_CIRCLE 0 90 #define CAIROUTIL_MARKER_CROSSHAIR 1 91 #define CAIROUTIL_MARKER_SQUARE 2 92 #define CAIROUTIL_MARKER_DIAMOND 3 93 #define CAIROUTIL_MARKER_X 4 94 #define CAIROUTIL_MARKER_XCROSSHAIR 5 95 96 void cairoutils_draw_marker(cairo_t* cairo, int id, double x, double y, double radius); 97 98 const char* cairoutils_get_marker_name(int i); 99 100 void cairoutils_print_color_names(const char* prefix); 101 void cairoutils_print_marker_names(const char* prefix); 102 103 #endif 104 105