Beispiel #1
0
    void PatchReader::checkSpatialTypeSize(
            splash::DataCollector* const dc,
            const uint32_t availableRanks,
            const int32_t id,
            const std::string particlePatchPathComponent
    ) const
    {
        // will later read into 1D buffer from first position on
        splash::Dimensions dstBuffer(availableRanks, 1, 1);
        splash::Dimensions dstOffset(0, 0, 0);
        // sizeRead will be set
        splash::Dimensions sizeRead(0, 0, 0);

        splash::CollectionType* colType = dc->readMeta(
            id,
            particlePatchPathComponent.c_str(),
            dstBuffer,
            dstOffset,
            sizeRead );

        // check if the 1D list of patches has the right length
        assert( sizeRead[0] == availableRanks );

        // currently only support uint64_t types to spare type conversation
        assert( typeid(*colType) == typeid(splash::ColTypeUInt64) );

        // free collections
        __delete( colType );
    }
CString TextCodecBrew::encode(const UChar* characters, size_t length, UnencodableHandling handling)
{
    if (!length)
        return "";

    unsigned int replacementCharacter = '?';

    // FIXME: Impossible to handle EntitiesForUnencodables or URLEncodedEntitiesForUnencodables with ICharsetConv.
    int code = ICharsetConv_Initialize(m_charsetConverter, m_internalEncodingName, m_encoding.name(), replacementCharacter);
    ASSERT(code == AEE_SUCCESS);

    Vector<char> result;

    int srcSize = length * sizeof(UChar);
    unsigned char* srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(characters));
    unsigned char* src = srcBegin;
    unsigned char* srcEnd = srcBegin + srcSize;

    Vector<unsigned char> dstBuffer(length * sizeof(UChar));

    while (src < srcEnd) {
        int numCharsConverted;
        unsigned char* dstBegin = dstBuffer.data();
        unsigned char* dst = dstBegin;
        int dstSize = dstBuffer.size();

        code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
        ASSERT(code != AEE_EINCOMPLETEITEM);

        if (code == AEE_ENOSUCH) {
            LOG_ERROR("Conversion error, Code=%d", code);
            return CString();
        }

        if (code == AEE_EBUFFERTOOSMALL) {
            // Increase the buffer and try it again.
            dstBuffer.grow(dstBuffer.size() * 2);
            continue;
        }

        if (code == AEE_EBADITEM)
            src += sizeof(UChar); // Skip the invalid character

        int numBytes = dst - dstBegin;
        if (numBytes > 0)
            result.append(dstBuffer.data(), numBytes);
    }

    return CString(result.data(), result.size());
}
Beispiel #3
0
    void PatchReader::readPatchAttribute(
        splash::DataCollector* const dc,
        const uint32_t availableRanks,
        const int32_t id,
        const std::string particlePatchPathComponent,
        uint64_t* const dest
    ) const
    {
        // will later read into 1D buffer from first position on
        splash::Dimensions dstBuffer(availableRanks, 1, 1);
        splash::Dimensions dstOffset(0, 0, 0);
        // sizeRead will be set
        splash::Dimensions sizeRead(0, 0, 0);

        // check if types, number of patches and names are supported
        checkSpatialTypeSize( dc, availableRanks, id, particlePatchPathComponent.c_str() );

        // read actual offset and extent data of particle patch component
        dc->read( id,
                  particlePatchPathComponent.c_str(),
                  sizeRead,
                  (void*)dest );
    }
