void NormalCompressorDXT1::compressBlock(ColorSet & set, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
    set.setUniformWeights();
    set.createMinimalSet(false);

	ClusterFit fit;
	fit.setMetric(compressionOptions.colorWeight);

    BlockDXT1 * block = new(output) BlockDXT1;
    
    if (set.isSingleColor(true))
	{
        Color32 c;
        c.r = uint8(clamp(set.colors[0].x, 0.0f, 1.0f) * 255);
        c.g = uint8(clamp(set.colors[0].y, 0.0f, 1.0f) * 255);
        c.b = uint8(clamp(set.colors[0].z, 0.0f, 1.0f) * 255);
        c.a = 255;
		OptimalCompress::compressDXT1(c, block);
	}
	else
	{
		fit.setColourSet(&set);
		
        Vector3 start, end;
        
        fit.compress4(&start, &end);
        QuickCompress::outputBlock4(set, start, end, block);

        if (fit.compress3(&start, &end)) {
            QuickCompress::outputBlock3(set, start, end, block);
        }
	}
}
Exemple #2
0
ColorSet * Solid::getColors()
{
	ColorSet * newColors = new ColorSet();

	for(int i = 0; i < colors.length(); i++)
	{
		newColors->AddColor(colors[i]);
	}

	return newColors;
}
// Each task compresses one block.
void ColorSetCompressorTask(void * data, int i)
{
    ColorSetCompressorContext * d = (ColorSetCompressorContext *) data;

    uint x = i % d->bw;
    uint y = i / d->bw;

    //for (uint x = 0; x < d->bw; x++)
    {
        ColorSet set;
        set.setColors(d->data, d->w, d->h, x * 4, y * 4);

        uint8 * ptr = d->mem + (y * d->bw + x) * d->bs;
        d->compressor->compressBlock(set, d->alphaMode, *d->compressionOptions, ptr);
    }
}
void ProductionCompressorBC5_Luma::compressBlock(ColorSet & set, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
    BlockATI2 * block = new(output) BlockATI2;

    AlphaBlock4x4 tmp;
    tmp.init(set, /*channel=*/0);
    OptimalCompress::compressDXT5A(tmp, &block->x);

    // Decode block->x
    AlphaBlock4x4 decoded;
    block->x.decodeBlock(&decoded);

    const float R = 1.0f / 256.0f; // Maximum residual that we can represent. @@ Tweak this.

    // Compute residual block.
    for (int i = 0; i < 16; i++) {
        float in = set.color(i).x;                      // [0,1]
        float out = float(decoded.alpha[i]) / 255.0f;   // [0,1]

        float residual = (out - in);                    // [-1,1], but usually [-R,R]

        // Normalize residual to [-1,1] range.
        residual /= R;

        // Pack in [0,1] range.
        residual = residual * 0.5f + 0.5f;

        tmp.alpha[i] = nv::ftoi_round(nv::saturate(residual) * 255.0f);
    }

    OptimalCompress::compressDXT5A(tmp, &block->y);
   
}
Exemple #5
0
    virtual void visit(AstNode* nodep) {
        if (nodep->user3p()) {
            SplitLogicVertex* vertexp = (SplitLogicVertex*)(nodep->user3p());
            uint32_t color = vertexp->color();
            m_colors.insert(color);
            UINFO(8, "  SVL " << vertexp << " has color " << color << "\n");

            // Record that all containing ifs have this color.
            for (IfStack::const_iterator it = m_ifStack.begin();
                 it != m_ifStack.end(); ++it) {
                m_ifColors[*it].insert(color);
            }
        }
        iterateChildren(nodep);
    }
