42 Context(
SvStream& rInStream, tsize_t nInSize)
51static tsize_t
tiff_read(thandle_t handle, tdata_t buf, tsize_t size)
53 Context* pContext =
static_cast<Context*
>(handle);
54 tsize_t nRead = pContext->rStream.ReadBytes(buf,
size);
57 if (nRead < size && !pContext->nShortReads)
59 memset(
static_cast<char*
>(buf) + nRead, 0,
size - nRead);
60 ++pContext->nShortReads;
71static toff_t
tiff_seek(thandle_t handle, toff_t offset,
int whence)
73 Context* pContext =
static_cast<Context*
>(handle);
78 pContext->rStream.Seek(offset);
81 pContext->rStream.SeekRel(offset);
85 pContext->rStream.SeekRel(offset);
88 assert(
false &&
"unknown seek type");
92 return pContext->rStream.Tell();
102 Context* pContext =
static_cast<Context*
>(handle);
103 return pContext->nSize;
108 auto origErrorHandler = TIFFSetErrorHandler(
nullptr);
109 auto origWarningHandler = TIFFSetWarningHandler(
nullptr);
111 TIFFSetErrorHandler(origErrorHandler);
112 TIFFSetWarningHandler(origWarningHandler);
116 TIFF* tif = TIFFClientOpen(
"libtiff-svstream",
"r", &aContext,
124 const auto nOrigPos = rTIFF.
Tell();
134 if (TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &
w) != 1)
136 SAL_WARN(
"filter.tiff",
"missing width");
140 if (TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &
h) != 1)
142 SAL_WARN(
"filter.tiff",
"missing height");
148 SAL_WARN(
"filter.tiff",
"image too large");
152 uint32_t nPixelsRequired;
158 SAL_WARN(
"filter.tiff",
"skipping oversized tiff image " <<
w <<
" x " <<
h);
164 const uint64_t MAX_SIZE = 200000000;
165 if (TIFFTileSize64(tif) > MAX_SIZE || nPixelsRequired > MAX_SIZE)
167 SAL_WARN(
"filter.tiff",
"skipping large tiffs");
172 std::vector<uint32_t> raster(nPixelsRequired);
173 if (TIFFReadRGBAImageOriented(tif,
w,
h, raster.data(), ORIENTATION_TOPLEFT, 1))
179 SAL_WARN(
"filter.tiff",
"cannot create image " <<
w <<
" x " <<
h);
187 SAL_WARN(
"filter.tiff",
"cannot create alpha " <<
w <<
" x " <<
h);
201 uint16_t nOrientation;
202 if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &nOrientation) != 1)
205 for (uint32_t
y = 0;
y <
h; ++
y)
207 const uint32_t* src = raster.data() +
w *
y;
208 for (uint32_t
x = 0;
x <
w; ++
x)
216 switch (nOrientation)
218 case ORIENTATION_LEFTBOT:
226 access->SetPixel(
y, dest,
Color(r, g, b));
227 accessAlpha->SetPixelIndex(
y, dest, 255 -
a);
237 BitmapEx aBitmapEx(bitmap, bitmapAlpha);
241 switch (nOrientation)
243 case ORIENTATION_LEFTBOT:
253 aAnimation.
Insert(aAnimationBitmap);
255 }
while (TIFFReadDirectory(tif));
259 const auto nImages = aAnimation.
Count();
265 rGraphic = aAnimation;
273 rTIFF.
Seek(nOrigPos);
#define ANIMATION_TIMEOUT_ON_CLICK
const BitmapEx & GetBitmapEx() const
bool Insert(const AnimationBitmap &rAnimationBitmap)
bool Rotate(Degree10 nAngle10, const Color &rFillColor)
Rotate bitmap by the specified angle.
const Size & GetSizePixel() const
sal_uInt64 Seek(sal_uInt64 nPos)
sal_uInt64 remainingSize()
This template handles BitmapAccess the RAII way.
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
static tsize_t tiff_write(thandle_t, tdata_t, tsize_t)
static int tiff_close(thandle_t)
static toff_t tiff_size(thandle_t handle)
static toff_t tiff_seek(thandle_t handle, toff_t offset, int whence)
bool ImportTiffGraphicImport(SvStream &rTIFF, Graphic &rGraphic)
static tsize_t tiff_read(thandle_t handle, tdata_t buf, tsize_t size)
#define SAL_WARN(area, stream)
std::enable_if< std::is_signed< T >::value, bool >::type checked_multiply(T a, T b, T &result)
#define STREAM_SEEK_TO_END