【发布时间】:2014-02-07 17:46:54
【问题描述】:
[edit] 按照 fadden@ 的建议重新格式化为问答格式。
在 ExtractMpegFramesTest_egl14.java.txt 方法 saveFrame() 中,有一个循环用于将 RGBA 重新排序为 ARGB 以进行位图 png 压缩(请参阅该文件的以下引用),如何优化?
// glReadPixels gives us a ByteBuffer filled with what is essentially big-endian RGBA
// data (i.e. a byte of red, followed by a byte of green...). We need an int[] filled
// with little-endian ARGB data to feed to Bitmap.
//
...
// So... we set the ByteBuffer to little-endian, which should turn the bulk IntBuffer
// get() into a straight memcpy on most Android devices. Our ints will hold ABGR data.
// Swapping B and R gives us ARGB. We need about 30ms for the bulk get(), and another
// 270ms for the color swap.
...
for (int i = 0; i < pixelCount; i++) {
int c = colors[i];
colors[i] = (c & 0xff00ff00) | ((c & 0x00ff0000) >> 16) | ((c & 0x000000ff) << 16);
}
【问题讨论】:
-
好主意!这个交换循环在 Java 中并不是特别快。
-
FWIW,我认为提供建议的“官方”方式是问,“我们如何才能使 ExtractMpegFramesTest 中的 saveFrame() 方法更有效?”,然后回答您自己的问题。这样一来,其他人也被鼓励提出自己的答案。见stackoverflow.com/help/self-answer。
-
重新格式化,谢谢fadden!
标签: java android android-mediacodec