11 #define _(String) gettext(String)
12 #define gettext_noop(String) String
13 #define N_(String) gettext_noop (String)
15 FileTIFF::FileTIFF(Asset *asset, File *file)
16 : FileList(asset, file, "TIFFLIST", ".tif", FILE_TIFF, FILE_TIFF_LIST)
18 asset->video_data = 1;
28 void FileTIFF::get_parameters(BC_WindowBase *parent_window,
30 BC_WindowBase* &format_window,
36 TIFFConfigVideo *window = new TIFFConfigVideo(parent_window, asset);
37 format_window = window;
38 window->create_objects();
45 int FileTIFF::check_sig(Asset *asset)
47 FILE *stream = fopen(asset->path, "rb");
52 fread(test, 10, 1, stream);
55 if(test[0] == 'I' && test[1] == 'I')
60 if(test[0] == 'T' && test[1] == 'I' && test[2] == 'F' && test[3] == 'F' &&
61 test[4] == 'L' && test[5] == 'I' && test[6] == 'S' && test[7] == 'T')
69 int FileTIFF::can_copy_from(Edit *edit, int64_t position)
71 if(edit->asset->format == FILE_TIFF_LIST ||
72 edit->asset->format == FILE_TIFF)
78 #define TIFF_RGB "rgb "
79 #define TIFF_RGBA "rgba"
82 int FileTIFF::read_frame_header(char *path)
87 if(!(stream = TIFFOpen(path, "rb")))
89 perror("FileTIFF::read_header");
93 TIFFGetField(stream, TIFFTAG_IMAGEWIDTH, &(asset->width));
94 TIFFGetField(stream, TIFFTAG_IMAGELENGTH, &(asset->height));
96 // TIFFGetField(stream, TIFFTAG_IMAGEDEPTH, &depth);
97 TIFFGetField(stream, TIFFTAG_SAMPLESPERPIXEL, &depth);
99 strcpy(asset->vcodec, TIFF_RGB);
101 strcpy(asset->vcodec, TIFF_RGBA);
103 //printf("FileTIFF::read_frame_header 1 %d\n", depth);
110 int FileTIFF::colormodel_supported(int colormodel)
112 if(!strcmp(asset->vcodec, TIFF_RGB))
118 int FileTIFF::get_best_colormodel(Asset *asset, int driver)
120 if(!strcmp(asset->vcodec, TIFF_RGB))
127 static tsize_t tiff_read(thandle_t ptr, tdata_t buf, tsize_t size)
129 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)ptr;
130 if(tiff_unit->data->get_compressed_size() < tiff_unit->offset + size)
132 memcpy(buf, tiff_unit->data->get_data() + tiff_unit->offset, size);
133 tiff_unit->offset += size;
137 static tsize_t tiff_write(thandle_t ptr, tdata_t buf, tsize_t size)
139 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)ptr;
140 //printf("tiff_write 1 %d\n", size);
141 if(tiff_unit->data->get_compressed_allocated() < tiff_unit->offset + size)
143 tiff_unit->data->allocate_compressed_data((tiff_unit->offset + size) * 2);
147 if(tiff_unit->data->get_compressed_size() < tiff_unit->offset + size)
148 tiff_unit->data->set_compressed_size(tiff_unit->offset + size);
149 memcpy(tiff_unit->data->get_data() + tiff_unit->offset,
152 tiff_unit->offset += size;
153 //printf("tiff_write 2\n");
157 static toff_t tiff_seek(thandle_t ptr, toff_t off, int whence)
159 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)ptr;
160 //printf("tiff_seek 1 %d %d\n", off, whence);
164 tiff_unit->offset = off;
167 tiff_unit->offset += off;
170 tiff_unit->offset = tiff_unit->data->get_compressed_size() + off;
173 //printf("tiff_seek 2\n");
174 return tiff_unit->offset;
177 static int tiff_close(thandle_t ptr)
182 static toff_t tiff_size(thandle_t ptr)
184 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)ptr;
185 return tiff_unit->data->get_compressed_size();
188 static int tiff_mmap(thandle_t ptr, tdata_t* pbase, toff_t* psize)
190 //printf("tiff_mmap 1\n");
191 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)ptr;
192 *pbase = tiff_unit->data->get_data();
193 *psize = tiff_unit->data->get_compressed_size();
194 //printf("tiff_mmap 10\n");
198 void tiff_unmap(thandle_t ptr, tdata_t base, toff_t size)
202 int FileTIFF::read_frame(VFrame *output, VFrame *input)
204 FileTIFFUnit *unit = new FileTIFFUnit(this, 0);
209 stream = TIFFClientOpen("FileTIFF",
220 //printf("FileTIFF::read_frame 1 %d\n", output->get_color_model());
221 if(output->get_color_model() == BC_RGBA8888 ||
222 output->get_color_model() == BC_RGB888)
224 //printf("FileTIFF::read_frame 2\n");
225 for(int i = 0; i < asset->height; i++)
227 TIFFReadScanline(stream, output->get_rows()[i], i, 0);
229 //printf("FileTIFF::read_frame 4\n");
233 printf("FileTIFF::read_frame color model = %d\n",
234 output->get_color_model());
243 int FileTIFF::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
245 FileTIFFUnit *tiff_unit = (FileTIFFUnit*)unit;
248 tiff_unit->offset = 0;
249 tiff_unit->data = data;
250 tiff_unit->data->set_compressed_size(0);
252 //printf("FileTIFF::write_frame 1\n");
253 TIFFConfigVideo::fix_codec(asset->vcodec);
254 //printf("FileTIFF::write_frame 1\n");
255 stream = TIFFClientOpen("FileTIFF",
266 //printf("FileTIFF::write_frame 1\n");
267 int depth, color_model;
268 if(!strcmp(asset->vcodec, TIFF_RGBA))
271 color_model = BC_RGBA8888;
276 color_model = BC_RGB888;
279 //printf("FileTIFF::write_frame 1\n");
280 TIFFSetField(stream, TIFFTAG_IMAGEWIDTH, asset->width);
281 TIFFSetField(stream, TIFFTAG_IMAGELENGTH, asset->height);
282 TIFFSetField(stream, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
283 TIFFSetField(stream, TIFFTAG_SAMPLESPERPIXEL, depth / 8);
284 TIFFSetField(stream, TIFFTAG_BITSPERSAMPLE, 8);
285 TIFFSetField(stream, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
286 TIFFSetField(stream, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(stream, (uint32_t)-1));
287 TIFFSetField(stream, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
289 //printf("FileTIFF::write_frame 1\n");
290 if(frame->get_color_model() == color_model)
292 for(int i = 0; i < asset->height; i++)
294 //printf("FileTIFF::write_frame 2 %d\n", i);
295 TIFFWriteScanline(stream, frame->get_rows()[i], i, 0);
296 //printf("FileTIFF::write_frame 3\n");
301 //printf("FileTIFF::write_frame 2\n");
302 if(tiff_unit->temp &&
303 tiff_unit->temp->get_color_model() != color_model)
305 delete tiff_unit->temp;
310 tiff_unit->temp = new VFrame(0,
315 //printf("FileTIFF::write_frame 3 %d %d\n", color_model, frame->get_color_model());
316 cmodel_transfer(tiff_unit->temp->get_rows(),
318 tiff_unit->temp->get_y(),
319 tiff_unit->temp->get_u(),
320 tiff_unit->temp->get_v(),
332 frame->get_color_model(),
337 //printf("FileTIFF::write_frame 5\n");
338 for(int i = 0; i < asset->height; i++)
340 TIFFWriteScanline(stream, tiff_unit->temp->get_rows()[i], i, 0);
342 //printf("FileTIFF::write_frame 6\n");
344 //printf("FileTIFF::write_frame 7\n");
346 //printf("FileTIFF::write_frame 71\n");
349 //printf("FileTIFF::write_frame 8\n");
354 FrameWriterUnit* FileTIFF::new_writer_unit(FrameWriter *writer)
356 return new FileTIFFUnit(this, writer);
366 FileTIFFUnit::FileTIFFUnit(FileTIFF *file, FrameWriter *writer)
367 : FrameWriterUnit(writer)
373 FileTIFFUnit::~FileTIFFUnit()
375 if(temp) delete temp;
389 TIFFConfigVideo::TIFFConfigVideo(BC_WindowBase *parent_window, Asset *asset)
390 : BC_Window(PROGRAM_NAME ": Video Compression",
391 parent_window->get_abs_cursor_x(),
392 parent_window->get_abs_cursor_y(),
396 this->parent_window = parent_window;
400 TIFFConfigVideo::~TIFFConfigVideo()
404 int TIFFConfigVideo::create_objects()
408 fix_codec(asset->vcodec);
409 add_subwindow(new TIFFConfigAlpha(this, x, y));
411 add_subwindow(new BC_OKButton(this));
415 int TIFFConfigVideo::close_event()
421 char* TIFFConfigVideo::alpha_to_codec(int use_alpha)
429 int TIFFConfigVideo::codec_to_alpha(char *codec)
431 if(!strcmp(codec, TIFF_RGBA))
437 void TIFFConfigVideo::fix_codec(char *codec)
439 if(strcmp(codec, TIFF_RGB) &&
440 strcmp(codec, TIFF_RGBA))
441 strcpy(codec, TIFF_RGB);
445 TIFFConfigAlpha::TIFFConfigAlpha(TIFFConfigVideo *gui, int x, int y)
448 TIFFConfigVideo::codec_to_alpha(gui->asset->vcodec),
454 int TIFFConfigAlpha::handle_event()
456 if(TIFFConfigVideo::codec_to_alpha(gui->asset->vcodec))
458 strcpy(gui->asset->vcodec, TIFF_RGB);
461 strcpy(gui->asset->vcodec, TIFF_RGBA);
463 update(TIFFConfigVideo::codec_to_alpha(gui->asset->vcodec));