1diff -Npur ffmpeg-5.1.2/libavcodec/rpzaenc.c ffmpeg-5.1.2-change/libavcodec/rpzaenc.c 2--- ffmpeg-5.1.2/libavcodec/rpzaenc.c 2022-07-23 01:58:39.000000000 +0800 3+++ ffmpeg-5.1.2-change/libavcodec/rpzaenc.c 2024-06-25 15:56:07.594394836 +0800 4@@ -205,7 +205,7 @@ static void get_max_component_diff(Block 5 6 // loop thru and compare pixels 7 for (y = 0; y < bi->block_height; y++) { 8- for (x = 0; x < bi->block_width; x++){ 9+ for (x = 0; x < bi->block_width; x++) { 10 // TODO: optimize 11 min_r = FFMIN(R(block_ptr[x]), min_r); 12 min_g = FFMIN(G(block_ptr[x]), min_g); 13@@ -277,7 +277,7 @@ static int leastsquares(uint16_t *block_ 14 return -1; 15 16 for (i = 0; i < bi->block_height; i++) { 17- for (j = 0; j < bi->block_width; j++){ 18+ for (j = 0; j < bi->block_width; j++) { 19 x = GET_CHAN(block_ptr[j], xchannel); 20 y = GET_CHAN(block_ptr[j], ychannel); 21 sumx += x; 22@@ -324,7 +324,7 @@ static int calc_lsq_max_fit_error(uint16 23 int max_err = 0; 24 25 for (i = 0; i < bi->block_height; i++) { 26- for (j = 0; j < bi->block_width; j++){ 27+ for (j = 0; j < bi->block_width; j++) { 28 int x_inc, lin_y, lin_x; 29 x = GET_CHAN(block_ptr[j], xchannel); 30 y = GET_CHAN(block_ptr[j], ychannel); 31@@ -419,7 +419,9 @@ static void update_block_in_prev_frame(c 32 uint16_t *dest_pixels, 33 const BlockInfo *bi, int block_counter) 34 { 35- for (int y = 0; y < 4; y++) { 36+ const int y_size = FFMIN(4, bi->image_height - bi->row * 4); 37+ 38+ for (int y = 0; y < y_size; y++) { 39 memcpy(dest_pixels, src_pixels, 8); 40 dest_pixels += bi->rowstride; 41 src_pixels += bi->rowstride; 42@@ -729,14 +731,15 @@ post_skip : 43 44 if (err > s->sixteen_color_thresh) { // DO SIXTEEN COLOR BLOCK 45 uint16_t *row_ptr; 46- int rgb555; 47+ int y_size, rgb555; 48 49 block_offset = get_block_info(&bi, block_counter); 50 51 row_ptr = &src_pixels[block_offset]; 52+ y_size = FFMIN(4, bi.image_height - bi.row * 4); 53 54- for (int y = 0; y < 4; y++) { 55- for (int x = 0; x < 4; x++){ 56+ for (int y = 0; y < y_size; y++) { 57+ for (int x = 0; x < 4; x++) { 58 rgb555 = row_ptr[x] & ~0x8000; 59 60 put_bits(&s->pb, 16, rgb555); 61@@ -744,6 +747,11 @@ post_skip : 62 row_ptr += bi.rowstride; 63 } 64 65+ for (int y = y_size; y < 4; y++) { 66+ for (int x = 0; x < 4; x++) 67+ put_bits(&s->pb, 16, 0); 68+ } 69+ 70 block_counter++; 71 } else { // FOUR COLOR BLOCK 72 block_counter += encode_four_color_block(min_color, max_color, 73