From c7e37c328387f164aabb1430dc1d9788bcdd41d2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 26 May 2022 14:19:56 +0200 Subject: Renamed the program to clockimg. --- LICENSE | 165 -------------------------------------------------------- LICENSE.txt | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 6 +-- README | 79 --------------------------- README.txt | 81 ++++++++++++++++++++++++++++ clockimg.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ genclockimg.c | 171 ---------------------------------------------------------- 7 files changed, 420 insertions(+), 418 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.txt delete mode 100644 README create mode 100644 README.txt create mode 100644 clockimg.c delete mode 100644 genclockimg.c diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 0a04128..0000000 --- a/LICENSE +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/Makefile b/Makefile index 503a651..fbf925e 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ +TARGET = clockimg +SRC = clockimg.o cairo_jpg.o + CFLAGS = `pkg-config cairo libjpeg popt --cflags` -D_XOPEN_SOURCE -g LDDFLAGS = `pkg-config cairo libjpeg popt --libs` -lm -SRC = genclockimg.o cairo_jpg.o -TARGET = genclockimg - $(TARGET): $(SRC) gcc $(SRC) -o $(TARGET) $(LDDFLAGS) diff --git a/README b/README deleted file mode 100644 index 69ae101..0000000 --- a/README +++ /dev/null @@ -1,79 +0,0 @@ - -GENCLOCKIMG - - genclockimg is a small program to generate clock face images. - I made it to generate a time index watermark for my timelapse videos. - - It is written in C and uses libjpeg, cairo and libpopt. These are fairly common - and chances are high you already have these installed on your system. - - I used Bernhard R. Fischer cairo_jpg library to handle JPEG images. - See https://github.com/rahra/cairo_jpg - -BUILDING - - To build genclockimg you need libjpeg, libcairo, libpopt and - their accompanying dev packages installed. You'll also need - a C compiler and GNU Make. - - To build the program: - - make - - To test: - - ./genclockimg - - A file 'out.png' should appear. - - To install: - - make install - - To uninstall: - - make uninstall - -RUNNING - - By default, running the program will create a 128x128 PNG image called 'out.png' - in the current directory. The image will contain a simple analog clock indicating - the current time. - -OPTIONS - - -o filename - Output filename. The .png extension is NOT added automaticly! - The output is always PNG, even if you name the file differently. - - -j - Write a JPEG file instead of PNG. - - -t HH:MM - Time to show on the clock - - -w width - Width of the clock image in pixels - - -h height - Height of the clock image in pixels - - -EXAMPLES - - Generate a series of clock images based on the timestamps of a series of source images: - - for file in *.jpg; do genclockimg -j -t `date -r "${file}" +"%H:%M"` -o "clock-${file}"; done - -LICENSE - - genclockimg is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser - General Public License as published by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - genclockimg is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU General Public License along with genclockimg. - If not, see https://www.gnu.org/licenses/. - - Copyright (c) 2022, Stijn Buys diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..2545945 --- /dev/null +++ b/README.txt @@ -0,0 +1,81 @@ + +CLOCKIMG + + clockimg outputs clock face images to JPEG or PNG. + I made it to generate a time index watermark for my timelapse videos. + + It is written in C and uses libjpeg, cairo and libpopt. These are fairly common + and chances are high you already have these installed on your system. + + I used Bernhard R. Fischer cairo_jpg library to handle JPEG images. + See https://github.com/rahra/cairo_jpg + +BUILDING + + To build clockimg you need libjpeg, libcairo, libpopt and + their accompanying dev packages installed. You'll also need + a C compiler and GNU Make. + + To build the program: + + make + + To test: + + ./clockimg + + A file 'out.png' should appear. + + To install: + + make install + + To uninstall: + + make uninstall + +RUNNING + + By default, running the program will create a 128x128 PNG image called 'out.png' + in the current directory. The image will contain a simple analog clock indicating + the current time. + +OPTIONS + + -o filename + Output filename. The .png extension is NOT added automaticly! + The output is always PNG, even if you name the file differently. + + -j + Write a JPEG file instead of PNG. + + -t HH:MM + Time to show on the clock + + -w width + Width of the clock image in pixels + + -h height + Height of the clock image in pixels + + +EXAMPLES + + Generate a series of clock images based on the timestamps of a series of source images: + + for file in *.jpg; do clockimg -j -t `date -r "${file}" +"%H:%M"` -o "clock-${file}"; done + +LICENSE + + clockimg is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser + General Public License as published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + clockimg is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License along with clockimg. + If not, see https://www.gnu.org/licenses/. + + Copyright (c) 2022, Stijn Buys + diff --git a/clockimg.c b/clockimg.c new file mode 100644 index 0000000..cb303d4 --- /dev/null +++ b/clockimg.c @@ -0,0 +1,171 @@ +/* + genclockimg + generates a clock face PNG image +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "cairo_jpg.h" + +int main (int argc, const char **argv) +{ + + /* configuration options */ + int img_width; + int img_height; + char *img_filename; + char img_filename_default[] = "out.png\0"; + char *timestr; + + int use_jpeg; + + /* timestamp represeting what time to draw */ + time_t clock_timestamp; + struct tm *clock_localtime; + int h; + int m; + + /* cairo surface and context */ + cairo_surface_t *surface; + cairo_t *context; + + /* popt options table */ + struct poptOption options_table[] = { + {"out", 'o', POPT_ARG_STRING, &img_filename, 0, "output filename", NULL }, + {"width", 'w', POPT_ARG_INT, &img_width, 0, "output image width", NULL }, + {"height", 'h', POPT_ARG_INT, &img_height, 0, "output image height", NULL }, + {"hours", '\0', POPT_ARG_INT, &h, 0, "hour to display", NULL }, + {"minutes", '\0', POPT_ARG_INT, &m, 0, "minutes to display", NULL }, + {"time", 't', POPT_ARG_STRING, ×tr, 0, "time to display as HH:MM", NULL}, + {"jpg", 'j', POPT_ARG_NONE, &use_jpeg, 0, "Write a JPEG file", NULL}, + POPT_AUTOHELP + {NULL, '\0', 0, NULL, 0, NULL, NULL} + }; + /* popt context */ + poptContext options_context; + + /* default filename is out.png */ + img_filename = NULL; + timestr = NULL; + use_jpeg = 0; + + /* default image size is 128x128 */ + img_width = 128; + img_height = 128; + + /* default timestamp is current localtime */ + clock_timestamp = time(NULL); + clock_localtime = localtime(&clock_timestamp); + h = clock_localtime->tm_hour % 12; + m = clock_localtime->tm_min; + + /* parse command line options */ + options_context = poptGetContext(NULL, argc, argv, options_table, 0); + + int result; + while ((result = poptGetNextOpt(options_context)) > 0 ) { + } + if (result < -1) { + /* an error occurred during option processing */ + fprintf(stderr, "%s: %s\n", poptBadOption(options_context, POPT_BADOPTION_NOALIAS),poptStrerror(result)); + exit(1); + } + + if (use_jpeg) { + img_filename_default[4] = 'j'; + img_filename_default[5] = 'p'; + img_filename_default[6] = 'g'; + } + + if (img_filename == NULL) { + img_filename = img_filename_default; + } + + if (timestr != NULL ) { + /* note: clock_localtime is already initialized here */ + strptime(timestr, "%H:%M", clock_localtime); + h = clock_localtime->tm_hour % 12; + m = clock_localtime->tm_min; + } + + /* keep hours and minutes into range */ + h %= 12; + m %= 60; + + /* create the cairo drawing context and an RGBA drawing surface */ + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, img_width, img_height); + context = cairo_create(surface); + + /* draw image */ + cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); + cairo_rectangle(context, 0, 0, img_width, img_height); + cairo_fill(context); + + int x1 = img_width / 2 -1; + int y1 = img_height / 2 -1; + + float r; + if (img_width < img_height) { + r = img_width / 2; + } else { + r = img_height /2; + } + float angle = 2.0f * M_PI / 12.0f; + + /* draw clock background */ + /* + cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); + cairo_arc(context, x1, y1, r-4, 0, 2 * M_PI); + cairo_fill(context); + */ + /* draw clock face */ + cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); + cairo_set_line_width (context, 1); + cairo_arc(context, x1, y1, r-4, 0, 2 * M_PI); + cairo_stroke(context); + + /* draw markers */ + cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); + cairo_set_line_width (context, 2); + for (int h = 0; h < 12; h++) { + cairo_move_to(context, x1 + (r - 10) * cosf(angle * h), y1 + (r - 10) * sinf(angle * h)); + cairo_line_to(context, x1 + (r - 4) * cosf(angle * h), y1 + (r - 4)* sinf(angle * h)); + } + cairo_stroke(context); + + /* draw handles */ + cairo_set_line_width (context, 4); + + /* hours handle */ + cairo_move_to(context, x1, y1); + cairo_line_to(context, x1 + (r/2 - 4) * sinf(angle * h + angle / 60 * m), y1 - (r/2 - 4) * cosf(angle * h + angle / 60 * m)); + + /* minutes handle */ + cairo_move_to(context, x1, y1); + cairo_line_to(context, x1 + (r - 10) * sinf(M_PI / 30.0f * m ), y1 - (r - 10) * cosf(M_PI / 30.0f * m)); + cairo_stroke(context); + + + /* write image file */ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + if (use_jpeg) { + status = cairo_image_surface_write_to_jpeg(surface, img_filename, 100); + } else { + status = cairo_surface_write_to_png(surface, img_filename); + } + if (status != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "Error saving %s\n", img_filename); + } + + /* cleanup */ + cairo_surface_destroy(surface); + poptFreeContext(options_context); + + return 0; +} diff --git a/genclockimg.c b/genclockimg.c deleted file mode 100644 index cb303d4..0000000 --- a/genclockimg.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - genclockimg - generates a clock face PNG image -*/ - -#include -#include -#include -#include -#include -#include -#include - -#include "cairo_jpg.h" - -int main (int argc, const char **argv) -{ - - /* configuration options */ - int img_width; - int img_height; - char *img_filename; - char img_filename_default[] = "out.png\0"; - char *timestr; - - int use_jpeg; - - /* timestamp represeting what time to draw */ - time_t clock_timestamp; - struct tm *clock_localtime; - int h; - int m; - - /* cairo surface and context */ - cairo_surface_t *surface; - cairo_t *context; - - /* popt options table */ - struct poptOption options_table[] = { - {"out", 'o', POPT_ARG_STRING, &img_filename, 0, "output filename", NULL }, - {"width", 'w', POPT_ARG_INT, &img_width, 0, "output image width", NULL }, - {"height", 'h', POPT_ARG_INT, &img_height, 0, "output image height", NULL }, - {"hours", '\0', POPT_ARG_INT, &h, 0, "hour to display", NULL }, - {"minutes", '\0', POPT_ARG_INT, &m, 0, "minutes to display", NULL }, - {"time", 't', POPT_ARG_STRING, ×tr, 0, "time to display as HH:MM", NULL}, - {"jpg", 'j', POPT_ARG_NONE, &use_jpeg, 0, "Write a JPEG file", NULL}, - POPT_AUTOHELP - {NULL, '\0', 0, NULL, 0, NULL, NULL} - }; - /* popt context */ - poptContext options_context; - - /* default filename is out.png */ - img_filename = NULL; - timestr = NULL; - use_jpeg = 0; - - /* default image size is 128x128 */ - img_width = 128; - img_height = 128; - - /* default timestamp is current localtime */ - clock_timestamp = time(NULL); - clock_localtime = localtime(&clock_timestamp); - h = clock_localtime->tm_hour % 12; - m = clock_localtime->tm_min; - - /* parse command line options */ - options_context = poptGetContext(NULL, argc, argv, options_table, 0); - - int result; - while ((result = poptGetNextOpt(options_context)) > 0 ) { - } - if (result < -1) { - /* an error occurred during option processing */ - fprintf(stderr, "%s: %s\n", poptBadOption(options_context, POPT_BADOPTION_NOALIAS),poptStrerror(result)); - exit(1); - } - - if (use_jpeg) { - img_filename_default[4] = 'j'; - img_filename_default[5] = 'p'; - img_filename_default[6] = 'g'; - } - - if (img_filename == NULL) { - img_filename = img_filename_default; - } - - if (timestr != NULL ) { - /* note: clock_localtime is already initialized here */ - strptime(timestr, "%H:%M", clock_localtime); - h = clock_localtime->tm_hour % 12; - m = clock_localtime->tm_min; - } - - /* keep hours and minutes into range */ - h %= 12; - m %= 60; - - /* create the cairo drawing context and an RGBA drawing surface */ - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, img_width, img_height); - context = cairo_create(surface); - - /* draw image */ - cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); - cairo_rectangle(context, 0, 0, img_width, img_height); - cairo_fill(context); - - int x1 = img_width / 2 -1; - int y1 = img_height / 2 -1; - - float r; - if (img_width < img_height) { - r = img_width / 2; - } else { - r = img_height /2; - } - float angle = 2.0f * M_PI / 12.0f; - - /* draw clock background */ - /* - cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); - cairo_arc(context, x1, y1, r-4, 0, 2 * M_PI); - cairo_fill(context); - */ - /* draw clock face */ - cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); - cairo_set_line_width (context, 1); - cairo_arc(context, x1, y1, r-4, 0, 2 * M_PI); - cairo_stroke(context); - - /* draw markers */ - cairo_set_source_rgba (context, 1.0, 1.0, 1.0, 1.0); - cairo_set_line_width (context, 2); - for (int h = 0; h < 12; h++) { - cairo_move_to(context, x1 + (r - 10) * cosf(angle * h), y1 + (r - 10) * sinf(angle * h)); - cairo_line_to(context, x1 + (r - 4) * cosf(angle * h), y1 + (r - 4)* sinf(angle * h)); - } - cairo_stroke(context); - - /* draw handles */ - cairo_set_line_width (context, 4); - - /* hours handle */ - cairo_move_to(context, x1, y1); - cairo_line_to(context, x1 + (r/2 - 4) * sinf(angle * h + angle / 60 * m), y1 - (r/2 - 4) * cosf(angle * h + angle / 60 * m)); - - /* minutes handle */ - cairo_move_to(context, x1, y1); - cairo_line_to(context, x1 + (r - 10) * sinf(M_PI / 30.0f * m ), y1 - (r - 10) * cosf(M_PI / 30.0f * m)); - cairo_stroke(context); - - - /* write image file */ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - if (use_jpeg) { - status = cairo_image_surface_write_to_jpeg(surface, img_filename, 100); - } else { - status = cairo_surface_write_to_png(surface, img_filename); - } - if (status != CAIRO_STATUS_SUCCESS) { - fprintf(stderr, "Error saving %s\n", img_filename); - } - - /* cleanup */ - cairo_surface_destroy(surface); - poptFreeContext(options_context); - - return 0; -} -- cgit v1.2.3