我正在尝试从任意像素阵列生成TIFF / EP Profile 2 raw(.dng)图像。该像素阵列表示拜耳模式(CFA)。
我研究了TIFF / EP文件规范,并且通过使用libtiff,我包含了我认为生成完整.dng文件所需的所有标记。但是,我无法使用dcraw转换创建的文件(dcraw显示它无法解码文件)。
在TIFF / EP规范中声明为强制的两个标签可能会给出一个问题,但似乎没有在libtiff中实现:SensingMethod和TIFF / EPStandardID标签。我是否真的必须包含它们(我已经看到示例代码忽略了这些标记,但仍然报告可以正常工作),如果是这样,我怎样才能手动将它们添加到libtiff?此外,设置SubIFD标记会产生错误消息“Assertion failed:* pa< = 0xFFFFFFFFUL,file tif_dirwrite.c,line 1869”
总而言之,我认为我的问题不仅仅是由于这三个标签而且我认为存在根本性的错误。也许你们中的某个人可以查看我的代码并提供一些线索?我不得不说libtiff的文档相当差,所以我的代码受到了极少数示例代码之一的启发:elphel_dng.c。
非常感谢!费边
PS。我在Dropbox
上传了生成的文件C ++
public class DatePickerCell<S, T> extends TableCell<S, Date> {
private DatePicker datePicker;
public DatePickerCell() {
super();
//if you want focus on your datepicker
/*Platform.runLater(new Runnable() {
@Override
public void run() {
datePicker.requestFocus();
}
});*/
}
@Override
public void updateItem(Date item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
if(datePicker != null) {
datePicker.setValue(getDate());
}
setText(null);
setGraphic(datePicker);
} else {
setText(getDate()
.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)));
setGraphic(null);
}
}
}
private void createDatePicker() {
this.datePicker = new DatePicker(getDate());
datePicker.setPromptText("dd/MM/yyyy");
datePicker.setEditable(true);
datePicker.setOnAction(t -> {
commitEdit(Date.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault())
.toInstant()));
datePicker.focusedProperty().addListener(((observable, oldValue,
newValue) -> {
if(!newValue)
commitEdit(Date.from(datePicker.getValue()
.atStartOfDay(ZoneId.systemDefault()).toInstant()));
}));
});
}
@Override
public void startEdit() {
super.startEdit();
if(!isEmpty()) {
createDatePicker();
setText(null);
setGraphic(datePicker);
}
}
@Override
public void cancelEdit() {
super.cancelEdit();
setText(getDate().toString());
setGraphic(null);
}
public LocalDate getDate() {
return getItem() == null ? LocalDate.now() :
getItem().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
}
答案 0 :(得分:2)
我有相同的要求,并从你离开的地方继续。这里有一些代码可生成128x128原始Bayer 10位DNG图像,该图像与dng_validate,dcraw,lightroom和resolve兼容。
我已经删除了几乎所有内容,并将最低限度保持为dng_validate。
#include <tiffio.h>
#include <math.h>
int main (void)
{
const int width = 128;
const int height = 128;
static const short bayerPatternDimensions[] = { 2, 2 };
static const float ColorMatrix1[] =
{
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
};
static const float AsShotNeutral[] =
{
1.0, 1.0, 1.0,
};
int row, i;
float gamma = 80;
#define GR 0x80, 0x20, 0x08, 0x02, 0x00,
#define WH 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
#define BL 0x00, 0x00, 0x00, 0x00, 0x00,
#define BLK(N) N N N N N N N N
// Arbitrary Bayer pixel values:
unsigned char image[] =
{
BLK(WH)
BLK(GR)
BLK(BL)
BLK(WH)
BLK(GR)
BLK(BL)
BLK(WH)
BLK(GR)
BLK(BL)
};
TIFF* tif = TIFFOpen ("out.dng", "w");
TIFFSetField (tif, TIFFTAG_DNGVERSION, "\01\01\00\00");
TIFFSetField (tif, TIFFTAG_SUBFILETYPE, 0);
TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 10);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, 1);
TIFFSetField (tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA);
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
TIFFSetField (tif, TIFFTAG_CFAREPEATPATTERNDIM, bayerPatternDimensions);
TIFFSetField (tif, TIFFTAG_CFAPATTERN, "\00\01\01\02");
TIFFSetField (tif, TIFFTAG_MAKE, "DNG");
TIFFSetField (tif, TIFFTAG_UNIQUECAMERAMODEL, "DNG");
TIFFSetField (tif, TIFFTAG_COLORMATRIX1, 9, ColorMatrix1);
TIFFSetField (tif, TIFFTAG_ASSHOTNEUTRAL, 3, AsShotNeutral);
TIFFSetField (tif, TIFFTAG_CFALAYOUT, 1);
TIFFSetField (tif, TIFFTAG_CFAPLANECOLOR, 3, "\00\01\02");
unsigned char* cur = image;
for (row = 0; row < height;)
{
for (i = 0; i < 32; ++i, ++row)
TIFFWriteScanline (tif, cur, row, 0);
cur += 40;
}
TIFFClose (tif);
return 0;
}
dcraw非常顽固地工作,我不得不在gdb中获取它的源代码和跟踪以找到错误的条件:
if (!load_raw || height < 22 || width < 22 ||
tiff_bps > 16 || tiff_samples > 6 || colors > 4)
is_raw = 0;
因此,您创建4x4图像的第一次尝试将自动失败。
答案 1 :(得分:0)
这不是一个答案,但它对于评论来说太大了,而且它是有助于找到解决方案的建设性意见......所以请不要投票。
如果您将文件重命名为.TIF
,然后在其中的两个子图像上运行 ImageMagick 的identify
命令,则会得到以下信息:
identify -verbose a.tif[0]
<强>输出强>
Image: a.tif
Base filename: a.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 4x4+0+0
Resolution: 75x75
Print size: 0.0533333x0.0533333
Units: PixelsPerInch
Type: Bilevel
Base type: TrueColor
Endianess: LSB
Colorspace: sRGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 16
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: nan
Colors: 1
Histogram:
16: ( 0, 0, 0) #000000 gray(0)
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 4x4+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Properties:
comment: DummyImageDescription
date:create: 2016-07-04T13:20:26+01:00
date:modify: 2016-07-04T13:20:26+01:00
signature: 17b0761f87b081d5cf10757ccc89f12be355c70e2e29df288b65b30710dcbcd1
tiff:alpha: unspecified
tiff:copyright: DummyCopyright
tiff:endian: lsb
tiff:make: DummyMake
tiff:model: DummyModel
tiff:photometric: RGB
tiff:rows-per-strip: 682
tiff:software: DummySoftware
tiff:subfiletype: REDUCEDIMAGE
tiff:timestamp: 2016:06:30 11:11:15
Artifacts:
filename: a.tif[0]
verbose: true
Tainted: False
Filesize: 1.33KB
Number pixels: 16
Pixels per second: 16PB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-04 http://www.imagemagick.org
对于第二个子图像:
identify -verbose a.tif[1]
<强>输出强>
Image: a.tif
Base filename: a.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 4x4+0+0
Units: PixelsPerInch
Type: Palette
Base type: TrueColor
Endianess: LSB
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 16
Red:
min: 0 (0)
max: 255 (1)
mean: 70.0625 (0.274755)
standard deviation: 88.1841 (0.34582)
kurtosis: -0.160699
skewness: 1.06679
entropy: 0.80381
Green:
min: 0 (0)
max: 255 (1)
mean: 59.8125 (0.234559)
standard deviation: 83.8438 (0.328799)
kurtosis: 0.828861
skewness: 1.43159
entropy: 0.884626
Blue:
min: 0 (0)
max: 255 (1)
mean: 67.6875 (0.265441)
standard deviation: 95.9861 (0.376416)
kurtosis: -0.141547
skewness: 1.19724
entropy: 0.811278
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 65.8542 (0.258252)
standard deviation: 89.4791 (0.350899)
kurtosis: 0.150059
skewness: 1.23551
entropy: 0.833238
Colors: 7
Histogram:
6: ( 0, 0, 0) #000000 black
2: ( 0, 1, 0) #000100 srgb(0,1,0)
1: ( 54,128,255) #3680FF srgb(54,128,255)
3: ( 90, 84, 85) #5A5455 srgb(90,84,85)
1: ( 96, 32, 0) #602000 srgb(96,32,0)
1: (191, 33, 63) #BF213F srgb(191,33,63)
2: (255,255,255) #FFFFFF white
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 4x4+0+0
Dispose: Undefined
Iterations: 0
Scene: 1
Compression: None
Orientation: TopLeft
Properties:
date:create: 2016-07-04T14:19:59+01:00
date:modify: 2016-07-04T14:19:59+01:00
signature: 19310563e3b3b718a9c7e4a49743acffb6fefbdbeb64a6742589e7efd0beb36a
tiff:alpha: unspecified
tiff:endian: lsb
tiff:photometric: unknown
tiff:rows-per-strip: 2048
Artifacts:
filename: a.tif[1]
verbose: true
Tainted: False
Filesize: 0B
Number pixels: 16
Pixels per second: 16PB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-04 http://www.imagemagick.org
您还可以按如下方式使用tiffdump
:
tiffdump YourFile
<强>输出强>
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 56 (0x38) next 632 (0x278)
SubFileType (254) LONG (4) 1<1>
ImageWidth (256) SHORT (3) 1<4>
ImageLength (257) SHORT (3) 1<4>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<2>
ImageDescription (270) ASCII (2) 22<DummyImageDescription\0>
Make (271) ASCII (2) 10<DummyMake\0>
Model (272) ASCII (2) 11<DummyModel\0>
StripOffsets (273) LONG (4) 1<8>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<3>
StripByteCounts (279) LONG (4) 1<48>
XResolution (282) RATIONAL (5) 1<75>
YResolution (283) RATIONAL (5) 1<75>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 14<DummySoftware\0>
DateTime (306) ASCII (2) 20<2016:06:30 11:11:15\0>
Copyright (33432) ASCII (2) 15<DummyCopyright\0>
50706 (0xc612) BYTE (1) 4<0x1 0x1 00 00>
50707 (0xc613) BYTE (1) 4<0x1 00 00 00>
50708 (0xc614) ASCII (2) 17<DummyUniqueModel\0>
50721 (0xc621) SRATIONAL (10) 9<2824.73 2.00517 Nan (2147483647/0) -1.76624 0 -1.67235 0 -1.86732 Nan (-2147483647/0)>
50728 (0xc628) RATIONAL (5) 3<0 1.875 0>
50778 (0xc65a) SHORT (3) 1<21>
50827 (0xc68b) BYTE (1) 1<0x44>
Directory 1: offset 632 (0x278) next 0 (0)
SubFileType (254) LONG (4) 1<0>
ImageWidth (256) SHORT (3) 1<4>
ImageLength (257) SHORT (3) 1<4>
BitsPerSample (258) SHORT (3) 1<8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<32803>
StripOffsets (273) LONG (4) 1<616>
SamplesPerPixel (277) SHORT (3) 1<1>
StripByteCounts (279) LONG (4) 1<16>
PlanarConfig (284) SHORT (3) 1<1>
33421 (0x828d) SHORT (3) 2<2 2>
33422 (0x828e) BYTE (1) 4<0x1 00 0x2 0x1>
50710 (0xc616) BYTE (1) 3<00 0x1 0x2>
50712 (0xc618) SHORT (3) 256<0 0 1 1 1 2 2 3 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 13 ...>
50717 (0xc61d) LONG (4) 1<255>