Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build #2458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,7 @@ class BufferReader : public Image::Reader {
bool hasBytes(unsigned n) const override { return (_idx + n - 1 < _len); }

uint8_t getNext() override {
if (_idx < _len) {
return _buf[_idx++];
}
return _buf[_idx++];
}

void skipBytes(unsigned n) override { _idx += n; }
Expand All @@ -789,9 +787,9 @@ class BufferReader : public Image::Reader {
class StreamReader : public Image::Reader {
public:
StreamReader(FILE *stream) : _stream(stream), _len(0), _idx(0) {
fseeko(_stream, 0, SEEK_END);
_len = ftello(_stream);
fseeko(_stream, 0, SEEK_SET);
fseek(_stream, 0, SEEK_END);
_len = ftell(_stream);
fseek(_stream, 0, SEEK_SET);
}

bool hasBytes(unsigned n) const override { return (_idx + n - 1 < _len); }
Expand All @@ -803,13 +801,13 @@ class StreamReader : public Image::Reader {

void skipBytes(unsigned n) override {
_idx += n;
fseeko(_stream, _idx, SEEK_SET);
fseek(_stream, _idx, SEEK_SET);
}

private:
FILE* _stream;
off_t _len;
off_t _idx;
unsigned _len;
unsigned _idx;
};

void Image::jpegToARGB(jpeg_decompress_struct* args, uint8_t* data, uint8_t* src, JPEGDecodeL decode) {
Expand Down Expand Up @@ -1289,8 +1287,12 @@ Image::getExifOrientation(Reader& jpeg) {
};
// The first two bytes of TIFF header are "II" if little-endian ("Intel")
// and "MM" if big-endian ("Motorola")
auto readUint32 = (isLE ? readUint32Little : readUint32Big);
auto readUint16 = (isLE ? readUint16Little : readUint16Big);
auto readUint32 = [readUint32Little, readUint32Big, isLE](Reader &jpeg) -> uint32_t {
return isLE ? readUint32Little(jpeg) : readUint32Big(jpeg);
};
auto readUint16 = [readUint16Little, readUint16Big, isLE](Reader &jpeg) -> uint32_t {
return isLE ? readUint16Little(jpeg) : readUint16Big(jpeg);
};
// offset to the IFD0 (offset from beginning of TIFF header, II/MM,
// which is 8 bytes before where we are after reading the uint32)
jpeg.skipBytes(readUint32(jpeg) - 8);
Expand Down
Loading