initial check-in
[blorb-thumbnailer.git] / main.c
blob37fd3ed494ebb512b133f7de9c908a50b50f67ee
1 /* main.c: thumbnail a blorb using embedded cover art
3 Copyright 2011 Lewis Gentry.
5 This program is free software: you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation, either version 3 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include "main.h"
19 #include <stdlib.h>
21 #define DEFAULTSIZE 128 /* Maximum thumbnail size in pixels square. */
23 /* Main returns EXIT_SUCCESS only if we successfully produce the
24 requested thumbnail. */
26 int main(int argc, char **argv)
28 FILE *blorb;
29 unsigned int size, id, chunk, length;
31 size = argc > 3 ? strtol(argv[3], NULL, 0) : DEFAULTSIZE;
32 if (size < 1 || argc < 3) {
33 printf("Usage: %s <input> <output> [size]\n", argv[0]);
34 return EXIT_FAILURE;
37 blorb = fopen(argv[1], "rb");
38 if (blorb && verify(blorb) && fspc(blorb, &id)) {
39 chunk = findpict(blorb, id);
40 length = chunklength(blorb, chunk);
41 if (chunk && length && thumb(blorb, length, argv[2], size))
42 return EXIT_SUCCESS;
44 return EXIT_FAILURE;