Changeset View
Changeset View
Standalone View
Standalone View
source/lib/tex/tex.cpp
Show First 20 Lines • Show All 741 Lines • ▼ Show 20 Lines | Status Tex::decode(const std::shared_ptr<u8>& Data, size_t DataSize) | ||||
CHECK_TEX(this); | CHECK_TEX(this); | ||||
UpdateMIPLevels(); | UpdateMIPLevels(); | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
Status Tex::encode(const OsPath& extension, DynArray* da) | Status Tex::encode(const OsPath& extension, DynArray* da, int quality) | ||||
{ | { | ||||
CHECK_TEX(this); | CHECK_TEX(this); | ||||
WARN_RETURN_STATUS_IF_ERR(tex_validate_plain_format(m_Bpp, m_Flags)); | WARN_RETURN_STATUS_IF_ERR(tex_validate_plain_format(m_Bpp, m_Flags)); | ||||
// we could be clever here and avoid the extra alloc if our current | // we could be clever here and avoid the extra alloc if our current | ||||
// memory block ensued from the same kind of texture file. this is | // memory block ensued from the same kind of texture file. this is | ||||
// most likely the case if in_img == get_data() + c->hdr_size(0). | // most likely the case if in_img == get_data() + c->hdr_size(0). | ||||
// this would make for zero-copy IO. | // this would make for zero-copy IO. | ||||
const size_t max_out_size = img_size()*4 + 256*KiB; | const size_t max_out_size = img_size()*4 + 256*KiB; | ||||
RETURN_STATUS_IF_ERR(da_alloc(da, max_out_size)); | RETURN_STATUS_IF_ERR(da_alloc(da, max_out_size)); | ||||
const ITexCodec* c; | const ITexCodec* c; | ||||
WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c)); | WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c)); | ||||
// encode into <da> | // encode into <da> | ||||
Status err = c->encode(this, da); | Status err = c->encode(this, da, quality); | ||||
if(err < 0) | if(err < 0) | ||||
{ | { | ||||
(void)da_free(da); | (void)da_free(da); | ||||
WARN_RETURN(err); | WARN_RETURN(err); | ||||
} | } | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
Show All 36 Lines |
Wildfire Games · Phabricator