OpenToonz - An open-source full-featured 2D animation creation software
C
fix crash on loading png in subbox
shun-iwasawacf34ed972c5d
diff --git a/toonz/sources/image/png/tiio_png.cpp b/toonz/sources/image/png/tiio_png.cppindex fc3d8b68d..dcfd6c02e 100644--- a/toonz/sources/image/png/tiio_png.cpp+++ b/toonz/sources/image/png/tiio_png.cpp@@ -278,7 +278,7 @@ public:png_bytep row_pointer = m_rowBuffer.get();png_read_row(m_png_ptr, row_pointer, NULL);- writeRow(buffer);+ writeRow(buffer, x0, x1);if (m_tempBuffer && m_y == ly) {m_tempBuffer.reset();@@ -320,7 +320,7 @@ public:png_bytep row_pointer = m_rowBuffer.get();png_read_row(m_png_ptr, row_pointer, NULL);- writeRow(buffer);+ writeRow(buffer, x0, x1);if (m_tempBuffer && m_y == ly) {m_tempBuffer.reset();@@ -347,7 +347,7 @@ public:Tiio::RowOrder getRowOrder() const override { return Tiio::TOP2BOTTOM; }- void writeRow(char *buffer) {+ void writeRow(char *buffer, int x0, int x1) {if (m_color_type == PNG_COLOR_TYPE_RGB_ALPHA ||m_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||m_color_type == PNG_COLOR_TYPE_PALETTE) { // PNG_COLOR_TYPE_PALETTE is@@ -355,7 +355,8 @@ public:if (m_bit_depth == 16) {TPixel32 *pix = (TPixel32 *)buffer;int i = -2;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 2 * 4;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB)pix[j].m = m_rowBuffer[i = i + 2];pix[j].r = m_rowBuffer[i = i + 2];@@ -386,7 +387,8 @@ public:} else {TPixel32 *pix = (TPixel32 *)buffer;int i = 0;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 4;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB)pix[j].m = m_rowBuffer[i++];pix[j].r = m_rowBuffer[i++];@@ -419,7 +421,8 @@ public:if (m_bit_depth == 16) {TPixel32 *pix = (TPixel32 *)buffer;int i = -2;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 2 * 3;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB) || \defined(TNZ_MACHINE_CHANNEL_ORDER_RGBM)pix[j].r = m_rowBuffer[i = i + 2];@@ -438,7 +441,8 @@ public:} else {TPixel32 *pix = (TPixel32 *)buffer;int i = 0;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 3;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB) || \defined(TNZ_MACHINE_CHANNEL_ORDER_RGBM)pix[j].r = m_rowBuffer[i++];@@ -458,14 +462,15 @@ public:}}- void writeRow(short *buffer) {+ void writeRow(short *buffer, int x0, int x1) {if (m_color_type == PNG_COLOR_TYPE_RGB_ALPHA ||m_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||m_color_type == PNG_COLOR_TYPE_PALETTE) { // PNG_COLOR_TYPE_PALETTE is// expanded to RGBATPixel64 *pix = (TPixel64 *)buffer;int i = -2; // 0;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 2 * 4;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB) || \defined(TNZ_MACHINE_CHANNEL_ORDER_RGBM)pix[j].r = mySwap(m_rowBuffer[i = i + 2]); // i++@@ -490,7 +495,8 @@ public:{ // grayscale e' gestito come RGB perche' si usa png_set_gray_to_rgbTPixel64 *pix = (TPixel64 *)buffer;int i = -2;- for (int j = 0; j < m_info.m_lx; j++) {+ i += x0 * 2 * 3;+ for (int j = x0; j <= x1; j++) {#if defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB) || \defined(TNZ_MACHINE_CHANNEL_ORDER_RGBM)pix[j].r = mySwap(m_rowBuffer[i = i + 2]);@@ -662,8 +668,8 @@ public:// tutto quello che segue lo metto in una funzione in cui scrivo il buffer// di restituzione della readLine- //è una funzione comune alle ReadLine- writeRow(buffer);+ // è una funzione comune alle ReadLine+ writeRow(buffer, x0, x1);}void readLineInterlace(short *buffer, int x0, int x1, int shrink) {@@ -739,8 +745,8 @@ public:// tutto quello che segue lo metto in una funzione in cui scrivo il buffer// di restituzione della readLine- //è una funzione comune alle ReadLine- writeRow(buffer);+ // è una funzione comune alle ReadLine+ writeRow(buffer, x0, x1);}};