重复压缩一个文件会出现什么结果?

From: http://stackoverflow.com/questions/1166385/how-many-times-can-a-file-be-compressed


For lossless compression, the only way you can know how many times you can gain by recompressing a file is by trying. It's going to depend on the compression algorithm and the file you're compressing.

Two files can never compress to the same output, so you can't go down to one byte. How could one byte represent all the files you could decompress to?

The reason that the second compression sometimes works is that a compression algorithm can't do omniscient perfect compression. There's a trade-off between the work it has to do and the time it takes to do it. Your file is being changed from all data to a combination of data about your data and the data itself.

Example

Take run-length encoding (probably the simplest useful compression) as an example.

04 04 04 04 43 43 43 43 51 52 11 bytes

That series of bytes could be compressed as:

[4] 04 [4] 43 [-2] 51 52 7 bytes (I'm putting meta data in brackets)

Where the positive number in brackets is a repeat count and the negative number in brackets is a command to emit the next -n characters as they are found.

In this case we could try one more compression:

[3] 04 [-4] 43 fe 51 52 7 bytes (fe is your -2 seen as two's complement data)

We gained nothing, and we'll start growing on the next iteration:

[-7] 03 04 fc 43 fe 51 52 8 bytes

We'll grow by one byte per iteration for a while, but it will actually get worse. One byte can only hold negative numbers to -128. We'll start growing by two bytes when the file surpasses 128 bytes in length. The growth will get still worse as the file gets bigger.

There's a headwind blowing against the compression program--the meta data. And also, for realcompressors, the header tacked on to the beginning of the file. That means that eventually the file will start growing with each additional compression.

### 回答1: 您好!我可以尝试为您提供一些指导和建议,但是无法为您提供完整的代码。 3DTILES是一种用于在 web 中可视化大型三维模型的格式。它支持许多压缩算法,包括但不限于: - Draco:一种开源的 3D 几何压缩算法,用于将三维几何体压缩到较小的文件大小。 - KTX:一种用于存储纹理的开放式文件格式,可以使用多种压缩算法进行压缩。 - glTF:一种用于交换 3D 模型的文件格式,可以使用多种压缩算法进行压缩。 如果您想开发一个 3DTILES 压缩程序,建议您考虑使用上述压缩算法之一。您可以在网上搜索有关如何使用这些算法的文档和示例代码,并根据自己的需要进行更改。 此外,建议您在开发 3DTILES 压缩程序之前,先了解 3DTILES 文件格式的基本结构和操作方式。您可以在 Cesium 官网(https://cesium.com/)上了解更多关于 3DTILES 文件格式的信息。 希望我的回答对您有所帮助! ### 回答2: 当然可以帮您写一个3DTILES文件压缩程序。3DTILES是一种用于存储、传输和呈现3D场景的开放标准。为了实现文件压缩,您可以考虑以下几个步骤: 首先,您需要了解3DTILES文件的结构和格式。了解3DTILES文件的组成部分、数据类型以及如何访问和解析这些数据是编写压缩程序的前提。 其次,您可以使用一种压缩算法(如LZ77、LZ78、DEFLATE等)对3DTILES文件进行压缩。这些算法可以通过查找和替换重复的数据来减小文件的大小。您可以选择合适的压缩算法,并实现该算法的相关功能。 接下来,您需要编写程序来读取原始的3DTILES文件,并将其数据传递给压缩算法进行处理。这可能需要您对文件的读取和写入进行编程,同时需要将数据转换为适当的格式进行处理。 最后,您可以将压缩后的数据写入新的3DTILES文件中,并保存在磁盘上。压缩后的文件将比原始文件更小,从而减少存储空间和传输时间开销。 需要注意的是,由于3DTILES文件可能包含大量的数据,压缩程序的实现可能有一定的挑战。因此,您可能需要具备一定的编程和算法知识来完成这个任务。如果您需要更具体的帮助或代码示例,建议您参考相关的编程文档和教程,或是咨询专业的软件开发人员。 ### 回答3: 当然可以帮您写一个3DTILES文件压缩程序。 3DTILES是一种用于存储和传输3D地理空间数据的开放格式。为了压缩3DTILES文件,我们可以采用以下步骤: 1. 首先,您需要理解3DTILES文件结构和数据类型,以便对其进行压缩。3DTILES文件通常由多个文件组成,其中包括顶点数据、纹理、索引等。 2. 接下来,您可以使用一种或多种数据压缩算法对不同类型的数据进行压缩。例如,对于顶点数据,您可以使用无损压缩算法,例如LZ77、DEFLATE等。对于纹理数据,您可以使用有损压缩算法,例如JPEG、PNG等。 3. 在压缩过程中,您还需要考虑文件的读取和解压缩效率。可以使用多线程或并行处理来提高压缩和解压缩速度。 4. 完成压缩程序后,您可以将其应用于您的3DTILES文件。通过运行该程序,您可以将原始的3DTILES文件转换为经过压缩文件。 需要注意的是,压缩过程可能导致一定程度的数据损失。您应该权衡压缩比和数据质量之间的平衡。为了确保压缩后的文件仍然可以被正常使用,并且不影响3DTILES文件的可视化效果和准确性,建议您在压缩程序中进行一定的测试和验证。 希望以上解答对您有所帮助,祝您成功编写3DTILES文件压缩程序!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值