static string_type get_string(std::uint32_t cp) { string_type str; std::size_t byte_size = get_byte_size(cp); str.reserve(byte_size); switch (byte_size) { case 4: { str.push_back( static_cast<char_type>(cp) ); break; } } return str; }
bool base_type_die::is_rep_compatible(std::shared_ptr<type_die> arg) const { // first, try to make arg concrete // HACK: strange infinite recursion bug here, so try using get_offset if (!arg->get_concrete_type()) return false; if (arg->get_concrete_type()->get_offset() != arg->get_offset()) return this->is_rep_compatible( arg->get_concrete_type()); auto arg_base_type = std::dynamic_pointer_cast<base_type_die>(arg); if (!arg_base_type) return false; return arg_base_type->get_encoding() == this->get_encoding() && arg_base_type->get_byte_size() == this->get_byte_size() && arg_base_type->get_bit_size () == this->get_bit_size() && arg_base_type->get_bit_offset() == this->get_bit_offset(); }
void* dds::get_texture_data(const char* file, int* w, int* h, int* mips, base::pixelfmt* pixfmt) { FILE* fp = fopen(file, "rb"); if(!fp) throw base::exception("file not found"); dds_hdr hdr; fread(&hdr, sizeof(hdr), 1, fp); if(!get_tex2d_desc(&hdr, w, h, mips, pixfmt)) return 0; int size = get_byte_size(*w, *h, *mips, *pixfmt); void* data = ::malloc(size); fread(data, size, 1, fp); fclose(fp); return data; }
bool dds::save_texture(const char* file, int w, int h, int mips, base::pixelfmt fmt, const void* data) { if( (NULL == file) || (w < 1) || (h < 1) || (data == NULL ) ) return false; dds_hdr hdr; hdr._magic = DDS_MAGIC; DDSURFACEDESC2* surf = &hdr._ddsd; int size = get_byte_size(w, h, mips, fmt); // memset(surf, 0, sizeof(DDSURFACEDESC2)); surf->dwSize = 124; surf->dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE; if(mips>1) surf->dwFlags |= DDSD_MIPMAPCOUNT; surf->dwWidth = w; surf->dwHeight = h; surf->dwPitchOrLinearSize = size; surf->dwMipMapCount = mips; if(!fill_pixel_format(&surf->ddpfPixelFormat, fmt)) return false; surf->ddsCaps.dwCaps1 = DDSCAPS_TEXTURE; if(mips>1) surf->ddsCaps.dwCaps1 |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX; //write to file FILE *fp = fopen(file, "wb"); fwrite(&hdr, sizeof(hdr), 1, fp); fwrite(data, 1, size, fp); fclose(fp); return true; }