4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 class DPXInStream : public InStream
30 DPXInStream(char * ptr, size_t sz);
31 virtual ~DPXInStream();
35 size_t Read(void * buf, const size_t size);
36 size_t ReadDirect(void * buf, const size_t size);
37 bool EndOfFile() const;
38 bool Seek(long offset, Origin origin);
46 DPXInStream::DPXInStream(char * ptr, size_t sz) :
53 DPXInStream::~DPXInStream()
58 void DPXInStream::Close()
65 void DPXInStream::Rewind()
70 size_t DPXInStream::Read(void * buf, const size_t size)
72 size_t data_to_read = MIN(size, bufsize - pos);
73 if ( data_to_read > 0 )
75 memcpy(buf, &databuf[pos], data_to_read);
81 size_t DPXInStream::ReadDirect(void * buf, const size_t size)
83 this->Read(buf, size);
86 bool DPXInStream::EndOfFile() const
93 bool DPXInStream::Seek(long offset, Origin origin)
99 if ( (size_t)offset < bufsize )
106 if ( pos+offset < bufsize )
113 if ( (size_t)offset < bufsize )
114 pos = bufsize - offset - 1;
125 FileDPX::FileDPX(Asset *asset, File *file)
126 : FileList(asset, file, "DPXLIST", ".dpx", FILE_DPX, FILE_DPX_LIST)
128 if(asset->format == FILE_UNKNOWN)
129 asset->format = FILE_DPX_LIST;
136 void FileDPX::get_parameters(BC_WindowBase *parent_window,
137 Asset *asset, BC_WindowBase* &format_window,
138 int audio_options, int video_options, EDL *edl)
142 int FileDPX::check_sig(Asset *asset, char *test)
144 if(test[0] == 'D' && test[1] == 'P' && test[2] == 'X' &&
145 test[3] == 'L' && test[4] == 'I' && test[5] == 'S' && test[6] == 'T')
152 int FileDPX::get_best_colormodel(Asset *asset, int driver)
157 int FileDPX::colormodel_supported(int colormodel)
162 int FileDPX::read_frame_header(char *path)
173 if (!header.Read(&img))
178 asset->width = header.Width();
179 asset->height = header.Height();
180 switch ( header.ComponentDataSize(0) )
182 case dpx::DataSize::kByte:
183 color_model = BC_RGB888;
186 case dpx::DataSize::kWord:
187 color_model = BC_RGB161616;
190 case dpx::DataSize::kInt:
191 case dpx::DataSize::kFloat:
192 case dpx::DataSize::kDouble:
193 color_model = BC_RGB_FLOAT;
199 int FileDPX::read_frame(VFrame *frame, VFrame *data)
201 DPXInStream inStream((char*)data->get_data(), data->get_compressed_size());
202 dpx::Reader dpxReader;
204 dpxReader.SetInStream(&inStream);
205 dpxReader.ReadHeader();
206 return dpxReader.ReadImage(0, frame->get_data()) ? 0 : 1;