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

Add ASTC Normalmap support #23

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
97 changes: 39 additions & 58 deletions 3rdparty/astc/astc_averages_and_directions.cpp
@@ -1,22 +1,19 @@
/*----------------------------------------------------------------------------*/
// ----------------------------------------------------------------------------
// This confidential and proprietary software may be used only as authorised
// by a licensing agreement from Arm Limited.
// (C) COPYRIGHT 2011-2019 Arm Limited, ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorised copies and
// copies may only be made to the extent permitted by a licensing agreement
// from Arm Limited.
// ----------------------------------------------------------------------------

/**
* This confidential and proprietary software may be used only as
* authorised by a licensing agreement from ARM Limited
* (C) COPYRIGHT 2011-2012 ARM Limited
* ALL RIGHTS RESERVED
*
* The entire notice above must be reproduced on all authorised
* copies and copies may only be made to the extent permitted
* by a licensing agreement from ARM Limited.
* @brief Functions for finding dominant direction of a set of colors.
*
* @brief Implements functions for finding dominant direction of a set of
* colors, using ARM patent pending method.
*/
/*----------------------------------------------------------------------------*/
* Uses Arm patent pending method.
*/

#include "astc_codec_internals.h"

#include <math.h>
#include "mathlib.h"

#ifdef DEBUG_CAPTURE_NAN
Expand All @@ -27,13 +24,11 @@
#include <fenv.h>
#endif

/* routines to compute average colors and dominant directions for blocks with 3 and 4 components. */

/*
for a full block, functions to compute averages and dominant directions. The averages and directions are computed separately for each partition.
We have separate versions for blocks with and without alpha, since the processing for blocks with alpha is significantly more expensive.
The direction vectors it produces are NOT normalized.
*/
// For a full block, functions to compute averages and dominant directions. The
// averages and directions are computed separately for each partition.
// We have separate versions for blocks with and without alpha, since the
// processing for blocks with alpha is significantly more expensive. The
// direction vectors it produces are NOT normalized.
void compute_averages_and_directions_rgba(const partition_info * pt,
const imageblock * blk,
const error_weight_block * ewb,
Expand Down Expand Up @@ -125,9 +120,6 @@ void compute_averages_and_directions_rgba(const partition_info * pt,
}
}




