Esempio n. 1
0
ImageTGA::ImageTGA (const ImageBuffer &ibuff)
  : _header (NULL)
{
  const GLubyte *colormap = NULL;
  const GLubyte *data_ptr;

  try
    {
      _name = ibuff.filename ();
      data_ptr = ibuff.data ();
      _standardCoordSystem = true;

      // Read TGA header
      _header = reinterpret_cast<const TGA_Header *>(data_ptr);
      data_ptr += sizeof (TGA_Header) + _header->id_lenght;

      // Get image information
      getTextureInfo ();

      // Memory allocation for pixel data
      _pixels = new GLubyte[_width * _height * _components];

      // Read color map, if present
      if (_header->colormap_type)
	{
	  // NOTE: color map is stored in BGR
	  colormap = data_ptr;
	  data_ptr += _header->cm_length * (_header->cm_size >> 3);
	}

      // Decode image data
      switch (_header->image_type)
	{
	case 0:
	  // No data
	  break;

	case 1:
	  // Uncompressed 8 bits color index
	  readTGA8bits (data_ptr, colormap);
	  break;

	case 2:
	  // Uncompressed 16-24-32 bits
	  switch (_header->pixel_depth)
	    {
	    case 16:
	      readTGA16bits (data_ptr);
	      break;

	    case 24:
	      readTGA24bits (data_ptr);
	      break;

	    case 32:
	      readTGA32bits (data_ptr);
	      break;
	    }

	  break;

	case 3:
	  // Uncompressed 8 or 16 bits grayscale
	  if (_header->pixel_depth == 8)
	    readTGAgray8bits (data_ptr);
	  else // 16 bits
	    readTGAgray16bits (data_ptr);

	  break;

	case 9:
	  // RLE compressed 8 bits color index
	  readTGA8bitsRLE (data_ptr, colormap);
	  break;

	case 10:
	  // RLE compressed 16-24-32 bits
	  switch (_header->pixel_depth)
	    {
	    case 16:
	      readTGA16bitsRLE (data_ptr);
	      break;

	    case 24:
	      readTGA24bitsRLE (data_ptr);
	      break;

	    case 32:
	      readTGA32bitsRLE (data_ptr);
	      break;
	    }

	  break;

	case 11:
	  // RLE compressed 8 or 16 bits grayscale
	  if (_header->pixel_depth == 8)
	    readTGAgray8bitsRLE (data_ptr);
	  else // 16 bits
	    readTGAgray16bitsRLE (data_ptr);

	  break;

	default:
	  // Image type is not correct, free memory and quit
	  throw ImageException ("Unknown TGA image type", _name);
	}
    }
void vixo_hairStyleMaya::exportColor(MString uvInfo,MString colorInfo,MDataBlock& data)
{
	//getUVinfo
	ifstream fin(uvInfo.asChar(),ios_base::in|ios_base::binary);

	int triNum;
	fin.read((char*)&triNum,sizeof(int));

	vector<int> hairNumPerTri(triNum);
	fin.read((char*)&hairNumPerTri[0],sizeof(int)*triNum);

	vector<int> ctrlVert(triNum*3);
	fin.read((char*)&ctrlVert[0],sizeof(int)*triNum*3);

	vector<int> hairStartIdxPerTri(triNum,0);
	int hairNum=0;
	for(int i=1;i<triNum;i++)
	{
		hairStartIdxPerTri[i]=hairStartIdxPerTri[i-1]+hairNumPerTri[i-1];
	}
	hairNum=hairStartIdxPerTri[triNum-1]+hairNumPerTri[triNum-1];

	vector<float> uvs(hairNum*2);
	fin.read((char*)&uvs[0],sizeof(float)*hairNum*2);
	fin.close();


	//getTextureInfo
	vector<follicleColor> follicleInfo(hairNum);
	getTextureInfo("densityMap",uvs,follicleInfo,data);
	getTextureInfo("tipColor",uvs,follicleInfo,data);
	getTextureInfo("baseColor",uvs,follicleInfo,data);
	getTextureInfo("tipOpacity",uvs,follicleInfo,data);
	getTextureInfo("baseOpacity",uvs,follicleInfo,data);

	vector<streampos> startPos(triNum);
	startPos[0]=sizeof(int)+sizeof(streampos)*triNum;
	for(int i=1;i<triNum;i++)
	{
		startPos[i]=startPos[i-1].operator+(sizeof(int)+sizeof(follicleColor)*hairNumPerTri[i-1]);
	}

	//Êä³ö
	fstream fout(colorInfo.asChar(),ios_base::out|ios_base::trunc|ios_base::binary);
	fout.write((char*)&triNum,sizeof(int));
	fout.write((char*)&startPos[0],sizeof(streampos)*triNum);
	for(int i=0;i<triNum;i++)
	{
		fout.write((char*)&hairNumPerTri[i],sizeof(int));
		fout.write((char*)&follicleInfo[hairStartIdxPerTri[i]],sizeof(follicleColor)*hairNumPerTri[i]);
	}
	fout.flush();
	fout.close();

	//Êä³ö
	/*
	colorInfo=colorInfo+"debug";
	fout.open(colorInfo.asChar(),ios_base::out|ios_base::trunc);
	fout<<triNum<<endl;
	for(int i=0;i<triNum;i++)
	{
		fout<<i<<":"<<startPos[i]<<'\t'<<hairNumPerTri[i]<<endl;
		for(int j=0;j<hairNumPerTri[i];j++)
		{
			fout<<'\t'<<j<<":"<<follicleInfo[hairStartIdxPerTri[i]+j].density<<'\t'<<follicleInfo[hairStartIdxPerTri[i]+j].tipColorB<<endl;
		}
	}
	fout.flush();
	fout.close();
	*/
}