MCPcopy Create free account
hub / github.com/benfry/processing4 / blitResize

Method blitResize

core/src/processing/core/PImage.java:1765–1818  ·  view source on GitHub ↗

Internal blitter/resizer/copier from toxi. Uses bilinear filtering if smooth() has been enabled 'mode' determines the blending mode used in the process.

(PImage img,
                          int srcX1, int srcY1, int srcX2, int srcY2,
                          int[] destPixels, int screenW, int screenH,
                          int destX1, int destY1, int destX2, int destY2,
                          int mode, boolean smooth)

Source from the content-addressed store, hash-verified

1763 * 'mode' determines the blending mode used in the process.
1764 */
1765 private void blitResize(PImage img,
1766 int srcX1, int srcY1, int srcX2, int srcY2,
1767 int[] destPixels, int screenW, int screenH,
1768 int destX1, int destY1, int destX2, int destY2,
1769 int mode, boolean smooth) {
1770 if (srcX1 < 0) srcX1 = 0;
1771 if (srcY1 < 0) srcY1 = 0;
1772 if (srcX2 > img.pixelWidth) srcX2 = img.pixelWidth;
1773 if (srcY2 > img.pixelHeight) srcY2 = img.pixelHeight;
1774
1775 int srcW = srcX2 - srcX1;
1776 int srcH = srcY2 - srcY1;
1777 int destW = destX2 - destX1;
1778 int destH = destY2 - destY1;
1779
1780 if (!smooth) {
1781 srcW++;
1782 srcH++;
1783 }
1784
1785 if (destW <= 0 || destH <= 0 ||
1786 srcW <= 0 || srcH <= 0 ||
1787 destX1 >= screenW || destY1 >= screenH ||
1788 srcX1 >= img.pixelWidth || srcY1 >= img.pixelHeight) {
1789 return;
1790 }
1791
1792 int dx = (int) (srcW / (float) destW * PRECISIONF);
1793 int dy = (int) (srcH / (float) destH * PRECISIONF);
1794
1795 srcXOffset = destX1 < 0 ? -destX1 * dx : srcX1 * PRECISIONF;
1796 srcYOffset = destY1 < 0 ? -destY1 * dy : srcY1 * PRECISIONF;
1797
1798 if (destX1 < 0) {
1799 destW += destX1;
1800 destX1 = 0;
1801 }
1802 if (destY1 < 0) {
1803 destH += destY1;
1804 destY1 = 0;
1805 }
1806
1807 destW = min(destW, screenW - destX1);
1808 destH = min(destH, screenH - destY1);
1809
1810 int destOffset = destY1 * screenW + destX1;
1811 srcBuffer = img.pixels;
1812
1813 if (smooth) {
1814 blitResizeBilinear(img, destPixels, destOffset, screenW, destW, destH, dx, dy, mode);
1815 } else {
1816 blitResizeNearest(img, destPixels, destOffset, screenW, destW, destH, dx, dy, mode);
1817 }
1818 }
1819
1820 private void blitResizeBilinear(PImage img,
1821 int[] destPixels, int destOffset, int screenW,

Callers 1

blendMethod · 0.95

Calls 3

minMethod · 0.95
blitResizeBilinearMethod · 0.95
blitResizeNearestMethod · 0.95

Tested by

no test coverage detected