void compute_averages_and_directions_rgb(const partition_info * pt,
const imageblock * blk,
const error_weight_block * ewb,
Expand Down Expand Up @@ -229,11 +221,9 @@ void compute_averages_and_directions_3_components(const partition_info * pt,
texel_weights = ewb->texel_weight_rgb;
else
{
texel_weights = ewb->texel_weight_gba;
ASTC_CODEC_INTERNAL_ERROR;
ASTC_CODEC_INTERNAL_ERROR();
}


for (partition = 0; partition < partition_count; partition++)
{
const uint8_t *weights = pt->texels_of_partition[partition];
Expand Down Expand Up @@ -305,9 +295,6 @@ void compute_averages_and_directions_3_components(const partition_info * pt,

}




void compute_averages_and_directions_2_components(const partition_info * pt,
const imageblock * blk,
const error_weight_block * ewb, const float2 * color_scalefactors, int component1, int component2, float2 * averages, float2 * directions)
Expand All @@ -325,13 +312,9 @@ void compute_averages_and_directions_2_components(const partition_info * pt,
texel_weights = ewb->texel_weight_gb;
else
{
texel_weights = ewb->texel_weight_rg;
// unsupported set of color components.
ASTC_CODEC_INTERNAL_ERROR;
exit(1);
ASTC_CODEC_INTERNAL_ERROR();
}


for (partition = 0; partition < partition_count; partition++)
{
const uint8_t *weights = pt->texels_of_partition[partition];
Expand All @@ -356,7 +339,6 @@ void compute_averages_and_directions_2_components(const partition_info * pt,
float2 average = base_sum * 1.0f / MAX(partition_weight, 1e-7f);
averages[partition] = average * csf.xy;


float2 sum_xp = float2(0, 0);
float2 sum_yp = float2(0, 0);

Expand Down Expand Up @@ -387,7 +369,6 @@ void compute_averages_and_directions_2_components(const partition_info * pt,

directions[partition] = best_vector;
}

}


Expand All @@ -407,20 +388,20 @@ float funcname( \
float errorsum = 0.0f; \
int partition; \
for(partition=0; partition<pt->partition_count; partition++) \
{ \
{ \
const uint8_t *weights = pt->texels_of_partition[ partition ]; \
int texelcount = pt->texels_per_partition[ partition ]; \
float lowparam = 1e10f; \
float highparam = -1e10f; \
processed_line2 l = plines[partition]; \
if( ewb->contains_zeroweight_texels ) \
{ \
{ \
for(i=0;i<texelcount;i++) \
{ \
{ \
int iwt = weights[i]; \
float texel_weight = ewb-> PASTE(texel_weight_ , c01_rname) [i]; \
if( texel_weight > 1e-20f ) \
{ \
{ \
float2 point = float2(blk->work_data[4*iwt + c0_iwt], blk->work_data[4*iwt + c1_iwt] ); \
float param = dot( point, l.bs ); \
float2 rp1 = l.amod + param*l.bis; \
Expand All @@ -430,12 +411,12 @@ float funcname( \
if( param < lowparam ) lowparam = param; \
if( param > highparam ) highparam = param; \
} \
} \
} \
} \
else \
{ \
{ \
for(i=0;i<texelcount;i++) \
{ \
{ \
int iwt = weights[i]; \
float2 point = float2(blk->work_data[4*iwt + c0_iwt], blk->work_data[4*iwt + c1_iwt] ); \
float param = dot( point, l.bs ); \
Expand All @@ -445,15 +426,15 @@ float funcname( \
errorsum += dot( ews. c01_name, dist*dist ); \
if( param < lowparam ) lowparam = param; \
if( param > highparam ) highparam = param; \
} \
} \
} \
float linelen = highparam - lowparam; \
if( !(linelen > 1e-7f) ) \
linelen = 1e-7f; \
length_of_lines[partition] = linelen; \
} \
} \
return errorsum; \
}
}


TWO_COMPONENT_ERROR_FUNC(compute_error_squared_rg, 0, 1, xy, rg)
Expand All @@ -478,20 +459,20 @@ float funcname( \
float errorsum = 0.0f; \
int partition; \
for(partition=0; partition<pt->partition_count; partition++) \
{ \
{ \
const uint8_t *weights = pt->texels_of_partition[ partition ]; \
int texelcount = pt->texels_per_partition[ partition ]; \
float lowparam = 1e10f; \
float highparam = -1e10f; \
processed_line3 l = plines[partition]; \
if( ewb->contains_zeroweight_texels ) \
{ \
{ \
for(i=0;i<texelcount;i++) \
{ \
{ \
int iwt = weights[i]; \
float texel_weight = ewb-> PASTE(texel_weight_ , c012_rname) [i]; \
if( texel_weight > 1e-20f ) \
{ \
{ \
float3 point = float3(blk->work_data[4*iwt + c0_iwt], blk->work_data[4*iwt + c1_iwt], blk->work_data[4*iwt + c2_iwt] ); \
float param = dot( point, l.bs ); \
float3 rp1 = l.amod + param*l.bis; \
Expand All @@ -500,13 +481,13 @@ float funcname( \
errorsum += dot( ews. c012_name, dist*dist ); \
if( param < lowparam ) lowparam = param; \
if( param > highparam ) highparam = param; \
} \
} \
} \
} \
else \
{ \
{ \
for(i=0;i<texelcount;i++) \
{ \
{ \
int iwt = weights[i]; \
float3 point = float3(blk->work_data[4*iwt + c0_iwt], blk->work_data[4*iwt + c1_iwt], blk->work_data[4*iwt + c2_iwt] ); \
float param = dot( point, l.bs ); \
Expand All @@ -516,15 +497,15 @@ float funcname( \
errorsum += dot( ews. c012_name, dist*dist ); \
if( param < lowparam ) lowparam = param; \
if( param > highparam ) highparam = param; \
} \
} \
} \
float linelen = highparam - lowparam; \
if( !(linelen > 1e-7f) ) \
linelen = 1e-7f; \
length_of_lines[partition] = linelen; \
} \
} \
return errorsum; \
}
}

THREE_COMPONENT_ERROR_FUNC(compute_error_squared_gba, 1, 2, 3, yzw, gba)
THREE_COMPONENT_ERROR_FUNC(compute_error_squared_rba, 0, 2, 3, xzw, rba)
Expand Down