Beispiel #1
0
// Virtual
// Encode the in memory RGB image into PNG format.
BOOL LLImagePNG::encode(const LLImageRaw* raw_image, F32 encode_time)
{
	llassert_always(raw_image);

    resetLastError();

	// Image logical size
	setSize(raw_image->getWidth(), raw_image->getHeight(), raw_image->getComponents());

	// Temporary buffer to hold the encoded image. Note: the final image
	// size should be much smaller due to compression.
	U32 bufferSize = getWidth() * getHeight() * getComponents() + 1024;
    U8* tmpWriteBuffer = new U8[ bufferSize ];

	// Delegate actual encoding work to wrapper
	LLPngWrapper pngWrapper;
	if (! pngWrapper.writePng(raw_image, tmpWriteBuffer))
	{
		setLastError(pngWrapper.getErrorMessage());
		delete[] tmpWriteBuffer;
		return FALSE;
	}

	// Resize internal buffer and copy from temp
	U32 encodedSize = pngWrapper.getFinalSize();
	allocateData(encodedSize);
	memcpy(getData(), tmpWriteBuffer, encodedSize);

	delete[] tmpWriteBuffer;

	return TRUE;
}
Beispiel #2
0
CAMdataHandler::CAMdataHandler(long size, int dType)
{
        allocateData(size,dType);
        setTypeFlag(dType);
        temporaryFlag   = 0;
        referenceCount  = 0;
}
Beispiel #3
0
void CAMdataHandler::initialize(long size, int dType)
{
        destroyData();
        allocateData(size,dType);
        setTypeFlag(dType);
        temporaryFlag   = 0;
}
AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
                                      const int numSamples) noexcept
  : numChannels (numChannels_),
    size (numSamples)
{
    jassert (numSamples >= 0);
    jassert (numChannels_ > 0);

    allocateData();
}
AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) noexcept
  : numChannels (other.numChannels),
    size (other.size)
{
    allocateData();
    const size_t numBytes = sizeof (float) * (size_t) size;

    for (int i = 0; i < numChannels; ++i)
        memcpy (channels[i], other.channels[i], numBytes);
}
Beispiel #6
0
void MeshBase::loadFromObj( const std::string& filename )
{
  preProcess();
  loadInfoFromObj( filename );
  allocateData();
  startWritingData();
  loadDataFromObj( filename );
  computeAabb();
  postProcess();
  finishWritingData();
}
Beispiel #7
0
void DImg::putImageData(uint width, uint height, bool sixteenBit, bool alpha, uchar* const data, bool copyData)
{
    // set image data, metadata is untouched

    bool null = (width == 0) || (height == 0);
    // allocateData, or code below will set null to false
    setImageData(true, width, height, sixteenBit, alpha);

    // replace data
    delete [] m_priv->data;

    if (null)
    {
        // image is null - no data
        m_priv->data = nullptr;
    }
    else if (copyData)
    {
        size_t size = allocateData();

        if (data)
        {
            memcpy(m_priv->data, data, size);
        }
    }
    else
    {
        if (data)
        {
            m_priv->data = data;
            m_priv->null = false;
        }
        else
        {
            allocateData();
        }
    }
}
Beispiel #8
0
// Reads a .tga file and creates an LLImageTGA with its data.
bool LLImageTGA::loadFile( const LLString& path )
{
	S32 len = path.size();
	if( len < 5 )
	{
		return false;
	}
	
	LLString extension = path.substr( len - 4, 4 );
	LLString::toLower(extension);
	if( ".tga" != extension )
	{
		return false;
	}
	
	FILE* file = LLFile::fopen(path.c_str(), "rb");	/* Flawfinder: ignore */
	if( !file )
	{
		llwarns << "Couldn't open file " << path << llendl;
		return false;
	}

	S32 file_size = 0;
	if (!fseek(file, 0, SEEK_END))
	{
		file_size = ftell(file);
		fseek(file, 0, SEEK_SET);
	}

	U8* buffer = allocateData(file_size);
	S32 bytes_read = fread(buffer, 1, file_size, file);
	if( bytes_read != file_size )
	{
		deleteData();
		llwarns << "Couldn't read file " << path << llendl;
		return false;
	}

	fclose( file );

	if( !updateData() )
	{
		llwarns << "Couldn't decode file " << path << llendl;
		deleteData();
		return false;
	}
	return true;
}
Beispiel #9
0
// Reads a .tga file and creates an LLImageTGA with its data.
bool LLImageTGA::loadFile( const std::string& path )
{
	S32 len = path.size();
	if( len < 5 )
	{
		return false;
	}
	
	std::string extension = gDirUtilp->getExtension(path);
	if( "tga" != extension )
	{
		return false;
	}
	
	LLFILE* file = LLFile::fopen(path, "rb");	/* Flawfinder: ignore */
	if( !file )
	{
		LL_WARNS() << "Couldn't open file " << path << LL_ENDL;
		return false;
	}

	S32 file_size = 0;
	if (!fseek(file, 0, SEEK_END))
	{
		file_size = ftell(file);
		fseek(file, 0, SEEK_SET);
	}

	U8* buffer = allocateData(file_size);
	S32 bytes_read = fread(buffer, 1, file_size, file);
	if( bytes_read != file_size )
	{
		deleteData();
		LL_WARNS() << "Couldn't read file " << path << LL_ENDL;
		fclose(file);
		return false;
	}

	fclose( file );

	if( !updateData() )
	{
		LL_WARNS() << "Couldn't decode file " << path << LL_ENDL;
		deleteData();
		return false;
	}
	return true;
}
Beispiel #10
0
 bool updateTexture() override {
     QMutexLocker lock(&m_source_access);
     if (m_source && m_source->m_new_data) {
         // copy/convert data to float texture buffer
         float* data = allocateData(m_source->m_dims, m_source->m_num_dims, 1);
         int num_elements = 1;
         for (int i = 0; i < m_source->m_num_dims; ++i) {
             num_elements *= m_source->m_dims[i];
         }
         for (int i = 0; i < num_elements; ++i) {
             data[i] = m_source->m_data[i];
         }
         commitData();
         return true;
     }
     return false;
 }
