Cocoa Port:
- Add the (Get/Set)FilterParameter family of methods for video filters that need parameters. - Make VideoFilter::RunFilter() and the destructor a little bit more thread-safe. - Do some minor code cleanup.
This commit is contained in:
parent
4abb36899b
commit
2914677ad6
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 2011 Roger Manuel
|
||||
Copyright (C) 2012 DeSmuME team
|
||||
Copyright (C) 2013 DeSmuME team
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -48,6 +48,13 @@
|
|||
- (UInt32 *) dstBufferPtr;
|
||||
- (NSSize) srcSize;
|
||||
- (NSSize) destSize;
|
||||
- (VideoFilterParamType) filterParameterType:(VideoFilterParamID)paramID;
|
||||
- (int) filterParameteri:(VideoFilterParamID)paramID;
|
||||
- (unsigned int) filterParameterui:(VideoFilterParamID)paramID;
|
||||
- (float) filterParameterf:(VideoFilterParamID)paramID;
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID intValue:(int)value;
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID uintValue:(unsigned int)value;
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID floatValue:(float)value;
|
||||
+ (NSString *) typeStringByID:(VideoFilterTypeID)typeID;
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 2011 Roger Manuel
|
||||
Copyright (C) 2012 DeSmuME team
|
||||
Copyright (C) 2013 DeSmuME team
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -182,6 +182,41 @@
|
|||
return NSMakeSize((CGFloat)vf->GetDstWidth(), (CGFloat)vf->GetDstHeight());
|
||||
}
|
||||
|
||||
- (VideoFilterParamType) filterParameterType:(VideoFilterParamID)paramID
|
||||
{
|
||||
return vf->GetFilterParameterType(paramID);
|
||||
}
|
||||
|
||||
- (int) filterParameteri:(VideoFilterParamID)paramID
|
||||
{
|
||||
return vf->GetFilterParameteri(paramID);
|
||||
}
|
||||
|
||||
- (unsigned int) filterParameterui:(VideoFilterParamID)paramID
|
||||
{
|
||||
return vf->GetFilterParameterui(paramID);
|
||||
}
|
||||
|
||||
- (float) filterParameterf:(VideoFilterParamID)paramID
|
||||
{
|
||||
return vf->GetFilterParameterf(paramID);
|
||||
}
|
||||
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID intValue:(int)value
|
||||
{
|
||||
vf->SetFilterParameteri(paramID, value);
|
||||
}
|
||||
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID uintValue:(unsigned int)value
|
||||
{
|
||||
vf->SetFilterParameterui(paramID, value);
|
||||
}
|
||||
|
||||
- (void) setFilterParameter:(VideoFilterParamID)paramID floatValue:(float)value
|
||||
{
|
||||
vf->SetFilterParameterf(paramID, value);
|
||||
}
|
||||
|
||||
+ (NSString *) typeStringByID:(VideoFilterTypeID)typeID
|
||||
{
|
||||
const char *vfTypeCString = VideoFilter::GetTypeStringByID(typeID);
|
||||
|
|
|
@ -25,6 +25,20 @@ int scanline_filter_b = 2;
|
|||
int scanline_filter_c = 2;
|
||||
int scanline_filter_d = 4;
|
||||
|
||||
//
|
||||
typedef struct
|
||||
{
|
||||
void *index;
|
||||
VideoFilterParamType type;
|
||||
} _VideoFilterParamAttributes;
|
||||
|
||||
static const _VideoFilterParamAttributes _VideoFilterParamAttributesList[] = {
|
||||
{&scanline_filter_a, VF_INT},
|
||||
{&scanline_filter_b, VF_INT},
|
||||
{&scanline_filter_c, VF_INT},
|
||||
{&scanline_filter_d, VF_INT},
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
CLASS CONSTRUCTORS
|
||||
********************************************************************************************/
|
||||
|
@ -80,6 +94,7 @@ VideoFilter::~VideoFilter()
|
|||
_vfThread.clear();
|
||||
|
||||
// Destroy everything else
|
||||
pthread_mutex_lock(&_mutexSrc);
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
while (this->_isFilterRunning)
|
||||
|
@ -92,8 +107,6 @@ VideoFilter::~VideoFilter()
|
|||
|
||||
pthread_mutex_unlock(&_mutexDst);
|
||||
|
||||
pthread_mutex_lock(&_mutexSrc);
|
||||
|
||||
free(_vfSrcSurfacePixBuffer);
|
||||
_vfSrcSurfacePixBuffer = NULL;
|
||||
_vfSrcSurface.Surface = NULL;
|
||||
|
@ -284,13 +297,12 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
|
|||
********************************************************************************************/
|
||||
uint32_t* VideoFilter::RunFilter()
|
||||
{
|
||||
pthread_mutex_lock(&this->_mutexSrc);
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
this->_isFilterRunning = true;
|
||||
uint32_t *destBufPtr = (uint32_t *)this->_vfDstSurface.Surface;
|
||||
|
||||
pthread_mutex_lock(&this->_mutexSrc);
|
||||
|
||||
if (this->_vfFunc == NULL)
|
||||
{
|
||||
memcpy(this->_vfDstSurface.Surface, this->_vfSrcSurface.Surface, this->_vfDstSurface.Width * this->_vfDstSurface.Height * sizeof(uint32_t));
|
||||
|
@ -317,11 +329,11 @@ uint32_t* VideoFilter::RunFilter()
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexSrc);
|
||||
|
||||
this->_isFilterRunning = false;
|
||||
pthread_cond_signal(&this->_condRunning);
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
pthread_mutex_unlock(&this->_mutexSrc);
|
||||
|
||||
return destBufPtr;
|
||||
}
|
||||
|
@ -505,6 +517,188 @@ unsigned int VideoFilter::GetDstHeight()
|
|||
return height;
|
||||
}
|
||||
|
||||
VideoFilterParamType VideoFilter::GetFilterParameterType(VideoFilterParamID paramID)
|
||||
{
|
||||
return _VideoFilterParamAttributesList[paramID].type;
|
||||
}
|
||||
|
||||
int VideoFilter::GetFilterParameteri(VideoFilterParamID paramID)
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
value = (int)(*((int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
value = (int)(*((unsigned int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
value = (int)(*((float *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
unsigned int VideoFilter::GetFilterParameterui(VideoFilterParamID paramID)
|
||||
{
|
||||
unsigned int value = 0;
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
value = (unsigned int)(*((int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
value = (unsigned int)(*((unsigned int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
value = (unsigned int)(*((float *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float VideoFilter::GetFilterParameterf(VideoFilterParamID paramID)
|
||||
{
|
||||
float value = 0.0f;
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
value = (float)(*((int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
value = (float)(*((unsigned int *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
value = (float)(*((float *)_VideoFilterParamAttributesList[paramID].index));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void VideoFilter::SetFilterParameteri(VideoFilterParamID paramID, int value)
|
||||
{
|
||||
if (paramID >= VideoFilterParamIDCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
*((int *)_VideoFilterParamAttributesList[paramID].index) = (int)value;
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
*((unsigned int *)_VideoFilterParamAttributesList[paramID].index) = (unsigned int)value;
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
*((float *)_VideoFilterParamAttributesList[paramID].index) = (float)value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
}
|
||||
|
||||
void VideoFilter::SetFilterParameterui(VideoFilterParamID paramID, unsigned int value)
|
||||
{
|
||||
if (paramID >= VideoFilterParamIDCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
*((int *)_VideoFilterParamAttributesList[paramID].index) = (int)value;
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
*((unsigned int *)_VideoFilterParamAttributesList[paramID].index) = (unsigned int)value;
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
*((float *)_VideoFilterParamAttributesList[paramID].index) = (float)value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
}
|
||||
|
||||
void VideoFilter::SetFilterParameterf(VideoFilterParamID paramID, float value)
|
||||
{
|
||||
if (paramID >= VideoFilterParamIDCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&this->_mutexDst);
|
||||
|
||||
switch (_VideoFilterParamAttributesList[paramID].type)
|
||||
{
|
||||
case VF_INT:
|
||||
*((int *)_VideoFilterParamAttributesList[paramID].index) = (int)value;
|
||||
break;
|
||||
|
||||
case VF_UINT:
|
||||
*((unsigned int *)_VideoFilterParamAttributesList[paramID].index) = (unsigned int)value;
|
||||
break;
|
||||
|
||||
case VF_FLOAT:
|
||||
*((float *)_VideoFilterParamAttributesList[paramID].index) = (float)value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->_mutexDst);
|
||||
}
|
||||
|
||||
// Task function for multithreaded filtering
|
||||
static void* RunVideoFilterTask(void *arg)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 2011 Roger Manuel
|
||||
Copyright (C) 2012 DeSmuME team
|
||||
Copyright (C) 2013 DeSmuME team
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,6 +28,10 @@
|
|||
#include "../utils/task.h"
|
||||
|
||||
|
||||
#define VIDEOFILTERTYPE_UNKNOWN_STRING "Unknown"
|
||||
|
||||
typedef void (*VideoFilterFunc)(SSurface Src, SSurface Dst);
|
||||
|
||||
// VIDEO FILTER TYPES
|
||||
enum VideoFilterTypeID
|
||||
{
|
||||
|
@ -54,10 +58,6 @@ enum VideoFilterTypeID
|
|||
VideoFilterTypeIDCount // Make sure this one is always last
|
||||
};
|
||||
|
||||
#define VIDEOFILTERTYPE_UNKNOWN_STRING "Unknown"
|
||||
|
||||
typedef void (*VideoFilterFunc)(SSurface Src, SSurface Dst);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
VideoFilterTypeID typeID;
|
||||
|
@ -89,6 +89,26 @@ const VideoFilterAttributes VideoFilterAttributesList[] = {
|
|||
{VideoFilterTypeID_EPXPlus1_5X, "EPX+ 1.5x", &RenderEPXPlus_1Point5x, 3, 2},
|
||||
{VideoFilterTypeID_HQ4XS, "HQ4xS", &RenderHQ4XS, 4, 1} };
|
||||
|
||||
// VIDEO FILTER PARAMETER DATA TYPES
|
||||
enum VideoFilterParamType
|
||||
{
|
||||
VF_INT = 0,
|
||||
VF_UINT,
|
||||
VF_FLOAT
|
||||
};
|
||||
|
||||
// VIDEO FILTER PARAMETERS
|
||||
// These tokens are used with the (Get/Set)FilterParameter family of methods.
|
||||
enum VideoFilterParamID
|
||||
{
|
||||
VF_PARAM_SCANLINE_A = 0, // Must always start at 0
|
||||
VF_PARAM_SCANLINE_B,
|
||||
VF_PARAM_SCANLINE_C,
|
||||
VF_PARAM_SCANLINE_D,
|
||||
|
||||
VideoFilterParamIDCount // Make sure this one is always last
|
||||
};
|
||||
|
||||
// Parameters struct for IPC
|
||||
typedef struct
|
||||
{
|
||||
|
@ -168,6 +188,13 @@ public:
|
|||
unsigned int GetSrcHeight();
|
||||
unsigned int GetDstWidth();
|
||||
unsigned int GetDstHeight();
|
||||
VideoFilterParamType GetFilterParameterType(VideoFilterParamID paramID);
|
||||
int GetFilterParameteri(VideoFilterParamID paramID);
|
||||
unsigned int GetFilterParameterui(VideoFilterParamID paramID);
|
||||
float GetFilterParameterf(VideoFilterParamID paramID);
|
||||
void SetFilterParameteri(VideoFilterParamID paramID, int value);
|
||||
void SetFilterParameterui(VideoFilterParamID paramID, unsigned int value);
|
||||
void SetFilterParameterf(VideoFilterParamID paramID, float value);
|
||||
};
|
||||
|
||||
static void* RunVideoFilterTask(void *arg);
|
||||
|
|
Loading…
Reference in New Issue