diff --git a/bin/crunch_x64.exe b/bin/crunch_x64.exe index b69019a..e1869b0 100644 Binary files a/bin/crunch_x64.exe and b/bin/crunch_x64.exe differ diff --git a/crnlib/crn_comp.cpp b/crnlib/crn_comp.cpp index 2557ef4..698b1a4 100644 --- a/crnlib/crn_comp.cpp +++ b/crnlib/crn_comp.cpp @@ -324,7 +324,7 @@ bool crn_comp::pack_blocks( for (uint c = 0; c < cNumComps; c++) { if (endpoint_remap[c]) { uint index = (*endpoint_remap[c])[m_endpoint_indices[b].component[c]]; - if (m_pParams->m_format == cCRNFmtETC1 ? !(bx & 1) || m_endpoint_indices[b].reference : !m_endpoint_indices[b].reference) { + if (m_pParams->m_format == cCRNFmtETC1 && (b & 1) ? m_endpoint_indices[b].reference : !m_endpoint_indices[b].reference) { int sym = index - endpoint_index[c]; if (sym < 0) sym += endpoint_remap[c]->size(); @@ -710,7 +710,7 @@ void crn_comp::optimize_color_endpoints_task(uint64 data, void* pData_ptr) { for (uint level = 0; level < m_levels.size(); level++) { for (uint endpoint_index = 0, b = m_levels[level].first_block, bEnd = b + m_levels[level].num_blocks; b < bEnd; b++) { uint index = remapping[m_endpoint_indices[b].component[cColor]]; - if (!m_endpoint_indices[b].reference) { + if (m_pParams->m_format == cCRNFmtETC1 && (b & 1) ? m_endpoint_indices[b].reference : !m_endpoint_indices[b].reference) { int sym = index - endpoint_index; hist[sym < 0 ? sym + n : sym]++; } @@ -787,7 +787,7 @@ void crn_comp::optimize_color() { crnlib::vector sum(n); for (uint i, i_prev = 0, b = 0; b < m_endpoint_indices.size(); b++, i_prev = i) { i = m_endpoint_indices[b].color; - if ((!m_endpoint_indices[b].reference || m_pParams->m_format == cCRNFmtETC1) && i != i_prev) { + if ((m_pParams->m_format == cCRNFmtETC1 && (b & 1) ? m_endpoint_indices[b].reference : !m_endpoint_indices[b].reference) && i != i_prev) { hist[i * n + i_prev]++; hist[i_prev * n + i]++; sum[i]++; diff --git a/crnlib/crn_dxt_hc.cpp b/crnlib/crn_dxt_hc.cpp index f7c7f09..431e5cb 100644 --- a/crnlib/crn_dxt_hc.cpp +++ b/crnlib/crn_dxt_hc.cpp @@ -218,7 +218,7 @@ bool dxt_hc::compress( uint16 selector_index = (c ? alpha_selectors_remap : color_selectors_remap)[m_selector_indices[b].component[c]]; selector_indices[b].component[c] = selector_index; } - endpoint_indices[b].reference = m_params.m_format == cETC1 ? m_endpoint_indices[b].reference : left_match ? 1 : top_match ? 2 : 0; + endpoint_indices[b].reference = m_params.m_format == cETC1 && (b & 1) ? m_endpoint_indices[b].reference : left_match ? 1 : top_match ? 2 : 0; } } } diff --git a/inc/crn_decomp.h b/inc/crn_decomp.h index 7fd1992..434b0ec 100644 --- a/inc/crn_decomp.h +++ b/inc/crn_decomp.h @@ -3567,15 +3567,21 @@ class crn_unpacker { if (y & 1) { endpoint_reference = buffer.endpoint_reference; } else { - reference_group = m_codec.decode(m_reference_encoding_dm) >> 4; - endpoint_reference = reference_group & 3; - reference_group >>= 2; - buffer.endpoint_reference = reference_group & 3; - reference_group >>= 2; + reference_group = m_codec.decode(m_reference_encoding_dm); + endpoint_reference = reference_group & 3 | reference_group >> 2 & 12; + buffer.endpoint_reference = reference_group >> 2 & 3 | reference_group >> 4 & 12; } - color_endpoint_index += m_codec.decode(m_endpoint_delta_dm[0]); - if (color_endpoint_index >= num_color_endpoints) - color_endpoint_index -= num_color_endpoints; + if (!(endpoint_reference & 3)) { + color_endpoint_index += m_codec.decode(m_endpoint_delta_dm[0]); + if (color_endpoint_index >= num_color_endpoints) + color_endpoint_index -= num_color_endpoints; + buffer.color_endpoint_index = color_endpoint_index; + } else if ((endpoint_reference & 3) == 1) { + buffer.color_endpoint_index = color_endpoint_index; + } else { + color_endpoint_index = buffer.color_endpoint_index; + } + endpoint_reference >>= 2; *(uint32*)&e0 = m_color_endpoints[color_endpoint_index]; uint32 selector = m_color_selectors[m_codec.decode(m_selector_delta_dm[0])]; if (endpoint_reference) {