Beispiel #4
0
    ProcessorTaskImageResponse ImageTask::process(
        ProcessorTaskImageRequest& request,
        const std::string& hostId,
        zmq::socket_t* socket)
    {
        ProcessorTaskImageResponse response;
        response.set_taskid(request.taskid());

        auto error = CMP_InitializeBCLibrary();
        if (error != BC_ERROR_NONE)
        {
            switch (error)
            {
            case BC_ERROR_LIBRARY_NOT_INITIALIZED: LOG("BC_ERROR_LIBRARY_NOT_INITIALIZED"); break;
            case BC_ERROR_LIBRARY_ALREADY_INITIALIZED: LOG("BC_ERROR_LIBRARY_ALREADY_INITIALIZED"); break;
            case BC_ERROR_INVALID_PARAMETERS: LOG("BC_ERROR_INVALID_PARAMETERS"); break;
            case BC_ERROR_OUT_OF_MEMORY: LOG("BC_ERROR_OUT_OF_MEMORY"); break;
            }
        }
        //ASSERT(error == BC_ERROR_NONE, "Block compression library failed to initialize");
        auto destinationSizeBytes = static_cast<uint32_t>(engine::formatBytes(
            static_cast<Format>(request.enginepackedformat()),
            request.width(),
            request.height()));

        std::vector<char> dstBuffer(destinationSizeBytes);

        CMP_Texture dstTexture;
        dstTexture.dwSize = sizeof(CMP_Texture);
        dstTexture.dwWidth = request.width();
        dstTexture.dwHeight = request.height();
        dstTexture.dwPitch = 0;
        dstTexture.format = static_cast<CMP_FORMAT>(request.targetcmbcformat());
        dstTexture.nBlockHeight = 4;
        dstTexture.nBlockWidth = 4;
        dstTexture.nBlockDepth = 1;
        dstTexture.dwDataSize = static_cast<CMP_DWORD>(destinationSizeBytes);
        dstTexture.pData = reinterpret_cast<uint8_t*>(dstBuffer.data());// +currentDstBytes;

        CMP_Texture srcTexture;
        srcTexture.dwSize = sizeof(CMP_Texture);
        srcTexture.dwWidth = request.width();
        srcTexture.dwHeight = request.height();
        srcTexture.dwPitch = request.stride();
        srcTexture.format = static_cast<CMP_FORMAT>(request.sourcecmformat());
        srcTexture.dwDataSize = static_cast<CMP_DWORD>(request.data().size());// dibSize;
        srcTexture.pData = const_cast<CMP_BYTE*>(reinterpret_cast<const CMP_BYTE*>(request.data().data()));

        CMP_CompressOptions options = {};
        options.dwSize = sizeof(CMP_CompressOptions);
        options.bDisableMultiThreading = true;
        //options.fquality = 1.0;

        ImporterSurfaceWork work;
        work.request = &request;
        work.lastProgress = 0.0f;
        work.socket = socket;
        work.hostId = hostId;

        CMP_ConvertTexture(
            &srcTexture,
            &dstTexture,
            &options,
            feedback,
            reinterpret_cast<DWORD_PTR>(&work),
            reinterpret_cast<DWORD_PTR>(nullptr));

        response.set_width(request.width());
        response.set_height(request.height());
        response.set_format(request.enginepackedformat());
        response.set_data(dstBuffer.data(), dstBuffer.size());
        LOG("Task finished encoding: %s", request.taskid().c_str());
        return response;
    }
