- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用 JAI 来写入和读取 TIFF 图像,但我最近在编码灰度图像时遇到了一个问题,我在每个 strip 的末尾得到 7 个黑色 (0
) 像素 (8每条线数):
只有在使用下面的 SSCE 将 DEFLATE
压缩设置为 deflate level 0
时,我才能重现它。任何其他值似乎都有效。
有时我也看到图像的 strip 向左移动了 30 像素左右。虽然我无法稳定地重现该问题,但如果您知道一些关于在 JAI 中编码 TIFF 的隐藏技巧,它也可能会解决这个问题。
private static byte[] genImage(int width, int height) {
byte[] pix = new byte[width * height];
Arrays.fill(pix, (byte)0xcf);
for (int j = 0; j < height; j++) {
Arrays.fill(pix, j*width + width/3, j*width + 2*width/3, (byte)0x7f);
}
return pix;
}
public static void main(String[] args) throws Exception {
int width = 256;
int height = 256;
byte[] pix = genImage(width, height);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
System.arraycopy(pix, 0, ((DataBufferByte)img.getRaster().getDataBuffer()).getData(), 0, width * height);
TIFFEncodeParam comp = new TIFFEncodeParam();
comp.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
comp.setDeflateLevel(0); // Changing 0 to values 1-9 "solves" the problem
FileOutputStream fos = new FileOutputStream("bugjai.tiff");
ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", fos, comp);
encoder.encode(img);
fos.close();
}
编辑:
我进一步调查检查了 8x8 图像上的文件内容。我将字节内容压缩为 0 级(使用 java.util.zip.Deflater
)并得到额外的 11 个字节。我在 strip 的末尾插入了这些字节并修补了 header 以反射(reflect)新的长度(值 4B
而不是 40
在位置 75h
) ,瞧!不再是 7 个像素。
所以 JAI 中似乎存在编码错误,“忘记”在放气时放置/计算字节数。然而,TIFF6 specification在第 15 页的开头说:
The Value is expected to begin on a word boundary; the corresponding Value Offset will thus be an even number
让我感到困惑的是:“开始”指的是文件中的位置? “修补”值从 40
变为 4B
,这不是偶数。 JAI 会不会以某种方式计算错误并四舍五入?
附录:
当“压缩”数据大于原始数据时,似乎会出现问题:在这里,当压缩数据为 75 字节长时,原始数据为 64 字节长。 JAI 可能假设图像的最大尺寸不能超过原始数据的尺寸。
最佳答案
因此,在问题中进行一些额外测试(参见编辑和附录)后,JAI 中似乎存在错误,将最大字节数限制为 width * heigth
。我猜他们假设没有压缩会增加图像的大小......除非你用 0
因子(我理解为“存储”)放气,在那里你得到像素,加上标题和尾部。由于 JAI 限制了写入的字节数,因此未正确写入尾符(如果有的话),并且数据未完全解码。
教训是:至少使用 1
的放气系数(在 the javadoc 中也标记为 BEST_SPEED
/MIN_COMPRESSION
)。
关于java - JAI TIFF 编解码器创建工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24475778/
令我惊讶的是,dart 没有内置的对象到 json 和 json 到对象的映射器。 我读到我们必须自己手动编写映射代码,这并不令人愉快。 无论如何,虽然我没有针对我的用例对其进行彻底测试,但我发现了
我有 16 位 PCM 音频,我想将其转换为 8 位 PCMU。据我所知,16 位到 8 位的转换很容易 - 只需从每个样本中删除最后 8 位即可。 我想知道如何将8位pcm转换为8位pcmu?任何文
我的任务是使用动态霍夫曼修改 JPEG 格式。所以我试图找到用Java编写的简单Jpeg解码器的源代码。谁能帮我? 最佳答案 看看这个:http://www.dreamincode.net/forum
我收到错误代码(如下),并且无法解码该字符串,我知道它正在查找 JSON 和我也保存的文件,但它无法解析。错误代码: Unexpected token VALUE(-10) at position 8
我制作了这个程序,它是一个随 secret 码。 public class SaadAbdullahCipher { private char[] alphabet = {'a', 'b'
总的来说,我对编程还很陌生,我想知道如何对输入的文本进行编码/解码。 对于 ex A -> D,所有字母必须减去 3 个字母B -> E等等 我将输入一些伪代码作为示例: INPUT MESSAGE:
是否有内置函数或受支持的包中的函数来获取基于输入字符集字符串,例如 ISO-8859-1 或 ISO-8859-15?现在我看到的唯一方法是自己匹配它: func getEncoderForChars
我是新来的。不知何故,我能够理解如何做到这一点。 我在下面做,但它给出了错误 - 无法读取数据,因为它的格式不正确。有人可以帮助我吗?从过去的 4 天开始,我一直坚持这一点。我真的很感激。 impor
就像标题所说,我正在尝试为一个我定义的类的对象编写一个自定义解码器,该对象包含我定义的类的其他对象。 “外部”类是一个 Edge,定义如下: class Edge: def __init__(
我想重新编码音频文件的音频流。以下gstreamer管道可以正常工作: gst-launch-1.0 filesrc location=input.flac ! decodebin ! audioco
使用Swift4、iOS11.1、Xcode9.1, 尝试匹配 Swift4 的可编码结构中的 JSON 文件,我遇到以下问题: 这是我的代码: struct Station: Codable {
正如标题所示,我正在寻找遵循 1.3 版本的 Java(+Android) WBXML 解析器/解码器。如果有必要的话,我什至可以考虑调用 native 代码。谢谢。 最佳答案 我确实记得不久前我使用
当 JABX 解码器尝试解码 xml 时,我遇到以下错误 线程“main”中出现异常 javax.xml.bind.UnmarshalException - 带有链接异常:[org.xml.sax.S
我正在处理不同尺寸(x,y)的图像。当在 MaxPooling2D 之后使用 UpSampling2D 时,它不能很好地重建它,因为 x-dim 不等于 y-dim。当 x=y (例如 28x28)时
http://www.lotterypost.com/js-compress.aspx 这个网站非常适合压缩 JS 但我想解码.... 除了在线之外,有没有最好的免费工具来编码/解码 Js 最佳答案
我刚刚在验证 JWT 时遇到了问题。我正在运行的代码是一个相当肮脏的黑客,它采用 JWT 的第二个组件并通过 Base64 解码器运行它。然而事实证明,通过一些 super 特殊的 JWT,我得到了一
我正在尝试使用 CUDA 解码器项目中的代码将解码后的图像文件保存回 BMP 图像。 if (g_bReadback && g_ReadbackSID)
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
在自己尝试 URL 解码之后,我设法想出了一些可行的想法 - 但它们不是很有效。由于 URL 解码是我的程序中可能出现严重瓶颈的地方,我决定上网寻找更有效的解决方案。我遇到了这篇 codeguru 文
是否可以“拦截” JAXB 的解码过程? 我有一个 xml 响应,部分应该转换为不同的 java 字段结构: ... 在我的 java 类中,我更愿意将其解码为 List ,
我是一名优秀的程序员,十分优秀!