~kamalmostafa/ubuntu/lucid/pdp/fix-504941-ftbfs

« back to all changes in this revision

Viewing changes to modules/image_special/pdp_grey2mask.c

  • Committer: Bazaar Package Importer
  • Author(s): Guenter Geiger (Debian/GNU)
  • Date: 2005-03-15 22:21:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050315222105-1q287rsihmd9j1tb
Tags: 1:0.12.4-2
* fixed the hardcoded depends
* added 3dp library

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Pure Data Packet module.
3
 
 *   Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
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
 
 
21
 
 
22
 
/* this module converts a greyscale image or the luma channel of a colour image
23
 
   to a colour image intensity mask, usable for multiplication */
24
 
 
25
 
#include "pdp.h"
26
 
#include "pdp_resample.h"
27
 
 
28
 
typedef struct pdp_grey2mask_struct
29
 
{
30
 
    t_object x_obj;
31
 
    t_float x_f;
32
 
 
33
 
    t_outlet *x_outlet0;
34
 
 
35
 
    int x_packet0;
36
 
    int x_dropped;
37
 
    int x_queue_id;
38
 
 
39
 
 
40
 
} t_pdp_grey2mask;
41
 
 
42
 
 
43
 
 
44
 
static void pdp_grey2mask_process_grey(t_pdp_grey2mask *x)
45
 
{
46
 
    t_pdp     *header = pdp_packet_header(x->x_packet0);
47
 
    short int *data   = (short int *)pdp_packet_data  (x->x_packet0);
48
 
    t_pdp     *newheader = 0;
49
 
    short int *newdata = 0;
50
 
    int       newpacket = -1;
51
 
 
52
 
    unsigned int w = header->info.image.width;
53
 
    unsigned int h = header->info.image.height;
54
 
 
55
 
    unsigned int size = w*h;
56
 
    unsigned int totalnbpixels = size;
57
 
    unsigned int u_offset = size;
58
 
    unsigned int v_offset = size + (size>>2);
59
 
 
60
 
    unsigned int row, col;
61
 
 
62
 
    newpacket = pdp_packet_new_image_YCrCb(w, h);
63
 
    newheader = pdp_packet_header(newpacket);
64
 
    newdata = (short int *)pdp_packet_data(newpacket);
65
 
 
66
 
    /* copy luma channel */
67
 
    memcpy(newdata, data, size * sizeof(s16));
68
 
    
69
 
    /* subsample luma -> chroma channel */
70
 
    pdp_resample_halve(data, newdata+u_offset, w, h);
71
 
 
72
 
    /* copy this to the other chroma channel */
73
 
    memcpy(newdata+v_offset,  newdata+u_offset, (size>>2)*sizeof(s16));
74
 
 
75
 
    /* delete source packet and replace with new packet */
76
 
    pdp_packet_mark_unused(x->x_packet0);
77
 
    x->x_packet0 = newpacket;
78
 
    return;
79
 
}
80
 
 
81
 
static void pdp_grey2mask_process_yv12(t_pdp_grey2mask *x)
82
 
{
83
 
    /* process only the luminance channel */
84
 
    pdp_grey2mask_process_grey(x);
85
 
}
86
 
 
87
 
 
88
 
 
89
 
static void pdp_grey2mask_process(t_pdp_grey2mask *x)
90
 
{
91
 
   int encoding;
92
 
   t_pdp *header = 0;
93
 
 
94
 
   /* check if image data packets are compatible */
95
 
   if ( (header = pdp_packet_header(x->x_packet0))
96
 
        && (PDP_IMAGE == header->type)){
97
 
    
98
 
        /* pdp_grey2mask_process inputs and write into active inlet */
99
 
        switch(pdp_packet_header(x->x_packet0)->info.image.encoding){
100
 
 
101
 
        case PDP_IMAGE_YV12:
102
 
            pdp_grey2mask_process_yv12(x);
103
 
            break;
104
 
 
105
 
        case PDP_IMAGE_GREY:
106
 
            pdp_grey2mask_process_grey(x);
107
 
            break;
108
 
 
109
 
        default:
110
 
            /* don't know the type, so dont pdp_grey2mask_process */
111
 
            
112
 
            break;
113
 
        }
114
 
    }
115
 
}
116
 
 
117
 
static void pdp_grey2mask_sendpacket(t_pdp_grey2mask *x)
118
 
{
119
 
    /* unregister and propagate if valid packet */
120
 
    pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet0);
121
 
}
122
 
 
123
 
static void pdp_grey2mask_input_0(t_pdp_grey2mask *x, t_symbol *s, t_floatarg f)
124
 
{
125
 
 
126
 
    int p = (int)f;
127
 
 
128
 
    if (s== gensym("register_ro"))  x->x_dropped = pdp_packet_copy_ro_or_drop(&x->x_packet0, p);
129
 
 
130
 
 
131
 
    if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){
132
 
 
133
 
 
134
 
        /* add the process method and callback to the process queue */
135
 
 
136
 
        //pdp_queue_add(x, pdp_grey2mask_process, pdp_grey2mask_sendpacket, &x->x_queue_id);
137
 
        // since the process method creates a packet, this is not processed in the thread
138
 
        // $$$TODO: fix this
139
 
        pdp_grey2mask_process(x);
140
 
        pdp_grey2mask_sendpacket(x);
141
 
    }
142
 
 
143
 
}
144
 
 
145
 
 
146
 
 
147
 
static void pdp_grey2mask_free(t_pdp_grey2mask *x)
148
 
{
149
 
    t_pdp_procqueue *q = pdp_queue_get_queue();
150
 
    pdp_procqueue_finish(q, x->x_queue_id);
151
 
    pdp_packet_mark_unused(x->x_packet0);
152
 
 
153
 
}
154
 
 
155
 
t_class *pdp_grey2mask_class;
156
 
 
157
 
 
158
 
 
159
 
void *pdp_grey2mask_new(void)
160
 
{
161
 
    int i;
162
 
 
163
 
    t_pdp_grey2mask *x = (t_pdp_grey2mask *)pd_new(pdp_grey2mask_class);
164
 
 
165
 
    x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); 
166
 
    x->x_packet0 = -1;
167
 
    x->x_queue_id = -1;
168
 
 
169
 
 
170
 
    return (void *)x;
171
 
}
172
 
 
173
 
 
174
 
#ifdef __cplusplus
175
 
extern "C"
176
 
{
177
 
#endif
178
 
 
179
 
 
180
 
void pdp_grey2mask_setup(void)
181
 
{
182
 
 
183
 
 
184
 
    pdp_grey2mask_class = class_new(gensym("pdp_grey2mask"), (t_newmethod)pdp_grey2mask_new,
185
 
        (t_method)pdp_grey2mask_free, sizeof(t_pdp_grey2mask), 0, A_NULL);
186
 
 
187
 
 
188
 
    class_addmethod(pdp_grey2mask_class, (t_method)pdp_grey2mask_input_0, gensym("pdp"),  A_SYMBOL, A_DEFFLOAT, A_NULL);
189
 
 
190
 
 
191
 
}
192
 
 
193
 
#ifdef __cplusplus
194
 
}
195
 
#endif