Skip to content

Commit

Permalink
change s_read_whole_image() to call s_read_one_line()
Browse files Browse the repository at this point in the history
instead of duplicating the calls to the low level line reading funcs
  • Loading branch information
Rupert committed Nov 15, 2024
1 parent 4e5af5b commit f6c7b97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

BasedOnStyle: WebKit

SortIncludes: false
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Right
AlignConsecutiveAssignments:
Expand Down
43 changes: 15 additions & 28 deletions bmp-read-loadimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* Copyright (c) 2024, Rupert Weber.
*
* This file is part of bmplib.
* bmplib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* bmplib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
* If not, see <https://www.gnu.org/licenses/>
*/

Expand Down Expand Up @@ -42,16 +42,18 @@
* \ /
* common prep work, \ /
* buffer allocation, s_load_image_or_line()
* sanity checks, etc. / \
* / \
* / \
* 'supervision' s_read_whole_image() s_read_one_line()
* \ /
* \ /
* \ /
* sanity checks, etc. | |
* | |
* | |
* s_read_whole_image() |
* \ |
* \ |
* s_read_one_line()
* |
* s_read_rgb_line()
* 'grunt work' s_read_indexed_line()
* s_read_rle_line()
* s_read_huffman_line()
*/

static inline unsigned long s_scaleint(unsigned long val, int frombits, int tobits) ATTR_CONST;
Expand Down Expand Up @@ -219,31 +221,16 @@ static BMPRESULT s_load_image_or_line(BMPREAD_R rp, unsigned char **restrict buf

static void s_read_whole_image(BMPREAD_R rp, unsigned char *restrict image)
{
int x = 0, y, yoff = 1;
int y, yoff = 1;
size_t linesize, real_y;

linesize = (size_t) rp->width * rp->result_bytes_per_pixel;

for (y = 0; y < rp->height; y += yoff) {
real_y = (rp->orientation == BMP_ORIENT_TOPDOWN) ? y : rp->height-1-y;
if (rp->rle) {
s_read_rle_line(rp, image + real_y * linesize, &x, &yoff);
if (x >= rp->width)
x = 0;
} else if (rp->ih->bitcount <= 8) {
if (rp->ih->compression == BI_OS2_HUFFMAN)
s_read_huffman_line(rp, image + real_y * linesize);
else
s_read_indexed_line(rp, image + real_y * linesize);
} else {
s_read_rgb_line(rp, image + real_y * linesize);
}
s_read_one_line(rp, image + real_y * linesize);
if (rp->rle_eof || s_stopping_error(rp))
break;
if (yoff > rp->height - y) {
logerr(rp->log, "RLE delta beyond image dimensions");
rp->invalid_delta = TRUE;
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions bmp-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@






static void s_decide_outformat(BMPWRITE_R wp);
static int s_write_palette(BMPWRITE_R wp);
static int s_save_line_rgb(BMPWRITE_R wp, const unsigned char *line);
Expand All @@ -54,8 +51,6 @@ static int s_check_already_saved(BMPWRITE_R wp);





/*****************************************************************************
* bmpwrite_new
*****************************************************************************/
Expand Down Expand Up @@ -385,6 +380,7 @@ API BMPRESULT bmpwrite_allow_2bit(BMPHANDLE h)
}



/*****************************************************************************
* bmpwrite_allow_huffman
*****************************************************************************/
Expand All @@ -406,6 +402,7 @@ API BMPRESULT bmpwrite_allow_huffman(BMPHANDLE h)
}



/*****************************************************************************
* bmpwrite_set_64bit
*****************************************************************************/
Expand Down

0 comments on commit f6c7b97

Please sign in to comment.