读取 Photoshop (PSD) 文件的 RLE 压缩层
我可以很好地读取原始数据,并且我的文件都没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只想知道通道像素数据大小(关于 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.