1 /* UIKit Tools - command-line utilities for UIKit
2 * Copyright (C) 2008-2012 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <mach/mach.h>
47 #include <IOKit/IOKitLib.h>
52 sdk
=/Developer
/Platforms
/iPhoneOS
.platform
/Developer
/SDKs
/iPhoneOS4
.3
.sdk
54 /Developer
/Platforms
/iPhoneOS
.platform
/Developer
/usr
/bin
/g
++ \
55 -Wall
-fmessage
-length
=0 \
56 -arch armv6
-miphoneos
-version
-min
=2.0 \
57 -isysroot
"${sdk}" -I
. -F
"${sdk}"/System
/Library
/PrivateFrameworks \
58 -framework IOKit
-framework IOMobileFramebuffer \
59 -o iomfsetgamma iomfsetgamma
.c
66 typedef void *IOMobileFramebufferRef
;
68 kern_return_t
IOMobileFramebufferOpen(io_service_t
, mach_port_t
, void *, IOMobileFramebufferRef
*);
69 kern_return_t
IOMobileFramebufferSetGammaTable(IOMobileFramebufferRef
, void *);
70 kern_return_t (*$IOMobileFramebufferGetGammaTable
)(IOMobileFramebufferRef
, void *);
72 #define _assert(test) \
74 fprintf(stderr, "_assert(%s)\n", #test); \
78 int main(int argc
, char *argv
[]) {
80 fprintf(stderr
, "usage: iomfsetgamma <red> <green> <blue>\n");
81 fprintf(stderr
, " example: 1.00 0.78 0.64\n");
85 unsigned rs
= strtod(argv
[1], NULL
) * 0x100;
88 unsigned gs
= strtod(argv
[2], NULL
) * 0x100;
91 unsigned bs
= strtod(argv
[3], NULL
) * 0x100;
95 mach_port_t self
= mach_task_self();
97 io_service_t service
= 0;
100 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleCLCD"));
102 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleH1CLCD"));
104 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleM2CLCD"));
106 _assert(service
!= 0);
108 IOMobileFramebufferRef fb
;
109 error
= IOMobileFramebufferOpen(service
, self
, 0, &fb
);
112 uint32_t data
[0xc00 / sizeof(uint32_t)];
113 memset(data
, 0, sizeof(data
));
115 FILE *file
= fopen("/tmp/.iomfgamma.dat", "rb");
117 $IOMobileFramebufferGetGammaTable
= dlsym(RTLD_DEFAULT
, "IOMobileFramebufferGetGammaTable");
118 _assert($IOMobileFramebufferGetGammaTable
!= NULL
);
119 error
= $
IOMobileFramebufferGetGammaTable(fb
, data
);
122 file
= fopen("/tmp/.iomfgamma.dat", "wb");
123 _assert(file
!= NULL
);
125 fwrite(data
, 1, sizeof(data
), file
);
128 file
= fopen("/tmp/.iomfgamma.dat", "rb");
129 _assert(file
!= NULL
);
132 fread(data
, 1, sizeof(data
), file
);
136 for (i
= 0; i
!= 256; ++i
) {
143 data
[j
+ 0x000] = data
[r
+ 0x000];
144 data
[j
+ 0x100] = data
[g
+ 0x100];
145 data
[j
+ 0x200] = data
[b
+ 0x200];
148 error
= IOMobileFramebufferSetGammaTable(fb
, data
);