| 1 | #include "frei0r.h" |
| 2 | #include <stdlib.h> |
| 3 | #include <assert.h> |
| 4 | |
| 5 | typedef struct blackwhite_instance |
| 6 | { |
| 7 | unsigned int width; |
| 8 | unsigned int height; |
| 9 | } blackwhite_instance_t; |
| 10 | |
| 11 | int f0r_init() |
| 12 | { |
| 13 | return 1; |
| 14 | } |
| 15 | |
| 16 | void f0r_deinit() |
| 17 | { /* no initialization required */ } |
| 18 | |
| 19 | void f0r_get_plugin_info(f0r_plugin_info_t* blackwhiteInfo) |
| 20 | { |
| 21 | blackwhiteInfo->name = "bw0r"; |
| 22 | blackwhiteInfo->author = "[email protected]"; |
| 23 | blackwhiteInfo->plugin_type = F0R_PLUGIN_TYPE_FILTER; |
| 24 | blackwhiteInfo->color_model = F0R_COLOR_MODEL_RGBA8888; |
| 25 | blackwhiteInfo->frei0r_version = FREI0R_MAJOR_VERSION; |
| 26 | blackwhiteInfo->major_version = 0; |
| 27 | blackwhiteInfo->minor_version = 9; |
| 28 | blackwhiteInfo->num_params = 0; |
| 29 | blackwhiteInfo->explanation = "Turns image black/white."; |
| 30 | } |
| 31 | |
| 32 | void f0r_get_param_info(f0r_param_info_t* info, int param_index) |
| 33 | { |
| 34 | /* no params */ |
| 35 | } |
| 36 | |
| 37 | f0r_instance_t f0r_construct(unsigned int width, unsigned int height) |
| 38 | { |
| 39 | blackwhite_instance_t* inst = (blackwhite_instance_t*)calloc(1, sizeof(*inst)); |
| 40 | inst->width = width; inst->height = height; |
| 41 | return (f0r_instance_t)inst; |
| 42 | } |
| 43 | |
| 44 | void f0r_destruct(f0r_instance_t instance) |
| 45 | { |
| 46 | free(instance); |
| 47 | } |
| 48 | |
| 49 | void f0r_set_param_value(f0r_instance_t instance, |
| 50 | f0r_param_t param, int param_index) |
| 51 | { /* no params */ } |
| 52 | |
| 53 | void f0r_get_param_value(f0r_instance_t instance, |
| 54 | f0r_param_t param, int param_index) |
| 55 | { /* no params */ } |
| 56 | |
| 57 | void f0r_update(f0r_instance_t instance, double time, |
| 58 | const uint32_t* inframe, uint32_t* outframe) |
| 59 | { |
| 60 | assert(instance); |
| 61 | blackwhite_instance_t* inst = (blackwhite_instance_t*)instance; |
| 62 | unsigned int w = inst->width; |
| 63 | unsigned int h = inst->height; |
| 64 | unsigned int x,y; |
| 65 | |
| 66 | uint32_t* dst = outframe; |
| 67 | const uint32_t* src = inframe; |
| 68 | for(y=h;y>0;--y) |
| 69 | for(x=w;x>0;--x,++src,++dst) |
| 70 | { |
| 71 | int tmpbw; |
| 72 | unsigned char* tmpc = (unsigned char*)src; |
| 73 | tmpbw = (tmpc[0] + tmpc[1] + tmpc[2]) / 3; |
| 74 | *dst = (tmpc[3] << 24) | (tmpbw << 16) | (tmpbw << 8) | tmpbw; |
| 75 | } |
| 76 | } |
| 77 |