String TextCodecBrew::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError)
{
    int code = ICharsetConv_Initialize(m_charsetConverter, m_encoding.name(), m_internalEncodingName, 0);
    ASSERT(code == AEE_SUCCESS);

    Vector<UChar> result;
    Vector<unsigned char> prefixedBytes(length);

    int srcSize;
    unsigned char* srcBegin;

    if (m_numBufferedBytes) {
        srcSize = length + m_numBufferedBytes;
        prefixedBytes.grow(srcSize);
        memcpy(prefixedBytes.data(), m_bufferedBytes, m_numBufferedBytes);
        memcpy(prefixedBytes.data() + m_numBufferedBytes, bytes, length);

        srcBegin = prefixedBytes.data();

        // all buffered bytes are consumed now
        m_numBufferedBytes = 0;
    } else {
        srcSize = length;
        srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bytes));
    }

    unsigned char* src = srcBegin;
    unsigned char* srcEnd = srcBegin + srcSize;

    Vector<UChar> dstBuffer(srcSize);

    while (src < srcEnd) {
        int numCharsConverted;
        unsigned char* dstBegin = reinterpret_cast<unsigned char*>(dstBuffer.data());
        unsigned char* dst = dstBegin;
        int dstSize = dstBuffer.size() * sizeof(UChar);

        code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
        ASSERT(code != AEE_ENOSUCH);

        if (code == AEE_EBUFFERTOOSMALL) {
            // Increase the buffer and try it again.
            dstBuffer.grow(dstBuffer.size() * 2);
            continue;
        }

        if (code == AEE_EBADITEM) {
            sawError = true;
            if (stopOnError) {
                result.append(L'?');
                break;
            }

            src++;
        }

        if (code == AEE_EINCOMPLETEITEM) {
            if (flush) {
                LOG_ERROR("Partial bytes at end of input while flush requested.");
                sawError = true;
                return String();
            }

            m_numBufferedBytes = srcEnd - src;
            memcpy(m_bufferedBytes, src, m_numBufferedBytes);
            break;
        }

        int numChars = (dst - dstBegin) / sizeof(UChar);
        if (numChars > 0)
            result.append(dstBuffer.data(), numChars);
    }

    return String::adopt(result);
}
void dng_limit_float_depth_task::Process (uint32 /* threadIndex */,
										  const dng_rect &tile,
										  dng_abort_sniffer * /* sniffer */)
	{
	
	dng_const_tile_buffer srcBuffer (fSrcImage, tile);
	dng_dirty_tile_buffer dstBuffer (fDstImage, tile);
	
	uint32 count0 = tile.H ();
	uint32 count1 = tile.W ();
	uint32 count2 = fDstImage.Planes ();
	
	int32 sStep0 = srcBuffer.fRowStep;
	int32 sStep1 = srcBuffer.fColStep;
	int32 sStep2 = srcBuffer.fPlaneStep;
	
	int32 dStep0 = dstBuffer.fRowStep;
	int32 dStep1 = dstBuffer.fColStep;
	int32 dStep2 = dstBuffer.fPlaneStep;

	const void *sPtr = srcBuffer.ConstPixel (tile.t,
											 tile.l,
											 0);
											 
		  void *dPtr = dstBuffer.DirtyPixel (tile.t,
											 tile.l,
											 0);

	OptimizeOrder (sPtr,
			       dPtr,
				   srcBuffer.fPixelSize,
				   dstBuffer.fPixelSize,
				   count0,
				   count1,
				   count2,
				   sStep0,
				   sStep1,
				   sStep2,
				   dStep0,
				   dStep1,
				   dStep2);
				   
	const real32 *sPtr0 = (const real32 *) sPtr;
		  real32 *dPtr0 = (      real32 *) dPtr;
		  
	real32 scale = fScale;
		  
	bool limit16 = (fBitDepth == 16);
	bool limit24 = (fBitDepth == 24);
				   
	for (uint32 index0 = 0; index0 < count0; index0++)
		{
		
		const real32 *sPtr1 = sPtr0;
			  real32 *dPtr1 = dPtr0;
			  
		for (uint32 index1 = 0; index1 < count1; index1++)
			{
			
			// If the scale is a NOP, and the data is packed solid, we can just do memory
			// copy.
			
			if (scale == 1.0f && sStep2 == 1 && dStep2 == 1)
				{
				
				if (dPtr1 != sPtr1)			// srcImage != dstImage
					{
				
					memcpy (dPtr1, sPtr1, count2 * (uint32) sizeof (real32));
					
					}
				
				}
				
			else
				{
			
				const real32 *sPtr2 = sPtr1;
					  real32 *dPtr2 = dPtr1;
					  
				for (uint32 index2 = 0; index2 < count2; index2++)
					{
					
					real32 x = sPtr2 [0];
					
					x *= scale;
					
					dPtr2 [0] = x;
					
					sPtr2 += sStep2;
					dPtr2 += dStep2;
					
					}
					
				}
				
			// The data is now in the destination buffer.
				
			if (limit16)
				{
			
				uint32 *dPtr2 = (uint32 *) dPtr1;
					  
				for (uint32 index2 = 0; index2 < count2; index2++)
					{
					
					uint32 x = dPtr2 [0];
					
					uint16 y = DNG_FloatToHalf (x);
					
					x = DNG_HalfToFloat (y);
											
					dPtr2 [0] = x;
					
					dPtr2 += dStep2;
					
					}
					
				}
				
			else if (limit24)
				{
			
				uint32 *dPtr2 = (uint32 *) dPtr1;
					  
				for (uint32 index2 = 0; index2 < count2; index2++)
					{
					
					uint32 x = dPtr2 [0];
											
					uint8 temp [3];
					
					DNG_FloatToFP24 (x, temp);
					
					x = DNG_FP24ToFloat (temp);
					
					dPtr2 [0] = x;
					
					dPtr2 += dStep2;
					
					}
					
				}
			  
			sPtr1 += sStep1;
			dPtr1 += dStep1;
			
			}
				   
		sPtr0 += sStep0;
		dPtr0 += dStep0;
		
		}
				   	
	}