Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cross to cubemap, added cubemap to cross #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion crnlib/crn_mipmapped_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ namespace crnlib
image_u8 tmp_img;
image_u8* pSrc_image = pSrc->get_unpacked_image(tmp_img, cUnpackFlagUncook | cUnpackFlagUnflip);

const mip_level* pDst = get_level(face_index, 0);
const mip_level* pDst = cubemap.get_level(face_index, 0);
image_u8* pDst_image = pDst->get_image();
CRNLIB_ASSERT(pDst_image);

Expand Down Expand Up @@ -2455,6 +2455,68 @@ namespace crnlib

return true;
}

bool mipmapped_texture::cubemap_to_vertical_cross()
{
if (get_num_faces() != 6)
return false;

const uint face_width = get_width();

if(face_width != get_height())
return false;

bool alpha_is_valid = has_alpha();

mipmapped_texture cross;

pixel_format fmt = alpha_is_valid ? PIXEL_FMT_A8R8G8B8 : PIXEL_FMT_R8G8B8;

cross.init(face_width * 3, face_width * 4, 1, 1, fmt, m_name.get_ptr(), cDefaultOrientationFlags);

const mip_level* pDst = cross.get_level(0, 0);
image_u8* pDst_image = pDst->get_image();
CRNLIB_ASSERT(pDst_image);

for (uint y = 0; y < cross.get_height(); y++)
{
for (uint x = 0; x < cross.get_width(); x++)
{
color_quad_u8& c = (*pDst_image)(x, y);

c = color_quad_u8(0, 0, 0, 0);
}
}

for (uint face_index = 0; face_index < 6; face_index++)
{
const mip_level* pSrc = get_level(face_index, 0);

image_u8 tmp_img;
image_u8* pSrc_image = pSrc->get_unpacked_image(tmp_img, cUnpackFlagUncook | cUnpackFlagUnflip);

const bool flipped = (face_index == 5);
const uint x_ofs = g_vertical_cross_image_offsets[face_index][0] * face_width;
const uint y_ofs = g_vertical_cross_image_offsets[face_index][1] * face_width;

for (uint y = 0; y < face_width; y++)
{
for (uint x = 0; x < face_width; x++)
{
const color_quad_u8& c = (flipped ? (*pSrc_image)(face_width - 1 - x, face_width - 1 - y) :
(*pSrc_image)(x, y));

(*pDst_image)(x_ofs + x, y_ofs + y) = c;
}
}
}

swap(cross);

CRNLIB_ASSERT(check());

return true;
}

bool mipmapped_texture::qdxt_pack_init(qdxt_state& state, mipmapped_texture& dst_tex, const qdxt1_params& dxt1_params, const qdxt5_params& dxt5_params, pixel_format fmt, bool cook)
{
Expand Down
2 changes: 2 additions & 0 deletions crnlib/crn_mipmapped_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ namespace crnlib

bool vertical_cross_to_cubemap();

bool cubemap_to_vertical_cross();

// Low-level clustered DXT (QDXT) compression
struct qdxt_state
{
Expand Down