From 77884757b2719bc92b0b78a4d7fe3b35b5d1599d Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Fri, 15 Nov 2024 22:01:00 -0500 Subject: [PATCH] fix windows build broke in #2296 because we don't run tests on PRs for some reason - getNext didn't return in all paths. Check wasn't necessary. - Windows doesn't have fseeko or ftello. I highly doubt we'll ever need 64 bits to address images. - Lambda functions get their own anonymous types and C++ standards don't require them to be interchangeable. --- src/Image.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index 970cd2e28..559f8a36c 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -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; } @@ -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); } @@ -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) { @@ -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);