| 1 | /* alphainjection.c |
| 2 | * Copyright (C) 2007 Richard Spindler ([email protected]) |
| 3 | * This file is a Frei0r plugin. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <assert.h> |
| 22 | |
| 23 | #include "frei0r.h" |
| 24 | |
| 25 | typedef struct alphainjection_instance |
| 26 | { |
| 27 | unsigned int width; |
| 28 | unsigned int height; |
| 29 | } alphainjection_instance_t; |
| 30 | |
| 31 | int f0r_init() |
| 32 | { |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | void f0r_deinit() |
| 37 | { /* no initialization required */ } |
| 38 | |
| 39 | void f0r_get_plugin_info(f0r_plugin_info_t* alphainjectionInfo) |
| 40 | { |
| 41 | alphainjectionInfo->name = "Alpha Injection"; |
| 42 | alphainjectionInfo->author = "Richard Spindler"; |
| 43 | alphainjectionInfo->plugin_type = F0R_PLUGIN_TYPE_MIXER2; |
| 44 | alphainjectionInfo->color_model = F0R_COLOR_MODEL_RGBA8888; |
| 45 | alphainjectionInfo->frei0r_version = FREI0R_MAJOR_VERSION; |
| 46 | alphainjectionInfo->major_version = 0; |
| 47 | alphainjectionInfo->minor_version = 9; |
| 48 | alphainjectionInfo->num_params = 0; |
| 49 | alphainjectionInfo->explanation = "Averages Input 1 and uses this as Alpha Channel on Input 2"; |
| 50 | } |
| 51 | |
| 52 | void f0r_get_param_info(f0r_param_info_t* info, int param_index) |
| 53 | { |
| 54 | /* no params */ |
| 55 | } |
| 56 | |
| 57 | f0r_instance_t f0r_construct(unsigned int width, unsigned int height) |
| 58 | { |
| 59 | alphainjection_instance_t* inst = (alphainjection_instance_t*)calloc(1, sizeof(*inst)); |
| 60 | inst->width = width; inst->height = height; |
| 61 | return (f0r_instance_t)inst; |
| 62 | } |
| 63 | |
| 64 | void f0r_destruct(f0r_instance_t instance) |
| 65 | { |
| 66 | free(instance); |
| 67 | } |
| 68 | |
| 69 | void f0r_set_param_value(f0r_instance_t instance, |
| 70 | f0r_param_t param, int param_index) |
| 71 | { /* no params */ } |
| 72 | |
| 73 | void f0r_get_param_value(f0r_instance_t instance, |
| 74 | f0r_param_t param, int param_index) |
| 75 | { /* no params */ } |
| 76 | |
| 77 | |
| 78 | void f0r_update2(f0r_instance_t instance, |
| 79 | double time, |
| 80 | const uint32_t* inframe1, |
| 81 | const uint32_t* inframe2, |
| 82 | const uint32_t* inframe3, |
| 83 | uint32_t* outframe) |
| 84 | { |
| 85 | assert(instance); |
| 86 | alphainjection_instance_t* inst = (alphainjection_instance_t*)instance; |
| 87 | unsigned int w = inst->width; |
| 88 | unsigned int h = inst->height; |
| 89 | unsigned int x,y; |
| 90 | |
| 91 | uint32_t* dst = outframe; |
| 92 | const uint32_t* alpha = inframe1; |
| 93 | const uint32_t* src = inframe2; |
| 94 | for(y=0;y<h;++y) |
| 95 | for(x=0;x<w;++x,++src) { |
| 96 | int tmpbw; |
| 97 | unsigned char* tmpc = (unsigned char*)alpha; |
| 98 | tmpbw = (tmpc[0] + tmpc[1] + tmpc[2]) / 3; |
| 99 | |
| 100 | *dst++ = ( 0x00ffffff & (*src) ) | (tmpbw << 24); |
| 101 | alpha++; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 |