bool csSimpleFormerLoader::LoadHeightmap32 (iDocumentNode* child, iSimpleFormerState* state) { csRef<iDataBuffer> buf; if (!(buf = GetDataBuffer (child))) return false; char* data = buf->GetData (); char c1 = *data++; char c2 = *data++; char c3 = *data++; char c4 = *data++; if (c1 != 'H' || c2 != 'M' || c3 != '3' || c4 != '2') { const char *filename = child->GetContentsValue (); synldr->ReportError ("crystalspace.terraformer.simple.loader", child, "File '%s' is not a heightmap32 file", filename); return false; } uint32 width = csLittleEndian::Convert (csGetFromAddress::UInt32 (data)); data += 4; uint32 height = csLittleEndian::Convert (csGetFromAddress::UInt32 (data)); data += 4; if (buf->GetSize () != (4+4+4+ width*height*4)) { const char *filename = child->GetContentsValue (); synldr->ReportError ("crystalspace.terraformer.simple.loader", child, "File '%s' is not a valid heightmap32 file: size mismatch", filename); return false; } RawHeightmapReader<GetterUint32<csLittleEndian> > reader (this, state); if (!reader.ReadData (data, width, height)) return false; return true; }
bool HeightFeederParser::Load (float* outputBuffer, size_t outputWidth, size_t outputHeight, size_t outputPitch, float heightScale, float offset) { if (sourceFormat == HEIGHT_SOURCE_IMAGE) { return LoadFromImage (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset); } // Handle loading from all other (raw) formats if (!vfs) return false; size_t valueSize = 0; switch (sourceFormat) { case HEIGHT_SOURCE_RAW8: valueSize = sizeof (uint8); break; case HEIGHT_SOURCE_RAW16LE: case HEIGHT_SOURCE_RAW16BE: valueSize = sizeof (uint16); break; case HEIGHT_SOURCE_RAW32LE: case HEIGHT_SOURCE_RAW32BE: case HEIGHT_SOURCE_RAWFLOATLE: case HEIGHT_SOURCE_RAWFLOATBE: valueSize = sizeof (uint32); break; case HEIGHT_SOURCE_IMAGE: // Can not happen. CS_ASSERT (false); } csRef<iDataBuffer> buf = vfs->ReadFile (sourceLocation.GetDataSafe (), false); if (!buf || ((outputHeight * outputWidth * valueSize) != buf->GetSize ())) return false; switch (sourceFormat) { case HEIGHT_SOURCE_RAW8: { RawHeightmapReader<GetterUint8> reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAW16LE: { RawHeightmapReader<GetterUint16<csLittleEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAW16BE: { RawHeightmapReader<GetterUint16<csBigEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAW32LE: { RawHeightmapReader<GetterUint32<csLittleEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAW32BE: { RawHeightmapReader<GetterUint32<csBigEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAWFLOATLE: { RawHeightmapReader<GetterFloat<csLittleEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_RAWFLOATBE: { RawHeightmapReader<GetterFloat<csBigEndian> > reader; return reader.ReadData (outputBuffer, outputWidth, outputHeight, outputPitch, heightScale, offset, buf->GetData ()); } break; case HEIGHT_SOURCE_IMAGE: // @@@FIXME: Handle this case? break; } return false; }