You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, we have an AR app that downloads a couple of textures for objects around the user. For these textures, we have to know the predominant color. The texture images (PNGs) are approx. 1.5mb.
We noticed significant frame drops, and when we analysed the root cause, we learned that ColorThief's "GetPixelFast" method is the actual culprit. More specifically, the following line:
var pixels = imageData.ToArray();
This array conversion takes around 1.5s. And it doesn't matter which quality setting we choose, as this array conversion is done before quality is taken into account.
Is there a way to speed this up, i.e. by copying only the required pixels into an array?
The text was updated successfully, but these errors were encountered:
privateint[][]GetPixelsFast(Texture2DsourceImage,intquality,boolignoreWhite,intmipLevel){varmipData=sourceImage.GetPixels32(mipLevel);varpixelCount=mipData.Length;// Store the RGB values in an array format suitable for quantize// function// numRegardedPixels must be rounded up to avoid an// ArrayIndexOutOfBoundsException if all pixels are good.varnumRegardedPixels=(quality<=0)?0:(pixelCount+quality-1)/quality;varnumUsedPixels=0;varpixelArray=newint[numRegardedPixels][];for(vari=0;i<pixelCount;i+=quality){varb=Convert.ToInt32(mipData[i].b);varg=Convert.ToInt32(mipData[i].g);varr=Convert.ToInt32(mipData[i].r);vara=Convert.ToInt32(mipData[i].a);// If pixel is mostly opaque and not whiteif(a>=125&&!(ignoreWhite&&r>250&&g>250&&b>250)){pixelArray[numUsedPixels]=new[]{r,g,b};numUsedPixels++;}}// Remove unused pixels from the arrayvarcopy=newint[numUsedPixels][];Array.Copy(pixelArray,copy,numUsedPixels);returncopy;}
It could be further sped up if a higher mip level would be used and if the rest of the logic directly operated on the returned COLOR32 values, I guess.
Not sure if this is a generic solution for all cases, but for me, it worked wonders.
Hi, we have an AR app that downloads a couple of textures for objects around the user. For these textures, we have to know the predominant color. The texture images (PNGs) are approx. 1.5mb.
We noticed significant frame drops, and when we analysed the root cause, we learned that ColorThief's "GetPixelFast" method is the actual culprit. More specifically, the following line:
var pixels = imageData.ToArray();
This array conversion takes around 1.5s. And it doesn't matter which quality setting we choose, as this array conversion is done before quality is taken into account.
Is there a way to speed this up, i.e. by copying only the required pixels into an array?
The text was updated successfully, but these errors were encountered: