Mercurial > hg > openttd
comparison src/os/macosx/splash.cpp @ 13363:4263b5bd13da draft
(svn r17872) -Codechange: apply coding style to splash.cpp
-Fix (r17871): missing variable declaration
author | smatz <smatz@openttd.org> |
---|---|
date | Sun, 25 Oct 2009 17:55:13 +0000 |
parents | b14687ab0a88 |
children | b6a87cffd56b |
comparison
equal
deleted
inserted
replaced
13362:b14687ab0a88 | 13363:4263b5bd13da |
---|---|
35 DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); | 35 DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
36 } | 36 } |
37 | 37 |
38 void DisplaySplashImage() | 38 void DisplaySplashImage() |
39 { | 39 { |
40 png_byte header[8]; | 40 FILE *f = FioFOpenFile(SPLASH_IMAGE_FILE); |
41 FILE *f; | |
42 png_structp png_ptr; | |
43 png_infop info_ptr, end_info; | |
44 uint width, height, bit_depth, color_type; | |
45 png_colorp palette; | |
46 int num_palette; | |
47 png_bytep *row_pointers; | |
48 uint y; | |
49 uint xoff, yoff; | |
50 int i; | |
51 | |
52 f = FioFOpenFile(SPLASH_IMAGE_FILE); | |
53 if (f == NULL) return; | 41 if (f == NULL) return; |
54 | 42 |
55 fread(header, 1, 8, f); | 43 png_byte header[8]; |
44 fread(header, sizeof(png_byte), 8, f); | |
56 if (png_sig_cmp(header, 0, 8) != 0) { | 45 if (png_sig_cmp(header, 0, 8) != 0) { |
57 fclose(f); | 46 fclose(f); |
58 return; | 47 return; |
59 } | 48 } |
60 | 49 |
61 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp) NULL, png_my_error, png_my_warning); | 50 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, png_my_error, png_my_warning); |
62 | 51 |
63 if (png_ptr == NULL) { | 52 if (png_ptr == NULL) { |
64 fclose(f); | 53 fclose(f); |
65 return; | 54 return; |
66 } | 55 } |
67 | 56 |
68 info_ptr = png_create_info_struct(png_ptr); | 57 png_infop info_ptr = png_create_info_struct(png_ptr); |
69 if (info_ptr == NULL) { | 58 if (info_ptr == NULL) { |
70 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); | 59 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); |
71 fclose(f); | 60 fclose(f); |
72 return; | 61 return; |
73 } | 62 } |
74 | 63 |
75 end_info = png_create_info_struct(png_ptr); | 64 png_infop end_info = png_create_info_struct(png_ptr); |
76 if (end_info == NULL) { | 65 if (end_info == NULL) { |
77 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); | 66 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); |
78 fclose(f); | 67 fclose(f); |
79 return; | 68 return; |
80 } | 69 } |
88 png_init_io(png_ptr, f); | 77 png_init_io(png_ptr, f); |
89 png_set_sig_bytes(png_ptr, 8); | 78 png_set_sig_bytes(png_ptr, 8); |
90 | 79 |
91 png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); | 80 png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); |
92 | 81 |
93 width = png_get_image_width(png_ptr, info_ptr); | 82 uint width = png_get_image_width(png_ptr, info_ptr); |
94 height = png_get_image_height(png_ptr, info_ptr); | 83 uint height = png_get_image_height(png_ptr, info_ptr); |
95 bit_depth = png_get_bit_depth(png_ptr, info_ptr); | 84 uint bit_depth = png_get_bit_depth(png_ptr, info_ptr); |
96 color_type = png_get_color_type(png_ptr, info_ptr); | 85 uint color_type = png_get_color_type(png_ptr, info_ptr); |
97 | 86 |
98 if (color_type != PNG_COLOR_TYPE_PALETTE || bit_depth != 8) { | 87 if (color_type != PNG_COLOR_TYPE_PALETTE || bit_depth != 8) { |
99 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); | 88 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
100 fclose(f); | 89 fclose(f); |
101 return; | 90 return; |
105 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); | 94 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
106 fclose(f); | 95 fclose(f); |
107 return; | 96 return; |
108 } | 97 } |
109 | 98 |
99 png_colorp palette; | |
100 int num_palette; | |
110 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); | 101 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); |
111 | 102 |
112 row_pointers = png_get_rows(png_ptr, info_ptr); | 103 png_bytep *row_pointers = png_get_rows(png_ptr, info_ptr); |
113 | 104 |
114 if (width > (uint) _screen.width) width = _screen.width; | 105 if (width > (uint) _screen.width) width = _screen.width; |
115 if (height > (uint) _screen.height) height = _screen.height; | 106 if (height > (uint) _screen.height) height = _screen.height; |
116 | 107 |
117 xoff = (_screen.width - width) / 2; | 108 uint xoff = (_screen.width - width) / 2; |
118 yoff = (_screen.height - height) / 2; | 109 uint yoff = (_screen.height - height) / 2; |
119 | 110 |
120 switch (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) { | 111 switch (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) { |
121 case 8: { | 112 case 8: { |
122 uint8 *dst_ptr = (uint8 *)_screen.dst_ptr; | 113 uint8 *dst_ptr = (uint8 *)_screen.dst_ptr; |
123 /* Initialize buffer */ | 114 /* Initialize buffer */ |
124 MemSetT(dst_ptr, 0xff, _screen.pitch * _screen.height); | 115 MemSetT(dst_ptr, 0xff, _screen.pitch * _screen.height); |
125 | 116 |
126 for (y = 0; y < height; y++) { | 117 for (uint y = 0; y < height; y++) { |
127 uint8 *src = row_pointers[y]; | 118 uint8 *src = row_pointers[y]; |
128 uint8 *dst = dst_ptr + (yoff + y) * _screen.pitch + xoff; | 119 uint8 *dst = dst_ptr + (yoff + y) * _screen.pitch + xoff; |
129 | 120 |
130 memcpy(dst, src, width); | 121 memcpy(dst, src, width); |
131 } | 122 } |
132 | 123 |
133 for (i = 0; i < num_palette; i++) { | 124 for (int i = 0; i < num_palette; i++) { |
134 _cur_palette[i].a = i == 0 ? 0 : 0xff; | 125 _cur_palette[i].a = i == 0 ? 0 : 0xff; |
135 _cur_palette[i].r = palette[i].red; | 126 _cur_palette[i].r = palette[i].red; |
136 _cur_palette[i].g = palette[i].green; | 127 _cur_palette[i].g = palette[i].green; |
137 _cur_palette[i].b = palette[i].blue; | 128 _cur_palette[i].b = palette[i].blue; |
138 } | 129 } |
149 case 32: { | 140 case 32: { |
150 uint32 *dst_ptr = (uint32 *)_screen.dst_ptr; | 141 uint32 *dst_ptr = (uint32 *)_screen.dst_ptr; |
151 /* Initialize buffer */ | 142 /* Initialize buffer */ |
152 MemSetT(dst_ptr, 0, _screen.pitch * _screen.height); | 143 MemSetT(dst_ptr, 0, _screen.pitch * _screen.height); |
153 | 144 |
154 for (y = 0; y < height; y++) { | 145 for (uint y = 0; y < height; y++) { |
155 uint8 *src = row_pointers[y]; | 146 uint8 *src = row_pointers[y]; |
156 uint32 *dst = dst_ptr + (yoff + y) * _screen.pitch + xoff; | 147 uint32 *dst = dst_ptr + (yoff + y) * _screen.pitch + xoff; |
157 | 148 |
158 for (x = 0; x < width; x++) { | 149 for (uint x = 0; x < width; x++) { |
159 dst[x] = palette[src[x]].blue | (palette[src[x]].green << 8) | (palette[src[x]].red << 16) | 0xff000000; | 150 dst[x] = palette[src[x]].blue | (palette[src[x]].green << 8) | (palette[src[x]].red << 16) | 0xff000000; |
160 } | 151 } |
161 } | 152 } |
162 } | 153 } |
163 break; | 154 break; |