diff --git a/src/sail-codecs/common/bmp/bmp.c b/src/sail-codecs/common/bmp/bmp.c index fac9216e..420c14bc 100644 --- a/src/sail-codecs/common/bmp/bmp.c +++ b/src/sail-codecs/common/bmp/bmp.c @@ -394,7 +394,7 @@ sail_status_t bmp_private_read_frame(void *state, struct sail_io *io, struct sai bool skip_pad_bytes = true; for (unsigned i = image->height; i > 0; i--) { - unsigned char *scan = (unsigned char *)image->pixels + image->bytes_per_line * (bmp_state->flipped ? (i - 1) : (image->height - i)); + unsigned char *scan = sail_scan_line(image->pixels, bmp_state->flipped ? (i - 1) : (image->height - i)); for (unsigned pixel_index = 0; pixel_index < image->width;) { if (bmp_state->version >= SAIL_BMP_V3 && bmp_state->v3.compression == SAIL_BI_RLE4) { diff --git a/src/sail-codecs/jpeg/jpeg.c b/src/sail-codecs/jpeg/jpeg.c index 3d584d12..cc9b498d 100644 --- a/src/sail-codecs/jpeg/jpeg.c +++ b/src/sail-codecs/jpeg/jpeg.c @@ -224,7 +224,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg(void *state, struct sail } for (unsigned row = 0; row < image->height; row++) { - unsigned char *scanline = (unsigned char *)image->pixels + row * image->bytes_per_line; + unsigned char *scanline = sail_scan_line(image, row); JSAMPROW samprow = (JSAMPROW)scanline; (void)jpeg_read_scanlines(jpeg_state->decompress_context, &samprow, 1); @@ -382,7 +382,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_jpeg(void *state, const struc } for (unsigned row = 0; row < image->height; row++) { - JSAMPROW samprow = (JSAMPROW)((const unsigned char *)image->pixels + row * image->bytes_per_line); + JSAMPROW samprow = (JSAMPROW)sail_scan_line(image, row); jpeg_write_scanlines(jpeg_state->compress_context, &samprow, 1); } diff --git a/src/sail-codecs/jpeg2000/jpeg2000.c b/src/sail-codecs/jpeg2000/jpeg2000.c index 8e667165..716fc855 100644 --- a/src/sail-codecs/jpeg2000/jpeg2000.c +++ b/src/sail-codecs/jpeg2000/jpeg2000.c @@ -297,7 +297,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg2000(void *state, struct } if (jpeg2000_state->channel_depth_scaled == 8) { - unsigned char *scan = (unsigned char *)image->pixels + row * image->bytes_per_line; + unsigned char *scan = sail_scan_line(image, row); for (unsigned column = 0; column < image->width; column++) { for (int channel = 0; channel < jpeg2000_state->number_channels; channel++) { @@ -305,7 +305,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg2000(void *state, struct } } } else { - uint16_t *scan = (uint16_t *)((uint8_t *)image->pixels + row * image->bytes_per_line); + uint16_t *scan = sail_scan_line(image, row); for (unsigned column = 0; column < image->width; column++) { for (int channel = 0; channel < jpeg2000_state->number_channels; channel++) { diff --git a/src/sail-codecs/pcx/helpers.c b/src/sail-codecs/pcx/helpers.c index be565cea..632df39f 100644 --- a/src/sail-codecs/pcx/helpers.c +++ b/src/sail-codecs/pcx/helpers.c @@ -154,7 +154,7 @@ sail_status_t pcx_private_build_palette(enum SailPixelFormat pixel_format, struc sail_status_t pcx_private_read_uncompressed(struct sail_io *io, unsigned bytes_per_plane_to_read, unsigned planes, unsigned char *buffer, struct sail_image *image) { for (unsigned row = 0; row < image->height; row++) { - unsigned char *target_scan = (unsigned char *)image->pixels + image->bytes_per_line * row; + unsigned char *target_scan = sail_scan_line(image, row); /* Read plane by plane and then merge them into the image pixels. */ for (unsigned plane = 0; plane < planes; plane++) { diff --git a/src/sail-codecs/pcx/pcx.c b/src/sail-codecs/pcx/pcx.c index 9ed1c030..6ca035bb 100644 --- a/src/sail-codecs/pcx/pcx.c +++ b/src/sail-codecs/pcx/pcx.c @@ -215,7 +215,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_pcx(void *state, struct sail_ } /* Merge planes into the image pixels. */ - unsigned char * const scan = (unsigned char *)image->pixels + image->bytes_per_line * row; + unsigned char * const scan = sail_scan_line(image, row); for (unsigned plane = 0; plane < pcx_state->pcx_header.planes; plane++) { const unsigned buffer_plane_offset = plane * pcx_state->pcx_header.bytes_per_line; diff --git a/src/sail-codecs/png/png.c b/src/sail-codecs/png/png.c index db58e2ae..4a89edfd 100644 --- a/src/sail-codecs/png/png.c +++ b/src/sail-codecs/png/png.c @@ -391,7 +391,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_ #ifdef PNG_APNG_SUPPORTED if (png_state->is_apng) { for (unsigned row = 0; row < image->height; row++) { - unsigned char *scanline = (unsigned char *)image->pixels + row * image->bytes_per_line; + unsigned char *scanline = sail_scan_line(image, row); memcpy(scanline, png_state->prev[row], png_state->first_image->bytes_per_line); @@ -430,12 +430,12 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_ } } else { for (unsigned row = 0; row < image->height; row++) { - png_read_row(png_state->png_ptr, (unsigned char *)image->pixels + row * image->bytes_per_line, NULL); + png_read_row(png_state->png_ptr, sail_scan_line(image, row), NULL); } } #else for (unsigned row = 0; row < image->height; row++) { - png_read_row(png_state->png_ptr, (unsigned char *)image->pixels + row * image->bytes_per_line, NULL); + png_read_row(png_state->png_ptr, sail_scan_line(image, row), NULL); } #endif } @@ -638,7 +638,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_png(void *state, const struct for (int current_pass = 0; current_pass < png_state->interlaced_passes; current_pass++) { for (unsigned row = 0; row < image->height; row++) { - png_write_row(png_state->png_ptr, (const unsigned char *)image->pixels + row * image->bytes_per_line); + png_write_row(png_state->png_ptr, sail_scan_line(image, row)); } } diff --git a/src/sail-codecs/psd/psd.c b/src/sail-codecs/psd/psd.c index 141e4709..7c35104d 100644 --- a/src/sail-codecs/psd/psd.c +++ b/src/sail-codecs/psd/psd.c @@ -272,7 +272,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_ SAIL_TRY(psd_state->io->strict_read(psd_state->io->stream, &value, sizeof(value))); for (unsigned i = count; i < count + c; i++) { - unsigned char *scan = (unsigned char *)image->pixels + row * image->bytes_per_line + i * bpp; + unsigned char *scan = (unsigned char *)sail_scan_line(image, row) + i * bpp; *(scan + channel) = value; } } else if (c < 128) { @@ -282,7 +282,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_ unsigned char value; SAIL_TRY(psd_state->io->strict_read(psd_state->io->stream, &value, sizeof(value))); - unsigned char *scan = (unsigned char *)image->pixels + row * image->bytes_per_line + i * bpp; + unsigned char *scan = (unsigned char *)sail_scan_line(image, row) + i * bpp; *(scan + channel) = value; } } @@ -297,7 +297,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_ SAIL_TRY(psd_state->io->strict_read(psd_state->io->stream, psd_state->scan_buffer, psd_state->bytes_per_channel)); for (unsigned count = 0; count < psd_state->bytes_per_channel; count++) { - unsigned char *scan = (unsigned char *)image->pixels + row * image->bytes_per_line + count * bpp; + unsigned char *scan = (unsigned char *)sail_scan_line(image, row) + count * bpp; *(scan + channel) = *(psd_state->scan_buffer + count); } } diff --git a/src/sail-codecs/tiff/tiff.c b/src/sail-codecs/tiff/tiff.c index e0513297..3db60624 100644 --- a/src/sail-codecs/tiff/tiff.c +++ b/src/sail-codecs/tiff/tiff.c @@ -330,7 +330,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_tiff(void *state, const struc } for (unsigned row = 0; row < image->height; row++) { - if (TIFFWriteScanline(tiff_state->tiff, (unsigned char *)image->pixels + row * image->bytes_per_line, tiff_state->line++, 0) < 0) { + if (TIFFWriteScanline(tiff_state->tiff, sail_scan_line(image, row), tiff_state->line++, 0) < 0) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); } } diff --git a/src/sail-codecs/webp/webp.c b/src/sail-codecs/webp/webp.c index 81f51e5b..57fe0da6 100644 --- a/src/sail-codecs/webp/webp.c +++ b/src/sail-codecs/webp/webp.c @@ -287,7 +287,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_webp(void *state, struct sail SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); } - uint8_t *dst_scanline = (uint8_t *)webp_state->canvas_image->pixels + webp_state->frame_y * image->bytes_per_line + webp_state->frame_x * webp_state->bytes_per_pixel; + uint8_t *dst_scanline = (uint8_t *)sail_scan_line(webp_state->canvas_image, webp_state->frame_y) + webp_state->frame_x * webp_state->bytes_per_pixel; uint8_t *src_scanline = image->pixels; for (unsigned row = 0; row < webp_state->frame_height; row++, dst_scanline += webp_state->canvas_image->bytes_per_line, diff --git a/src/sail-common/image.c b/src/sail-common/image.c index 01d4b864..c921b2a9 100644 --- a/src/sail-common/image.c +++ b/src/sail-common/image.c @@ -181,9 +181,9 @@ sail_status_t sail_mirror_vertically(struct sail_image *image) { SAIL_TRY(sail_malloc(image->bytes_per_line, &line)); for (unsigned row1 = 0, row2 = image->height - 1; row1 < row2; row1++, row2--) { - memcpy(line, (unsigned char *)image->pixels + image->bytes_per_line * row1, image->bytes_per_line); - memcpy((unsigned char *)image->pixels + image->bytes_per_line * row1, (unsigned char *)image->pixels + image->bytes_per_line * row2, image->bytes_per_line); - memcpy((unsigned char *)image->pixels + image->bytes_per_line * row2, line, image->bytes_per_line); + memcpy(line, sail_scan_line(image, row1), image->bytes_per_line); + memcpy(sail_scan_line(image, row1), sail_scan_line(image, row2), image->bytes_per_line); + memcpy(sail_scan_line(image, row2), line, image->bytes_per_line); } sail_free(line); @@ -201,7 +201,7 @@ sail_status_t sail_mirror_horizontally(struct sail_image *image) { SAIL_TRY(sail_malloc(bytes_per_pixel, &pixel)); for (unsigned row = 0; row < image->height; row++) { - unsigned char *scan = (unsigned char *)image->pixels + image->bytes_per_line * row; + unsigned char *scan = sail_scan_line(image, row); for (unsigned col1 = 0, col2 = image->width - bytes_per_pixel; col1 < col2; col1 += bytes_per_pixel, col2 -= bytes_per_pixel) { memcpy(pixel, scan + col1, bytes_per_pixel);