~ubuntu-branches/ubuntu/utopic/libopenraw/utopic

« back to all changes in this revision

Viewing changes to demo/cfa.cpp

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-04-03 22:41:08 UTC
  • mto: (7.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20090403224108-f90nhq50nv5ze5ce
Tags: upstream-0.0.6
ImportĀ upstreamĀ versionĀ 0.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
 
 
22
#include <stdlib.h>
23
23
#include <iostream>
24
24
#include <libopenraw/libopenraw.h>
25
25
#include <libopenraw/debug.h>
76
76
        else {
77
77
                f = fopen("image.cfa", "wb");
78
78
        }
79
 
        fwrite(rdata.data(), 1, rdata.size(), f);
 
79
    // Convert data byte order to most significant byte first
 
80
    if(rdata.bpc() == 16) {
 
81
                uint8_t* buf = (uint8_t*)malloc(rdata.size());
 
82
                uint8_t* p = buf;
 
83
        uint16_t* n = reinterpret_cast<uint16_t*>(rdata.data());
 
84
        for(size_t i = 0; i < rdata.size() / 2; i++) {
 
85
            unsigned char lo = n[i] & 0xFF;
 
86
            unsigned char hi = n[i] >> 8;
 
87
            p[i * 2]   = hi;
 
88
            p[i * 2 + 1] = lo;
 
89
        }
 
90
                fwrite(buf, 1, rdata.size(), f);
 
91
                free(buf);
 
92
    }
 
93
        else {
 
94
                fwrite(rdata.data(), 1, rdata.size(), f);
 
95
        }
80
96
        fclose(f);
81
97
        
82
98
        return 0;