- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从一个 16 位 dpx 文件中读取像素数据,该文件是先前 git repo 的扩展名。 (因为它只支持 10 位)。
我正在使用这个 header和 cpp处理 header 信息并获取此类数据。
请注意,变量 _pixelOffset、_width、_height 和 _channels 基于 dpx 的标题信息。 pPixels 是一个 float* 数组:
#include <iostream>
#include <fstream>
#include <dpxHeader.h>
//First read the file as binary.
std::ifstream _in(_filePath.asChar(), std::ios_base::binary);
// Seek to the pixel offset to start reading where the pixel data starts.
if (!_in.seekg (_pixelOffset, std::ios_base::beg))
{
std::cerr << "Cannot seek to start of pixel data " << _filePath << " in DPX file.";
return MS::kFailure;
}
// Create char to store data of width length of the image
unsigned char *rawLine = new unsigned char[_width * 4]();
// Iterate over height pixels
for (int y = 0; y < _height; ++y)
{
// Read full pixel data for width.
if (!_in.read ((char *)&rawLine[0], _width * 4))
{
std::cerr << "Cannot read scan line " << y << " " << "from DPX file " << std::endl;
return MS::kFailure;
}
// Iterator over width
for (int x = 0; x < _width; ++x)
{
// We do this to flip the image because it's flipped vertically when read in
int index = ((_height - 1 - y) * _width * _channels) + x * _channels;
unsigned int word = getU32(rawLine + 4 * x, _byteOrder);
pPixels[index] = (((word >> 22) & 0x3ff)/1023.0);
pPixels[index+1] = (((word >> 12) & 0x3ff)/1023.0);
pPixels[index+2] = (((word >> 02) & 0x3ff)/1023.0);
}
}
delete [] rawLine;
这目前适用于 10 位文件,但由于我是按位操作的新手,所以我不确定如何将其扩展到 12 位和 16 位。任何人对我有任何线索或正确的方向吗?
最佳答案
这种文件格式有些全面,但如果您只针对已知的子集,那么扩展它应该不会太难。
从您的代码示例看来,您目前正在处理每个像素三个分量,并且这些分量填充为 32 位字。根据您提供的规范,在这种模式下,12 位和 16 位都将每个字存储两个组件。对于 12 位,每个分量的高 4 位是填充数据。您将需要三个 32 位字来获得六个颜色分量来解码两个像素:
...
unsigned int word0 = getU32(rawLine + 6 * x + 0, _byteOrder);
unsigned int word1 = getU32(rawLine + 6 * x + 4, _byteOrder);
unsigned int word2 = getU32(rawLine + 6 * x + 8, _byteOrder);
// First pixel
pPixels[index] = (word0 & 0xffff) / (float)0xffff; // (or 0xfff for 12-bit)
pPixels[index+1] = (word0 >> 16) / (float)0xffff;
pPixels[index+2] = (word1 & 0xffff) / (float)0xffff;
x++;
if(x >= _width) break; // In case of an odd amount of pixels
// Second pixel
pPixels[index+3] = (word1 >> 16) / (float)0xffff;
pPixels[index+4] = (word2 & 0xffff) / (float)0xffff;
pPixels[index+5] = (word2 >> 16) / (float)0xffff;
...
关于c++ - 读取 16 位 DPX 像素数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40164939/
我正在尝试制作一个素数列表。我已经对它进行了编码,但它只告诉我 1 - 100 的质数是 1。我不确定为什么会发生这种情况。我还想为它制作一个JFrame。 import javax.swing.JO
我正在尝试学习 lisp,但我在处理素数方面遇到了一些困难。我需要一个函数 is-prime,如果它是素数,我必须返回 t,如果不是,我必须返回 nil。 (prime 41) => t (prime
我正在尝试检查给定的数字是否是质数。首先采用试分割法。但该程序的行为很奇怪。这是我使用的。 int no; no = Integer.parseInt(jTextField1.getText());
判断一个数是否为素数。使用代码块 13.12 执行。编译器GNU GCC 4.7.0 #include main() { int input,check,count; printf(
从 Uncle Bob 的书 Clean Code(示例是用 Java 编写的,所以这是我的第一个 Java 翻译),我一直在研究素数的重构示例。 问题是:您将如何重构以下代码? 这里有 4 个版本:
此方法旨在递归地遍历该方法并判断数字是否为“ super 素数”。 super 素数是一个本身是素数的数字,每次它被 10 除时,所有这些数字也是素数。例如 2333 是超素数,因为 233 是素数,
这是一个接受输入并打印它是否为质数的代码最后一个 if 总是打印“false”,为什么? (print "Enter a positive integer") (setq num (read)) (s
我正在尝试生成一个 BigInteger 类型的随机质数,它介于我提供的最小值和最大值之间。 我知道 BigInteger.probablePrime(int bitlength, random),但
背景信息: 所以我想计算一个数内的所有质数,然后将它们相加。 sumPrimes(10) 应该返回 17 因为 2 + 3 + 5 + 7 = 17。 挑战来了 --> https://www.fre
我是 python 的初级程序员,对我正在编写的代码有疑问: number = int(input("Enter a random number: ")) for num in range(1, nu
质数又称素数。指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数。素数在数论中有着很重要的地位。比1大但不是素数的数称为合数。1和0既非素数也非合数。质数是与合数相对立的两个概
复制代码 代码如下: <?php for($i = 2; $i < 1001; $i++) { $primes = 0; for($k = 1; $k <
ruby判断一个数是否为质数 质数又称素数。一个大于1的自然数,如果除了1和它自身外,不能被其他自然数整除的数;(除0以外)否则称为合数 。根据算术基本定理,每一个比1大的整数,要么本身是一个质数
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
经过几个小时的谷歌搜索,我仍然处于停滞状态。如果有人指出我的公式或编码选择中的错误,我将不胜感激。请记住我是 Swift 的新手。我不习惯非 C 风格的 for 循环。 if textFiel
我已将我的问题上传为屏幕截图。 最佳答案 费马小定理 x^p mod p = x mod p or x^(p-1) mod p = 1 (if p does not divide x
初等数论 素数定义 设整数 \(p\ne 0,\pm 1\) 。如果 \(p\) 除了平凡约数以外没有其他约数,那么称 \(p\) 为素
我有以下数字数组: var array = [5,9,12,19,23,24,31,44,49,62]; 我试图找出每一个是偶数和合数,奇数和合数,还是奇数和素数。我首先尝试找到偶数和合数: for
import java.util.Scanner; public class array1 { public static void main(String [] args){
我是一名优秀的程序员,十分优秀!