Uint32 get_image_information(el_file_ptr file, image_t* image) { Uint32 dds, result; if (file == 0) { LOG_ERROR("Invalid file!"); return 0; } dds = 0; if (el_get_size(file) >= 4) { if (check_dds(el_get_pointer(file))) { dds = 1; } } if (dds == 1) { result = get_dds_information(file, image); el_seek(file, 0, SEEK_SET); return result; } else { return get_sdl_image_information(file, image); } }
static Uint32 init_dds_image(el_file_ptr file, DdsHeader *header) { Uint8 magic[4]; el_read(file, sizeof(magic), magic); if (!check_dds(magic)) { LOG_ERROR_OLD("File '%s' is invalid. Wrong magic number for a " "valid DDS.", el_file_name(file)); return 0; } el_read(file, sizeof(DdsHeader), header); header->m_size = SDL_SwapLE32(header->m_size); header->m_flags = SDL_SwapLE32(header->m_flags); header->m_height = SDL_SwapLE32(header->m_height); header->m_width = SDL_SwapLE32(header->m_width); header->m_size_or_pitch = SDL_SwapLE32(header->m_size_or_pitch); header->m_depth = SDL_SwapLE32(header->m_depth); header->m_mipmap_count = SDL_SwapLE32(header->m_mipmap_count); header->m_reserved1[0] = SDL_SwapLE32(header->m_reserved1[0]); header->m_reserved1[1] = SDL_SwapLE32(header->m_reserved1[1]); header->m_reserved1[2] = SDL_SwapLE32(header->m_reserved1[2]); header->m_reserved1[3] = SDL_SwapLE32(header->m_reserved1[3]); header->m_reserved1[4] = SDL_SwapLE32(header->m_reserved1[4]); header->m_reserved1[5] = SDL_SwapLE32(header->m_reserved1[5]); header->m_reserved1[6] = SDL_SwapLE32(header->m_reserved1[6]); header->m_reserved1[7] = SDL_SwapLE32(header->m_reserved1[7]); header->m_reserved1[8] = SDL_SwapLE32(header->m_reserved1[8]); header->m_reserved1[9] = SDL_SwapLE32(header->m_reserved1[9]); header->m_reserved1[10] = SDL_SwapLE32(header->m_reserved1[10]); header->m_pixel_format.m_size = SDL_SwapLE32(header->m_pixel_format.m_size); header->m_pixel_format.m_flags = SDL_SwapLE32(header->m_pixel_format.m_flags); header->m_pixel_format.m_fourcc = SDL_SwapLE32(header->m_pixel_format.m_fourcc); header->m_pixel_format.m_bit_count = SDL_SwapLE32(header->m_pixel_format.m_bit_count); header->m_pixel_format.m_red_mask = SDL_SwapLE32(header->m_pixel_format.m_red_mask); header->m_pixel_format.m_green_mask = SDL_SwapLE32(header->m_pixel_format.m_green_mask); header->m_pixel_format.m_blue_mask = SDL_SwapLE32(header->m_pixel_format.m_blue_mask); header->m_pixel_format.m_alpha_mask = SDL_SwapLE32(header->m_pixel_format.m_alpha_mask); header->m_caps.m_caps1 = SDL_SwapLE32(header->m_caps.m_caps1); header->m_caps.m_caps2 = SDL_SwapLE32(header->m_caps.m_caps2); header->m_caps.m_caps3 = SDL_SwapLE32(header->m_caps.m_caps3); header->m_caps.m_caps4 = SDL_SwapLE32(header->m_caps.m_caps4); header->m_reserved2 = SDL_SwapLE32(header->m_reserved2); return validate_header(header, el_file_name(file)); }
Uint32 load_image_data_file(el_file_ptr file, const Uint32 compression, const Uint32 unpack, const Uint32 strip_mipmaps, const Uint32 base_level, image_t* image) { char buffer[128]; el_file_ptr alpha_file; Uint32 dds, result; if (file == 0) { LOG_ERROR("Invalid file!"); return 0; } dds = 0; if (el_get_size(file) >= 4) { if (check_dds(el_get_pointer(file))) { dds = 1; } } if (dds == 1) { result = load_dds(file, compression, unpack, strip_mipmaps, base_level, image); } else { result = load_image_SDL(file, image); } if ((result == 0) || (image->image == 0)) { LOG_ERROR("Can't load file '%s'!", el_file_name(file)); el_close(file); return 0; } if ((dds != 1) && (check_alpha_image_name(el_file_name(file), sizeof(buffer), buffer) != 0)) { alpha_file = el_open_custom(buffer); if (alpha_file == 0) { LOG_ERROR("Can't load file '%s'!", buffer); el_close(file); return 0; } load_image_SDL_alpha(alpha_file, image); el_close(alpha_file); } el_close(file); return 1; }