1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*
* Copyright (C) 2006 - 2017 René Rebe, ExactCODE GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2. A copy of the GNU General
* Public License can be found in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
* ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* All rights reserved. Commercial licensing options are
* available from the copyright holder ExactCODE GmbH Germany.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "raw.hh"
int RAWCodec::readImage(std::istream* stream, Image& image, const std::string& decompress)
{
if (image.w <= 0 || image.bps == 0 || image.spp == 0) {
std::cerr << "RAWCodec: image parameters not sufficiently defined!" << std::endl;
return false;
}
int h = image.h;
if (h > 0) // if we know the height up-front
image.resize(image.w, image.h);
int y = 0;
for (y = 0; h <= 0 || y < h; ++y)
{
if (h <= 0) // height not known up-front, resize line by line
image.resize (image.w, y + 1);
stream->read((char*)image.getRawData() + image.stride() * y,
image.stride());
if (!stream->good())
break;
}
if (h > 0)
{
if (y <= h) {
std::cerr << "RAWCodec: Error reading line: " << y << std::endl;
return false;
}
return true;
}
else
{
if (y == 0) {
std::cerr << "RAWCodec: Error reading a line of image with undefined height at all (stride: " << image.stride() << ")" << std::endl;
return false;
}
image.resize (image.w, y); // final size of scanlines fully read
return true;
}
}
bool RAWCodec::writeImage (std::ostream* stream, Image& image, int quality,
const std::string& compress)
{
if (!image.getRawData())
return false;
stream->write((char*)image.getRawData(), image.stride()*image.h);
return stream->good();
}
RAWCodec raw_loader;
|