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