| 58 | status_t |
| 59 | load_splash_data(stage2_args* args, Directory* volume) |
| 60 | { |
| 61 | dprintf("load_splash_data: enter\n"); |
| 62 | |
| 63 | // splash.raw |
| 64 | int fd = open_from(volume, "home/config/settings/kernel/splash.raw", O_RDONLY); |
| 65 | if (fd < 0) |
| 66 | { |
| 67 | dprintf("load_splash_data: error opening home/config/settings/kernel/splash.raw\n"); |
| 68 | unload_splash_data(); |
| 69 | return fd; |
| 70 | } |
| 71 | dprintf("load_splash_data: home/config/settings/kernel/splash.raw opened\n"); |
| 72 | splashImage = (bootSplashImage*)malloc(sizeof(bootSplashImage)); |
| 73 | if (!splashImage) |
| 74 | { |
| 75 | dprintf("load_splash_data: not enough memory to alloc splash image\n"); |
| 76 | return B_NO_MEMORY; |
| 77 | } |
| 78 | dprintf("load_splash_data: splashImage=%p\n", splashImage); |
| 79 | memset(splashImage, 0, sizeof(bootSplashImage)); |
| 80 | if(read(fd, &(splashImage->width), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 81 | { |
| 82 | dprintf("load_splash_data: cant read image width from splash image\n"); |
| 83 | unload_splash_data(); |
| 84 | return B_IO_ERROR; |
| 85 | } |
| 86 | if(read(fd, &(splashImage->height), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 87 | { |
| 88 | dprintf("load_splash_data: cant read image height from splash image\n"); |
| 89 | unload_splash_data(); |
| 90 | return B_IO_ERROR; |
| 91 | } |
| 92 | if(read(fd, &(splashImage->size), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 93 | { |
| 94 | dprintf("load_splash_data: cant read image size from splash image\n"); |
| 95 | unload_splash_data(); |
| 96 | return B_IO_ERROR; |
| 97 | } |
| 98 | splashImage->data = (unsigned char*)malloc(splashImage->size); |
| 99 | if(!splashImage->data) |
| 100 | { |
| 101 | dprintf("load_splash_data: not enough memory to alloc splash image data\n"); |
| 102 | unload_splash_data(); |
| 103 | return B_NO_MEMORY; |
| 104 | } |
| 105 | memset(splashImage->data, 0, splashImage->size); |
| 106 | if(read(fd, splashImage->data, splashImage->size) != splashImage->size) |
| 107 | { |
| 108 | dprintf("load_splash_data: cant read image data from splash image\n"); |
| 109 | unload_splash_data(); |
| 110 | return B_IO_ERROR; |
| 111 | } |
| 112 | dprintf("load_splash_data: splash image width=%d, height=%d, size=%d, pointer=%p, data pointer=%p\n", splashImage->width, splashImage->height, splashImage->size, splashImage, splashImage->data); |
| 113 | close(fd); |
| 115 | // icons.raw |
| 116 | fd = open_from(volume, "home/config/settings/kernel/icons.raw", O_RDONLY); |
| 117 | if (fd < 0) |
| 118 | { |
| 119 | dprintf("load_splash_data: error opening home/config/settings/kernel/icons.raw\n"); |
| 120 | unload_splash_data(); |
| 121 | return fd; |
| 122 | } |
| 123 | dprintf("load_splash_data: home/config/settings/kernel/icons.raw opened\n"); |
| 124 | splashIcons = (bootSplashImage*)malloc(sizeof(bootSplashImage)); |
| 125 | if (!splashIcons) |
| 126 | { |
| 127 | dprintf("load_splash_data: not enough memory to alloc splash icons image\n"); |
| 128 | return B_NO_MEMORY; |
| 129 | } |
| 130 | dprintf("load_splash_data: splashIcons=%p\n", splashIcons); |
| 131 | memset(splashIcons, 0, sizeof(bootSplashImage)); |
| 132 | if(read(fd, &(splashIcons->width), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 133 | { |
| 134 | dprintf("load_splash_data: cant read image width from splash icons image\n"); |
| 135 | unload_splash_data(); |
| 136 | return B_IO_ERROR; |
| 137 | } |
| 138 | if(read(fd, &(splashIcons->height), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 139 | { |
| 140 | dprintf("load_splash_data: cant read image height from splash icons image\n"); |
| 141 | unload_splash_data(); |
| 142 | return B_IO_ERROR; |
| 143 | } |
| 144 | if(read(fd, &(splashIcons->size), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 145 | { |
| 146 | dprintf("load_splash_data: cant read image size from splash icons image\n"); |
| 147 | unload_splash_data(); |
| 148 | return B_IO_ERROR; |
| 149 | } |
| 150 | splashIcons->data = (unsigned char*)malloc(splashIcons->size); |
| 151 | if(!splashIcons->data) |
| 152 | { |
| 153 | dprintf("load_splash_data: not enough memory to alloc splash icons image data\n"); |
| 154 | unload_splash_data(); |
| 155 | return B_NO_MEMORY; |
| 156 | } |
| 157 | memset(splashIcons->data, 0, splashIcons->size); |
| 158 | if(read(fd, splashIcons->data, splashIcons->size) != splashIcons->size) |
| 159 | { |
| 160 | dprintf("load_splash_data: cant read image data from splash icons image\n"); |
| 161 | unload_splash_data(); |
| 162 | return B_IO_ERROR; |
| 163 | } |
| 164 | dprintf("load_splash_data: splash icons image width=%d, height=%d, size=%d, pointer=%p, data pointer=%p\n", splashIcons->width, splashIcons->height, splashIcons->size, splashIcons, splashIcons->data); |
| 165 | close(fd); |
| 166 | |
| 167 | // palette.raw |
| 168 | fd = open_from(volume, "home/config/settings/kernel/palette.raw", O_RDONLY); |
| 169 | if (fd < 0) |
| 170 | { |
| 171 | dprintf("load_splash_data: error opening home/config/settings/kernel/palette.raw\n"); |
| 172 | unload_splash_data(); |
| 173 | return fd; |
| 174 | } |
| 175 | dprintf("load_splash_data: home/config/settings/kernel/palette.raw opened\n"); |
| 176 | splashPalette = (bootSplashPalette*)malloc(sizeof(bootSplashPalette)); |
| 177 | if (!splashPalette) |
| 178 | { |
| 179 | dprintf("load_splash_data: not enough memory to alloc splash palette\n"); |
| 180 | return B_NO_MEMORY; |
| 181 | } |
| 182 | dprintf("load_splash_data: splashPalette=%p\n", splashPalette); |
| 183 | memset(splashPalette, 0, sizeof(bootSplashPalette)); |
| 184 | if(read(fd, &(splashPalette->size), sizeof(unsigned int)) != sizeof(unsigned int)) |
| 185 | { |
| 186 | dprintf("load_splash_data: cant read size from splash palette\n"); |
| 187 | unload_splash_data(); |
| 188 | return B_IO_ERROR; |
| 189 | } |
| 190 | splashPalette->data = (unsigned char*)malloc(splashPalette->size); |
| 191 | if(!splashPalette->data) |
| 192 | { |
| 193 | dprintf("load_splash_data: not enough memory to alloc splash palette data\n"); |
| 194 | unload_splash_data(); |
| 195 | return B_NO_MEMORY; |
| 196 | } |
| 197 | memset(splashPalette->data, 0, splashPalette->size); |
| 198 | if(read(fd, splashPalette->data, splashPalette->size) != splashPalette->size) |
| 199 | { |
| 200 | dprintf("load_splash_data: cant read data from splash palette\n"); |
| 201 | unload_splash_data(); |
| 202 | return B_IO_ERROR; |
| 203 | } |
| 204 | dprintf("load_splash_data: splash palette size=%d, pointer=%p, data pointer=%p\n", splashPalette->size, splashPalette, splashPalette->data); |
| 205 | close(fd); |
| 206 | |
| 207 | return B_OK; |
| 208 | } |
| 209 | |
| 210 | void |
| 211 | unload_splash_data() |
| 212 | { |
| 213 | dprintf("unload_splash_data\n"); |
| 214 | if (splashImage) |
| 215 | { |
| 216 | if (splashImage->data) |
| 217 | { |
| 218 | free(splashImage->data); |
| 219 | splashImage->data = NULL; |
| 220 | } |
| 221 | free(splashImage); |
| 222 | splashImage = NULL; |
| 223 | } |
| 224 | if (splashIcons) |
| 225 | { |
| 226 | if (splashIcons->data) |
| 227 | { |
| 228 | free(splashIcons->data); |
| 229 | splashIcons->data = NULL; |
| 230 | } |
| 231 | free(splashIcons); |
| 232 | splashIcons = NULL; |
| 233 | } |
| 234 | if (splashPalette) |
| 235 | { |
| 236 | if (splashPalette->data) |
| 237 | { |
| 238 | free(splashPalette->data); |
| 239 | splashPalette->data = NULL; |
| 240 | } |
| 241 | free(splashPalette); |
| 242 | splashPalette = NULL; |
| 243 | } |
| 244 | } |
| 245 | |
| 845 | // data - image data |
| 846 | // imageLeft - cropped image left point |
| 847 | // imageRight - cropped image right point |
| 848 | // imageTop - cropped image top point |
| 849 | // imageBottom - cropped image bottom point |
| 850 | // imageWidth - image width |
| 851 | // imageHeight - image height |
| 852 | // palette - image palette |
| 853 | static void |
| 854 | blit16_cropped(const uint8 *data, uint16 imageLeft, uint16 imageTop, uint16 imageRight, uint16 imageBottom, |
| 855 | uint16 imageWidth, uint16 imageHeight, const uint8 *palette, uint16 left, uint16 top) |
| 856 | { |
| 857 | int32 dataOffset = (imageWidth * imageTop) + imageLeft; |
| 859 | uint16 *start = (uint16 *)(sFrameBuffer |
| 860 | + gKernelArgs.frame_buffer.bytes_per_row * top + 2 * left); |
| 861 | |
| 862 | for (int32 y = imageTop; y < imageBottom; y++) { |
| 863 | for (int32 x = imageLeft; x < imageRight; x++) { |
| 864 | uint16 color = data[(y * (imageWidth)) + x] * 3; |
| 865 | |
| 866 | start[x] = ((palette[color + 0] >> 3) << 11) |
| 867 | | ((palette[color + 1] >> 2) << 5) |
| 868 | | ((palette[color + 2] >> 3)); |
| 869 | dataOffset += imageWidth; |
| 870 | } |
| 871 | |
| 872 | |
| 873 | start = (uint16 *)((addr_t)start |
| 874 | + gKernelArgs.frame_buffer.bytes_per_row); |
| 875 | } |
| 876 | |
| 877 | // for (int32 i = 0; i < (imageBottom - imageTop); i++) { |
| 878 | // memcpy((void *)(start + gKernelArgs.frame_buffer.bytes_per_row * i), |
| 879 | // &data[dataOffset], imageRight - imageLeft); |
| 880 | // dataOffset += imageWidth; |
| 881 | // } |
| 882 | } |
| 883 | |
| 953 | static void |
| 954 | blit_8bit_image_cropped(const uint8 *data, uint16 imageLeft, uint16 imageTop, uint16 imageRight, uint16 imageBottom, |
| 955 | uint16 imageWidth, uint16 imageHeight, const uint8 *palette, uint16 left, uint16 top) |
| 956 | { |
| 957 | dprintf("blit_8bit_image_cropped: depth=%d\n", gKernelArgs.frame_buffer.depth); |
| 958 | switch (gKernelArgs.frame_buffer.depth) { |
| 959 | case 16: |
| 960 | return blit16_cropped(data, imageLeft, imageTop, imageRight, imageBottom, imageWidth, imageHeight, palette, left, top); |
| 961 | case 8: |
| 962 | case 4: |
| 963 | case 15: |
| 964 | case 24: |
| 965 | case 32: |
| 966 | return; |
| 967 | } |
| 968 | } |
| 1118 | void |
| 1119 | set_bootsplash_stage(int stage) |
| 1120 | { |
| 1121 | bootStage = stage; |
| 1122 | |
| 1123 | if (!bootLogoMode) |
| 1124 | return; |
| 1125 | |
| 1126 | // clear the video memory |
| 1127 | memset((void *)sFrameBuffer, 0, |
| 1128 | gKernelArgs.frame_buffer.physical_buffer.size); |
| 1129 | |
| 1130 | dprintf("set_bootsplash_stage: drawing logo\n"); |
| 1131 | if (splashImage && splashImage->data && splashPalette && splashPalette->data) |
| 1132 | { |
| 1133 | blit_8bit_image(splashImage->data, splashImage->width, splashImage->height, splashPalette->data, |
| 1134 | gKernelArgs.frame_buffer.width - splashImage->width - 80, |
| 1135 | gKernelArgs.frame_buffer.height - splashImage->height ); |
| 1136 | } |
| 1137 | dprintf("set_bootsplash_stage: drawing icons\n"); |
| 1138 | if (splashIcons && splashIcons->data && splashPalette && splashPalette->data) |
| 1139 | { |
| 1140 | int iconsx = (gKernelArgs.frame_buffer.width / 2) - (splashIcons->width / 2); |
| 1141 | int iconsy = (gKernelArgs.frame_buffer.height / 2) - (splashIcons->height / 4); |
| 1142 | blit_8bit_image_cropped(splashIcons->data, 0, 32, splashIcons->width, 64, splashIcons->width, splashIcons->height, |
| 1143 | splashPalette->data, iconsx, iconsy ); |
| 1144 | if (bootStage > 0) |
| 1145 | { |
| 1146 | blit_8bit_image_cropped(splashIcons->data, 0, 0, bootStage * 32, 32, splashIcons->width, splashIcons->height, |
| 1147 | splashPalette->data, iconsx, iconsy ); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |