Example #1
0
    //---------------------------------------------------------------------    
	Codec::DecodeResult PVRTCCodec::decodeV2(DataStreamPtr& stream) const
	{
		PVRTCTexHeaderV2 header;
        uint32 flags = 0, formatFlags = 0;
        size_t numFaces = 1; // Assume one face until we know otherwise

        ImageData *imgData = OGRE_NEW ImageData();
		MemoryDataStreamPtr output;

        // Read the PVRTC header
        stream->read(&header, sizeof(PVRTCTexHeaderV2));

        // Get format flags
        flags = header.flags;
        flipEndian(reinterpret_cast<void*>(flags), sizeof(uint32));
        formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK;

        uint32 bitmaskAlpha = header.bitmaskAlpha;
        flipEndian(reinterpret_cast<void*>(bitmaskAlpha), sizeof(uint32));

        if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2)
        {
            if (formatFlags == kPVRTextureFlagTypePVRTC_4)
            {
                imgData->format = bitmaskAlpha ? PF_PVRTC_RGBA4 : PF_PVRTC_RGB4;
            }
            else if (formatFlags == kPVRTextureFlagTypePVRTC_2)
            {
                imgData->format = bitmaskAlpha ? PF_PVRTC_RGBA2 : PF_PVRTC_RGB2;
            }

            imgData->depth = 1;
            imgData->width = header.width;
            imgData->height = header.height;
            imgData->num_mipmaps = static_cast<ushort>(header.numMipmaps);

            // PVRTC is a compressed format
            imgData->flags |= IF_COMPRESSED;
        }

        // Calculate total size from number of mipmaps, faces and size
		imgData->size = Image::calculateSize(imgData->num_mipmaps, numFaces, 
                                             imgData->width, imgData->height, imgData->depth, imgData->format);

		// Bind output buffer
		output.bind(OGRE_NEW MemoryDataStream(imgData->size));

		// Now deal with the data
		void *destPtr = output->getPtr();
        stream->read(destPtr, imgData->size);
        destPtr = static_cast<void*>(static_cast<uchar*>(destPtr));

		DecodeResult ret;
		ret.first = output;
		ret.second = CodecDataPtr(imgData);

		return ret;
	}
 void flipEndian(void * pData, size_t size, size_t count)
 {
     for(size_t index = 0; index < count; index++)
     {
         flipEndian((void *)((int)pData + (index * size)), size);
     }
 }
Example #3
0
    void Serializer::flipFromLittleEndian(void* pData, size_t size, size_t count)
    {
		if(mFlipEndian)
		{
	        flipEndian(pData, size, count);
		}
    }
Example #4
0
 void Serializer::flipEndian(void * pData, size_t size, size_t count)
 {
     for(unsigned int index = 0; index < count; index++)
     {
         flipEndian((void *)((long)pData + (index * size)), size);
     }
 }
Example #5
0
INT32 MicroSequencer::readBits(INT32 numBits, BOOL reverseOrder) {
    while (bitsLeft < numBits) {
        if (pc < 0x1800) {
            currentBits |= (ivoiceROM.peek(pc) << bitsLeft);
            bitsLeft += 8;
            pc = (pc+1) & 0xFFFF;
        }
        else if (pc == 0x1800 && fifoSize > 0) {
            currentBits |= (fifoBytes[fifoHead] << bitsLeft);
            fifoHead = (fifoHead+1) & 0x3F;
            fifoSize--;
            bitsLeft += 10;
        }
        else {
            currentBits |= (0x03FF << bitsLeft);
            bitsLeft += 10;
            pc = (pc+1) & 0xFFFF;
        }

    }

    INT32 output = currentBits & bitMasks[numBits-1];
    if (reverseOrder)
        output = flipEndian(output, numBits);
    currentBits = currentBits >> numBits;
    bitsLeft -= numBits;
    return output;
}
Example #6
0
	//---------------------------------------------------------------------
	uint32 StreamSerialiser::calculateChecksum(Chunk* c)
	{
		// Always calculate checksums in little endian to make sure they match 
		// Otherwise checksums for the same data on different endians will not match
		uint32 id = c->id;
		uint16 version = c->version;
		uint32 length = c->length;
#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
		flipEndian(&id, sizeof(uint32));
		flipEndian(&version, sizeof(uint16));
		flipEndian(&length, sizeof(uint32));
#endif
		uint32 hashVal = FastHash((const char*)&id, sizeof(uint32));
		hashVal = FastHash((const char*)&version, sizeof(uint16), hashVal);
		hashVal = FastHash((const char*)&length, sizeof(uint32), hashVal);

		return hashVal;
	}
Example #7
0
    //---------------------------------------------------------------------    
    void ETCCodec::flipEndian(void * pData, size_t size, size_t count) const
    {
#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
		for(unsigned int index = 0; index < count; index++)
        {
            flipEndian((void *)((long)pData + (index * size)), size);
        }
#endif
    }
Example #8
0
	//---------------------------------------------------------------------
	void StreamSerialiser::readData(void* buf, size_t size, size_t count)
	{
		checkStream(true, true, false);

		size_t totSize = size * count;
		mStream->read(buf, totSize);

		if (mFlipEndian)
			flipEndian(buf, size, count);

	}
Example #9
0
	//---------------------------------------------------------------------
	String PVRTCCodec::magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const
	{
		if (maxbytes >= sizeof(uint32))
		{
			uint32 fileType;
			memcpy(&fileType, magicNumberPtr, sizeof(uint32));
			flipEndian(&fileType, sizeof(uint32), 1);

			if (PVR3_MAGIC == fileType || PVR2_MAGIC == fileType)
			{
				return String("pvr");
			}
		}

		return StringUtil::BLANK;
	}
Example #10
0
    //---------------------------------------------------------------------    
	String ETCCodec::magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const
	{
		if (maxbytes >= sizeof(uint32))
		{
			uint32 fileType;
			memcpy(&fileType, magicNumberPtr, sizeof(uint32));
			flipEndian(&fileType, sizeof(uint32), 1);

			if (PKM_MAGIC == fileType)
				return String("pkm");
		
			if (KTX_MAGIC == fileType)
                return String("ktx");
		}

		return StringUtil::BLANK;
	}
Example #11
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeData(const void* buf, size_t size, size_t count)
	{
		checkStream(false, false, true);

		size_t totSize = size * count;
		if (mFlipEndian)
		{
			void* pToWrite = OGRE_MALLOC(totSize, MEMCATEGORY_GENERAL);
			memcpy(pToWrite, buf, totSize);

			flipEndian(pToWrite, size, count);
			mStream->write(pToWrite, totSize);

			OGRE_FREE(pToWrite, MEMCATEGORY_GENERAL);
		}
		else
		{
			mStream->write(buf, totSize);
		}

	}
    void flipFromLittleEndian(void* pData, size_t size, size_t count)
    {
#	if OGRE_ENDIAN == OGRE_ENDIAN_BIG
        flipEndian(pData, size, count);
#	endif
    }
Example #13
0
void MicroSequencer::JSR(INT32 immed4) {
    INT32 newpc = (page << 12) | (flipEndian(immed4, 4) << 8) | readBits(8, TRUE);
    stack = pc;
    pc = newpc;
    bitsLeft = 0;
}
Example #14
0
void MicroSequencer::SETMODE(INT32 immed4) {
    immed4 = flipEndian(immed4, 4);
    mode = immed4 & 0x3;
    repeatPrefix = (immed4 & 0xC) >> 2;
}
Example #15
0
void MicroSequencer::JMP(INT32 immed4) {
    pc = (page << 12) | (flipEndian(immed4, 4) << 8) | readBits(8, TRUE);
    bitsLeft = 0;
}
Example #16
0
void MicroSequencer::SETPAGE(INT32 immed4) {
    this->page = flipEndian(immed4, 4);
}
Example #17
0
	//---------------------------------------------------------------------
	void StreamSerialiser::flipEndian(void * pData, size_t size)
	{
		flipEndian(pData, size, 1);
	}
Example #18
0
  int mpiUser::doImgCalcs(void)
   {

      //
      // we hav these variables on each new image at our disposal
      //

      //public_double_image[0] integrating dark, [1] is the integrating std iamge.
       //num_dark_integrate is how many darks we must integrate total.
         //num_images_to_calc is total images to calc across all ranks
     // img_num_pixels is number if pixels in the iamge.
     //img_size_x, img_size_y is size of iamge in pixels
     // public_short_image are new image, [0] is new iamge

   // my_message is the gui settings, and all mpi iamges. specs from image from detector is there as well.
    //        detector image sopecs also appear at end of piblic_short_image[0], after pidxels. getImageSpecs gets this into
   //  image_specs    - the specs of the image from the detector. also copied into my_message in super class.
    //is_calc_image - if true that means we have an image to calc in this rank.

        printTrace("mpiUser::doImgCalcs================================================");


                //get img specs for public  iamge 0

        if (is_calc_image)
        {
            //get specs for pub img 0
            getImageSpecs(0);


            if (is_print_trace)
            {
                printf("Rank %d got Img num %d\n",rank,image_specs->inpt_img_cnt);
            }

            if (my_message.mpi_save_mem_file && is_calc_image)
            {
                writeImageRaw(public_short_image[0],pub_sh_img_size_bytes*sizeof(short) ,"PubImg",0);
            }


            image_specs->is_descrambled=false;

            //we normally uyse img 0,. if desc is on, we outptu to img 1, so we use that one...



            if (my_message.mpi_is_descramble)
            {
                //take pub image putput to private image
                //partialDescramble(imgx, imgy,0, count,rank,numprocs);

                //we have a bunch of public_image[], all mapped to one contiguous mem
                //starting at public_iamge[0][0]. hwere is the map
                // public_image[0] - raw iamge for all ranks
                // publc_image[1] -descramled image for ll ranks



                image_specs->is_descrambled=true;

                printTrace("doImgCalcs,mpi_b_image_desc2 ");

                if (is_made_desc_table)
                    this->tableDescramble2(1,0);
                else
                {
                    //make desc table and inverse desc table
                    //also desc the image to pub image 1. we will end up desc. again after
                    //making table, so the desc operation here is ONLTY for makin gtable.
                    // desc image is not used.
                    this->descramble_image_jtw1(public_short_image[1],
                                            public_short_image[0],
                                            img_size_x,
                                            img_size_y,
                                            img_num_pixels);

                    //alter desc table to remove overscan lines
                    //!!if (message&mpi_b_remove_overscan)
                    this->removeOverscan(public_short_image[1],
                                             public_short_image[1],
                                             img_size_x,
                                             img_size_y,
                                             img_num_pixels);

                    //we will calc new desc table as we desc image
                    is_made_desc_table=true;

                    //now clear the image and do a table descranble. this is needed if overscan
                    //removal is on, so extra puixels at end of images will be zero.
                    //extra pixels happen becasue we remove overscan pixels, and shift whole image\
                    // to top left corner. so we end up w/ extra pixels on right and bottom.
                    clearImages(1);

                    //now do the actual desc, amd rem overscan
                    this->tableDescramble2(1,0);


                }
                //do this calc
                memcpy(public_short_image[0],public_short_image[1],img_num_pixels*sizeof(short));

            }


            if (my_message.mpi_is_flip_endian)
            {
                flipEndian(0);
            }

            my_message.gui.is_acq_dark_RBV=is_acc_darks;

            if (is_acc_darks)
            {
                //accum pub img 0 into dark accum... of needed.
                // 1st 0 is input imate or puclc_sh_image 0.
                //2nd arg0 is puiblic double image 0.

                accumDarkStd(0,0);


                //
                // now we must make a square image, and accum into the 2nd pub image.
                //

                // make a sqire image
                double dval;
                for (int p=0; p<img_num_pixels;p++)
                {
                    dval =(double) public_short_image[0][p];
                    dval = dval*dval;
                    square_image[p] = dval;
                }

                //accum square intop public_double_iamge[1]
                accumDarkStd(square_image,1);

            }

            if (my_message.mpi_sub_dark && is_calc_image)
            {


                //0 is offset from top of image, 1 is publc_image[1]
                printTrace("doImgCalcs, mpi_b_sub_dark");
                subDark(0);


            }

            image_specs->dark_accum_tot=dark_integrate_counter;
            image_specs->rank_dark_accum_cnt=rank_dark_accum_cnt;

            if (my_message.mpi_is_makeraw_imm )
            {
                printTrace("mpiUser- making raw IMM\n");

                my_imm.rawToIMM(
                        (unsigned char*)public_short_image[0],
                        img_num_pixels*sizeof(short),
                        2,
                        img_size_x,
                        img_size_y,
                        0,
                        0,
                        image_specs->inpt_img_cnt,
                        temp_image,
                        &my_message.imm_bytes);

                    //imm_bytes is img siize plus imm header size
                image_specs->is_raw_imm=true;
                image_specs->is_raw=false;
                image_specs->imm_num_pixels=img_num_pixels;
                image_specs->is_compressed=false;
                image_specs->num_pixels=my_message.imm_bytes/2;

                immHeader *immh = (immHeader*)temp_image;
                immh->systick=image_specs->system_clock;
                immh->elapsed=(double)(immh->systick) / 1000.0;
                immh->corecotick=image_specs->inpt_img_cnt;
                memcpy(public_short_image[0],temp_image,my_message.imm_bytes);
            }

            if (my_message.mpi_is_makecomp_imm )
            {
                printTrace("mpiUser- making comp IMM\n");
                my_imm.rawToCompIMM(
                        (unsigned char*)public_short_image[0],
                        img_num_pixels*sizeof(short),
                        2,
                        img_size_x,
                        img_size_y,
                        0,
                        image_specs->img_len_shorts * 2,//max size of space for data
                        (unsigned char*)temp_image,
                        &my_message.imm_bytes);


                image_specs->is_raw_imm=false;
                image_specs->is_raw=false;
                immHeader *imh = (immHeader*)((unsigned char*)temp_image);
                image_specs->imm_num_pixels=imh->dlen;
                image_specs->is_compressed=true;
                image_specs->num_pixels=my_message.imm_bytes/2;

                immHeader *immh = (immHeader*)temp_image;
                immh->systick=image_specs->system_clock;
                immh->elapsed=(double)(immh->systick) / 1000.0;
                immh->corecotick=image_specs->inpt_img_cnt;


                memcpy(public_short_image[0],temp_image,my_message.imm_bytes);

            }


            if (my_message.gui.which_img_view==1)
            {
                //adrk img
                //std img
                image_specs->is_raw_imm=false;
                image_specs->is_raw=true;

                image_specs->imm_num_pixels=0;
                image_specs->is_compressed=false;
                image_specs->num_pixels=img_num_pixels;


                for (int k=0;k<img_num_pixels;k++)
                {
                    public_short_image[0][k]=(unsigned short)(public_double_image[0][k]);
                }

            }

            if (my_message.gui.which_img_view==2)
            {
                //std img
                image_specs->is_raw_imm=false;
                image_specs->is_raw=true;

                image_specs->imm_num_pixels=0;
                image_specs->is_compressed=false;
                image_specs->num_pixels=img_num_pixels;


                for (int k=0;k<img_num_pixels;k++)
                {
                    public_short_image[0][k]=(unsigned short)(public_double_image[1][k]);
                }

            }

            if (my_message.gui.which_img_view==3)
            {
                //thresh img:

                image_specs->is_raw_imm=false;
                image_specs->is_raw=true;

                image_specs->imm_num_pixels=0;
                image_specs->is_compressed=false;
                image_specs->num_pixels=img_num_pixels;

                memcpy(public_short_image[0],sthresh_image,img_num_pixels*sizeof(short));
            }

            image_specs->processed_by_rank=rank;
    }

        //must be outside of the if_calc_iamge
        // this must execute on every rank regardless if we have img.
        // has barriers and fences etc.

        //we get total average of all darks into pub dooub img 0.
        //is_finish_darks goes true when it is time to compute total sum,
        // that is, when accum is done. we must set to false ourselves.
        if (is_finish_darks)
        {
            combineDarkStd(0,1.0);
            // here we will get basic sum of all squared images into pub doub img 1.
            double noise_mult_factor =1.0;
            combineDarkStd(1,noise_mult_factor);

            //writeImageRaw(public_double_image[0],img_num_pixels*sizeof(double),"AA_DsumImage",0);
            //writeImageRaw(public_double_image[1],img_num_pixels*sizeof(double),"AA_DsumSqImage",0);
            // now calc the std image and thresh hold iamges
            calcThresh();
           // writeImageRaw(public_double_image[0],img_num_pixels*sizeof(double),"AA_DAveImage",0);
            //writeImageRaw(public_double_image[1],img_num_pixels*sizeof(double),"AA_DStdImage",0);

            //writeImageRaw(sdark_image,img_num_pixels*sizeof(short),"AA_UDarkImage",0);
            //writeImageRaw(sthresh_image,img_num_pixels*sizeof(short),"AA_UThreshImage",0);

            //writeImageRaw(square_image,img_num_pixels*sizeof(double),"AA_DVarianceImg",0);

            //is_finish_darks=false;
        }





        printTrace("mpiUser::doImgCalcs_______________________________________________");


return(1);
  }
