| 1 | /* glow.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 <math.h> |
| 21 | #include "frei0r.h" |
| 22 | #include <stdlib.h> |
| 23 | #include "frei0r/blur.h" |
| 24 | |
| 25 | typedef struct glow_instance { |
| 26 | double blur; |
| 27 | int w, h; |
| 28 | uint32_t* blurred; |
| 29 | f0r_instance_t* blur_instance; |
| 30 | } glow_instance_t; |
| 31 | |
| 32 | int f0r_init() |
| 33 | { |
| 34 | return 1; |
| 35 | } |
| 36 | void f0r_deinit() |
| 37 | { /* empty */ } |
| 38 | |
| 39 | void f0r_get_plugin_info( f0r_plugin_info_t* info ) |
| 40 | { |
| 41 | info->name = "Glow"; |
| 42 | info->author = "Richard Spindler"; |
| 43 | info->plugin_type = F0R_PLUGIN_TYPE_FILTER; |
| 44 | info->color_model = F0R_COLOR_MODEL_RGBA8888; |
| 45 | info->frei0r_version = FREI0R_MAJOR_VERSION; |
| 46 | info->major_version = 0; |
| 47 | info->minor_version = 1; |
| 48 | info->num_params = 1; |
| 49 | info->explanation = "Creates a Glamorous Glow"; |
| 50 | |
| 51 | } |
| 52 | void f0r_get_param_info( f0r_param_info_t* info, int param_index ) |
| 53 | { |
| 54 | switch ( param_index ) { |
| 55 | case 0: |
| 56 | info->name = "Blur"; |
| 57 | info->type = F0R_PARAM_DOUBLE; |
| 58 | info->explanation = "Blur of the glow"; |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | f0r_instance_t f0r_construct(unsigned int width, unsigned int height) |
| 64 | { |
| 65 | glow_instance_t* inst = (glow_instance_t*)calloc(1, sizeof(*inst)); |
| 66 | inst->w = width; |
| 67 | inst->h = height; |
| 68 | inst->blurred = (uint32_t*)malloc( width * height * sizeof(uint32_t) ); |
| 69 | inst->blur_instance = (f0r_instance_t *)blur_construct( width, height ); |
| 70 | blur_set_param_value(inst->blur_instance, &inst->blur, 0 ); |
| 71 | return (f0r_instance_t)inst; |
| 72 | } |
| 73 | void f0r_destruct(f0r_instance_t instance) |
| 74 | { |
| 75 | glow_instance_t* inst = (glow_instance_t*)instance; |
| 76 | blur_destruct(inst->blur_instance); |
| 77 | free(inst->blurred); |
| 78 | free(instance); |
| 79 | } |
| 80 | void f0r_set_param_value(f0r_instance_t instance, |
| 81 | f0r_param_t param, int param_index) |
| 82 | { |
| 83 | glow_instance_t* inst = (glow_instance_t*)instance; |
| 84 | switch ( param_index ) { |
| 85 | case 0: |
| 86 | inst->blur = (*((double*)param)) / 20.0; |
| 87 | blur_set_param_value(inst->blur_instance, &inst->blur, 0 ); |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | void f0r_get_param_value(f0r_instance_t instance, |
| 92 | f0r_param_t param, int param_index) |
| 93 | { |
| 94 | glow_instance_t* inst = (glow_instance_t*)instance; |
| 95 | switch ( param_index ) { |
| 96 | case 0: |
| 97 | *((double*)param) = inst->blur * 20.0; |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | void f0r_update(f0r_instance_t instance, double time, |
| 102 | const uint32_t* inframe, uint32_t* outframe) |
| 103 | { |
| 104 | glow_instance_t* inst = (glow_instance_t*)instance; |
| 105 | |
| 106 | uint8_t* dst = (uint8_t*)outframe; |
| 107 | const uint8_t* src = (uint8_t*)inframe; |
| 108 | const uint8_t* blur = (uint8_t*)inst->blurred; |
| 109 | |
| 110 | int len = inst->w * inst->h * 4; |
| 111 | |
| 112 | blur_update(inst->blur_instance, 0.0, inframe, inst->blurred ); |
| 113 | |
| 114 | int i; |
| 115 | for ( i = 0; i < len; i++ ) { |
| 116 | *dst = 255 - ( ( 255 - *src ) * ( 255 - *blur ) ) / 255; |
| 117 | // 1 - ( ( 1 - A ) * ( 1 - B ) ) |
| 118 | dst++; |
| 119 | src++; |
| 120 | blur++; |
| 121 | } |
| 122 | |
| 123 | } |
| 124 |