Skip to content

Commit

Permalink
Replace global variables pixel_progress etc with Progress class
Browse files Browse the repository at this point in the history
  • Loading branch information
d11mshepcar committed Apr 16, 2019
1 parent 74ea92b commit 0fbe20f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 94 deletions.
14 changes: 7 additions & 7 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const std::vector<std::string> transforms = {"Channel_Compact", "YCoCg", "?? YCb
"?? Other ??" };
// Plenty of room for future extensions: transform "Other" can be used to encode identifiers of arbitrary many other transforms

// Some global variables used to show progress and to know when to stop a partial/progressive decode
// (TODO: avoid global variables)
int64_t pixels_todo = 0;
int64_t pixels_done = 0;
int progressive_qual_target = 0;
int progressive_qual_shown = -1;

Progress::Progress()
{
pixels_todo = 0;
pixels_done = 0;
progressive_qual_target = 0;
progressive_qual_shown = -1;
}

// The order in which the planes are encoded.
// Lookback (animations-only, value refers to a previous frame) has to be first, because all other planes are not encoded if lookback != 0
Expand Down
16 changes: 11 additions & 5 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ limitations under the License.
#include "io.hpp"


extern int64_t pixels_todo;
extern int64_t pixels_done;
extern int progressive_qual_target;
extern int progressive_qual_shown;

// Variables used to show progress and to know when to stop a partial/progressive decode
struct Progress
{
Progress();
int64_t pixels_todo;
int64_t pixels_done;
int progressive_qual_target;
int progressive_qual_shown;
int quality() const { return (int)(10000 * pixels_done / pixels_todo); }
bool reached_target() const { return quality() >= progressive_qual_target; }
};

#define MAX_TRANSFORM 13
#define MAX_PREDICTOR 2
Expand Down
Loading

0 comments on commit 0fbe20f

Please sign in to comment.