Example #19
0
    //---------------------------------------------------------------------
	bool ETCCodec::decodeKTX(DataStreamPtr& stream, DecodeResult& result) const
	{
        KTXHeader header;
        // Read the ETC1 header
        stream->read(&header, sizeof(KTXHeader));

		const uint8 KTXFileIdentifier[12] = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A };
		if (memcmp(KTXFileIdentifier, &header.identifier, sizeof(KTXFileIdentifier)) != 0 )
			return false;

		if (header.endianness == KTX_ENDIAN_REF_REV)
			flipEndian(&header.glType, sizeof(uint32), 1);

        ImageData *imgData = OGRE_NEW ImageData();
        imgData->depth = 1;
        imgData->width = header.pixelWidth;
        imgData->height = header.pixelHeight;
		imgData->num_mipmaps = static_cast<ushort>(header.numberOfMipmapLevels - 1);

		switch(header.glInternalFormat)
		{
		case 37492: // GL_COMPRESSED_RGB8_ETC2
            imgData->format = PF_ETC2_RGB8;
			break;
        case 37496:// GL_COMPRESSED_RGBA8_ETC2_EAC
			imgData->format = PF_ETC2_RGBA8;
            break;
		case 37494: // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
            imgData->format = PF_ETC2_RGB8A1;
			break;
		case 35986: // ATC_RGB
			imgData->format = PF_ATC_RGB;
			break;
		case 35987: // ATC_RGB_Explicit
			imgData->format = PF_ATC_RGBA_EXPLICIT_ALPHA;
			break;
		case 34798: // ATC_RGB_Interpolated
			imgData->format = PF_ATC_RGBA_INTERPOLATED_ALPHA;
			break;
		case 33777: // DXT 1
	        imgData->format = PF_DXT1;
			break;
		case 33778: // DXT 3
	        imgData->format = PF_DXT3;
			break;
		case 33779: // DXT 5
	        imgData->format = PF_DXT5;
			break;
		default:		
	        imgData->format = PF_ETC1_RGB8;
			break;
		}
		
		imgData->flags = 0;
		if (header.glType == 0 || header.glFormat == 0)
	        imgData->flags |= IF_COMPRESSED;

		size_t numFaces = 1; // Assume one face until we know otherwise
                             // Calculate total size from number of mipmaps, faces and size
		imgData->size = Image::calculateSize(imgData->num_mipmaps, numFaces,
                                             imgData->width, imgData->height, imgData->depth, imgData->format);

		stream->skip(header.bytesOfKeyValueData);

		// Bind output buffer
		MemoryDataStreamPtr output;
		output.bind(OGRE_NEW MemoryDataStream(imgData->size));

		// Now deal with the data
		uchar* destPtr = output->getPtr();
		for (uint32 level = 0; level < header.numberOfMipmapLevels; ++level)
		{
			uint32 imageSize = 0;
			stream->read(&imageSize, sizeof(uint32));
			stream->read(destPtr, imageSize);
			destPtr += imageSize;
		}

		result.first = output;
		result.second = CodecDataPtr(imgData);
        
		return true;
	}
