8 #include <IOKit/IOKitLib.h>
13 sdk
=/Developer
/Platforms
/iPhoneOS
.platform
/Developer
/SDKs
/iPhoneOS4
.3
.sdk
15 /Developer
/Platforms
/iPhoneOS
.platform
/Developer
/usr
/bin
/g
++ \
16 -Wall
-fmessage
-length
=0 \
17 -arch armv6
-miphoneos
-version
-min
=2.0 \
18 -isysroot
"${sdk}" -I
. -F
"${sdk}"/System
/Library
/PrivateFrameworks \
19 -framework IOKit
-framework IOMobileFramebuffer \
20 -o iomfsetgamma iomfsetgamma
.c
27 typedef void *IOMobileFramebufferRef
;
29 kern_return_t
IOMobileFramebufferOpen(io_service_t
, mach_port_t
, void *, IOMobileFramebufferRef
*);
30 kern_return_t
IOMobileFramebufferSetGammaTable(IOMobileFramebufferRef
, void *);
31 kern_return_t (*$IOMobileFramebufferGetGammaTable
)(IOMobileFramebufferRef
, void *);
33 #define _assert(test) \
35 fprintf(stderr, "_assert(%s)\n", #test); \
39 int main(int argc
, char *argv
[]) {
41 fprintf(stderr
, "usage: iomfsetgamma <red> <green> <blue>\n");
42 fprintf(stderr
, " example: 1.00 0.78 0.64\n");
46 unsigned rs
= strtod(argv
[1], NULL
) * 0x100;
49 unsigned gs
= strtod(argv
[2], NULL
) * 0x100;
52 unsigned bs
= strtod(argv
[3], NULL
) * 0x100;
56 mach_port_t self
= mach_task_self();
58 io_service_t service
= 0;
61 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleCLCD"));
63 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleH1CLCD"));
65 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleM2CLCD"));
67 _assert(service
!= 0);
69 IOMobileFramebufferRef fb
;
70 error
= IOMobileFramebufferOpen(service
, self
, 0, &fb
);
73 uint32_t data
[0xc00 / sizeof(uint32_t)];
74 memset(data
, 0, sizeof(data
));
76 FILE *file
= fopen("/tmp/.iomfgamma.dat", "rb");
78 $IOMobileFramebufferGetGammaTable
= dlsym(RTLD_DEFAULT
, "IOMobileFramebufferGetGammaTable");
79 _assert($IOMobileFramebufferGetGammaTable
!= NULL
);
80 error
= $
IOMobileFramebufferGetGammaTable(fb
, data
);
83 file
= fopen("/tmp/.iomfgamma.dat", "wb");
84 _assert(file
!= NULL
);
86 fwrite(data
, 1, sizeof(data
), file
);
89 file
= fopen("/tmp/.iomfgamma.dat", "rb");
90 _assert(file
!= NULL
);
93 fread(data
, 1, sizeof(data
), file
);
97 for (i
= 0; i
!= 256; ++i
) {
104 data
[j
+ 0x000] = data
[r
+ 0x000];
105 data
[j
+ 0x100] = data
[g
+ 0x100];
106 data
[j
+ 0x200] = data
[b
+ 0x200];
109 error
= IOMobileFramebufferSetGammaTable(fb
, data
);