Skip to content

Commit

Permalink
[coreImage, addLogo] Allow to reduce opacity of logo images containin…
Browse files Browse the repository at this point in the history
…g alpha channel
  • Loading branch information
eumagga0x2a committed Dec 15, 2017
1 parent 03ff117 commit c9f8f26
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion avidemux_core/ADM_coreImage/include/ADM_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ virtual ~ADMImage();
bool blacken(void);
bool copyTo(ADMImage *target, uint32_t x, uint32_t y);
bool copyToAlpha(ADMImage *target, uint32_t x, uint32_t y,uint32_t alpha);
bool copyWithAlphaChannel(ADMImage *target, uint32_t x, uint32_t y);
bool copyWithAlphaChannel(ADMImage *target, uint32_t x, uint32_t y, uint32_t opacity=255);
bool copyLeftSideTo(ADMImage *dest);
/* Some utilitarian functions */
bool saveAsBmp(const char *filename);
Expand Down
12 changes: 8 additions & 4 deletions avidemux_core/ADM_coreImage/src/ADM_imageOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ bool ADMImage::copyToAlpha(ADMImage *dest, uint32_t x,uint32_t y,uint32_t alpha)
* @return
*/

static bool blitWithAlpha(uint8_t *dst, uint8_t *src, uint8_t *alpha,int dstStride, int srcStride,int alphaStride,int w,int h, int mul)
static bool blitWithAlpha(uint8_t *dst, uint8_t *src, uint8_t *alpha, int dstStride, int srcStride, int alphaStride, int w, int h, int mul, uint32_t opacity)
{
for(int k=0;k<h;k++)
{
for(int j=0;j<w;j++)
{
int a=alpha[mul*j];
if(opacity<255)
{
a*=opacity;
a>>=8;
}
uint32_t x=(255-a)*dst[j]+a*src[j];
dst[j]=x>>8;
}
Expand All @@ -245,9 +250,8 @@ static bool blitWithAlpha(uint8_t *dst, uint8_t *src, uint8_t *alpha,int dstStri
}
return true;
}
bool ADMImage::copyWithAlphaChannel(ADMImage *dest, uint32_t x,uint32_t y)
bool ADMImage::copyWithAlphaChannel(ADMImage *dest, uint32_t x,uint32_t y,uint32_t opacity)
{

uint32_t box_w=_width, box_h=_height;
// Clip if needed
if(y>dest->_height)
Expand Down Expand Up @@ -293,7 +297,7 @@ bool ADMImage::copyWithAlphaChannel(ADMImage *dest, uint32_t x,uint32_t y)
dstPitches[i],
srcPitches[i],
alphaStride,
ww,hh,mul);
ww,hh,mul,opacity);
}
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion avidemux_plugins/ADM_videoFilters6/logo/ADM_vidLogo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool addLogopFilter::getNextFrame(uint32_t *fn,ADMImage *image)
if(myImage)
{
if(myImage->GetReadPtr(PLANAR_ALPHA))
myImage->copyWithAlphaChannel(image,configuration.x,configuration.y);
myImage->copyWithAlphaChannel(image,configuration.x,configuration.y,configuration.alpha);
else
myImage->copyToAlpha(image,configuration.x,configuration.y,configuration.alpha);
}
Expand Down
13 changes: 3 additions & 10 deletions avidemux_plugins/ADM_videoFilters6/logo/qt4/Q_logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,9 @@ bool Ui_logoWindow::tryToLoadimage(const char *imageName)
imageHeight=image->GetHeight(PLANAR_Y);
this->imageName=std::string(imageName);
ui.labelImage->setText(this->imageName.c_str());

if(image->GetReadPtr(PLANAR_ALPHA))
ui.spinAlpha->setEnabled(false);
else
ui.spinAlpha->setEnabled(true);
status=true;

ADM_info("We have alpha\n");
status=true;
}
}
enableLowPart(status);
Expand Down Expand Up @@ -368,10 +364,7 @@ uint8_t flyLogo::processYuv(ADMImage* in, ADMImage *out)

ADMImage *myImage=parent->image;
if(myImage->GetReadPtr(PLANAR_ALPHA))
{
ADM_info("We have alpha\n");
myImage->copyWithAlphaChannel(out,param.x,param.y);
}
myImage->copyWithAlphaChannel(out,param.x,param.y,param.alpha);
else
myImage->copyToAlpha(out,param.x,param.y,param.alpha);
return true;
Expand Down

0 comments on commit c9f8f26

Please sign in to comment.