Project

General

Profile

Patch #1271 » printStructure-3.diff

This patch supersedes the previous ones. - Ben Touchette, 15 Feb 2017 15:31

View differences:

exiv2-0.26.as/include/exiv2/orfimage.hpp 2017-01-24 10:08:23.000000000 -0500
79 79

  
80 80
        //! @name Manipulators
81 81
        //@{
82
        void printStructure(std::ostream& out, PrintStructureOption option,int depth);
82 83
        void readMetadata();
83 84
        void writeMetadata();
84 85
        /*!
exiv2-0.26.as/include/exiv2/rafimage.hpp 2017-01-24 10:08:23.000000000 -0500
78 78

  
79 79
        //! @name Manipulators
80 80
        //@{
81
        void printStructure(std::ostream& out, PrintStructureOption option,int depth);
81 82
        void readMetadata();
82 83
        /*!
83 84
          @brief Todo: Write metadata back to the image. This method is not
exiv2-0.26.as/include/exiv2/riffvideo.hpp 2017-01-24 10:08:23.000000000 -0500
71 71

  
72 72
        //! @name Manipulators
73 73
        //@{
74
        void printStructure(std::ostream& out, PrintStructureOption option,int depth);
74 75
        void readMetadata();
75 76
        void writeMetadata();
76 77
        //@}
......
185 186
        RiffVideo(const RiffVideo& rhs);
186 187
        //! Assignment operator
187 188
        RiffVideo& operator=(const RiffVideo& rhs);
189
        bool equalsRiffTag(Exiv2::DataBuf& buf ,const char* str);
188 190
        //@}
189 191

  
190 192
    private:
193
        const static int RIFF_TAG_SIZE;
194
        const static char* RIFF_CHUNK_HEADER_ICCP;
195
        const static char* RIFF_CHUNK_HEADER_EXIF;
196
        const static char* RIFF_CHUNK_HEADER_XMP;
191 197
        //! Variable to check the end of metadata traversing.
192 198
        bool continueTraversing_;
193 199
        //! Variable which stores current stream being processsed.
exiv2-0.26.as/include/exiv2/rw2image.hpp 2017-01-24 10:08:23.000000000 -0500
76 76

  
77 77
        //! @name Manipulators
78 78
        //@{
79
        void printStructure(std::ostream& out, PrintStructureOption option,int depth);
79 80
        void readMetadata();
80 81
        /*!
81 82
          @brief Todo: Write metadata back to the image. This method is not
exiv2-0.26.as/src/cr2image.cpp 2017-02-01 07:23:55.000000000 -0500
107 107
            throw Error(3, "CR2");
108 108
        }
109 109
        clearMetadata();
110
        std::ofstream devnull;
111
        printStructure(devnull, kpsRecursive, 0);
110 112
        ByteOrder bo = Cr2Parser::decode(exifData_,
111 113
                                         iptcData_,
112 114
                                         xmpData_,
exiv2-0.26.as/src/orfimage.cpp 2017-02-01 07:23:55.000000000 -0500
89 89
        throw(Error(32, "Image comment", "ORF"));
90 90
    }
91 91

  
92
    void OrfImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
93
        std::cout << "ORF IMAGE" << std::endl;
94
        if (io_->open() != 0) throw Error(9, io_->path(), strError());
95
        // Ensure that this is the correct image type
96
        if ( imageType() == ImageType::none )
97
            if (!isOrfType(*io_, false)) {
98
            if (io_->error() || io_->eof()) throw Error(14);
99
                throw Error(15);
100
        }
101

  
102
        io_->seek(0,BasicIo::beg);
103

  
104
        printTiffStructure(io(),out,option,depth-1);
105
    } // OrfImage::printStructure
106

  
92 107
    void OrfImage::readMetadata()
93 108
    {
94 109
#ifdef DEBUG
......
104 119
            throw Error(3, "ORF");
105 120
        }
106 121
        clearMetadata();
122
        std::ofstream devnull;
123
        printStructure(devnull, kpsRecursive, 0);
107 124
        ByteOrder bo = OrfParser::decode(exifData_,
108 125
                                         iptcData_,
109 126
                                         xmpData_,
exiv2-0.26.as/src/rafimage.cpp 2017-02-01 17:39:32.000000000 -0500
34 34

  
35 35
#include "rafimage.hpp"
36 36
#include "tiffimage.hpp"
37
#include "image_int.hpp"
37 38
#include "image.hpp"
38 39
#include "basicio.hpp"
39 40
#include "error.hpp"
......
95 96
        throw(Error(32, "Image comment", "RAF"));
96 97
    }
97 98

  
99
    void RafImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
100
        if (io_->open() != 0) {
101
            throw Error(9, io_->path(), strError());
102
        }
103
        // Ensure this is the correct image type
104
        if (!isRafType(*io_, true)) {
105
            if (io_->error() || io_->eof()) throw Error(14);
106
            throw Error(3, "RAF");
107
        }
108
        bool bPrint = option==kpsBasic || option==kpsRecursive;
109
        if ( bPrint ) {
110
            io_->seek(0,BasicIo::beg); // rewind
111

  
112
            if ( bPrint ) {
113
                out << Internal::indent(depth)
114
                    << "STRUCTURE OF RAF FILE: "
115
                    << io().path()
116
                    << std::endl;
117
                out << Internal::indent(depth)
118
                    << Internal::stringFormat("    Length |   Offset | Payload")
119
                    << std::endl;
120
            }
121

  
122
            byte magicdata [17];
123
            io_->read(magicdata, 16);
124
            magicdata[16] = 0;
125
            if ( bPrint ) {
126
                out << Internal::indent(depth)
127
                    << Internal::stringFormat("  %8u | %8u | ", 16, 0)
128
                    << "Magic number : "
129
                    << std::string((char*)&magicdata)
130
                    << std::endl;
131
            }
132

  
133
            byte data1 [5];
134
            io_->read(data1, 4);
135
            data1[4] = 0;
136
            if ( bPrint ) {
137
                out << Internal::indent(depth)
138
                    << Internal::stringFormat("  %8u | %8u | ", 4, 16)
139
                    << "data 1 : "
140
                    << std::string((char*)&data1)
141
                    << std::endl;
142
            }
143

  
144
            byte data2 [9];
145
            io_->read(data2, 8);
146
            data2[8] = 0;
147
            if ( bPrint ) {
148
                out << Internal::indent(depth)
149
                    << Internal::stringFormat("  %8u | %8u | ", 8, 20)
150
                    << "data 2 : "
151
                    << std::string((char*)&data2)
152
                    << std::endl;
153
            }
154

  
155
            byte camdata [33];
156
            io_->read(camdata, 32);
157
            camdata[32] = 0;
158
            if ( bPrint ) {
159
                out << Internal::indent(depth)
160
                    << Internal::stringFormat("  %8u | %8u | ", 32, 28)
161
                    << "camera : "
162
                    << std::string((char*)&camdata)
163
                    << std::endl;
164
            }
165

  
166
            byte dir_version [5];
167
            io_->read(dir_version, 4);
168
            dir_version[4] = 0;
169
            if ( bPrint ) {
170
                out << Internal::indent(depth)
171
                    << Internal::stringFormat("  %8u | %8u | ", 4, 60)
172
                    << "dir version : "
173
                    << std::string((char*)&dir_version)
174
                    << std::endl;
175
            }
176

  
177
            byte unknown [20];
178
            io_->read(unknown, 20);
179

  
180
            byte jpg_img_offset [4];
181
            io_->read(jpg_img_offset, 4);
182
            byte jpg_img_length [4];
183
            io_->read(jpg_img_length, 4);
184
            long jpg_img_off = Exiv2::getULong((const byte *) jpg_img_offset, bigEndian);
185
            long jpg_img_len = Exiv2::getULong((const byte *) jpg_img_length, bigEndian);
186
            std::stringstream j_off;
187
            std::stringstream j_len;
188
            j_off << jpg_img_off;
189
            j_len << jpg_img_len;
190
            if ( bPrint ) {
191
                out << Internal::indent(depth)
192
                    << Internal::stringFormat("  %8u | %8u | ", 4, 84)
193
                    << "JPEG Image Offset : "
194
                    << j_off.str()
195
                    << std::endl;
196
                out << Internal::indent(depth)
197
                    << Internal::stringFormat("  %8u | %8u | ", 4, 88)
198
                    << "JPEG Image Length : "
199
                    << j_len.str()
200
                    << std::endl;
201
            }
202

  
203
            byte cfa_header_offset [4];
204
            io_->read(cfa_header_offset, 4);
205
            byte cfa_header_length [4];
206
            io_->read(cfa_header_length, 4);
207
            long cfa_hdr_off = Exiv2::getULong((const byte *) cfa_header_offset, bigEndian);
208
            long cfa_hdr_len = Exiv2::getULong((const byte *) cfa_header_length, bigEndian);
209
            std::stringstream ch_off;
210
            std::stringstream ch_len;
211
            ch_off << cfa_hdr_off;
212
            ch_len << cfa_hdr_len;
213
            if ( bPrint ) {
214
                out << Internal::indent(depth)
215
                    << Internal::stringFormat("  %8u | %8u | ", 4, 92)
216
                    << "CFA Header Offset : "
217
                    << ch_off.str()
218
                    << std::endl;
219
                out << Internal::indent(depth)
220
                    << Internal::stringFormat("  %8u | %8u | ", 4, 96)
221
                    << "CFA Header Length : "
222
                    << ch_len.str()
223
                    << std::endl;
224
            }
225

  
226
            byte cfa_offset [4];
227
            io_->read(cfa_offset, 4);
228
            byte cfa_length [4];
229
            io_->read(cfa_length, 4);
230
            long cfa_off = Exiv2::getULong((const byte *) cfa_offset, bigEndian);
231
            long cfa_len = Exiv2::getULong((const byte *) cfa_length, bigEndian);
232
            std::stringstream c_off;
233
            std::stringstream c_len;
234
            c_off << cfa_off;
235
            c_len << cfa_len;
236
            if ( bPrint ) {
237
                out << Internal::indent(depth)
238
                    << Internal::stringFormat("  %8u | %8u | ", 4, 100)
239
                    << "CFA Offset : "
240
                    << c_off.str()
241
                    << std::endl;
242
                out << Internal::indent(depth)
243
                    << Internal::stringFormat("  %8u | %8u | ", 4, 104)
244
                    << "CFA Length : "
245
                    << c_len.str()
246
                    << std::endl;
247
            }
248

  
249
            io_->seek(jpg_img_off, BasicIo::beg); // rewind
250
            DataBuf payload(16); // header is different from chunks
251
            io_->read(payload.pData_, payload.size_);
252
            if ( bPrint ) {
253
                out << Internal::indent(depth)
254
                    << Internal::stringFormat("  %8u | %8u | ", jpg_img_len, jpg_img_off)
255
                    << "jpg image / exif : "
256
                    << Internal::binaryToString(payload, payload.size_)
257
                    << std::endl;
258
            }
259

  
260
            io_->seek(cfa_hdr_off, BasicIo::beg); // rewind
261
            io_->read(payload.pData_, payload.size_);
262
            if ( bPrint ) {
263
                out << Internal::indent(depth)
264
                    << Internal::stringFormat("  %8u | %8u | ", cfa_hdr_len, cfa_hdr_off)
265
                    << "CFA Header: "
266
                    << Internal::binaryToString(payload, payload.size_)
267
                    << std::endl;
268
            }
269

  
270
            io_->seek(cfa_off, BasicIo::beg); // rewind
271
            io_->read(payload.pData_, payload.size_);
272
            if ( bPrint ) {
273
                out << Internal::indent(depth)
274
                    << Internal::stringFormat("  %8u | %8u | ", cfa_len, cfa_off)
275
                    << "CFA : "
276
                    << Internal::binaryToString(payload, payload.size_)
277
                    << std::endl;
278
            }
279
        }
280
    } // RafImage::printStructure
281

  
98 282
    void RafImage::readMetadata()
99 283
    {
100 284
#ifdef DEBUG
......
107 291
            if (io_->error() || io_->eof()) throw Error(14);
108 292
            throw Error(3, "RAF");
109 293
        }
110
        byte const* pData = io_->mmap();
111
        long size = io_->size();
112
        if (size < 88 + 4) throw Error(14); // includes the test for -1
113
        uint32_t const start = getULong(pData + 84, bigEndian) + 12;
114
        if (static_cast<uint32_t>(size) < start) throw Error(14);
294

  
115 295
        clearMetadata();
296

  
297
        io_->seek(84,BasicIo::beg);
298
        byte jpg_img_offset [4];
299
        io_->read(jpg_img_offset, 4);
300
        byte jpg_img_length [4];
301
        io_->read(jpg_img_length, 4);
302
        long jpg_img_off = Exiv2::getULong((const byte *) jpg_img_offset, bigEndian);
303
        long jpg_img_len = Exiv2::getULong((const byte *) jpg_img_length, bigEndian);
304

  
305
        DataBuf buf(jpg_img_len - 12);
306
        io_->seek(jpg_img_off + 12,BasicIo::beg);
307
        io_->read(buf.pData_, buf.size_ - 12);
308
        if (io_->error() || io_->eof()) throw Error(14);
309

  
310
        io_->seek(0,BasicIo::beg); // rewind
311

  
116 312
        ByteOrder bo = TiffParser::decode(exifData_,
117 313
                                          iptcData_,
118 314
                                          xmpData_,
119
                                          pData + start,
120
                                          size - start);
315
                                          buf.pData_,
316
                                          buf.size_);
121 317

  
122
        exifData_["Exif.Image2.JPEGInterchangeFormat"] = getULong(pData + 84, bigEndian);
123
        exifData_["Exif.Image2.JPEGInterchangeFormatLength"] = getULong(pData + 88, bigEndian);
318
        exifData_["Exif.Image2.JPEGInterchangeFormat"] = getULong(jpg_img_offset, bigEndian);
319
        exifData_["Exif.Image2.JPEGInterchangeFormatLength"] = getULong(jpg_img_length, bigEndian);
124 320

  
125 321
        setByteOrder(bo);
126 322
    } // RafImage::readMetadata
exiv2-0.26.as/src/riffvideo.cpp 2017-02-01 07:23:55.000000000 -0500
41 41
#include "tags_int.hpp"
42 42
#include "types.hpp"
43 43
#include "tiffimage_int.hpp"
44
#include "image_int.hpp"
44 45
// + standard includes
45 46
#include <cmath>
46 47

  
......
516 517
        return "video/riff";
517 518
    }
518 519

  
520
    const int RiffVideo::RIFF_TAG_SIZE = 0x4;
521
    const char* RiffVideo::RIFF_CHUNK_HEADER_ICCP = "ICCP";
522
    const char* RiffVideo::RIFF_CHUNK_HEADER_EXIF = "EXIF";
523
    const char* RiffVideo::RIFF_CHUNK_HEADER_XMP  = "XMP ";
524

  
525
    /*!
526
     @brief Function used to check equality of a Tags with a
527
     particular string (ignores case while comparing).
528
     @param buf Data buffer that will contain Tag to compare
529
     @param str char* Pointer to string
530
     @return Returns true if the buffer value is equal to string.
531
     */
532
    bool RiffVideo::equalsRiffTag(Exiv2::DataBuf& buf, const char* str) {
533
        for(int i = 0; i < 4; i++ )
534
            if(toupper(buf.pData_[i]) != str[i])
535
                return false;
536
        return true;
537
    }
538

  
539
    void RiffVideo::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
540
        if (io_->open() != 0) {
541
            throw Error(9, io_->path(), strError());
542
        }
543
        // Ensure this is the correct image type
544
        if (!isRiffType(*io_, true)) {
545
            if (io_->error() || io_->eof()) throw Error(14);
546
            throw Error(3, "RIFF");
547
        }
548

  
549
        bool bPrint  = option==kpsBasic || option==kpsRecursive;
550
        if ( bPrint || option == kpsXMP || option == kpsIccProfile || option == kpsIptcErase ) {
551
            byte      data [RIFF_TAG_SIZE * 2];
552
            io_->read(data, RIFF_TAG_SIZE * 2);
553
            uint64_t filesize = Exiv2::getULong(data + RIFF_TAG_SIZE, littleEndian);
554
            DataBuf  chunkId(5)      ;
555
            chunkId.pData_[4] = '\0' ;
556

  
557
            if ( bPrint ) {
558
                out << Internal::indent(depth)
559
                    << "STRUCTURE OF RIFF FILE: "
560
                    << io().path()
561
                    << std::endl;
562
                out << Internal::indent(depth)
563
                    << Internal::stringFormat(" Chunk |       Length |       Offset | Payload")
564
                    << std::endl;
565
            }
566

  
567
            io_->seek(0,BasicIo::beg); // rewind
568
            while ( !io_->eof() && (uint64_t) io_->tell() < filesize) {
569
                uint64_t offset = (uint64_t) io_->tell();
570
                byte     size_buff[RIFF_TAG_SIZE];
571
                io_->read(chunkId.pData_, RIFF_TAG_SIZE);
572
                io_->read(size_buff, RIFF_TAG_SIZE);
573
                long size = Exiv2::getULong(size_buff, littleEndian);
574
                DataBuf payload(offset?size:RIFF_TAG_SIZE); // header is different from chunks
575
                io_->read(payload.pData_, payload.size_);
576

  
577
                if ( bPrint ) {
578
                    out << Internal::indent(depth)
579
                        << Internal::stringFormat("  %s | %12u | %12u | ", (const char*)chunkId.pData_,size,(uint32_t)offset)
580
                        << Internal::binaryToString(payload,payload.size_>32?32:payload.size_)
581
                        << std::endl;
582
                }
583

  
584
                if ( equalsRiffTag(chunkId, RIFF_CHUNK_HEADER_EXIF) && option==kpsRecursive ) {
585
                    // create memio object with the payload, then print the structure
586
                    BasicIo::AutoPtr p = BasicIo::AutoPtr(new MemIo(payload.pData_,payload.size_));
587
                    printTiffStructure(*p,out,option,depth);
588
                }
589

  
590
                bool bPrintPayload = (equalsRiffTag(chunkId, RIFF_CHUNK_HEADER_XMP) && option==kpsXMP)
591
                                     || (equalsRiffTag(chunkId, RIFF_CHUNK_HEADER_ICCP) && option==kpsIccProfile)
592
                ;
593
                if ( bPrintPayload ) {
594
                    out.write((const char*) payload.pData_,payload.size_);
595
                }
596

  
597
                if ( offset && io_->tell() % 2 ) io_->seek(+1, BasicIo::cur); // skip padding byte on sub-chunks
598
            }
599
        }
600
    } // RiffVideo::printStructure
601

  
519 602
    void RiffVideo::writeMetadata()
520 603
    {
521 604
    } // RiffVideo::writeMetadata
exiv2-0.26.as/src/rw2image.cpp 2017-02-01 12:26:49.000000000 -0500
100 100
        throw(Error(32, "Image comment", "RW2"));
101 101
    }
102 102

  
103
    void Rw2Image::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
104
        std::cout << "RW2 IMAGE" << std::endl;
105
        if (io_->open() != 0) throw Error(9, io_->path(), strError());
106
        // Ensure that this is the correct image type
107
        if ( imageType() == ImageType::none )
108
            if (!isRw2Type(*io_, false)) {
109
                if (io_->error() || io_->eof()) throw Error(14);
110
                throw Error(15);
111
            }
112

  
113
        io_->seek(0,BasicIo::beg);
114

  
115
        printTiffStructure(io(),out,option,depth-1);
116
    } // Rw2Image::printStructure
117

  
103 118
    void Rw2Image::readMetadata()
104 119
    {
105 120
#ifdef DEBUG
......
115 130
            throw Error(3, "RW2");
116 131
        }
117 132
        clearMetadata();
133
        std::ofstream devnull;
134
        printStructure(devnull, kpsRecursive, 0);
118 135
        ByteOrder bo = Rw2Parser::decode(exifData_,
119 136
                                         iptcData_,
120 137
                                         xmpData_,
exiv2-0.26.as/src/webpimage.cpp 2017-02-01 07:23:55.000000000 -0500
412 412

  
413 413
    void WebPImage::printStructure(std::ostream& out, PrintStructureOption option,int depth)
414 414
    {
415
        if (io_->open() != 0) throw Error(9, io_->path(), strError());
416
        IoCloser closer(*io_);
415
        if (io_->open() != 0) {
416
            throw Error(9, io_->path(), strError());
417
        }
417 418
        // Ensure this is the correct image type
418 419
        if (!isWebPType(*io_, true)) {
419 420
            if (io_->error() || io_->eof()) throw Error(14);
(3-3/3)