读取 Photoshop (PSD) 文件的 RLE 压缩层

发布于 2024-11-18 15:13:21 字数 1623 浏览 4 评论 0原文

我基于官方 PSD 文件格式文档

我可以很好地读取原始数据,并且我的文件都没有 ZIP 压缩。我所需要的只是让 RLE 的东西发挥作用。

现在,我对解压缩信息不感兴趣。我只想将其读入并以压缩形式存储在内存中。稍后我会处理解压的问题。

我所做的就是计算 RLE 数据的大小,并逐个通道批量读取它。这是我用来计算通道数据大小的函数:

用 ActionScript 3.0 编写

////////////////////////////////////////////////////////////////////
// Compute RLE Data Size
////////////////////////////////////////////////////////////////////
protected function _computeRLESize( data_ : ByteArray, record_ : PSDLayerRecord ) : int
{
    var numScanlines : int;
    var ii : int;
    var size : int;
    var totalSize : int;
    var pad : int;

    // Compute our total time
    totalSize = ( record_.bottom - record_.top ) * ( record_.right - record_.left );

    // Find our number of scanlines
    numScanlines = record_.bottom - record_.top;

    // Initialize our size
    size = 0;

    // Loop through each line to see how many bytes we have
    trace( "Num Scanlines: " + numScanlines );
    for ( ii = 0; ii < numScanlines; ii++ )
    {
        pad = data_.readShort();
        if ( pad % 2 != 0 ) pad++;
        size += pad;
    }

    // Output our compression
    trace( "Image is at " + size + " / " + totalSize + " compression" );

    // When we're done, back up to the beginning so we can read it
    data_.position -= numScanlines * 2;

    // Return our size
    return size + numScanlines * 2;
}

我已经让其他四位专业编码人员与官方文档一起研究了这段代码,他们都找不到任何问题。

感谢您的任何帮助。

I'm basing this off the official PSD File Format documentation

I can read raw data just fine, and none of my files have ZIP compression. All I need is to get the RLE stuff to work.

Right now, I'm not interested in decompressing the information. I just want to read it in and store it in memory in its compressed form. I'll deal with decompressing later.

All I'm doing is computing the size of the RLE data, and reading it in bulk, channel by channel. This is the function I'm using to compute the size of the channel data:

Written in ActionScript 3.0

////////////////////////////////////////////////////////////////////
// Compute RLE Data Size
////////////////////////////////////////////////////////////////////
protected function _computeRLESize( data_ : ByteArray, record_ : PSDLayerRecord ) : int
{
    var numScanlines : int;
    var ii : int;
    var size : int;
    var totalSize : int;
    var pad : int;

    // Compute our total time
    totalSize = ( record_.bottom - record_.top ) * ( record_.right - record_.left );

    // Find our number of scanlines
    numScanlines = record_.bottom - record_.top;

    // Initialize our size
    size = 0;

    // Loop through each line to see how many bytes we have
    trace( "Num Scanlines: " + numScanlines );
    for ( ii = 0; ii < numScanlines; ii++ )
    {
        pad = data_.readShort();
        if ( pad % 2 != 0 ) pad++;
        size += pad;
    }

    // Output our compression
    trace( "Image is at " + size + " / " + totalSize + " compression" );

    // When we're done, back up to the beginning so we can read it
    data_.position -= numScanlines * 2;

    // Return our size
    return size + numScanlines * 2;
}

I've had four other professional coders study this code together with the official documentation, and none of them could find anything wrong with it.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-11-25 15:13:21

您只想知道通道像素数据大小(关于 RLE 或 RAW 压缩)吗?您可以从图层记录中的通道信息中获取大小。

Do you just want to know the channel pixel data size (regarding of RLE or RAW compression)? You can get the size from the channels info in layer record.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文