]> git.saurik.com Git - apple/boot.git/blob - i386/util/dumptiff.m
boot-132.tar.gz
[apple/boot.git] / i386 / util / dumptiff.m
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Dump a tiff file into a format that is easily
26 * used by the booter.
27 *
28 * Copyright 1993 NeXT, Inc.
29 * All rights reserved.
30 */
31
32 #import <stdio.h>
33 #import <sys/param.h>
34 #import "bitmap.h"
35 #import "cursor.h"
36 #import "BooterBitmap.h"
37
38 #define DEFAULT_CURSOR_NAME "ns_wait"
39
40 void printCursors(char *name, int bg_color, int use_c_mode)
41 {
42 id bitmap;
43 char buf[MAXPATHLEN];
44 bitmap = [[BooterBitmap alloc] init];
45
46 [bitmap setWidth:16];
47 [bitmap setHeight:16];
48 [bitmap setColorDataBytes:64];
49 [bitmap setBgColor:bg_color];
50 [bitmap setTwoBitsPerPixelAlphaData:(unsigned char *)waitAlpha2];
51
52 sprintf(buf,"%s1",name);
53 [bitmap setTwoBitsPerPixelColorData:waitData2W1];
54 use_c_mode ? [bitmap writeAsCFile:buf] :
55 [bitmap writeAsBinaryFile:buf];
56
57 sprintf(buf,"%s2",name);
58 [bitmap setTwoBitsPerPixelColorData:waitData2W2];
59 use_c_mode ? [bitmap writeAsCFile:buf] :
60 [bitmap writeAsBinaryFile:buf];
61
62 sprintf(buf,"%s3",name);
63 [bitmap setTwoBitsPerPixelColorData:waitData2W3];
64 use_c_mode ? [bitmap writeAsCFile:buf] :
65 [bitmap writeAsBinaryFile:buf];
66
67 [bitmap free];
68 }
69
70 void usage(void)
71 {
72 fprintf(stderr,"Usage: dumptiff [-b <bgcolor] [-c] [-C] [-o <ofile>] <tiff>\n");
73 fprintf(stderr,"-C prints cursor bitmaps\n");
74 fprintf(stderr,"-c creates files <tiff>.h and <tiff>_bitmap.h\n");
75 fprintf(stderr,"(default is to create binary .bitmap file)\n");
76 exit(1);
77 }
78
79 void
80 main(int argc, char **argv)
81 {
82 id bitmap;
83 char buf[MAXPATHLEN], *file;
84 int vflag=0, errflag=0, pcursors=0, c, ret;
85 extern char *optarg;
86 extern int optind;
87 int bg_color = BG_COLOR;
88 int use_c_mode = 0;
89 char *output_name = NULL;
90
91 while ((c = getopt(argc, argv, "Ccvb:o:")) != EOF)
92 switch (c) {
93 case 'C':
94 pcursors++;
95 break;
96 case 'c':
97 use_c_mode++;
98 break;
99 case 'v':
100 vflag++;
101 break;
102 case 'b':
103 bg_color = atoi(optarg);
104 break;
105 case 'o':
106 output_name = optarg;
107 break;
108 default:
109 errflag++;
110 break;
111 }
112
113 if (pcursors && !errflag) {
114 if (output_name == NULL)
115 output_name = DEFAULT_CURSOR_NAME;
116 printCursors(output_name, bg_color, use_c_mode);
117 exit(0);
118 }
119
120 if (errflag || (optind != argc-1))
121 usage();
122
123 file = argv[optind];
124 if (strcmp(file + strlen(file) - strlen(".tiff"), ".tiff") != 0)
125 sprintf(buf,"%s.tiff",file);
126 else
127 sprintf(buf,"%s",file);
128 bitmap = [[BooterBitmap alloc] initFromTiffFile:buf];
129 if (bitmap == nil) {
130 fprintf(stderr, "Could not create booter bitmap object\n");
131 exit(1);
132 }
133 [bitmap setBgColor:bg_color];
134
135 buf[strlen(buf) - strlen(".tiff")] = '\0';
136 if (output_name == NULL)
137 output_name = buf;
138
139 ret = use_c_mode ?
140 [bitmap writeAsCFile: output_name] :
141 [bitmap writeAsBinaryFile: output_name];
142
143 [bitmap free];
144 exit(ret);
145 }
146