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