void blend_ass_image(AVPicture *dest, const ASS_Image *image, int imgw, int imgh, enum PixelFormat pixel_format) { uint8_t rgba_color[] = { AR(image->color), AG(image->color), AB(image->color), AA(image->color) }; uint8_t rect_r, rect_g, rect_b, rect_a; int dest_r, dest_g, dest_b, dest_a; int x, y; uint32_t *dst2; uint8_t *src, *src2; uint8_t *dst = dest->data[0]; if (pixel_format != PIX_FMT_RGBA) return; dst += image->dst_y * dest->linesize[0] + image->dst_x * 4; src = image->bitmap; for (y = 0; y < image->h; y++) { dst2 = (uint32_t *) dst; src2 = src; for (x = 0; x < image->w; x++) { uint8_t image_pixel = *(src2++); uint32_t *pixel = (dst2++); rect_r = image_pixel & rgba_color[0]; rect_g = image_pixel & rgba_color[1]; rect_b = image_pixel & rgba_color[2]; rect_a = image_pixel & rgba_color[3]; RGBA_IN(dest_r, dest_g, dest_b, dest_a, pixel); // write subtitle on the image dest_r = ALPHA_BLEND_RGB(dest_r, rect_r, rect_a); dest_g = ALPHA_BLEND_RGB(dest_g, rect_g, rect_a); dest_b = ALPHA_BLEND_RGB(dest_b, rect_b, rect_a); RGBA_OUT(pixel, dest_r, dest_g, dest_b, dest_a); } dst += dest->linesize[0]; src += image->stride; } }
void blend_subrect_rgba(AVPicture *dest, const AVSubtitleRect *rect, int imgw, int imgh, enum PixelFormat pixel_format) { int rect_r, rect_g, rect_b, rect_a; int dest_r, dest_g, dest_b, dest_a; uint32_t *pal; uint32_t *dst2; uint8_t *src, *src2; int x, y; uint8_t *dst = dest->data[0]; if (pixel_format != PIX_FMT_RGBA) return; dst += rect->y * dest->linesize[0] + rect->x * 4; src = rect->pict.data[0]; pal = (uint32_t *) rect->pict.data[1]; for (y = 0; y < rect->h; y++) { dst2 = (uint32_t *) dst; src2 = src; for (x = 0; x < rect->w; x++) { uint32_t *rect_pixel = &pal[*(src2++)]; uint32_t *pixel = (dst2++); // read subtitle rgba8888 RGBA_IN(rect_r, rect_g, rect_b, rect_a, rect_pixel); RGBA_IN(dest_r, dest_g, dest_b, dest_a, pixel); // write subtitle on the image dest_r = ALPHA_BLEND_RGB(dest_r, rect_r, rect_a); dest_g = ALPHA_BLEND_RGB(dest_g, rect_g, rect_a); dest_b = ALPHA_BLEND_RGB(dest_b, rect_b, rect_a); RGBA_OUT(pixel, dest_r, dest_g, dest_b, dest_a); } dst += dest->linesize[0]; src += rect->pict.linesize[0]; } }
/* N->1 blending with per-surface alpha */ static void BlitNto1SurfaceAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB; unsigned dR, dG, dB; const unsigned A = info->a; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); dR = dstfmt->palette->colors[*dst].r; dG = dstfmt->palette->colors[*dst].g; dB = dstfmt->palette->colors[*dst].b; ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); dR &= 0xff; dG &= 0xff; dB &= 0xff; /* Pack RGB into 8bit pixel */ if ( palmap == NULL ) { *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); } else { *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; } dst++; src += srcbpp; },