void SoXipCPUMprRender::readyBuffers(SoState *state) { SbXipImageDimensions dim(0, 0, 0); SoXipDataImage *imgData = 0; SbXipImage *image = 0; // Volume imgData = volume.getValue(); dim = SbXipImageDimensions(0,0,0); if (imgData && (image = imgData->get())) { // If data has changed, update MPR if (imgData->getDataId() != mVolDataId) { mVolDataId = imgData->getDataId(); mUpdateFlag |= UPDATE_MPR; } if (mVolDataType != image->getType() || mVolBitsUsed != image->getBitsStored()) { mVolDataType = image->getType(); mVolBitsUsed = image->getBitsStored(); mMPRSize = SbVec2s(-1, -1); // force buffer resizing } mVolBuf = image->refBufferPtr(); dim = imgData->get()->getDimAllocated(); // If dimensions have changed, update Cache if (dim != mVolDim) { mVolDim = dim; mUpdateFlag |= UPDATE_MPRCACHE; } } else { mVolBuf = 0; mVolDim = dim; mVolDataId = 0; } // Transfer function LUT imgData = (SoXipDataImage *) SoXipLutElement::get(state); if (imgData && (image = imgData->get()) && image->getType() == SbXipImage::FLOAT && image->getComponentLayoutType() == SbXipImage::RGBA) { // If there was no LUT before, resize buffers if (!mLutBuf) mMPRSize = SbVec2s(-1, -1); mLutSize = image->getDimStored()[0]; mLutBuf = (float*) image->refBufferPtr(); // If data has changed, update MPR if (imgData->getDataId() != mLutDataId) { mLutDataId = imgData->getDataId(); mUpdateFlag |= UPDATE_MPR; } } else { // If there was a LUT before, force resizing if (mLutBuf) mMPRSize = SbVec2s(-1, -1); mLutBuf = 0; mLutSize = 0; mLutDataId = 0; } }
SbXipImage* SoXipLoadBMP::loadBMP(const char *fileName) { try { BMP bmp; bmp.ReadFromFile(fileName); int numBits = bmp.TellBitDepth(); int width = bmp.TellWidth(); int height = bmp.TellHeight(); int bitsStored = 8; int samplesPerPixel = 0; SbXipImage::ComponentType compType = SbXipImage::INTERLEAVED; SbXipImage::ComponentLayoutType compLayoutType = SbXipImage::RGB; if(numBits<=24) { samplesPerPixel = 3; compLayoutType = SbXipImage::RGB; } else if(numBits == 32) { samplesPerPixel = 4; compLayoutType = SbXipImage::RGBA; } SbVec3f pos(0, 0, 0); SbVec3f scale(width, height, 1); SbMatrix rotMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1); SbMatrix modelMatrix; modelMatrix.setScale(scale); //modelMatrix.setTransform(pos, SbRotation(rotMatrix), scale); SbXipImage *image = new SbXipImage(SbXipImageDimensions(width, height, 1), SbXipImageDimensions(width, height, 1), SbXipImage::UNSIGNED_BYTE, bitsStored, samplesPerPixel, compType, compLayoutType, modelMatrix); unsigned char *buffer = (unsigned char *) image->refBufferPtr(); if(numBits<=24) { for(int i = 0; i < height; i++) { for(int j = 0; j < width; j++) { RGBApixel pixel = bmp.GetPixel(j,(height -1) - i ); buffer[3*i*width+3*j] = pixel.Red; buffer[3*i*width+3*j+1] = pixel.Green; buffer[3*i*width+3*j+2] = pixel.Blue; } } } else if(numBits == 32) { for(int i=0; i<height; i++) { for(int j=0; j<width; j++) { RGBApixel pixel = bmp.GetPixel(j, height-i); buffer[4*i*width+4*j] = pixel.Red; buffer[4*i*width+4*j+1] = pixel.Green; buffer[4*i*width+4*j+2] = pixel.Blue; buffer[4*i*width+4*j+3] = pixel.Alpha; } } } image->unrefBufferPtr(); return image; } catch(...) { SoDebugError::postInfo(__FILE__, "Exception loadBMP"); // Fix me need to delete allocated memory! return 0; } }