Replace MIN/MAX/MID with std::min/std::max/mid

Originally committed to SVN as r5078.
This commit is contained in:
Thomas Goyne 2010-12-31 21:03:03 +00:00
parent c6a823c731
commit 833e69b09f
21 changed files with 41 additions and 52 deletions

View file

@ -162,7 +162,7 @@ int AssTime::GetMS () const {
/// @param _ms
///
void AssTime::SetMS (int ms) {
time = MID(0, ms, 10 * 60 * 60 * 1000 - 1);
time = mid(0, ms, 10 * 60 * 60 * 1000 - 1);
}

View file

@ -95,7 +95,7 @@ void DirectSoundPlayer::OpenStream() {
int aim = waveFormat.nAvgBytesPerSec * 15/100; // 150 ms buffer
int min = DSBSIZE_MIN;
int max = DSBSIZE_MAX;
bufSize = MIN(MAX(min,aim),max);
bufSize = std::min(std::max(min,aim),max);
DSBUFFERDESC desc;
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;

View file

@ -292,7 +292,7 @@ void DirectSoundPlayer2Thread::Run()
int aim = waveFormat.nAvgBytesPerSec * (wanted_latency*buffer_length)/1000;
int min = DSBSIZE_MIN;
int max = DSBSIZE_MAX;
DWORD bufSize = MIN(MAX(min,aim),max); // size of entier playback buffer
DWORD bufSize = mid(min,aim,max); // size of entier playback buffer
DSBUFFERDESC desc;
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;

View file

@ -295,11 +295,11 @@ OSSPlayerThread::OSSPlayerThread(OSSPlayer *par) : wxThread(wxTHREAD_JOINABLE)
wxThread::ExitCode OSSPlayerThread::Entry() {
// Use small enough writes for good timing accuracy with all
// timing methods.
const int wsize = parent->rate / 25;
const unsigned long wsize = parent->rate / 25;
void *buf = malloc(wsize * parent->bpf);
while (!TestDestroy() && parent->cur_frame < parent->end_frame) {
int rsize = MIN(wsize, parent->end_frame - parent->cur_frame);
int rsize = std::min(wsize, parent->end_frame - parent->cur_frame);
parent->provider->GetAudioWithVolume(buf, parent->cur_frame,
rsize, parent->volume);
int written = ::write(parent->dspdev, buf, rsize * parent->bpf);

View file

@ -70,7 +70,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *src) {
// Allocate cache blocks
try {
for (int i = 0; i < blockcount; i++) {
blockcache[i] = new char[MIN(CacheBlockSize,ssize-i*CacheBlockSize)];
blockcache[i] = new char[std::min<size_t>(CacheBlockSize,ssize-i*CacheBlockSize)];
}
}
catch (...) {
@ -162,8 +162,7 @@ void RAMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const {
// Copy
while (bytesremaining) {
int readsize=MIN(bytesremaining,CacheBlockSize);
readsize = MIN(readsize,CacheBlockSize - start_offset);
int readsize = std::min<int>(bytesremaining, CacheBlockSize - start_offset);
memcpy(charbuf,(char *)(blockcache[i++]+start_offset),readsize);

View file

@ -585,7 +585,7 @@ void BaseGrid::DrawImage(wxDC &dc) {
// Visible lines
int drawPerScreen = h/lineHeight + 1;
int nDraw = MID(0,drawPerScreen,GetRows()-yPos);
int nDraw = mid(0,drawPerScreen,GetRows()-yPos);
int maxH = (nDraw+1) * lineHeight;
// Row colors
@ -819,7 +819,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
int row = event.GetY()/lineHeight + yPos - 1;
bool headerClick = row < yPos;
if (holding && !click) {
row = MID(0,row,GetRows()-1);
row = mid(0,row,GetRows()-1);
}
AssDialogue *dlg = GetDialogue(row);
if (!dlg) row = 0;
@ -945,7 +945,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
void BaseGrid::ScrollTo(int y) {
int w,h;
GetClientSize(&w,&h);
int nextY = MID(0,y,GetRows()+2 - h/lineHeight);
int nextY = mid(0,y,GetRows()+2 - h/lineHeight);
if (yPos != nextY) {
yPos = nextY;
if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos);
@ -964,7 +964,7 @@ void BaseGrid::AdjustScrollbar() {
int rows = GetRows();
bool barToEnable = drawPerScreen < rows+2;
yPos = MID(0,yPos,rows - drawPerScreen);
yPos = mid(0,yPos,rows - drawPerScreen);
scrollBar->Freeze();
scrollBar->GetSize(&sw,&sh);
@ -1208,7 +1208,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
extendRow = -1;
}
int next = MID(0,curLine+dir*step,GetRows()-1);
int next = mid(0,curLine+dir*step,GetRows()-1);
SetActiveLine(GetDialogue(next));
SelectRow(next);
MakeCellVisible(next,0,false);
@ -1218,7 +1218,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
// Move active only
if (alt && !shift && !ctrl) {
extendRow = -1;
int next = MID(0,GetDialogueIndex(GetActiveLine())+dir*step,GetRows()-1);
int next = mid(0,GetDialogueIndex(GetActiveLine())+dir*step,GetRows()-1);
SetActiveLine(GetDialogue(next));
Refresh(false);
MakeCellVisible(next,0,false);
@ -1229,7 +1229,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
if (shift && !ctrl && !alt) {
// Find end
if (extendRow == -1) GetDialogueIndex(GetActiveLine());
extendRow = MID(0,extendRow+dir*step,GetRows()-1);
extendRow = mid(0,extendRow+dir*step,GetRows()-1);
// Set range
int i1 = GetDialogueIndex(GetActiveLine());

View file

@ -311,7 +311,7 @@ void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
float r = R/255.f, g = G/255.f, b = B/255.f;
float h, s, l;
float maxrgb = MAX(r, MAX(g, b)), minrgb = MIN(r, MIN(g, b));
float maxrgb = std::max(r, std::max(g, b)), minrgb = std::min(r, std::min(g, b));
l = (minrgb + maxrgb) / 2;
@ -356,7 +356,7 @@ void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
float r = R/255.f, g = G/255.f, b = B/255.f;
float h, s, v;
float maxrgb = MAX(r, MAX(g, b)), minrgb = MIN(r, MIN(g, b));
float maxrgb = std::max(r, std::max(g, b)), minrgb = std::min(r, std::min(g, b));
v = maxrgb;

View file

@ -99,7 +99,7 @@ void DialogProgress::SetProgress(int cur,int max) {
// Check if it's the main thread, if so, just process it now
if (wxIsMainThread()) {
gauge->SetValue(MID(0,value,100));
gauge->SetValue(mid(0,value,100));
wxYield();
return;
}
@ -124,7 +124,7 @@ void DialogProgress::SetProgress(int cur,int max) {
void DialogProgress::OnUpdateProgress(wxCommandEvent &event)
{
int value = event.GetInt();
if (gauge->GetValue() != value) gauge->SetValue(MID(0,value,100));
if (gauge->GetValue() != value) gauge->SetValue(mid(0,value,100));
wxMutexLocker locker(mutex);
count--;
}

View file

@ -123,7 +123,7 @@ DialogTimingProcessor::DialogTimingProcessor(wxWindow *parent,SubtitlesGrid *_gr
wxStaticText *adjsThresText = new wxStaticText(this,-1,_("Threshold:"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTRE);
adjacentThres = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(60,-1),0,NumValidator(&adjsThresTime));
adjacentThres->SetToolTip(_("Maximum difference between start and end time for two subtitles to be made continuous, in milliseconds."));
adjacentBias = new wxSlider(this,-1,MID(0,int(OPT_GET("Tool/Timing Post Processor/Adjacent Bias")->GetDouble()*100),100),0,100,wxDefaultPosition,wxSize(-1,20));
adjacentBias = new wxSlider(this,-1,mid(0,int(OPT_GET("Tool/Timing Post Processor/Adjacent Bias")->GetDouble()*100),100),0,100,wxDefaultPosition,wxSize(-1,20));
adjacentBias->SetToolTip(_("Sets how to set the adjoining of lines. If set totally to left, it will extend start time of the second line; if totally to right, it will extend the end time of the first line."));
AdjacentSizer->Add(adjsEnable,0,wxRIGHT|wxEXPAND,10);
AdjacentSizer->Add(adjsThresText,0,wxRIGHT|wxALIGN_CENTER,5);

View file

@ -101,7 +101,7 @@ DialogVideoDetails::DialogVideoDetails(wxWindow *parent)
///
wxString DialogVideoDetails::PrettyAR(int width, int height)
{
int limit = (int)ceil(sqrt(double(MIN(width, height))));
int limit = (int)ceil(sqrt(double(std::min(width, height))));
for (int i=2;i<=limit;i++) {
while (width % i == 0 && height % i == 0) {
width /= i;

View file

@ -99,7 +99,7 @@ void SplineCurve::Smooth(Vector2D const& P0,Vector2D const& P3,float smooth) {
// Validate
if (type != CURVE_LINE) return;
if (p1 == p2) return;
smooth = MID(0.f,smooth,1.f);
smooth = mid(0.f,smooth,1.f);
// Get points
Vector2D P1 = p1;
@ -210,7 +210,7 @@ float SplineCurve::GetQuickDistance(Vector2D const& ref) const {
/// @return
///
float SplineCurve::GetClosestSegmentPart(Vector2D const& pt1,Vector2D const& pt2,Vector2D const& pt3) const {
return MID(0.f,(pt3-pt1).Dot(pt2-pt1)/(pt2-pt1).SquareLen(),1.f);
return mid(0.f,(pt3-pt1).Dot(pt2-pt1)/(pt2-pt1).SquareLen(),1.f);
}
/// @brief Closest distance between p3 and segment p1-p2

View file

@ -107,8 +107,8 @@ struct field_setter : public std::binary_function<AssDialogue*, T, void> {
void get_selection(SubsTextEditCtrl *TextEdit, int &start, int &end) {
TextEdit->GetSelection(&start, &end);
int len = TextEdit->GetText().size();
start = MID(0,TextEdit->GetReverseUnicodePosition(start),len);
end = MID(0,TextEdit->GetReverseUnicodePosition(end),len);
start = mid(0,TextEdit->GetReverseUnicodePosition(start),len);
end = mid(0,TextEdit->GetReverseUnicodePosition(end),len);
}
/// @brief Get the value of a tag at a specified position in a line

View file

@ -989,7 +989,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
GetBoundsOfWordAtPosition(currentWordPos,start,end);
wxString text = GetText();
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
SetText(text.Left(std::max(0,start)) + suggestion + text.Mid(end+1));
// Set selection
SetSelectionU(start,start+suggestion.Length());

View file

@ -210,7 +210,7 @@ void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) {
int src_stride = img->stride;
int dst_stride = frame.pitch[0];
int dst_delta = dst_stride - img->w*4;
//int stride = MIN(src_stride,dst_stride);
//int stride = std::min(src_stride,dst_stride);
const unsigned char *src = img->bitmap;
unsigned char *dst = frame.data[0] + (img->dst_y * dst_stride + img->dst_x * 4);
unsigned int k,ck,t;

View file

@ -123,7 +123,7 @@ wxArrayString MySpellThesaurus::GetLanguageList() {
// For each idxtionary match, see if it can find the corresponding .dat
for (unsigned int i=0;i<idx.Count();i++) {
wxString curdat = idx[i].Left(MAX(0,signed(idx[i].Length())-4)) + _T(".dat");
wxString curdat = idx[i].Left(std::max(0,signed(idx[i].Length())-4)) + _T(".dat");
for (unsigned int j=0;j<dat.Count();j++) {
// Found match
if (curdat == dat[j]) {

View file

@ -74,17 +74,7 @@ void RestartAegisub();
/// @brief Templated abs() function
template <typename T> T tabs(T x) { return x < 0 ? -x : x; }
#ifndef MIN
#define MIN(a,b) ((a)<(b))?(a):(b)
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b))?(a):(b)
#endif
#ifndef MID
#define MID(a,b,c) MAX((a),MIN((b),(c)))
#endif
template<typename T> inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); }
#ifndef FORCEINLINE
#ifdef __VISUALC__

View file

@ -447,7 +447,7 @@ void VideoContext::SetAspectRatio(int type, double value) {
if (type != 4) value = GetARFromType(type);
arType = type;
arValue = MID(.5, value, 5.);
arValue = mid(.5, value, 5.);
ARChange(arType, arValue);
}

View file

@ -487,12 +487,12 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
}
if (event.Leaving()) {
video.x = INT_MIN;
video.y = INT_MIN;
video.x = INT_MIN;
video.y = INT_MIN;
}
else {
video.x = event.GetX();
video.y = event.GetY();
video.x = event.GetX();
video.y = event.GetY();
}
tool->OnMouseEvent(event);

View file

@ -88,7 +88,7 @@ VideoSlider::~VideoSlider() {
///
void VideoSlider::SetValue(int value) {
if (val == value) return;
val = MID(0, value, max);
val = mid(0, value, max);
Refresh(false);
}
@ -284,7 +284,7 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
// Fast move
if (!ctrl && !shift && alt) {
if (VideoContext::Get()->IsPlaying()) return;
int target = MID(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max);
int target = mid<int>(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max);
if (target != val) VideoContext::Get()->JumpToFrame(target);
return;
}

View file

@ -142,10 +142,10 @@ void VisualToolClip::UpdateHold() {
if (curY1 > curY2) std::swap(curY1,curY2);
// Limit to video area
curX1 = MID(0,curX1,video.w);
curX2 = MID(0,curX2,video.w);
curY1 = MID(0,curY1,video.h);
curY2 = MID(0,curY2,video.h);
curX1 = mid(0,curX1,video.w);
curX2 = mid(0,curX2,video.w);
curY1 = mid(0,curY1,video.h);
curY2 = mid(0,curY2,video.h);
SetFeaturePositions();
}

View file

@ -63,8 +63,8 @@ void VisualToolScale::Draw() {
if (!curDiag) return;
int len = 160;
int dx = MID(len/2+10,posx,video.w-len/2-30);
int dy = MID(len/2+10,posy,video.h-len/2-30);
int dx = mid(len/2+10,posx,video.w-len/2-30);
int dy = mid(len/2+10,posy,video.h-len/2-30);
SetLineColour(colour[0]);
SetFillColour(colour[1],0.3f);