Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_Image.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. ImagePixelData::ImagePixelData (Image::PixelFormat format, int w, int h)
  21. : pixelFormat (format), width (w), height (h)
  22. {
  23. jassert (format == Image::RGB || format == Image::ARGB || format == Image::SingleChannel);
  24. jassert (w > 0 && h > 0); // It's illegal to create a zero-sized image!
  25. }
  26. ImagePixelData::~ImagePixelData()
  27. {
  28. listeners.call ([this] (Listener& l) { l.imageDataBeingDeleted (this); });
  29. }
  30. void ImagePixelData::sendDataChangeMessage()
  31. {
  32. listeners.call ([this] (Listener& l) { l.imageDataChanged (this); });
  33. }
  34. int ImagePixelData::getSharedCount() const noexcept
  35. {
  36. return getReferenceCount();
  37. }
  38. //==============================================================================
  39. ImageType::ImageType() {}
  40. ImageType::~ImageType() {}
  41. Image ImageType::convert (const Image& source) const
  42. {
  43. if (source.isNull() || getTypeID() == source.getPixelData()->createType()->getTypeID())
  44. return source;
  45. const Image::BitmapData src (source, Image::BitmapData::readOnly);
  46. Image newImage (create (src.pixelFormat, src.width, src.height, false));
  47. Image::BitmapData dest (newImage, Image::BitmapData::writeOnly);
  48. if (src.pixelStride == dest.pixelStride && src.pixelFormat == dest.pixelFormat)
  49. {
  50. for (int y = 0; y < dest.height; ++y)
  51. memcpy (dest.getLinePointer (y), src.getLinePointer (y), (size_t) dest.lineStride);
  52. }
  53. else
  54. {
  55. for (int y = 0; y < dest.height; ++y)
  56. for (int x = 0; x < dest.width; ++x)
  57. dest.setPixelColour (x, y, src.getPixelColour (x, y));
  58. }
  59. return newImage;
  60. }
  61. //==============================================================================
  62. class SoftwarePixelData : public ImagePixelData
  63. {
  64. public:
  65. SoftwarePixelData (Image::PixelFormat formatToUse, int w, int h, bool clearImage)
  66. : ImagePixelData (formatToUse, w, h),
  67. pixelStride (formatToUse == Image::RGB ? 3 : ((formatToUse == Image::ARGB) ? 4 : 1)),
  68. lineStride ((pixelStride * jmax (1, w) + 3) & ~3)
  69. {
  70. imageData.allocate ((size_t) lineStride * (size_t) jmax (1, h), clearImage);
  71. }
  72. std::unique_ptr<LowLevelGraphicsContext> createLowLevelContext() override
  73. {
  74. sendDataChangeMessage();
  75. return std::make_unique<LowLevelGraphicsSoftwareRenderer> (Image (*this));
  76. }
  77. void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override
  78. {
  79. bitmap.data = imageData + (size_t) x * (size_t) pixelStride + (size_t) y * (size_t) lineStride;
  80. bitmap.pixelFormat = pixelFormat;
  81. bitmap.lineStride = lineStride;
  82. bitmap.pixelStride = pixelStride;
  83. if (mode != Image::BitmapData::readOnly)
  84. sendDataChangeMessage();
  85. }
  86. ImagePixelData::Ptr clone() override
  87. {
  88. auto s = new SoftwarePixelData (pixelFormat, width, height, false);
  89. memcpy (s->imageData, imageData, (size_t) lineStride * (size_t) height);
  90. return *s;
  91. }
  92. std::unique_ptr<ImageType> createType() const override { return std::make_unique<SoftwareImageType>(); }
  93. private:
  94. HeapBlock<uint8> imageData;
  95. const int pixelStride, lineStride;
  96. JUCE_LEAK_DETECTOR (SoftwarePixelData)
  97. };
  98. SoftwareImageType::SoftwareImageType() {}
  99. SoftwareImageType::~SoftwareImageType() {}
  100. ImagePixelData::Ptr SoftwareImageType::create (Image::PixelFormat format, int width, int height, bool clearImage) const
  101. {
  102. return *new SoftwarePixelData (format, width, height, clearImage);
  103. }
  104. int SoftwareImageType::getTypeID() const
  105. {
  106. return 2;
  107. }
  108. //==============================================================================
  109. NativeImageType::NativeImageType() {}
  110. NativeImageType::~NativeImageType() {}
  111. int NativeImageType::getTypeID() const
  112. {
  113. return 1;
  114. }
  115. #if JUCE_WINDOWS || JUCE_LINUX
  116. ImagePixelData::Ptr NativeImageType::create (Image::PixelFormat format, int width, int height, bool clearImage) const
  117. {
  118. return new SoftwarePixelData (format, width, height, clearImage);
  119. }
  120. #endif
  121. //==============================================================================
  122. class SubsectionPixelData : public ImagePixelData
  123. {
  124. public:
  125. SubsectionPixelData (ImagePixelData::Ptr source, Rectangle<int> r)
  126. : ImagePixelData (source->pixelFormat, r.getWidth(), r.getHeight()),
  127. sourceImage (std::move (source)), area (r)
  128. {
  129. }
  130. std::unique_ptr<LowLevelGraphicsContext> createLowLevelContext() override
  131. {
  132. auto g = sourceImage->createLowLevelContext();
  133. g->clipToRectangle (area);
  134. g->setOrigin (area.getPosition());
  135. return g;
  136. }
  137. void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override
  138. {
  139. sourceImage->initialiseBitmapData (bitmap, x + area.getX(), y + area.getY(), mode);
  140. if (mode != Image::BitmapData::readOnly)
  141. sendDataChangeMessage();
  142. }
  143. ImagePixelData::Ptr clone() override
  144. {
  145. jassert (getReferenceCount() > 0); // (This method can't be used on an unowned pointer, as it will end up self-deleting)
  146. auto type = createType();
  147. Image newImage (type->create (pixelFormat, area.getWidth(), area.getHeight(), pixelFormat != Image::RGB));
  148. {
  149. Graphics g (newImage);
  150. g.drawImageAt (Image (*this), 0, 0);
  151. }
  152. return *newImage.getPixelData();
  153. }
  154. std::unique_ptr<ImageType> createType() const override { return sourceImage->createType(); }
  155. /* as we always hold a reference to image, don't double count */
  156. int getSharedCount() const noexcept override { return getReferenceCount() + sourceImage->getSharedCount() - 1; }
  157. private:
  158. friend class Image;
  159. const ImagePixelData::Ptr sourceImage;
  160. const Rectangle<int> area;
  161. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubsectionPixelData)
  162. };
  163. Image Image::getClippedImage (const Rectangle<int>& area) const
  164. {
  165. if (area.contains (getBounds()))
  166. return *this;
  167. auto validArea = area.getIntersection (getBounds());
  168. if (validArea.isEmpty())
  169. return {};
  170. return Image (*new SubsectionPixelData (image, validArea));
  171. }
  172. //==============================================================================
  173. Image::Image() noexcept
  174. {
  175. }
  176. Image::Image (ReferenceCountedObjectPtr<ImagePixelData> instance) noexcept
  177. : image (std::move (instance))
  178. {
  179. }
  180. Image::Image (PixelFormat format, int width, int height, bool clearImage)
  181. : image (NativeImageType().create (format, width, height, clearImage))
  182. {
  183. }
  184. Image::Image (PixelFormat format, int width, int height, bool clearImage, const ImageType& type)
  185. : image (type.create (format, width, height, clearImage))
  186. {
  187. }
  188. Image::Image (const Image& other) noexcept
  189. : image (other.image)
  190. {
  191. }
  192. Image& Image::operator= (const Image& other)
  193. {
  194. image = other.image;
  195. return *this;
  196. }
  197. Image::Image (Image&& other) noexcept
  198. : image (std::move (other.image))
  199. {
  200. }
  201. Image& Image::operator= (Image&& other) noexcept
  202. {
  203. image = std::move (other.image);
  204. return *this;
  205. }
  206. Image::~Image()
  207. {
  208. }
  209. JUCE_DECLARE_DEPRECATED_STATIC (const Image Image::null;)
  210. int Image::getReferenceCount() const noexcept { return image == nullptr ? 0 : image->getSharedCount(); }
  211. int Image::getWidth() const noexcept { return image == nullptr ? 0 : image->width; }
  212. int Image::getHeight() const noexcept { return image == nullptr ? 0 : image->height; }
  213. Rectangle<int> Image::getBounds() const noexcept { return image == nullptr ? Rectangle<int>() : Rectangle<int> (image->width, image->height); }
  214. Image::PixelFormat Image::getFormat() const noexcept { return image == nullptr ? UnknownFormat : image->pixelFormat; }
  215. bool Image::isARGB() const noexcept { return getFormat() == ARGB; }
  216. bool Image::isRGB() const noexcept { return getFormat() == RGB; }
  217. bool Image::isSingleChannel() const noexcept { return getFormat() == SingleChannel; }
  218. bool Image::hasAlphaChannel() const noexcept { return getFormat() != RGB; }
  219. std::unique_ptr<LowLevelGraphicsContext> Image::createLowLevelContext() const
  220. {
  221. if (image != nullptr)
  222. return image->createLowLevelContext();
  223. return {};
  224. }
  225. void Image::duplicateIfShared()
  226. {
  227. if (getReferenceCount() > 1)
  228. image = image->clone();
  229. }
  230. Image Image::createCopy() const
  231. {
  232. if (image != nullptr)
  233. return Image (image->clone());
  234. return {};
  235. }
  236. Image Image::rescaled (int newWidth, int newHeight, Graphics::ResamplingQuality quality) const
  237. {
  238. if (image == nullptr || (image->width == newWidth && image->height == newHeight))
  239. return *this;
  240. auto type = image->createType();
  241. Image newImage (type->create (image->pixelFormat, newWidth, newHeight, hasAlphaChannel()));
  242. Graphics g (newImage);
  243. g.setImageResamplingQuality (quality);
  244. g.drawImageTransformed (*this, AffineTransform::scale ((float) newWidth / (float) image->width,
  245. (float) newHeight / (float) image->height), false);
  246. return newImage;
  247. }
  248. Image Image::convertedToFormat (PixelFormat newFormat) const
  249. {
  250. if (image == nullptr || newFormat == image->pixelFormat)
  251. return *this;
  252. auto w = image->width, h = image->height;
  253. auto type = image->createType();
  254. Image newImage (type->create (newFormat, w, h, false));
  255. if (newFormat == SingleChannel)
  256. {
  257. if (! hasAlphaChannel())
  258. {
  259. newImage.clear (getBounds(), Colours::black);
  260. }
  261. else
  262. {
  263. const BitmapData destData (newImage, 0, 0, w, h, BitmapData::writeOnly);
  264. const BitmapData srcData (*this, 0, 0, w, h);
  265. for (int y = 0; y < h; ++y)
  266. {
  267. auto src = reinterpret_cast<const PixelARGB*> (srcData.getLinePointer (y));
  268. auto dst = destData.getLinePointer (y);
  269. for (int x = 0; x < w; ++x)
  270. dst[x] = src[x].getAlpha();
  271. }
  272. }
  273. }
  274. else if (image->pixelFormat == SingleChannel && newFormat == Image::ARGB)
  275. {
  276. const BitmapData destData (newImage, 0, 0, w, h, BitmapData::writeOnly);
  277. const BitmapData srcData (*this, 0, 0, w, h);
  278. for (int y = 0; y < h; ++y)
  279. {
  280. auto src = reinterpret_cast<const PixelAlpha*> (srcData.getLinePointer (y));
  281. auto dst = reinterpret_cast<PixelARGB*> (destData.getLinePointer (y));
  282. for (int x = 0; x < w; ++x)
  283. dst[x].set (src[x]);
  284. }
  285. }
  286. else
  287. {
  288. if (hasAlphaChannel())
  289. newImage.clear (getBounds());
  290. Graphics g (newImage);
  291. g.drawImageAt (*this, 0, 0);
  292. }
  293. return newImage;
  294. }
  295. NamedValueSet* Image::getProperties() const
  296. {
  297. return image == nullptr ? nullptr : &(image->userData);
  298. }
  299. //==============================================================================
  300. Image::BitmapData::BitmapData (Image& im, int x, int y, int w, int h, BitmapData::ReadWriteMode mode)
  301. : width (w), height (h)
  302. {
  303. // The BitmapData class must be given a valid image, and a valid rectangle within it!
  304. jassert (im.image != nullptr);
  305. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= im.getWidth() && y + h <= im.getHeight());
  306. im.image->initialiseBitmapData (*this, x, y, mode);
  307. jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
  308. }
  309. Image::BitmapData::BitmapData (const Image& im, int x, int y, int w, int h)
  310. : width (w), height (h)
  311. {
  312. // The BitmapData class must be given a valid image, and a valid rectangle within it!
  313. jassert (im.image != nullptr);
  314. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= im.getWidth() && y + h <= im.getHeight());
  315. im.image->initialiseBitmapData (*this, x, y, readOnly);
  316. jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
  317. }
  318. Image::BitmapData::BitmapData (const Image& im, BitmapData::ReadWriteMode mode)
  319. : width (im.getWidth()),
  320. height (im.getHeight())
  321. {
  322. // The BitmapData class must be given a valid image!
  323. jassert (im.image != nullptr);
  324. im.image->initialiseBitmapData (*this, 0, 0, mode);
  325. jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
  326. }
  327. Image::BitmapData::~BitmapData()
  328. {
  329. }
  330. Colour Image::BitmapData::getPixelColour (int x, int y) const noexcept
  331. {
  332. jassert (isPositiveAndBelow (x, width) && isPositiveAndBelow (y, height));
  333. auto pixel = getPixelPointer (x, y);
  334. switch (pixelFormat)
  335. {
  336. case Image::ARGB: return Colour ( ((const PixelARGB*) pixel)->getUnpremultiplied());
  337. case Image::RGB: return Colour (*((const PixelRGB*) pixel));
  338. case Image::SingleChannel: return Colour (*((const PixelAlpha*) pixel));
  339. case Image::UnknownFormat:
  340. default: jassertfalse; break;
  341. }
  342. return {};
  343. }
  344. void Image::BitmapData::setPixelColour (int x, int y, Colour colour) const noexcept
  345. {
  346. jassert (isPositiveAndBelow (x, width) && isPositiveAndBelow (y, height));
  347. auto pixel = getPixelPointer (x, y);
  348. auto col = colour.getPixelARGB();
  349. switch (pixelFormat)
  350. {
  351. case Image::ARGB: ((PixelARGB*) pixel)->set (col); break;
  352. case Image::RGB: ((PixelRGB*) pixel)->set (col); break;
  353. case Image::SingleChannel: ((PixelAlpha*) pixel)->set (col); break;
  354. case Image::UnknownFormat:
  355. default: jassertfalse; break;
  356. }
  357. }
  358. //==============================================================================
  359. void Image::clear (const Rectangle<int>& area, Colour colourToClearTo)
  360. {
  361. if (image != nullptr)
  362. {
  363. auto g = image->createLowLevelContext();
  364. g->setFill (colourToClearTo);
  365. g->fillRect (area, true);
  366. }
  367. }
  368. //==============================================================================
  369. Colour Image::getPixelAt (int x, int y) const
  370. {
  371. if (isPositiveAndBelow (x, getWidth()) && isPositiveAndBelow (y, getHeight()))
  372. {
  373. const BitmapData srcData (*this, x, y, 1, 1);
  374. return srcData.getPixelColour (0, 0);
  375. }
  376. return {};
  377. }
  378. void Image::setPixelAt (int x, int y, Colour colour)
  379. {
  380. if (isPositiveAndBelow (x, getWidth()) && isPositiveAndBelow (y, getHeight()))
  381. {
  382. const BitmapData destData (*this, x, y, 1, 1, BitmapData::writeOnly);
  383. destData.setPixelColour (0, 0, colour);
  384. }
  385. }
  386. void Image::multiplyAlphaAt (int x, int y, float multiplier)
  387. {
  388. if (isPositiveAndBelow (x, getWidth()) && isPositiveAndBelow (y, getHeight())
  389. && hasAlphaChannel())
  390. {
  391. const BitmapData destData (*this, x, y, 1, 1, BitmapData::readWrite);
  392. if (isARGB())
  393. reinterpret_cast<PixelARGB*> (destData.data)->multiplyAlpha (multiplier);
  394. else
  395. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  396. }
  397. }
  398. template <class PixelType>
  399. struct PixelIterator
  400. {
  401. template <class PixelOperation>
  402. static void iterate (const Image::BitmapData& data, const PixelOperation& pixelOp)
  403. {
  404. for (int y = 0; y < data.height; ++y)
  405. {
  406. auto p = data.getLinePointer (y);
  407. for (int x = 0; x < data.width; ++x)
  408. {
  409. pixelOp (*reinterpret_cast<PixelType*> (p));
  410. p += data.pixelStride;
  411. }
  412. }
  413. }
  414. };
  415. template <class PixelOperation>
  416. static void performPixelOp (const Image::BitmapData& data, const PixelOperation& pixelOp)
  417. {
  418. switch (data.pixelFormat)
  419. {
  420. case Image::ARGB: PixelIterator<PixelARGB> ::iterate (data, pixelOp); break;
  421. case Image::RGB: PixelIterator<PixelRGB> ::iterate (data, pixelOp); break;
  422. case Image::SingleChannel: PixelIterator<PixelAlpha>::iterate (data, pixelOp); break;
  423. case Image::UnknownFormat:
  424. default: jassertfalse; break;
  425. }
  426. }
  427. struct AlphaMultiplyOp
  428. {
  429. float alpha;
  430. template <class PixelType>
  431. void operator() (PixelType& pixel) const
  432. {
  433. pixel.multiplyAlpha (alpha);
  434. }
  435. };
  436. void Image::multiplyAllAlphas (float amountToMultiplyBy)
  437. {
  438. jassert (hasAlphaChannel());
  439. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite);
  440. performPixelOp (destData, AlphaMultiplyOp { amountToMultiplyBy });
  441. }
  442. struct DesaturateOp
  443. {
  444. template <class PixelType>
  445. void operator() (PixelType& pixel) const
  446. {
  447. pixel.desaturate();
  448. }
  449. };
  450. void Image::desaturate()
  451. {
  452. if (isARGB() || isRGB())
  453. {
  454. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite);
  455. performPixelOp (destData, DesaturateOp());
  456. }
  457. }
  458. void Image::createSolidAreaMask (RectangleList<int>& result, float alphaThreshold) const
  459. {
  460. if (hasAlphaChannel())
  461. {
  462. auto threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  463. SparseSet<int> pixelsOnRow;
  464. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  465. for (int y = 0; y < srcData.height; ++y)
  466. {
  467. pixelsOnRow.clear();
  468. auto lineData = srcData.getLinePointer (y);
  469. if (isARGB())
  470. {
  471. for (int x = 0; x < srcData.width; ++x)
  472. {
  473. if (reinterpret_cast<const PixelARGB*> (lineData)->getAlpha() >= threshold)
  474. pixelsOnRow.addRange (Range<int> (x, x + 1));
  475. lineData += srcData.pixelStride;
  476. }
  477. }
  478. else
  479. {
  480. for (int x = 0; x < srcData.width; ++x)
  481. {
  482. if (*lineData >= threshold)
  483. pixelsOnRow.addRange (Range<int> (x, x + 1));
  484. lineData += srcData.pixelStride;
  485. }
  486. }
  487. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  488. {
  489. auto range = pixelsOnRow.getRange (i);
  490. result.add (Rectangle<int> (range.getStart(), y, range.getLength(), 1));
  491. }
  492. result.consolidate();
  493. }
  494. }
  495. else
  496. {
  497. result.add (0, 0, getWidth(), getHeight());
  498. }
  499. }
  500. void Image::moveImageSection (int dx, int dy,
  501. int sx, int sy,
  502. int w, int h)
  503. {
  504. if (dx < 0)
  505. {
  506. w += dx;
  507. sx -= dx;
  508. dx = 0;
  509. }
  510. if (dy < 0)
  511. {
  512. h += dy;
  513. sy -= dy;
  514. dy = 0;
  515. }
  516. if (sx < 0)
  517. {
  518. w += sx;
  519. dx -= sx;
  520. sx = 0;
  521. }
  522. if (sy < 0)
  523. {
  524. h += sy;
  525. dy -= sy;
  526. sy = 0;
  527. }
  528. const int minX = jmin (dx, sx);
  529. const int minY = jmin (dy, sy);
  530. w = jmin (w, getWidth() - jmax (sx, dx));
  531. h = jmin (h, getHeight() - jmax (sy, dy));
  532. if (w > 0 && h > 0)
  533. {
  534. auto maxX = jmax (dx, sx) + w;
  535. auto maxY = jmax (dy, sy) + h;
  536. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, BitmapData::readWrite);
  537. auto dst = destData.getPixelPointer (dx - minX, dy - minY);
  538. auto src = destData.getPixelPointer (sx - minX, sy - minY);
  539. auto lineSize = (size_t) destData.pixelStride * (size_t) w;
  540. if (dy > sy)
  541. {
  542. while (--h >= 0)
  543. {
  544. const int offset = h * destData.lineStride;
  545. memmove (dst + offset, src + offset, lineSize);
  546. }
  547. }
  548. else if (dst != src)
  549. {
  550. while (--h >= 0)
  551. {
  552. memmove (dst, src, lineSize);
  553. dst += destData.lineStride;
  554. src += destData.lineStride;
  555. }
  556. }
  557. }
  558. }
  559. } // namespace juce