void CompressorBC7::compressBlock(ColorSet & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
{
	// !!!UNDONE: support channel weights
	// !!!UNDONE: set flags once, not per block (this is especially sketchy since block compression is multithreaded...)

	AVPCL::mode_rgb = false;
	AVPCL::flag_premult = (alphaMode == AlphaMode_Premultiplied);
	AVPCL::flag_nonuniform = false;
	AVPCL::flag_nonuniform_ati = false;

	// Convert NVTT's tile struct to AVPCL's.
	AVPCL::Tile avpclTile(tile.w, tile.h);
	memset(avpclTile.data, 0, sizeof(avpclTile.data));
	for (uint y = 0; y < tile.h; ++y)
		for (uint x = 0; x < tile.w; ++x)
			avpclTile.data[y][x] = tile.color(x, y) * 255.0f;

	AVPCL::compress(avpclTile, (char *)output);
}
void CompressorBC6::compressBlock(ColorSet & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
{
	// !!!UNDONE: support channel weights
	// !!!UNDONE: set flags once, not per block (this is especially sketchy since block compression is multithreaded...)

	NV_UNUSED(alphaMode); // ZOH does not support alpha.

    if (compressionOptions.pixelType == PixelType_UnsignedFloat ||
        compressionOptions.pixelType == PixelType_UnsignedNorm ||
        compressionOptions.pixelType == PixelType_UnsignedInt)
    {
        ZOH::Utils::FORMAT = ZOH::UNSIGNED_F16;
    }
    else
    {
        ZOH::Utils::FORMAT = ZOH::SIGNED_F16;
    }

	// Convert NVTT's tile struct to ZOH's, and convert float to half.
	ZOH::Tile zohTile(tile.w, tile.h);
	memset(zohTile.data, 0, sizeof(zohTile.data));
	memset(zohTile.importance_map, 0, sizeof(zohTile.importance_map));
	for (uint y = 0; y < tile.h; ++y)
	{
		for (uint x = 0; x < tile.w; ++x)
		{
			Vector3 color = tile.color(x, y).xyz();
			uint16 rHalf = to_half(color.x);
			uint16 gHalf = to_half(color.y);
			uint16 bHalf = to_half(color.z);
			zohTile.data[y][x].x = ZOH::Tile::half2float(rHalf);
			zohTile.data[y][x].y = ZOH::Tile::half2float(gHalf);
			zohTile.data[y][x].z = ZOH::Tile::half2float(bHalf);
			zohTile.importance_map[y][x] = 1.0f;
		}
	}

    ZOH::compress(zohTile, (char *)output);
}
Exemple #8
0
int BuddhabrotSketch::GetGroup(double th, Complex *pts, GLcolor *cols, int n)
{
	ColorSet colorset;
	colorset.fromHues(BASIC_HUE_SET, 10, 0.9, 1.0);
	colorset.offsetHues(270);	// ?

	// shorthand path
	Path *pPath = ((Path*)(m_pPath.get()));

	ASSERT(n>=GetGroupSize());
	int count = 0;
	Complex c, z;
	for(int j=0; j<pPath->getGroupSize(); ++j)
	{
		c = pPath->get(th, j);
		z = c;

		int i;
		for(i=0; i<m_nMaxIter; ++i)
		{
			z = (z*z + c);
			if(normal(z) > 4.0)
				break;
		}

		// slight alteration here:
		// we're not going to plot short orbits, only
		// interesting ones whose length is at least MinIter.
		if(i < m_nMaxIter && i >= m_nMinIter)
		{
			// plot this point's orbit, until it hits the bailout value

			int nStopIter = i;

			z = c;
			for(i=0; i<=nStopIter; ++i)		// was i<=m_nMaxIter
			{
				z = (z*z) + c;
				pts[count] = z;
				// color according to...
				switch(m_nColorScheme)
				{
				case 0:
					// abs(c)?
					cols[count].SetHSV(360*log(abs(c)), 0.9, 0.9, m_fBrightness);
					break;
				case 1:
					// iter? (busy)
//					cols[count].SetHSV((i-m_nMinIter)*360.0/(m_nMaxIter-m_nMinIter+1), 0.9, 0.9, m_fBrightness);
					cols[count].SetHSV((i*360.0/m_nMaxIter), 0.9, 0.9, m_fBrightness);
					break;
				case 2:
					// c.arg?
					cols[count].SetHSV(arg(c)*360.0/6.283, 0.9, 0.9, m_fBrightness);
					break;
				case 3:
					// ring index? (this makes bright figures with little or no blur)
					cols[count].SetHSV(j*360.0/pPath->getGroupSize(), 0.9, 0.9, m_fBrightness);
					break;
				case 4:
					// stopiter?
					cols[count].SetHSV((nStopIter-m_nMinIter)*360.0/(m_nMaxIter-m_nMinIter+1), 0.9, 0.9, m_fBrightness);
				}

				++count;
			}
		}
	}

	ASSERT(count <= n);
	return count;
}