Example #20
0
	//---------------------------------------------------------------------    
	Codec::DecodeResult PVRTCCodec::decodeV3(DataStreamPtr& stream) const
	{
		PVRTCTexHeaderV3 header;
        PVRTCMetadata metadata;
        uint32 flags = 0;
        size_t numFaces = 1; // Assume one face until we know otherwise

        ImageData *imgData = OGRE_NEW ImageData();
		MemoryDataStreamPtr output;

        // Read the PVRTC header
        stream->read(&header, sizeof(PVRTCTexHeaderV3));

        // Read the PVRTC metadata
        if(header.metaDataSize)
        {
            stream->read(&metadata, sizeof(PVRTCMetadata));
        }

        // Identify the pixel format
        switch (header.pixelFormat)
        {
            case kPVRTC1_PF_2BPP_RGB:
                imgData->format = PF_PVRTC_RGB2;
                break;
            case kPVRTC1_PF_2BPP_RGBA:
                imgData->format = PF_PVRTC_RGBA2;
                break;
            case kPVRTC1_PF_4BPP_RGB:
                imgData->format = PF_PVRTC_RGB4;
                break;
            case kPVRTC1_PF_4BPP_RGBA:
                imgData->format = PF_PVRTC_RGBA4;
                break;
            case kPVRTC2_PF_2BPP:
                imgData->format = PF_PVRTC2_2BPP;
                break;
            case kPVRTC2_PF_4BPP:
                imgData->format = PF_PVRTC2_4BPP;
                break;
        }

        // Get format flags
        flags = header.flags;
        flipEndian(reinterpret_cast<void*>(flags), sizeof(uint32));

        imgData->depth = header.depth;
        imgData->width = header.width;
        imgData->height = header.height;
        imgData->num_mipmaps = static_cast<ushort>(header.mipMapCount);

        // PVRTC is a compressed format
        imgData->flags |= IF_COMPRESSED;

        if(header.numFaces == 6)
            imgData->flags |= IF_CUBEMAP;

        if(header.depth > 1)
            imgData->flags |= IF_3D_TEXTURE;

        // Calculate total size from number of mipmaps, faces and size
		imgData->size = Image::calculateSize(imgData->num_mipmaps, numFaces, 
                                             imgData->width, imgData->height, imgData->depth, imgData->format);

		// Bind output buffer
		output.bind(OGRE_NEW MemoryDataStream(imgData->size));

		// Now deal with the data
		void *destPtr = output->getPtr();
        
        uint width = imgData->width;
        uint height = imgData->height;
        uint depth = imgData->depth;

        // All mips for a surface, then each face
        for(size_t mip = 0; mip <= imgData->num_mipmaps; ++mip)
		{
            for(size_t surface = 0; surface < header.numSurfaces; ++surface)
            {
                for(size_t i = 0; i < numFaces; ++i)
                {
                    // Load directly
                    size_t pvrSize = PixelUtil::getMemorySize(width, height, depth, imgData->format);
                    stream->read(destPtr, pvrSize);
                    destPtr = static_cast<void*>(static_cast<uchar*>(destPtr) + pvrSize);
                }
            }

            // Next mip
            if(width!=1) width /= 2;
            if(height!=1) height /= 2;
            if(depth!=1) depth /= 2;
		}

        DecodeResult ret;
		ret.first = output;
		ret.second = CodecDataPtr(imgData);

		return ret;
	}