Skip to content

Commit

Permalink
small API fix:
Browse files Browse the repository at this point in the history
+ the sink::Reset() was not resetting pos_
+ we were not calling sink->Reset() at the beginning of the Encode() call.
  This is convenient in the event one would want to re-use the same Sink object
  over multiple Encode() calls.

Change-Id: I983f0ac17bd50aabd6eb3a1e9de1aae65664b739
  • Loading branch information
Skal committed Mar 24, 2021
1 parent b6e44de commit dea9a07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bit_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ template<class T> class Sink : public ByteSink {
return true;
}
virtual bool Finalize() { ptr_->resize(pos_); return true; }
virtual void Reset() { ptr_->clear(); }
virtual void Reset() {
ptr_->clear();
pos_ = 0;
}

protected:
T* const ptr_;
Expand Down
1 change: 1 addition & 0 deletions src/enc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Encoder::Encoder(SjpegYUVMode yuv_mode, int W, int H, ByteSink* const sink)
InitializeStaticPointers();
memset(dc_codes_, 0, sizeof(dc_codes_)); // safety
memset(ac_codes_, 0, sizeof(ac_codes_));
sink->Reset();
}

Encoder::~Encoder() {
Expand Down

0 comments on commit dea9a07

Please sign in to comment.