Beispiel #11
0
// make the copy buffer if needed. 
// then copy the current data to the copy buffer and return the start of the copy.
//
MLSample* MLSignal::getCopy()
{
	if (!mCopy)
	{
		mCopy = allocateData(mSize);
		if (mCopy)
		{
			mCopyAligned = initializeData(mCopy, mSize);
		}
		else
		{
			std::cerr << "MLSignal::getCopy: out of memory!\n";
		}
	}
	std::copy(mDataAligned, mDataAligned + mSize, mCopyAligned);
	return mCopyAligned;
}
Beispiel #12
0
MLSignal& MLSignal::operator= (const MLSignal& other)
{
	if (this != &other) // protect against self-assignment
	{
		if (mSize != other.mSize)
		{
			// 1: allocate new memory and copy the elements
			mSize = other.mSize;
			MLSample * newData = allocateData(mSize);
			MLSample * newDataAligned = initializeData(newData, mSize);
			std::copy(other.mDataAligned, other.mDataAligned + mSize, newDataAligned);

			// 2: deallocate old memory
			delete[] mData;
			
			// 3: assign the new memory to the object
			mData = newData;
			mDataAligned = newDataAligned;
			mConstantMask = other.mConstantMask;
			mWidth = other.mWidth;
			mHeight = other.mHeight;
			mDepth = other.mDepth;
			mHeightBits = other.mHeightBits;
			mWidthBits = other.mWidthBits;
			mDepthBits = other.mDepthBits;
			mRate = other.mRate;
		}
		else 
		{
			// keep existing data buffer.
			// copy other elements
			std::copy(other.mDataAligned, other.mDataAligned + this->mSize, mDataAligned);
			
			// copy other info
			mConstantMask = other.mConstantMask;
			mWidth = other.mWidth;
			mHeight = other.mHeight;
			mDepth = other.mDepth;
			mHeightBits = other.mHeightBits;
			mWidthBits = other.mWidthBits;
			mDepthBits = other.mDepthBits;
			mRate = other.mRate;
		}
	}
	return *this;
}
Beispiel #13
0
MLSignal::MLSignal(const MLSignal& other) :
	mData(0),
	mDataAligned(0),
	mCopy(0),
	mCopyAligned(0)
{
	mSize = other.mSize;
	mData = allocateData(mSize);
	mDataAligned = initializeData(mData, mSize);
	mConstantMask = other.mConstantMask;
	mWidth = other.mWidth;
	mHeight = other.mHeight;
	mDepth = other.mDepth;
	mHeightBits = other.mHeightBits;
	mWidthBits = other.mWidthBits;
	mDepthBits = other.mDepthBits;
	mRate = other.mRate;
	std::copy(other.mDataAligned, other.mDataAligned + mSize, mDataAligned);
}
Beispiel #14
0
CAMdataHandler::CAMdataHandler( const CAMdataHandler& A)
{
    if(A.temporaryFlag == 1)
    {
        dataType        = A.dataType;
        dataSize        = A.dataSize;
        dataPointer     = A.dataPointer;
        temporaryFlag   = 0;
        referenceCount  = 0;

    }
    else
    {
        allocateData(A.dataSize,A.dataType);
        setTypeFlag(A.dataType);
        copyData(A.dataSize,A.dataPointer);
        temporaryFlag   = 0;
        referenceCount  = 0;
    }
}
Beispiel #15
0
void  CAMdataHandler::initialize(const CAMdataHandler& A)
{


    if(A.temporaryFlag == 1)
    {
        dataType        = A.dataType;
        dataSize        = A.dataSize;
        dataPointer     = A.dataPointer;
        temporaryFlag   = 0;
    }
    else
    {
        destroyData();
        allocateData(A.dataSize,A.dataType);
        setTypeFlag(A.dataType);
        copyData(A.dataSize,A.dataPointer);
        temporaryFlag   = 0;
    }
}
Beispiel #16
0
void DImg::detach()
{
    // are we being shared?
    if (!m_priv->hasMoreReferences())
    {
        return;
    }

    DSharedDataPointer<Private> old = m_priv;

    m_priv = new Private;
    copyImageData(old);
    copyMetaData(old);

    if (old->data)
    {
        size_t size = allocateData();
        memcpy(m_priv->data, old->data, size);
    }
}
Beispiel #17
0
//
//********************************************************************************
//                    ASSIGNMENT
//********************************************************************************
//
CAMdataHandler&  CAMdataHandler::operator =( const CAMdataHandler& A)
{
    if(A.temporaryFlag == 1)
    {
        dataType        = A.dataType;
        dataSize        = A.dataSize;
        dataPointer     = A.dataPointer;
        temporaryFlag   = 0;
        referenceCount  = 0;
    }
    else
    {
        destroyData();
        allocateData(A.dataSize,A.dataType);
        setTypeFlag(A.dataType);
        copyData(A.dataSize,A.dataPointer);
        temporaryFlag   = 0;
        referenceCount  = 0;
    }
    return *this;
}
Beispiel #18
0
MLSample* MLSignal::setDims (int width, int height, int depth)
{
	mDataAligned = 0;	
	// delete old
	if (mData)
	{
		delete[] mData;
	}

	mWidth = width;
	mHeight = height;
	mDepth = depth;
	mWidthBits = bitsToContain(width);
	mHeightBits = bitsToContain(height);
	mDepthBits = bitsToContain(depth);
	mSize = 1 << mWidthBits << mHeightBits << mDepthBits;
	mData = allocateData(mSize);	
	mDataAligned = initializeData(mData, mSize);	
	mConstantMask = mSize - 1;
	return mDataAligned;
}
Beispiel #19
0
bool SceneCullingState::addCullingVolumeToZone( U32 zoneId, const SceneCullingVolume& volume )
{
   PROFILE_SCOPE( SceneCullingState_addCullingVolumeToZone );

   AssertFatal( zoneId < mZoneStates.size(), "SceneCullingState::addCullingVolumeToZone - Zone ID out of range" );
   SceneZoneCullingState& zoneState = mZoneStates[ zoneId ];

   // [rene, 07-Apr-10] I previously used to attempt to merge things here and detect whether
   //    the visibility state of the zone has changed at all.  Since we allow polyhedra to be
   //    degenerate here and since polyhedra cannot be merged easily like frustums, I have opted
   //    to remove this for now.  I'm also convinced that with the current traversal system it
   //    adds little benefit.

   // Link the volume to the zone state.

   typedef SceneZoneCullingState::CullingVolumeLink LinkType;

   LinkType* link = reinterpret_cast< LinkType* >( allocateData( sizeof( LinkType ) ) );

   link->mVolume = volume;
   link->mNext = zoneState.mCullingVolumes;
   zoneState.mCullingVolumes = link;

   if( volume.isOccluder() )
      zoneState.mHaveOccluders = true;
   else
      zoneState.mHaveIncluders = true;

   // Mark sorting state as dirty.

   zoneState.mHaveSortedVolumes = false;

   // Set the visibility flag for the zone.
   
   if( volume.isIncluder() )
      mZoneVisibilityFlags.set( zoneId );

   return true;
}
AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) noexcept
  : numChannels (other.numChannels),
    size (other.size),
    allocatedBytes (other.allocatedBytes)
{
    if (allocatedBytes == 0)
    {
        allocateChannels (other.channels, 0);
    }
    else
    {
        allocateData();

        if (other.isClear)
        {
            clear();
        }
        else
        {
            for (int i = 0; i < numChannels; ++i)
                FloatVectorOperations::copy (channels[i], other.channels[i], size);
        }
    }
}
Beispiel #21
0
U8* LLImageBase::allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 size)
{
	setSize(width, height, ncomponents);
	return allocateData(size); // virtual
}
Beispiel #22
0
BOOL LLImageBMP::encode(const LLImageRaw* raw_image, F32 encode_time)
{
	llassert_always(raw_image);
	
	resetLastError();

	S32 src_components = raw_image->getComponents();
	S32 dst_components =  ( src_components < 3 ) ? 1 : 3;

	if( (2 == src_components) || (4 == src_components) )
	{
		llinfos << "Dropping alpha information during BMP encoding" << llendl;
	}

	setSize(raw_image->getWidth(), raw_image->getHeight(), dst_components);
	
	U8 magic[14];
	LLBMPHeader header;
	int header_bytes = 14+sizeof(header);
	llassert(header_bytes == 54);
	if (getComponents() == 1)
	{
		header_bytes += 1024; // Need colour LUT.
	}
	int line_bytes = getComponents() * getWidth();
	int alignment_bytes = (3 * line_bytes) % 4;
	line_bytes += alignment_bytes;
	int file_bytes = line_bytes*getHeight() + header_bytes;

	// Allocate the new buffer for the data.
	if(!allocateData(file_bytes)) //memory allocation failed
	{
		return FALSE ;
	}

	magic[0] = 'B'; magic[1] = 'M';
	magic[2] = (U8) file_bytes;
	magic[3] = (U8)(file_bytes>>8);
	magic[4] = (U8)(file_bytes>>16);
	magic[5] = (U8)(file_bytes>>24);
	magic[6] = magic[7] = magic[8] = magic[9] = 0;
	magic[10] = (U8) header_bytes;
	magic[11] = (U8)(header_bytes>>8);
	magic[12] = (U8)(header_bytes>>16);
	magic[13] = (U8)(header_bytes>>24);
	header.mSize = 40;
	header.mWidth = getWidth();
	header.mHeight = getHeight();
	header.mPlanes = 1;
	header.mBitsPerPixel = (getComponents()==1)?8:24;
	header.mCompression = 0;
	header.mAlignmentPadding = 0;
	header.mImageSize = 0;
#if LL_DARWIN
	header.mHorzPelsPerMeter = header.mVertPelsPerMeter = 2834;	// 72dpi
#else
	header.mHorzPelsPerMeter = header.mVertPelsPerMeter = 0;
#endif
	header.mNumColors = header.mNumColorsImportant = 0;

	// convert BMP header to little endian (no-op on little endian builds)
	llendianswizzleone(header.mSize);
	llendianswizzleone(header.mWidth);
	llendianswizzleone(header.mHeight);
	llendianswizzleone(header.mPlanes);
	llendianswizzleone(header.mBitsPerPixel);
	llendianswizzleone(header.mCompression);
	llendianswizzleone(header.mAlignmentPadding);
	llendianswizzleone(header.mImageSize);
	llendianswizzleone(header.mHorzPelsPerMeter);
	llendianswizzleone(header.mVertPelsPerMeter);
	llendianswizzleone(header.mNumColors);
	llendianswizzleone(header.mNumColorsImportant);

	U8* mdata = getData();
	
	// Output magic, then header, then the palette table, then the data.
	U32 cur_pos = 0;
	memcpy(mdata, magic, 14);
	cur_pos += 14;
	memcpy(mdata+cur_pos, &header, 40);	/* Flawfinder: ignore */
	cur_pos += 40;
	if (getComponents() == 1)
	{
		S32 n;
		for (n=0; n < 256; n++)
		{
			mdata[cur_pos++] = (U8)n;
			mdata[cur_pos++] = (U8)n;
			mdata[cur_pos++] = (U8)n;
			mdata[cur_pos++] = 0;
		}
	}
	
	// Need to iterate through, because we need to flip the RGB.
	const U8* src = raw_image->getData();
	U8* dst = mdata + cur_pos;

	for( S32 row = 0; row < getHeight(); row++ )
	{
		for( S32 col = 0; col < getWidth(); col++ )
		{
			switch( src_components )
			{
			case 1:
				*dst++ = *src++;
				break;
			case 2:
				{
					U32 lum = src[0];
					U32 alpha = src[1];
					*dst++ = (U8)(lum * alpha / 255);
					src += 2;
					break;
				}
			case 3:
			case 4:
				dst[0] = src[2];
				dst[1] = src[1];
				dst[2] = src[0];
				src += src_components;
				dst += 3;
				break;
			}

		}
		for( S32 i = 0; i < alignment_bytes; i++ )
		{
			*dst++ = 0;
		}
	}

	return TRUE;
}
BOOL LLImageTGA::encode(const LLImageRaw* raw_image, F32 encode_time)
{
	llassert_always(raw_image);
	
	deleteData();

	setSize(raw_image->getWidth(), raw_image->getHeight(), raw_image->getComponents());

	// Data from header
	mIDLength = 0;		// Length of identifier string
	mColorMapType = 0;	// 0 = No Map

	// Supported: 2 = Uncompressed true color, 3 = uncompressed monochrome without colormap
	switch( getComponents() )
	{
	case 1:
		mImageType = 3;		
		break;
	case 2:	 // Interpret as intensity plus alpha
	case 3:
	case 4:
		mImageType = 2;		
		break;
	default:
		return FALSE;
	}

	// Color map stuff (unsupported)
	mColorMapIndexLo = 0;		// First color map entry (low order byte)
	mColorMapIndexHi = 0;		// First color map entry (high order byte)
	mColorMapLengthLo = 0;		// Color map length (low order byte)
	mColorMapLengthHi = 0;		// Color map length (high order byte)
	mColorMapDepth = 0;	// Size of color map entry (15, 16, 24, or 32 bits)

	// Image offset relative to origin.
	mXOffsetLo = 0;		// X offset from origin (low order byte)
	mXOffsetHi = 0;		// X offset from origin (hi order byte)
	mYOffsetLo = 0;		// Y offset from origin (low order byte)
	mYOffsetHi = 0;		// Y offset from origin (hi order byte)

	// Height and width
	mWidthLo = U8(getWidth() & 0xFF);			// Width (low order byte)
	mWidthHi = U8((getWidth() >> 8) & 0xFF);	// Width (hi order byte)
	mHeightLo = U8(getHeight() & 0xFF);			// Height (low order byte)
	mHeightHi = U8((getHeight() >> 8) & 0xFF);	// Height (hi order byte)

	S32 bytes_per_pixel;
	switch( getComponents() )
	{
	case 1:
		bytes_per_pixel = 1;		
		break;
	case 3:
		bytes_per_pixel = 3;		
		break;
	case 2:	 // Interpret as intensity plus alpha.  Store as RGBA.
	case 4:
		bytes_per_pixel = 4;		
		break;
	default:
		return FALSE;
	}
	mPixelSize = U8(bytes_per_pixel * 8);		// 8, 16, 24, 32 bits per pixel

	mAttributeBits = (4 == bytes_per_pixel) ? 8 : 0;	// 4 bits: number of attribute bits (alpha) per pixel
	mOriginRightBit = 0;	// 1 bit: origin, 0 = left, 1 = right
	mOriginTopBit = 0;	// 1 bit: origin, 0 = bottom, 1 = top
	mInterleave = 0;	// 2 bits: interleaved flag, 0 = none, 1 = interleaved 2, 2 = interleaved 4


	const S32 TGA_HEADER_SIZE = 18;
	const S32 COLOR_MAP_SIZE = 0;
	mDataOffset = TGA_HEADER_SIZE + mIDLength + COLOR_MAP_SIZE; // Offset from start of data to the actual header.

	S32 pixels = getWidth() * getHeight();
	S32 datasize = mDataOffset + bytes_per_pixel * pixels;
	U8* dst = allocateData(datasize);

	// Write header
	*(dst++) = mIDLength;		
	*(dst++) = mColorMapType;	
	*(dst++) = mImageType;		
	*(dst++) = mColorMapIndexLo;		
	*(dst++) = mColorMapIndexHi;		
	*(dst++) = mColorMapLengthLo;		
	*(dst++) = mColorMapLengthHi;		
	*(dst++) = mColorMapDepth;	
	*(dst++) = mXOffsetLo;		
	*(dst++) = mXOffsetHi;		
	*(dst++) = mYOffsetLo;		
	*(dst++) = mYOffsetHi;		
	*(dst++) = mWidthLo;		
	*(dst++) = mWidthHi;		
	*(dst++) = mHeightLo;		
	*(dst++) = mHeightHi;		
	*(dst++) = mPixelSize;		
	*(dst++) =
		((mInterleave & 3) << 5) |
		((mOriginTopBit & 1) << 4) |
		((mOriginRightBit & 1) << 3) |
		((mAttributeBits & 0xF) << 0);	

	// Write pixels
	const U8* src = raw_image->getData();
	llassert( dst == getData() + mDataOffset );
	S32 i = 0;
	S32 j = 0;
	switch( getComponents() )
	{
	case 1:
		memcpy( dst, src, bytes_per_pixel * pixels );	/* Flawfinder: ignore */
		break;

	case 2:
		while( pixels-- )
		{
			dst[i + 0] = src[j + 0];	// intensity
			dst[i + 1] = src[j + 0];	// intensity
			dst[i + 2] = src[j + 0];	// intensity
			dst[i + 3] = src[j + 1];	// alpha
			i += 4;
			j += 2;
		}
		break;

	case 3:
		while( pixels-- )
		{
			dst[i + 0] = src[i + 2];	// blue
			dst[i + 1] = src[i + 1];	// green
			dst[i + 2] = src[i + 0];	// red
			i += 3;
		}
		break;

	case 4:
		while( pixels-- )
		{
			dst[i + 0] = src[i + 2];	// blue
			dst[i + 1] = src[i + 1];	// green
			dst[i + 2] = src[i + 0];	// red
			dst[i + 3] = src[i + 3];	// alpha
			i += 4;
		}
		break;
	}
	
	return TRUE;
}
Beispiel #24
0
VectorMem::VectorMem(int size)
    : ParticleMem(), deadIndex(0)
{
    allocateData(size);
}