Declare src pointers as const
diff --git a/apps/shared/y4m.c b/apps/shared/y4m.c
index 3283abc..05f6cdc 100644
--- a/apps/shared/y4m.c
+++ b/apps/shared/y4m.c
@@ -514,7 +514,7 @@
for (int plane = AVIF_CHAN_Y; plane <= lastPlane; ++plane) {
uint32_t planeHeight = avifImagePlaneHeight(avif, plane); // 0 for UV if 4:0:0.
uint32_t planeWidthBytes = avifImagePlaneWidth(avif, plane) << (avif->depth > 8);
- uint8_t * row = avifImagePlane(avif, plane);
+ const uint8_t * row = avifImagePlane(avif, plane);
uint32_t rowBytes = avifImagePlaneRowBytes(avif, plane);
for (uint32_t y = 0; y < planeHeight; ++y) {
if (fwrite(row, 1, planeWidthBytes, f) != planeWidthBytes) {
diff --git a/include/avif/internal.h b/include/avif/internal.h
index 1fd7f3e..baf1124 100644
--- a/include/avif/internal.h
+++ b/include/avif/internal.h
@@ -78,7 +78,7 @@
uint32_t height;
uint32_t srcDepth;
- uint8_t * srcPlane;
+ const uint8_t * srcPlane;
uint32_t srcRowBytes;
uint32_t srcOffsetBytes;
uint32_t srcPixelBytes;
diff --git a/src/alpha.c b/src/alpha.c
index 0df1697..c6fcbc2 100644
--- a/src/alpha.c
+++ b/src/alpha.c
@@ -45,17 +45,17 @@
// no depth rescale, uint16_t -> uint16_t
for (uint32_t j = 0; j < params->height; ++j) {
- uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
+ const uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
uint8_t * dstRow = ¶ms->dstPlane[params->dstOffsetBytes + (j * params->dstRowBytes)];
for (uint32_t i = 0; i < params->width; ++i) {
- *((uint16_t *)&dstRow[i * params->dstPixelBytes]) = *((uint16_t *)&srcRow[i * params->srcPixelBytes]);
+ *((uint16_t *)&dstRow[i * params->dstPixelBytes]) = *((const uint16_t *)&srcRow[i * params->srcPixelBytes]);
}
}
} else {
// no depth rescale, uint8_t -> uint8_t
for (uint32_t j = 0; j < params->height; ++j) {
- uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
+ const uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
uint8_t * dstRow = ¶ms->dstPlane[params->dstOffsetBytes + (j * params->dstRowBytes)];
for (uint32_t i = 0; i < params->width; ++i) {
dstRow[i * params->dstPixelBytes] = srcRow[i * params->srcPixelBytes];
@@ -70,10 +70,10 @@
// depth rescale, uint16_t -> uint16_t
for (uint32_t j = 0; j < params->height; ++j) {
- uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
+ const uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
uint8_t * dstRow = ¶ms->dstPlane[params->dstOffsetBytes + (j * params->dstRowBytes)];
for (uint32_t i = 0; i < params->width; ++i) {
- int srcAlpha = *((uint16_t *)&srcRow[i * params->srcPixelBytes]);
+ int srcAlpha = *((const uint16_t *)&srcRow[i * params->srcPixelBytes]);
float alphaF = (float)srcAlpha / srcMaxChannelF;
int dstAlpha = (int)(0.5f + (alphaF * dstMaxChannelF));
dstAlpha = AVIF_CLAMP(dstAlpha, 0, dstMaxChannel);
@@ -84,10 +84,10 @@
// depth rescale, uint16_t -> uint8_t
for (uint32_t j = 0; j < params->height; ++j) {
- uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
+ const uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
uint8_t * dstRow = ¶ms->dstPlane[params->dstOffsetBytes + (j * params->dstRowBytes)];
for (uint32_t i = 0; i < params->width; ++i) {
- int srcAlpha = *((uint16_t *)&srcRow[i * params->srcPixelBytes]);
+ int srcAlpha = *((const uint16_t *)&srcRow[i * params->srcPixelBytes]);
float alphaF = (float)srcAlpha / srcMaxChannelF;
int dstAlpha = (int)(0.5f + (alphaF * dstMaxChannelF));
dstAlpha = AVIF_CLAMP(dstAlpha, 0, dstMaxChannel);
@@ -101,7 +101,7 @@
// depth rescale, uint8_t -> uint16_t
for (uint32_t j = 0; j < params->height; ++j) {
- uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
+ const uint8_t * srcRow = ¶ms->srcPlane[params->srcOffsetBytes + (j * params->srcRowBytes)];
uint8_t * dstRow = ¶ms->dstPlane[params->dstOffsetBytes + (j * params->dstRowBytes)];
for (uint32_t i = 0; i < params->width; ++i) {
int srcAlpha = srcRow[i * params->srcPixelBytes];
diff --git a/src/avif.c b/src/avif.c
index a73c187..b0ba46b 100644
--- a/src/avif.c
+++ b/src/avif.c
@@ -206,7 +206,7 @@
if (!dstRow) {
continue;
}
- uint8_t * srcRow = avifImagePlane(srcImage, plane);
+ const uint8_t * srcRow = avifImagePlane(srcImage, plane);
uint32_t srcRowBytes = avifImagePlaneRowBytes(srcImage, plane);
uint32_t dstRowBytes = avifImagePlaneRowBytes(dstImage, plane);
uint32_t planeWidthBytes = avifImagePlaneWidth(dstImage, plane) << (dstImage->depth > 8);
diff --git a/src/codec_aom.c b/src/codec_aom.c
index c98a61d..c833082 100644
--- a/src/codec_aom.c
+++ b/src/codec_aom.c
@@ -880,7 +880,7 @@
if (aomImageAllocated) {
const uint32_t bytesPerRow = ((image->depth > 8) ? 2 : 1) * image->width;
for (uint32_t j = 0; j < image->height; ++j) {
- uint8_t * srcAlphaRow = &image->alphaPlane[j * image->alphaRowBytes];
+ const uint8_t * srcAlphaRow = &image->alphaPlane[j * image->alphaRowBytes];
uint8_t * dstAlphaRow = &aomImage.planes[0][j * aomImage.stride[0]];
memcpy(dstAlphaRow, srcAlphaRow, bytesPerRow);
}
@@ -910,7 +910,7 @@
uint32_t bytesPerRow = bytesPerPixel * planeWidth;
for (uint32_t j = 0; j < planeHeight; ++j) {
- uint8_t * srcRow = &image->yuvPlanes[yuvPlane][j * image->yuvRowBytes[yuvPlane]];
+ const uint8_t * srcRow = &image->yuvPlanes[yuvPlane][j * image->yuvRowBytes[yuvPlane]];
uint8_t * dstRow = &aomImage.planes[yuvPlane][j * aomImage.stride[yuvPlane]];
memcpy(dstRow, srcRow, bytesPerRow);
}
diff --git a/src/read.c b/src/read.c
index f7a44e8..4dc7cd3 100644
--- a/src/read.c
+++ b/src/read.c
@@ -1406,14 +1406,14 @@
if (alpha) {
// A
for (unsigned int j = 0; j < heightToCopy; ++j) {
- uint8_t * src = &tile->image->alphaPlane[j * tile->image->alphaRowBytes];
+ const uint8_t * src = &tile->image->alphaPlane[j * tile->image->alphaRowBytes];
uint8_t * dst = &dstImage->alphaPlane[(yaColOffset * pixelBytes) + ((yaRowOffset + j) * dstImage->alphaRowBytes)];
memcpy(dst, src, yaRowBytes);
}
} else {
// Y
for (unsigned int j = 0; j < heightToCopy; ++j) {
- uint8_t * src = &tile->image->yuvPlanes[AVIF_CHAN_Y][j * tile->image->yuvRowBytes[AVIF_CHAN_Y]];
+ const uint8_t * src = &tile->image->yuvPlanes[AVIF_CHAN_Y][j * tile->image->yuvRowBytes[AVIF_CHAN_Y]];
uint8_t * dst =
&dstImage->yuvPlanes[AVIF_CHAN_Y][(yaColOffset * pixelBytes) + ((yaRowOffset + j) * dstImage->yuvRowBytes[AVIF_CHAN_Y])];
memcpy(dst, src, yaRowBytes);
@@ -1429,12 +1429,12 @@
size_t uvRowOffset = yaRowOffset >> formatInfo.chromaShiftY;
size_t uvRowBytes = yaRowBytes >> formatInfo.chromaShiftX;
for (unsigned int j = 0; j < heightToCopy; ++j) {
- uint8_t * srcU = &tile->image->yuvPlanes[AVIF_CHAN_U][j * tile->image->yuvRowBytes[AVIF_CHAN_U]];
+ const uint8_t * srcU = &tile->image->yuvPlanes[AVIF_CHAN_U][j * tile->image->yuvRowBytes[AVIF_CHAN_U]];
uint8_t * dstU =
&dstImage->yuvPlanes[AVIF_CHAN_U][(uvColOffset * pixelBytes) + ((uvRowOffset + j) * dstImage->yuvRowBytes[AVIF_CHAN_U])];
memcpy(dstU, srcU, uvRowBytes);
- uint8_t * srcV = &tile->image->yuvPlanes[AVIF_CHAN_V][j * tile->image->yuvRowBytes[AVIF_CHAN_V]];
+ const uint8_t * srcV = &tile->image->yuvPlanes[AVIF_CHAN_V][j * tile->image->yuvRowBytes[AVIF_CHAN_V]];
uint8_t * dstV =
&dstImage->yuvPlanes[AVIF_CHAN_V][(uvColOffset * pixelBytes) + ((uvRowOffset + j) * dstImage->yuvRowBytes[AVIF_CHAN_V])];
memcpy(dstV, srcV, uvRowBytes);
@@ -3815,7 +3815,7 @@
return AVIF_RESULT_NOT_IMPLEMENTED;
}
- uint8_t * alphaPlane = image->alphaPlane;
+ const uint8_t * alphaPlane = image->alphaPlane;
const uint32_t alphaRowBytes = image->alphaRowBytes;
// We cannot do the range conversion in place since it will modify the
@@ -3829,17 +3829,17 @@
if (image->depth > 8) {
for (uint32_t j = 0; j < image->height; ++j) {
- uint8_t * srcRow = &alphaPlane[j * alphaRowBytes];
+ const uint8_t * srcRow = &alphaPlane[j * alphaRowBytes];
uint8_t * dstRow = &image->alphaPlane[j * image->alphaRowBytes];
for (uint32_t i = 0; i < image->width; ++i) {
- int srcAlpha = *((uint16_t *)&srcRow[i * 2]);
+ int srcAlpha = *((const uint16_t *)&srcRow[i * 2]);
int dstAlpha = avifLimitedToFullY(image->depth, srcAlpha);
*((uint16_t *)&dstRow[i * 2]) = (uint16_t)dstAlpha;
}
}
} else {
for (uint32_t j = 0; j < image->height; ++j) {
- uint8_t * srcRow = &alphaPlane[j * alphaRowBytes];
+ const uint8_t * srcRow = &alphaPlane[j * alphaRowBytes];
uint8_t * dstRow = &image->alphaPlane[j * image->alphaRowBytes];
for (uint32_t i = 0; i < image->width; ++i) {
int srcAlpha = srcRow[i];