diff options
160 files changed, 4998 insertions, 13832 deletions
diff --git a/CHANGES.LOG b/CHANGES.LOG index eeb0931..67215ce 100644 --- a/CHANGES.LOG +++ b/CHANGES.LOG @@ -75,3 +75,61 @@ v0.9: 2003/02/27 fixed pdp_xv bang crash added pdp_grey2mask added pdp_slice_cut/pdp_slice_glue (experimental/nondoc) + +v0.10: 2003/03/06 + modules code reorganization + removed pdp_affine object and added compatibility object based on pdp_cheby + added pdp_mchp and PDP_IMAGE_MCHP packet format (experimental) + added pdp_and, pdp_or, pdp_xor, pdp_not, pdp_bitmask, pdp_bitdepth + added base class for pdp objects + added incremental garbage collector + added support for "not so pure" data packets + added opengl subproject containing a pdp_glx display object + added a PDP_TEX opengl texture packet (opengl lib) + added PDP_IMAGE_GREY8, PDP_IMAGE_RGB8, PDP_IMAGE_RGBA8 packets + (0.10.1) fixed (fatal) bug in pdp_base, and bug in pdp_noise (non-mmx) + (0.10.1) pdp_glx now compiles on mac osx + +v0.11: 2003/04/08 + updated pdp_trigger to behave like pd's trigger object + added automatic philips web cam detection + removed "zombie" packet passing and made pool manager thread safe + (this required an api change: backward compat for pdp thread proc broken) + added gem style object rendering & transformation objects (opengl lib) + removed pdp_gradient binary module (it is now an abstraction) + added pdp_loop (a packet array / loop sampler) + added pdp_description + added support for libquicktime on osx (thanks Jamie) + added support for accumulation packets (dpd) (still experimental) + (0.11.1) fixed some packet registering and frame dropping bugs + +v0.12: 2003/06/21 + added support for high level packet conversion (mime-like descriptions) + added pdp_convert + added "memlimit" message to pdp_control (to limit pdp's mem usage) + maximum nb of packets is now only limited by the memlimit + added new basic type: bitmap/*/* (PDP_BITMAP) for standard fourcc formats + cleaned up pdp_xv/glx (x window glue code reuse) + fixed rgb/bgr bug in conversion code + added pdp_abs, pdp_zthresh + completed dpd framework (for context based processing, i.e. 3dp) + rewrote gem like 3d library on top of dpd (it's almost stable) + added a matrix type (float/double real/complex) for linear algebra stuff + added matrix processors pdp_m_*: mv, mm, +=mm, LU, LU_inverse, LU_solve + pdp_cheby now accepts an array with a mapping function + added pdp_plasma + fixed outlet_pdp bug (this caused all kind of weirdness) + added embedded scheme interpreter for testing (see the guile/ dir) + added simple forth-style scripting language (pdp's rpn calculator) + added png load/save support to pdp_reg + (0.12.1) fixed OSX compilation probs + (0.12.1) fixed texture coordinate bugs (pdp_opengl) + (0.12.1) added multipass rendering support (pdp_opengl) + (0.12.1) pdp_cog (Johannes Taelman's gaussian blob estimator) + (0.12.1) pdp_sthresh, hthresh, positive, offset, sign + (0.12.1) pdp_agc, contrast, flip_lr, flip_tb + (0.12.1) added pdp and pdp_opengl examples + (0.12.2) pdp_histo, dither, pointcloud + (0.12.2) more examples & added some conversion code + (0.12.2) fixed c++ compilation issues + @@ -9,15 +9,16 @@ pdp_all: darwin: pdp_all rm -f pdp.pd_darwin - $(CC) -bundle -bundle_loader $(PD_EXECUTABLE) -o pdp.pd_darwin modules/*.o system/*.o $(PDP_LIBS) + $(CC) -o pdp.pd_darwin modules/*/*.o system/*/*.o $(PDP_LIBS) -bundle -undefined error -twolevel_namespace -bundle_loader $(PD_EXECUTABLE) + linux: pdp_all rm -f pdp.pd_linux - $(CC) -export_dynamic -shared -o pdp.pd_linux modules/*.o system/*.o $(PDP_LIBS) + $(CC) -export_dynamic -shared -o pdp.pd_linux modules/*/*.o system/*/*.o $(PDP_LIBS) linux_mmx: pdp_all rm -f pdp.pd_linux - $(CC) -export_dynamic -shared -o pdp.pd_linux modules/*.o system/*.o system/mmx/*.o $(PDP_LIBS) + $(CC) -export_dynamic -shared -o pdp.pd_linux modules/*/*.o system/*/*.o $(PDP_LIBS) buildclean: make -C include clean @@ -30,6 +31,8 @@ clean: buildclean distroclean: buildclean make -C scaf clean + make -C opengl clean + make -C guile clean mrproper: clean make -C scaf mrproper @@ -37,10 +40,12 @@ mrproper: clean rm -rf config.log rm -rf config.status rm -rf autom4te.cache - rm -rf Makefile.config + #this needs to stay in to keep the makefiles working + #rm -rf Makefile.config tags: - etags --language=auto include/*.h system/mmx/*.s system/*.c modules/*.c + etags --language=auto include/*.h system/mmx/*.s system/*/*.c \ + modules/*/*.c scaf/*/*.c scaf/*/*.s opengl/*/*.c tagsclean: rm -f TAGS @@ -48,7 +53,6 @@ tagsclean: install: all #check if pd is installed. if this fails make install will stop here. - test -d $(prefix)/lib/pd install -m 755 $(PDP_LIBRARY_NAME) $(prefix)/lib/pd/externs install -m 755 -d $(prefix)/include/pdp install -m 644 include/*.h $(prefix)/include/pdp diff --git a/Makefile.config.in b/Makefile.config.in index 2f163db..5b0c2ac 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -13,16 +13,18 @@ PDP_TARGET = @PDP_TARGET@ PDP_LIBRARY_NAME = @PDP_LIBRARY_NAME@ PDP_OPTMOD = @PDP_OPTMOD@ PDP_EXTRA_CPPFLAGS = @PDP_EXTRA_CPPFLAGS@ +PDP_EXTRA_CFLAGS = @PDP_EXTRA_CFLAGS@ SDL_FLAGS = -D_REENTRANT -PDP_CPPFLAGS = -I. -I/usr/X11R6/include -I../include $(PD_CPPFLAGS) $(PDP_EXTRA_CPPFLAGS) +PDP_CPPFLAGS = -I. -I/usr/X11R6/include -I../include -I../../include $(PD_CPPFLAGS) $(PDP_EXTRA_CPPFLAGS) PDP_LIBS = @LIBS@ PDP_AFLAGS = #--gstabs PDP_CFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -ffast-math \ - -Wall -W -Wstrict-prototypes -Werror \ + -Wall -W -Wstrict-prototypes \ -Wno-unused -Wno-parentheses -Wno-switch -DPDP_VERSION=\"$(PDP_VERSION)\" \ - -g $(SDL_CFLAGS) + -g $(SDL_CFLAGS) $(PDP_EXTRA_CFLAGS) +# -Werror # -Wshadow # compiler and assembler @@ -1,4 +1,4 @@ -PDP - Pure Data Packet v0.9 +PDP - Pure Data Packet v0.12.2 a packet processing library for pure data Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> @@ -26,30 +26,47 @@ This external pd library is a framework for image/video processing (and other raw data packets) that is fast, simple and flexible and as much as possible compatible with the pd messaging system. +This distro contains the main pdp library and 3 extension libs: +* pdp_scaf (in directory scaf/) +* pdp_opengl (in directory opengl/) +* pdp_guile (in directory guile) Features: -* packet formats: greyscale and YV12 encoded images, - binary cellular automata (CA) -* sources: noise, video4linux and quicktime (with audio), CA -* sinks: xvideo display, sdl +* packet formats: greyscale and YCrCb encoded images, + binary cellular automata (CA), textures, render buffers, + matrices. +* sources: noise, video4linux and quicktime (with audio), CA, plasma +* sinks: xvideo display, sdl, glx display * filters: convolution, biquad time, biquad space, CA * warping: rotate, zoom, stretch * transforms: colour translation/scaling, grey->palette * add, mul, mix, random pixel mix * utility objs: packet register, snapshot, trigger -* packet delay line -* minimal forth system for defining CA rules (only for mmx) +* packet delay line, loop, .. +* and more.. (see doc/reference.txt) + +Optional features + +* cellular automata simulator and effects processor with + built in forth extension language (only for mmx) +* opengl 3d processing (gem like, but built around packets) +* embedded guile interpreter + +See the README files in the scaf/ opengl/ and guile/ dirs for more +info on the extension libraries. Requirements: * pd * linux +* libgsl * a video4linux device for video input. special support for philips webcam included. * libquicktime (not quicktime4linux!) for quicktime playback. -* an X display with XVideo extension or SDL for video display. +* libpng for png image loading/saving +* an X display with XVideo extension, glx or SDL for video display. Documentation: @@ -72,54 +89,80 @@ make Options for configure: --enable-mmx compile with mmx support ---enable-pwc compile with philips webcam support +--enable-pwc force pdp_v4l to use philips web cam If pd is not installed in /usr/local you'll have to specify the prefix on the configure command line with -./configure --prefix=dir +./configure --prefix=/prefix type make install -To install pd in $prefix/lib/pd: the library in externs/ +To install pdp in $prefix/lib/pd: the library in externs/ the abstractions in extra/ and the documentation in doc/5.reference and doc/pdp +You can also try the "buildall" script. This will configure, build +and install the whole distribution. It works for intel/mmx. + NOTE: If you're not using the standard pd install location, and have -everything in a single tree, just untar pdp next to the pd source tree. +everything in a single tree, just untar pdp next to the pd source tree, +or set the prefix dir to the location of the pd source. Bugs: See the TODO file. Apart from the few items listed on top of this -file, pdp is fairly stable. If you encounter a crash please consider -sending a bug report. +file, pdp is fairly stable: i am unaware of crash bugs. If you encounter +a crash please consider sending a bug report. -Additional Remarks: +PiDiP Is Definitely In Pieces -* The modules that depend on system libraries only get compiled when -the configure script can locate them. If compilation or linking fails -please let me know. NOTE: If you have libquicktime and quicktime4linux -installed, this can give problems with the configure script. Consider -removing quicktime4linux. (libquicktime is a drop-in replacement). +Have a look at Yves Degoyon's PiDiP library, the must have addition +to the basic pdp library. It contains a lot of extra effects (from +EffecTV and FreeJ), a quicktime recording object, streaming modules, +ascii art objects ... (the list is growing rapidly ;) +Yves also did a gem2pd and a pdp2gem object to connect pdp and gem +together. -* The reason i use YV12 and not RGB is simple: it's faster, and for -linear operations it doesn't make much difference. Most camera's and -codecs use a luma/chroma system, and most video cards support hardware -accellerated display. Note that in YUV, the u (Cb) and v (Cr) components -can be negative, so saturation after multiplication with a positive -(or negative) value produces not only black and white, but also red, -green, blue and their complements. In short, in YUV, nonlinear operations -have a different effect than in RGB. Another thing: all the spatial -operations are not implemented "correctly" because of the subsampling -involved. +http://ydegoyon.free.fr/ + + +Acknowledgements + +PDP is no longer a one man show. Many thanks to the people who +directly or indirectly contributed to this project. Either by +writing a giant extension lib (thanks Yves) or by contributing code +snippets (Thanks Martin, CK), or by giving mental support, feedback, +bug reports and ideas. + +I also wish to thank the GEM crew. This project borrows a lot of ideas +and some code from the GEM project. And while i'm at it, i wish to +thank everyone who contributed code to the PD project as a whole and +the people that are very helpful at answering questions on the mailing +list. + +Last but not least i wish to thank Miller for making the PD project +open source. If that didn't happen i wouldn't know what i'd be doing +now :) + + +Some Remarks: + +* New versions of this package can be found at +http://zwizwa.fartit.com/pd/pdp +Experimental relases are in the subdirectory test/ -* The image packets are 16bit/component planar. This is to simplify -the mmx code and to have a little more headroom and precision for -processing. +* If you have libquicktime and quicktime4linux installed, this can +give problems with the configure script. Consider removing +quicktime4linux. (libquicktime is a drop-in replacement). + +* The modules that depend on system libraries only get compiled when +the configure script can locate them. If compilation or linking fails +please let me know. * Packets can be processed in a low priority thread with a dropping mechanism to prevent overload or audio drops, or they can be processed @@ -131,32 +174,69 @@ care about a dropped video frame here and there, switch on the pdp thread. Note that when using the pdp thread, the control flow is no longer depth first. Additinal delays will be introduced. -* There have been some requests for an osx port, but i wil probably not -do this myself (at least not right now). However, the platform -independent part of pdp compiles on darwin, although it is not of much -use yet without input and output modules. - -* Have a look at Yves Degoyon's PiDiP library. It contains some extra -effects (from EffecTV and FreeJ), a quicktime recording object, some -streaming modules, ... (the list is growing rapidly ;) see -http://ydegoyon.free.fr/ +* Pdp runs on osx, using an x server (apple or fink) and libquickime +(fink). pdp_xv does not work yet. Once apple includes xv support in +their x server, it should. Until then, use pdp_glx for output. * Some quicktime remarks: pdp_qt~ is still a bit experimental, you might try pdp_yqt in yves' lib to see if it works better for you. Also, it seems that libquicktime does not work with compressed headers. The suggested codec is jpeg (photo) and uncompressed audio with the same -samplerate as the one pd is using. (hint: compile libquicktime with -mmx jpeg support) +samplerate as the one pd is using. You can use other codecs, but i've +found this one to perform the best. (hint: compile libquicktime with +mmx jpeg support) Try to avoid the mpga codec. It is haunted. + +* The reason i use YV12 and not RGB is simple: it's faster, and for +linear operations it doesn't make much difference. Most camera's and +codecs use a luma/chroma system, and most video cards support hardware +accellerated display. Note that in YUV, the u (Cb) and v (Cr) components +can be negative, so saturation after multiplication with a positive +(or negative) value produces not only black and white, but also red, +green, blue and their complements. In short, in YUV, nonlinear operations +have a different effect than in RGB. Another thing: all the spatial +operations are not implemented "correctly" because of the subsampling +involved.The image packets are 16bit/component planar. This is to +simplify the mmx code and to have a little more headroom and precision +for processing. + +* Since version 0.11 there is a type system used for identifying a +packet type and performing type conversion. A type is represented +by a symbol, with subtypes separated by the "/" character. I.e. +"image/grey/320x240" is a grey 16 bit/component image with dimensions +320 by 240. For conversions a wildcard can be specified. I.e. +"image/*/*" which matches image type packets with all encodings +and dimensions. + +* Since version 0.12 there are 2 different image data types: "image/*/*" +and "bitmap/*/*". The image type is the native 16 bit/component pdp +type. It supports the subtypes "image/grey/*": one channel grey +scale images, "image/YCrCb/*": luma/chroma packets with subsampled +chroma planes and "image/multi/*": a multi channel planar format (i.e. +to store 3 or 4 channel rgb or rgba data). Almost all processors +use this data type. The bitmap type is an intermediate type which +can contain standard fourcc encoded 8 bit/component images i.e. +"bitmap/rgb/*", "bitmap/yv12/*", "bitmap/grey/*". Currently no processors +support this type natively, so you have to use pdp_convert to convert +them to "image/*/*". * Writing new objects is not much different than normal pd externs. Pdp just adds some functions to the pd kernel for package allocation, manipulation and communication. The api is very raw to keep it as -simple as possible. In the future there will probably be a layer on -top of this that will make things a bit less spartan. +simple as possible. Since 0.10 there is a pdp_base object you can +derive your objects from. Have a look at pdp_add, pdp_gain and +pdp_noise to see how it works. There is not much documentation, but +i do my best to keep things clean so the code and the header files +should get you started. You can always just send me an email for info, +or ask on the pd-dev list. Since version 0.12 there is a simple forth +scripting language in pdp. This is far from finished, but it should +make pdp programming a lot easier. + +* Philips webcam detection is now automatic. However this requires a +fairly recent kernel (one which includes the pwc driver version 8.6 +or higher). If you have a pwc and pdp_v4l does not display a +"pwc detected" message, you can conifigure with --enable-pwc. This +forces pdp_v4l to use the pwc api extensions. -* New versions of this package can be found at -http://zwizwa.fartit.com/pd/pdp -Experimental relases are in the subdirectory test/ Directory structure: @@ -166,10 +246,12 @@ doc/introduction/ getting started with pdp doc/examples/ some example patches doc/objects/ pd style reference documentation include/ header files -modules/ pdp module code -scaf/ CA extension lib (needs to be compiled separately) +modules/ pd object code +opengl/ opengl extension lib (experimental) +scaf/ CA extension lib +guile/ scheme extension lib system/ core pdp system -system/mmx/ mmx assembler files + @@ -181,4 +263,5 @@ Have Fun, Tom -last modified: 2003/02/24 +last modified: 2003/07/20 + @@ -1,39 +1,57 @@ -fatal crash bugs: - -* none that i know of (if pdp dies on you, please let me know) - - -todo 0.9: - -* 2D affine transforms parametrized by vectors (center, x-axis, y-axis) +known bugs: + +* running out of memory (using delay lines or loops) will likely crash pd. +short story: don't, use pdp_control's memlimit for limiting pdp's memory usage. +* no known other fatal (crashing) bugs. please let me know if you find one. + + + +todo 0.13: + +* add source type to source objects (noise,plasma,constant,...) +* pdp_crop/pad +* seed plasma +* reorganize headers to cut down compile time +* fullscreen x command -> add window manager suppression +* where to solve autoconvert? per type, or central in pdp_base? 2 cases: +- template based autoconvert: in pdp_base +- compatibility based autoconvert: i.e. pdp_add (solve in base: move_passive) +* finish high level packet conversion: +- move 8bit images to packet level (iow: cleanup pdp_qt, pdp_v4l, pdp_xv) +- add bitmap packet support to source modules (optim for pdp_opengl usage) +- get rid of pdp_type* methods +* fix mac/linux name differences (use pdp_video, pdp_movie, pdp_window) +* pdp_xv framerate doc + pwc addons + +todo 0.14: + +* stress test the memory manager. it looks like there's a bug that pops up after running for a while +* image packet -> sound: interpret as sonogram: intensity = magnitude, colour = phase +* enable audio output on bttv cards in pdp_v4l +* fix cache slicer objects + thread problems (add slice objects to forth) +* derive as much classes as possible from pdp_base class (part of module code reorg) +* displacement warp, substitution warp, refraction warp, timespace warp, wormhole warp +* check the use of varargs for image processing dispatching routine +* more scopes +* 2D affine transforms parametrized by vectors (center, x-axis, y-axis) (np1 + matrix processing objects) * some abstractions around pdp_cheby (colour shape, ...) -* add real trigger object (problem with 3 phase protocol ?) -* absolute value object -* displacement warp, substitution warp +* thresholding (abstraction using pdp_cheby?) + absolute value object * efficient rescalers: pdp_double pdp_halve * move float color conversion and float<->fixed point conv code to system * crop, shift (pad+scroll) - -todo 0.10: - -* solve biquad (blur) boundary init prob +* solve biquad (blur) mmx boundary init prob (bands at edges: solve with proper init?) * optimize blur effect (1 pole ? / dependency stalls) -* jpeg/png file and streaming support? -* thresholding +* jpeg/png packet and streaming support (pdp_netsend / pdp_netreceive : binary compat issues!!) * find out why resampling code (warping) is so slow (reg->mem->reg->mem stalls?) * mmx profiling * add audio resampling in pdp_qt~ * use pd_error instead of post for errors -* interface with gem -* think about the memory allocation strategy (there is no garbage collection right now) -* add automatic pwc detection -* frame rate limited delay line (burst delay?) - -wish list: - -* ascii art packet stuff (yves?) +* ascii art packet processors * 3D time space interpolation * colour keying -* camera controller (motion tracking ?) -* moebius transforms (integer inverse square root??) & other complex plane stuff +* motion tracking +* moebius transforms +* type multiplexing: find a way to use the same name for packet processors. (-> forth) +i.e. pdp_add should add images, but also vectors, ascii packets, textures,... + diff --git a/TODO.EXP b/TODO.EXP new file mode 100644 index 0000000..f3d1955 --- /dev/null +++ b/TODO.EXP @@ -0,0 +1,58 @@ + +experimental stuff + +todo: + +* modify 2D rotation to be used as arbitrary rotation (givens) +* add 3D rotation +* frame rate limited delay line (burst delay?) +* optimize resampling code (mipmapped packed 16bit format?) + + +* cache slicer + +pdp_slice_cut & pdp_slice_glue seem to have a significant impact on performance +for long chains with simple (memory rate limited) operators. especially when a lot +of passive packets are involved. todo: make a vertical slicer + mmx transpose object +to use this for horizontal and vertical processors too (vertical processors: more efficient +because of alignment). find out why this doesn't work in threads + think about a possibility +to do first layout a buffer structure, and then do incremental processing (outside of pd/pdp: +for constructing optimized signal processors using some kind of intermediate language +and automatic slice dimension selection) +NOTE: solve this as a forth script for specific abstractions. + +* new image packet types + +*) PDP_IMAGE_MCHP + +multi channel stuff. this packet type is to solve some problems with the subsampled +chroma planes in PDP_IMAGE_YV12. although it is fast, it is best to have an equally +sampled, arbitrary number of channels image type available. + + +*) PDP_IMAGE_PCK4 + +the main reason for this package type is in resampling code to have single pixel +access mmx routines. but is it worth it? probably not.. mipmap image packet for resampling? + + +* new vectors, matrices & gsl packets + +general matrix math is a nice thing to have. wrapping gsl is a possibility. it can use +atlas for fast matrix math. finish better type handling first. + + +* opengl -> see also opengl/TODO + +move opengl stuff to dpd. +todo: +- think about pbufs / textures : isolate system specific stuff + + +* better type handling + +core is in place. todo: +- better (tree) search algorithm (breadth first + cost) +- add more converters + + diff --git a/abstractions/pdp_affine.pd b/abstractions/pdp_affine.pd new file mode 100644 index 0000000..831d8ae --- /dev/null +++ b/abstractions/pdp_affine.pd @@ -0,0 +1,15 @@ +#N canvas 600 556 450 300 10; +#X obj 47 39 inlet; +#X obj 111 39 inlet; +#X obj 170 38 inlet; +#X obj 98 151 pdp_cheby; +#X obj 63 205 outlet; +#X text 26 7 for patch compatibility with older versions of pdp; +#X msg 119 98 coef 1 \$1; +#X msg 197 97 coef 0 \$1; +#X connect 0 0 3 0; +#X connect 1 0 6 0; +#X connect 2 0 7 0; +#X connect 3 0 4 0; +#X connect 6 0 3 0; +#X connect 7 0 3 0; diff --git a/abstractions/pdp_agc.pd b/abstractions/pdp_agc.pd new file mode 100644 index 0000000..bd67c58 --- /dev/null +++ b/abstractions/pdp_agc.pd @@ -0,0 +1,28 @@ +#N canvas 572 396 450 300 10; +#X obj 174 115 pdp_cog; +#X obj 174 222 /; +#X obj 174 147 t b f; +#X obj 116 89 pdp_t p p; +#X obj 116 252 pdp_gain; +#X text 22 13 an automatic gain control using the pdp_cog object; +#X obj 23 40 inlet; +#X obj 238 146 inlet; +#X obj 174 183 f \$1; +#X obj 116 279 outlet; +#X text 158 36 creation argument or right inlet; +#X text 157 51 is desired average intensity; +#X obj 23 62 route chanmask; +#X msg 23 102 chanmask \$1; +#X connect 0 0 2 0; +#X connect 1 0 4 1; +#X connect 2 0 8 0; +#X connect 2 1 1 1; +#X connect 3 0 4 0; +#X connect 3 1 0 0; +#X connect 4 0 9 0; +#X connect 6 0 12 0; +#X connect 7 0 8 1; +#X connect 8 0 1 0; +#X connect 12 0 13 0; +#X connect 12 1 3 0; +#X connect 13 0 4 0; diff --git a/abstractions/pdp_cheby3o.pd b/abstractions/pdp_cheby3o.pd new file mode 100644 index 0000000..db9c83f --- /dev/null +++ b/abstractions/pdp_cheby3o.pd @@ -0,0 +1,22 @@ +#N canvas 29 385 450 300 10; +#X obj 42 87 inlet; +#X obj 194 189 outlet; +#X obj 194 159 pdp_cheby 3; +#X msg 115 87 coef 0 \$1; +#X msg 194 86 coef 1 \$1; +#X msg 278 85 coef 2 \$1; +#X msg 358 84 coef 3 \$1; +#X obj 115 62 inlet; +#X obj 194 62 inlet; +#X obj 278 61 inlet; +#X obj 358 60 inlet; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 5 0 2 0; +#X connect 6 0 2 0; +#X connect 7 0 3 0; +#X connect 8 0 4 0; +#X connect 9 0 5 0; +#X connect 10 0 6 0; diff --git a/abstractions/pdp_contrast.pd b/abstractions/pdp_contrast.pd new file mode 100644 index 0000000..83e8cce --- /dev/null +++ b/abstractions/pdp_contrast.pd @@ -0,0 +1,41 @@ +#N canvas 700 349 450 324 10; +#X obj 42 159 pdp_sthresh; +#X obj 42 261 pdp_gain; +#X msg 100 211 -1; +#X obj 100 235 /; +#X obj 170 195 - 1; +#X obj 170 167 * 2; +#X text 10 -1 contrast enhancement (works on YCrCb and greyscale); +#X obj 170 100 moses 0.49; +#X msg 235 123 0.49; +#X obj 262 83 / 2; +#X msg 87 101 chanmask 1; +#X obj 170 46 loadbang; +#X obj 170 75 f \$1; +#X obj 42 47 inlet; +#X obj 262 45 inlet; +#X obj 42 285 outlet; +#X text 11 13 i.e. to process the output of pdp_agc; +#X obj 170 141 f; +#X obj 42 185 pdp_t p b; +#X connect 0 0 18 0; +#X connect 1 0 15 0; +#X connect 2 0 3 0; +#X connect 3 0 1 1; +#X connect 4 0 3 1; +#X connect 5 0 4 0; +#X connect 7 0 17 0; +#X connect 7 1 8 0; +#X connect 8 0 17 0; +#X connect 9 0 7 0; +#X connect 10 0 1 0; +#X connect 10 0 0 0; +#X connect 11 0 10 0; +#X connect 11 0 12 0; +#X connect 12 0 7 0; +#X connect 13 0 0 0; +#X connect 14 0 9 0; +#X connect 17 0 0 1; +#X connect 17 0 5 0; +#X connect 18 0 1 0; +#X connect 18 1 2 0; diff --git a/abstractions/pdp_conv_sobel_edge.pd b/abstractions/pdp_conv_sobel_edge.pd index ccf0c38..6bbb7db 100644 --- a/abstractions/pdp_conv_sobel_edge.pd +++ b/abstractions/pdp_conv_sobel_edge.pd @@ -6,8 +6,9 @@ #X obj 149 71 pdp_mul; #X text 123 105 this uses the horizontal and vertical sobel directional masks squared as an edge detector.; -#X obj 15 9 inlet; +#X obj 14 -6 inlet; #X obj 15 151 outlet; +#X obj 15 15 pdp_trigger p p; #X connect 0 0 3 0; #X connect 0 0 3 1; #X connect 1 0 4 0; @@ -15,5 +16,6 @@ masks squared as an edge detector.; #X connect 2 0 7 0; #X connect 3 0 2 0; #X connect 4 0 2 1; -#X connect 6 0 0 0; -#X connect 6 0 1 0; +#X connect 6 0 8 0; +#X connect 8 0 0 0; +#X connect 8 1 1 0; diff --git a/abstractions/pdp_diff.pd b/abstractions/pdp_diff.pd new file mode 100644 index 0000000..a3ad5f4 --- /dev/null +++ b/abstractions/pdp_diff.pd @@ -0,0 +1,14 @@ +#N canvas 550 527 517 215 10; +#X obj 62 132 pdp_sub; +#X obj 62 104 pdp_reg; +#X obj 62 72 pdp_trigger bang pdp; +#X obj 62 38 inlet; +#X obj 62 163 outlet; +#X text 161 17 compute the difference between current; +#X text 161 33 and previous frame; +#X connect 0 0 4 0; +#X connect 1 0 0 1; +#X connect 2 0 1 0; +#X connect 2 1 1 1; +#X connect 2 1 0 0; +#X connect 3 0 2 0; diff --git a/abstractions/pdp_dither.pd b/abstractions/pdp_dither.pd new file mode 100644 index 0000000..c579cc8 --- /dev/null +++ b/abstractions/pdp_dither.pd @@ -0,0 +1,30 @@ +#N canvas 563 412 450 378 10; +#X obj 209 213 pdp_abs; +#X obj 209 144 pdp_noise; +#X obj 57 249 pdp_sub; +#X obj 209 172 pdp_grey; +#X obj 57 148 pdp_grey; +#X obj 57 88 inlet; +#X msg 209 114 type grey; +#X obj 57 204 pdp_contrast \$1; +#X obj 57 308 outlet; +#X obj 57 117 pdp_t p b; +#X obj 157 87 inlet; +#X obj 209 86 loadbang; +#X text 25 8 a dither effect; +#X text 26 45 returns a grey image (image/grey/*); +#X obj 57 277 pdp_sign; +#X text 26 23 right inlet is contrast; +#X connect 0 0 2 1; +#X connect 1 0 3 0; +#X connect 2 0 14 0; +#X connect 3 0 0 0; +#X connect 4 0 7 0; +#X connect 5 0 9 0; +#X connect 6 0 1 0; +#X connect 7 0 2 0; +#X connect 9 0 4 0; +#X connect 9 1 1 0; +#X connect 10 0 7 1; +#X connect 11 0 6 0; +#X connect 14 0 8 0; diff --git a/abstractions/pdp_gain3.pd b/abstractions/pdp_gain3.pd new file mode 100644 index 0000000..76ed097 --- /dev/null +++ b/abstractions/pdp_gain3.pd @@ -0,0 +1,27 @@ +#N canvas 576 356 409 204 10; +#X obj 107 82 pdp_gain; +#X obj 107 115 pdp_gain; +#X obj 107 146 pdp_gain; +#X obj 107 50 inlet; +#X obj 184 49 inlet; +#X obj 250 49 inlet; +#X obj 309 48 inlet; +#X obj 107 178 outlet; +#X obj 19 22 loadbang; +#X msg 19 50 chanmask 1; +#X msg 19 84 chanmask 2; +#X msg 19 117 chanmask 4; +#X text 113 14 set gain independently for 3 channels; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 2 0 7 0; +#X connect 3 0 0 0; +#X connect 4 0 0 1; +#X connect 5 0 1 1; +#X connect 6 0 2 1; +#X connect 8 0 9 0; +#X connect 9 0 0 0; +#X connect 9 0 10 0; +#X connect 10 0 1 0; +#X connect 10 0 11 0; +#X connect 11 0 2 0; diff --git a/abstractions/pdp_gradient.pd b/abstractions/pdp_gradient.pd new file mode 100644 index 0000000..8867c69 --- /dev/null +++ b/abstractions/pdp_gradient.pd @@ -0,0 +1,58 @@ +#N canvas 465 0 719 454 10; +#X obj 49 19 inlet; +#X obj 216 399 outlet; +#X obj 216 235 pdp_gain; +#X obj 216 286 pdp_gain; +#X obj 216 340 pdp_gain; +#X msg 361 217 chanmask 1; +#X msg 361 268 chanmask 2; +#X obj 361 178 loadbang; +#X obj 99 267 unpack 0 0 0; +#X msg 361 322 chanmask 4; +#X obj 216 146 pdp_grey2mask; +#X obj 5 198 unpack 0 0 0; +#X obj 267 207 r \$0-ch1; +#X obj 267 260 r \$0-ch2; +#X obj 267 312 r \$0-ch3; +#X obj 5 328 s \$0-ch1; +#X obj 127 328 s \$0-ch3; +#X obj 66 328 s \$0-ch2; +#X obj 5 229 pdp_ut_rgb2ycrcb; +#X msg 111 46 rgb 1 0.5 0; +#X msg 111 74 ycrcb 1 0.5 0; +#X text 230 46 set a red/green/blue gradient; +#X text 140 16 a gradient abstraction based on gain and grey2mask; +#X obj 49 118 route rgb ycrcb; +#X text 308 391 hint: replace pdp_gain by pdp_cheby to get nonlinear +gradients.; +#X text 229 76 set a luma/chroma_red/chroma_blue gradient; +#X text 322 146 this copies luma channel to chroma channels; +#X connect 0 0 23 0; +#X connect 2 0 3 0; +#X connect 3 0 4 0; +#X connect 4 0 1 0; +#X connect 5 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 3 0; +#X connect 6 0 9 0; +#X connect 7 0 5 0; +#X connect 7 0 19 0; +#X connect 8 0 15 0; +#X connect 8 1 17 0; +#X connect 8 2 16 0; +#X connect 9 0 4 0; +#X connect 10 0 2 0; +#X connect 11 0 18 0; +#X connect 11 1 18 1; +#X connect 11 2 18 2; +#X connect 12 0 2 1; +#X connect 13 0 3 1; +#X connect 14 0 4 1; +#X connect 18 0 15 0; +#X connect 18 1 17 0; +#X connect 18 2 16 0; +#X connect 19 0 23 0; +#X connect 20 0 23 0; +#X connect 23 0 11 0; +#X connect 23 1 8 0; +#X connect 23 2 10 0; diff --git a/abstractions/pdp_grey.pd b/abstractions/pdp_grey.pd new file mode 100644 index 0000000..fb1fa20 --- /dev/null +++ b/abstractions/pdp_grey.pd @@ -0,0 +1,7 @@ +#N canvas 608 510 395 122 10; +#X obj 39 23 inlet; +#X obj 39 51 pdp_convert image/grey/*; +#X obj 39 79 outlet; +#X text 101 21 backwards compatibility abstraction; +#X connect 0 0 1 0; +#X connect 1 0 2 0; diff --git a/abstractions/pdp_m_inverse.pd b/abstractions/pdp_m_inverse.pd new file mode 100644 index 0000000..e942e8a --- /dev/null +++ b/abstractions/pdp_m_inverse.pd @@ -0,0 +1,11 @@ +#N canvas 805 557 415 150 10; +#X obj 21 49 pdp_m_LU; +#X obj 21 24 inlet; +#X obj 21 103 outlet; +#X text 150 31 computes a matrix inverse using the; +#X text 149 48 LU decomposition (PA = LU); +#X text 148 84 (uses double precision processing); +#X obj 21 77 pdp_m_LU_inverse; +#X connect 0 0 6 0; +#X connect 1 0 0 0; +#X connect 6 0 2 0; diff --git a/abstractions/pdp_motion_fade.pd b/abstractions/pdp_motion_fade.pd new file mode 100644 index 0000000..fa61735 --- /dev/null +++ b/abstractions/pdp_motion_fade.pd @@ -0,0 +1,19 @@ +#N canvas 58 0 508 168 10; +#X obj 29 17 inlet; +#X obj 29 124 outlet; +#X obj 29 99 pdp_bqt; +#X obj 87 18 inlet; +#X text 94 102 pdp_motion_fade uses pdp_bqt (time biquad filter) configured +as an highpass filter to produce a motion triggered fade-out effect. +; +#X obj 340 -1 loadbang; +#X obj 340 24 f \$1; +#X obj 87 42 pdp_ut_logmap_comp 0.01 0.4; +#X msg 87 68 hpf \$1 0.25; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X connect 3 0 7 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X connect 7 0 8 0; +#X connect 8 0 2 0; diff --git a/abstractions/pdp_offset.pd b/abstractions/pdp_offset.pd new file mode 100644 index 0000000..da8a8a4 --- /dev/null +++ b/abstractions/pdp_offset.pd @@ -0,0 +1,17 @@ +#N canvas 515 434 450 300 10; +#X obj 48 69 inlet; +#X obj 48 243 outlet; +#X obj 48 191 pdp_cheby; +#X msg 173 93 coef 0 \$1; +#X obj 103 69 loadbang; +#X obj 173 68 inlet; +#X obj 103 111 float \$1; +#X text 45 21 add an offset to an image; +#X msg 103 138 reset \, coef 1 1 \, coef 0 \$1; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X connect 3 0 2 0; +#X connect 4 0 6 0; +#X connect 5 0 3 0; +#X connect 6 0 8 0; +#X connect 8 0 2 0; diff --git a/abstractions/pdp_png_to.pd b/abstractions/pdp_png_to.pd new file mode 100644 index 0000000..b6a9bcb --- /dev/null +++ b/abstractions/pdp_png_to.pd @@ -0,0 +1,21 @@ +#N canvas 0 0 450 300 10; +#X obj 37 50 inlet; +#X obj 102 262 outlet; +#X obj 102 209 pdp_convert \$1; +#X obj 102 180 pdp_reg; +#X text 34 15 load a png file and convert to a packet type specified +by the creation argument. default = bitmap/*/*; +#X obj 102 121 symbol; +#X msg 102 149 load_png \$1 \, bang; +#X obj 37 81 route bang; +#X msg 37 208 bang; +#X obj 102 236 pdp_reg; +#X connect 0 0 7 0; +#X connect 2 0 9 0; +#X connect 3 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 3 0; +#X connect 7 0 8 0; +#X connect 7 1 5 0; +#X connect 8 0 9 0; +#X connect 9 0 1 0; diff --git a/abstractions/pdp_qtloop~.pd b/abstractions/pdp_qtloop~.pd new file mode 100644 index 0000000..300e586 --- /dev/null +++ b/abstractions/pdp_qtloop~.pd @@ -0,0 +1,183 @@ +#N canvas 273 0 555 778 10; +#X obj 82 83 inlet; +#X obj 255 82 inlet; +#X obj 103 506 pdp_loop; +#X obj 154 702 outlet; +#X obj 18 473 r \$0-loopin; +#X obj 24 145 s \$0-filename; +#X text 60 59 bang or hot frame; +#X text 142 727 packet outlet; +#X msg 132 137 bang; +#X obj 82 111 route open bang; +#X obj 103 554 pdp_convert image/YCrCb/*; +#X obj 294 214 s \$0-playaudioframe; +#X obj 294 237 outlet; +#X obj 132 375 mod; +#X obj 178 345 r \$0-nbframes; +#X obj 418 363 outlet; +#X obj 333 706 outlet~; +#X obj 419 702 outlet~; +#N canvas 34 6 711 881 more_logic 0; +#X obj 215 518 pdp_qt; +#X obj 246 772 symbol \$0-L; +#X obj 340 773 symbol \$0-R; +#X msg 246 797 dump \$1 0; +#X msg 340 797 dump \$1 1; +#X msg 140 473 open \$1; +#X obj 21 367 symbol; +#X obj 216 729 t f b; +#X obj 232 490 r \$0-qtin; +#X obj 340 833 s \$0-qtin; +#X obj 245 318 s \$0-loopin; +#X obj 21 338 r \$0-filename; +#X obj 215 692 s \$0-loopin; +#X text 337 227 new movie loaded \, nb of frames received here; +#X text 268 730 dump audio; +#X text 374 288 set loop size; +#X obj 215 463 until; +#X text 262 465 dump frames; +#X obj 215 258 t f f; +#X msg 245 289 size \$1 \, record; +#X text 374 303 start recording; +#X obj 199 435 f 0; +#X obj 252 551 s \$0-nbframes; +#X obj 215 227 r \$0-nbframes; +#X msg 21 494 DONE; +#X obj 21 671 print pdp_qtloop~; +#X obj 215 661 pdp_convert bitmap/yv12/*; +#X obj 215 348 t f f; +#X obj 233 601 pack 0 0; +#X obj 21 393 t b b b s; +#X msg 233 627 decoding frame \$1 of \$2; +#X obj 233 576 + 1; +#X text 407 661 images are stored in 12bpp; +#X obj 217 173 outlet~; +#X obj 318 173 outlet~; +#X obj 217 144 tabplay~ \$0-L; +#X obj 318 144 tabplay~ \$0-R; +#X obj 217 106 * 1920; +#X obj 217 41 r \$0-playaudioframe; +#X text 215 18 restart audio playback from frame #; +#X text 277 106 samplerate / framerate; +#X obj 32 32 table \$0-L; +#X obj 32 56 table \$0-R; +#N canvas 367 318 450 300 fracframemodulo 0; +#X obj 93 43 inlet; +#X obj 93 274 outlet; +#X obj 93 97 /; +#X obj 109 67 r \$0-nbframes; +#X obj 123 147 int; +#X obj 93 122 t f f; +#X obj 93 179 -; +#X obj 109 220 r \$0-nbframes; +#X obj 93 248 *; +#X connect 0 0 2 0; +#X connect 2 0 5 0; +#X connect 3 0 2 1; +#X connect 4 0 6 1; +#X connect 5 0 6 0; +#X connect 5 1 4 0; +#X connect 6 0 8 0; +#X connect 7 0 8 1; +#X connect 8 0 1 0; +#X restore 217 68 pd fracframemodulo; +#X connect 0 0 26 0; +#X connect 0 1 31 0; +#X connect 0 2 22 0; +#X connect 1 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 9 0; +#X connect 4 0 9 0; +#X connect 5 0 0 0; +#X connect 6 0 29 0; +#X connect 7 1 1 0; +#X connect 7 1 2 0; +#X connect 8 0 0 0; +#X connect 11 0 6 0; +#X connect 16 0 0 0; +#X connect 18 0 27 0; +#X connect 18 1 19 0; +#X connect 19 0 10 0; +#X connect 21 0 16 0; +#X connect 23 0 18 0; +#X connect 24 0 25 0; +#X connect 26 0 12 0; +#X connect 27 0 21 1; +#X connect 27 0 28 1; +#X connect 28 0 30 0; +#X connect 29 0 24 0; +#X connect 29 1 7 0; +#X connect 29 2 21 0; +#X connect 29 3 5 0; +#X connect 30 0 25 0; +#X connect 31 0 28 0; +#X connect 35 0 33 0; +#X connect 36 0 34 0; +#X connect 37 0 35 0; +#X connect 37 0 36 0; +#X connect 38 0 43 0; +#X connect 43 0 37 0; +#X restore 333 673 pd more_logic; +#X obj 132 170 f; +#X obj 132 287 t f f; +#X text 240 61 cold frame; +#X obj 162 375 mod; +#X obj 162 319 + 1; +#X obj 118 613 pdp_route; +#X obj 154 661 pdp_mix; +#X text 273 257 frame nb outlet; +#X msg 176 461 0; +#X msg 208 461 1; +#X obj 176 488 f; +#X text 215 408 get current and next frame from pdp_loop; +#X obj 132 219 int; +#X obj 206 267 -; +#X obj 132 196 t f f f; +#X obj 132 249 t f f; +#X text 277 317 crossfade fraction; +#X obj 206 317 s \$0-frac; +#X obj 198 631 r \$0-frac; +#X obj 206 292 * -1; +#X obj 103 408 t f b; +#X obj 162 408 t f b; +#X text 397 385 nb frames outlet; +#X connect 0 0 9 0; +#X connect 1 0 19 1; +#X connect 2 0 10 0; +#X connect 4 0 2 0; +#X connect 8 0 19 0; +#X connect 9 0 5 0; +#X connect 9 1 8 0; +#X connect 9 2 19 0; +#X connect 10 0 24 0; +#X connect 13 0 39 0; +#X connect 14 0 13 1; +#X connect 14 0 22 1; +#X connect 14 0 15 0; +#X connect 18 0 16 0; +#X connect 18 1 17 0; +#X connect 19 0 33 0; +#X connect 20 0 13 0; +#X connect 20 1 23 0; +#X connect 22 0 40 0; +#X connect 23 0 22 0; +#X connect 24 0 25 0; +#X connect 24 1 25 1; +#X connect 25 0 3 0; +#X connect 27 0 29 0; +#X connect 28 0 29 0; +#X connect 29 0 24 1; +#X connect 31 0 34 0; +#X connect 32 0 38 0; +#X connect 33 0 31 0; +#X connect 33 1 32 1; +#X connect 33 2 12 0; +#X connect 33 2 11 0; +#X connect 34 0 20 0; +#X connect 34 1 32 0; +#X connect 37 0 25 2; +#X connect 38 0 36 0; +#X connect 39 0 2 0; +#X connect 39 1 27 0; +#X connect 40 0 2 0; +#X connect 40 1 28 0; diff --git a/abstractions/pdp_saturation.pd b/abstractions/pdp_saturation.pd index f96f79d..44f5a86 100644 --- a/abstractions/pdp_saturation.pd +++ b/abstractions/pdp_saturation.pd @@ -1,13 +1,18 @@ -#N canvas 247 212 237 275 10; -#X obj 44 52 inlet; -#X obj 139 53 inlet; -#X obj 44 202 outlet; -#X obj 44 139 pdp_gain; -#X msg 101 103 u \$1; -#X msg 139 103 v \$1; -#X connect 0 0 3 0; -#X connect 1 0 4 0; -#X connect 1 0 5 0; -#X connect 3 0 2 0; -#X connect 4 0 3 0; -#X connect 5 0 3 0; +#N canvas 322 388 509 326 10; +#X obj 39 105 inlet; +#X obj 270 103 inlet; +#X obj 39 255 outlet; +#X obj 85 105 loadbang; +#X text 32 14 adjust colour saturation by applying a gain to the chroma +channels.; +#X text 31 47 this only works for image/YCrCb/* packets and 3 channel +image/multi/* packets containing luma and chroma channels.; +#X obj 39 192 pdp_gain; +#X msg 85 155 chanmask 6 \, gain \$1; +#X obj 85 131 f \$1; +#X connect 0 0 6 0; +#X connect 1 0 6 1; +#X connect 3 0 8 0; +#X connect 6 0 2 0; +#X connect 7 0 6 0; +#X connect 8 0 7 0; diff --git a/abstractions/pdp_save_png_sequence.pd b/abstractions/pdp_save_png_sequence.pd new file mode 100644 index 0000000..786df47 --- /dev/null +++ b/abstractions/pdp_save_png_sequence.pd @@ -0,0 +1,28 @@ +#N canvas 654 482 490 382 10; +#X obj 54 65 inlet; +#X obj 119 362 pdp_reg; +#X obj 119 130 pdp_t b p; +#X obj 119 186 + 1; +#X obj 54 93 route bang; +#X obj 119 251 makefilename /tmp/frame%d.png; +#X obj 119 215 moses \$1; +#X obj 140 279 print; +#X msg 119 305 save_png \$1; +#X msg 54 126 0; +#X text 146 10 save a png sequence in the /tmp directory; +#X text 146 25 creation argument is the number of frames; +#X obj 119 160 f \$1; +#X text 146 40 send a bang to start writing; +#X connect 0 0 4 0; +#X connect 2 0 12 0; +#X connect 2 1 1 0; +#X connect 3 0 6 0; +#X connect 3 0 12 1; +#X connect 4 0 9 0; +#X connect 4 1 2 0; +#X connect 5 0 7 0; +#X connect 5 0 8 0; +#X connect 6 0 5 0; +#X connect 8 0 1 0; +#X connect 9 0 12 1; +#X connect 12 0 3 0; diff --git a/abstractions/pdp_tag.pd b/abstractions/pdp_tag.pd new file mode 100644 index 0000000..d1884f6 --- /dev/null +++ b/abstractions/pdp_tag.pd @@ -0,0 +1,19 @@ +#N canvas 700 231 450 300 10; +#X obj 56 25 inlet; +#X obj 55 191 outlet; +#X msg 162 174 \$1 \$2 \$3 \$4; +#X text 148 31 tag a pdp message (for routing); +#X obj 0 110 symbol \$1; +#X obj 56 68 unpack s s 0; +#X obj 55 139 pack s s s 0; +#X obj 39 91 t b s; +#X obj 55 165 route list; +#X connect 0 0 5 0; +#X connect 4 0 6 0; +#X connect 5 0 7 0; +#X connect 5 1 6 2; +#X connect 5 2 6 3; +#X connect 6 0 8 0; +#X connect 7 0 4 0; +#X connect 7 1 6 1; +#X connect 8 0 1 0; diff --git a/abstractions/rgb2ycrcb.pd b/abstractions/rgb2ycrcb.pd new file mode 100644 index 0000000..acb517f --- /dev/null +++ b/abstractions/rgb2ycrcb.pd @@ -0,0 +1,7 @@ +#N canvas 318 162 450 300 10; +#X obj 94 76 inlet; +#X obj 144 76 inlet; +#X obj 195 76 inlet; +#X text 94 53 red; +#X text 143 52 green; +#X text 197 53 blue; diff --git a/bin/pdp-config b/bin/pdp-config new file mode 100644 index 0000000..dd0bdf7 --- /dev/null +++ b/bin/pdp-config @@ -0,0 +1,39 @@ +#!/bin/sh + +prefix=/usr/local +version=0.12.2 + +usage="\ +Usage: pdp-config [--version] [--cflags] [--libdir]" + +if test $# -eq 0; then + echo "${usage}" 1>&2 + exit 1 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case $1 in + -n) + NEWLINE="-n" + ;; + --libdir) + echo $NEWLINE $prefix/lib/scaf + ;; + --version) + echo $NEWLINE $version + ;; + --cflags) + echo $NEWLINE -I$prefix/include/pdp + ;; + *) + echo "${usage}" 1>&2 + exit 1 + ;; + esac + shift +done diff --git a/configure.ac b/configure.ac index 50f9c1b..44342c8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(system/pdp.c) +AC_INIT(system/kernel/pdp.c) AC_CONFIG_HEADER(include/pdp_config.h) AC_PROG_CC AC_HEADER_STDC -dnl TAG CVS WHEN VERSION CHANGES !!! -PDP_VERSION=0.9 +dnl TAG CVS WHEN RELEASE VERSION CHANGES !!! +PDP_VERSION=0.12.2 AC_SUBST(PDP_VERSION) AC_ARG_ENABLE(pwc, @@ -14,6 +14,9 @@ AC_ARG_ENABLE(pwc, AC_ARG_ENABLE(mmx, [ --enable-mmx enable MMX support], MMX=yes, MMX=no) +AC_ARG_ENABLE(sdl, + [ --enable-sdl enable SDL support], SDL=yes, SDL=no) + if test $prefix == NONE; then @@ -46,10 +49,8 @@ AC_CHECK_HEADER(m_pd.h,, echo "WARNING: m_pd.h not found. Is PD installed?" echo "WARNING: if you have changed PD_CPPFLAGS in Makefile.config.in you can ignore this warning." ) - AC_CHECK_LIB(m,sin) - ARCH=`uname -s` if test $ARCH == Linux; then @@ -75,39 +76,67 @@ dnl Darwin specific stuff: this is still pretty experimental dnl How to test if frameworks are present ???? if test $ARCH == Darwin then - PDP_OPTMOD="$PDP_OPTMOD pdp_sdl.o" - LIBS="$LIBS -framework SDL" - PDP_EXTRA_CPPFLAGS="$PDP_EXTRA_INCLUDE -I/Library/Frameworks/SDL.framework/Headers" - PD_EXECUTABLE=ihavenocluewherethepdbinaryislocated - AC_DEFINE(HAVE_PDP_SDL, 1, build pdp_sdl) - -dnl These are checks for libraries. -dnl Objects that depend on a lib only get included when the lib is found. + PD_EXECUTABLE=$prefix/bin/pd + LIBS="$LIBS -L/sw/lib" + CPPFLAGS="$CPPFLAGS -I/sw/include" + PDP_EXTRA_CPPFLAGS="-I/sw/include" + +dnl if not darwin, assume target is linux else + PDP_EXTRA_CFLAGS=-Werror + + AC_CHECK_HEADER(linux/videodev.h, + PDP_OPTMOD="$PDP_OPTMOD pdp_v4l.o" + AC_DEFINE(HAVE_PDP_V4L, 1, build pdp_v4l), + echo " linux/videodev.h not found: not building pdp_v4l") + + +fi + +AC_CHECK_LIB(gslcblas,main) +AC_CHECK_LIB(gsl,main,, + echo "ERROR: libgsl not found" + exit) +LIBS="$LIBS -lgslcblas -lgsl" + - AC_CHECK_LIB(quicktime, lqt_decode_video, - PDP_OPTMOD="$PDP_OPTMOD pdp_qt.o" - LIBS="$LIBS -lquicktime" - AC_DEFINE(HAVE_PDP_QT, 1, build pdp_qt), - echo " libquicktime not found: not building pdp_qt") +AC_CHECK_LIB(Xv, XvPutImage, + PDP_OPTMOD="$PDP_OPTMOD pdp_xv.o" + LIBS="$LIBS -L/usr/X11R6/lib -lX11 -lXv -lXext" + AC_DEFINE(HAVE_PDP_XV, 1, build pdp_xv), + echo " libXv not found: not building pdp_xv", + -L/usr/X11R6/lib -lX11 -lXext) + +AC_CHECK_LIB(quicktime, lqt_decode_video, + PDP_OPTMOD="$PDP_OPTMOD pdp_qt.o" + LIBS="$LIBS -lquicktime" + AC_DEFINE(HAVE_PDP_QT, 1, build pdp_qt), + echo " libquicktime not found: not building pdp_qt") + + +AC_CHECK_LIB(png, png_read_image, + LIBS="$LIBS -lpng" + AC_DEFINE(HAVE_PDP_PNG, 1, build png support), + echo " libpng not found: not building png support") + + +AC_CHECK_LIB(GL, glXSwapBuffers, + PDP_OPTMOD="$PDP_OPTMOD pdp_glx.o" + LIBS="$LIBS -lGL -lGLU" + AC_DEFINE(HAVE_PDP_GLX, 1, build pdp_glx), + echo " libGL not found: not building pdp_glx", + -L/usr/X11R6/lib -lGLU) + + +dnl optional sdl stuff +if test $SDL == yes +then AC_CHECK_LIB(SDL, SDL_Init, PDP_OPTMOD="$PDP_OPTMOD pdp_sdl.o" LIBS="$LIBS -lSDL" AC_DEFINE(HAVE_PDP_SDL, 1, build pdp_sdl), echo " libSDL not found: not building pdp_sdl") - - AC_CHECK_LIB(Xv, XvPutImage, - PDP_OPTMOD="$PDP_OPTMOD pdp_xv.o" - LIBS="$LIBS -L/usr/X11R6/lib -lX11 -lXv -lXext" - AC_DEFINE(HAVE_PDP_XV, 1, build pdp_xv), - echo " libXv not found: not building pdp_xv", - -L/usr/X11R6/lib -lX11 -lXext) - - AC_CHECK_HEADER(linux/videodev.h, - PDP_OPTMOD="$PDP_OPTMOD pdp_v4l.o" - AC_DEFINE(HAVE_PDP_V4L, 1, build pdp_v4l), - echo " linux/videodev.h not found: not building pdp_v4l") fi @@ -117,6 +146,7 @@ echo target is $PDP_TARGET AC_SUBST(PD_CPPFLAGS) AC_SUBST(PD_EXECUTABLE) AC_SUBST(PDP_EXTRA_CPPFLAGS) +AC_SUBST(PDP_EXTRA_CFLAGS) AC_SUBST(PDP_LIBRARY_NAME) AC_SUBST(PDP_TARGET) AC_SUBST(PDP_OPTMOD) diff --git a/debug/c++test.cc b/debug/c++test.cc new file mode 100644 index 0000000..4183e8c --- /dev/null +++ b/debug/c++test.cc @@ -0,0 +1,4 @@ +#include "pdp.h" +int main(void) +{ +} diff --git a/debug/gdb_pdp_load b/debug/gdb_pdp_load index 3cf4da8..d771437 100644 --- a/debug/gdb_pdp_load +++ b/debug/gdb_pdp_load @@ -1,7 +1,9 @@ cd ~/pd/packet file ~/pd/distro/pd/bin/pd.debug # file ~/pd/distro/pd/bin/pd -set args -r 44100 -alsa -frags 64 -lib pdp -nodac -noadc -path abstractions doc/objects/pdp_grey2mask.pd +#set args -r 44100 -alsa -frags 64 -lib pdp -lib opengl/pdp_opengl -nodac -noadc -path abstractions:opengl/abstractions opengl/doc/examples/example12.pd +set args -r 44100 -alsa -frags 64 -lib pdp -nodac -noadc -path abstractions doc/objects/pdp_pointcloud.pd +#opengl/test/pdp_ogl_draw_limb.pd # set args -lib pdp -nodac -noadc -path abstractions test/test_pdp_thread.pd # set args -lib pdp -nodac -noadc test/test_pdp_ca.pd # set args -r 44100 -alsa -frags 64 -lib pdp -nodac -noadc test/test_pdp_qt_read.pd diff --git a/doc/examples/example01.pd b/doc/examples/example01.pd index d4afc19..94db2ea 100644 --- a/doc/examples/example01.pd +++ b/doc/examples/example01.pd @@ -1,4 +1,4 @@ -#N canvas 142 294 518 446 10; +#N canvas 657 0 518 446 10; #X obj 133 414 pdp_xv; #X obj 177 76 pdp_v4l; #X obj 177 33 metro 40; @@ -21,13 +21,13 @@ #X text 223 174 edge detect; #X text 222 200 amplify; #X text 232 6 process in greyscale; -#X obj 133 252 pdp_add; #X text 322 287 motion phase shifter; #X text 320 354 grey -> colour palette; #X msg 36 323 rgb 1 0.5 0; -#X floatatom 170 386 5 0 0; +#X obj 133 252 pdp_add; +#X msg 133 216 debug; #X connect 1 0 12 0; -#X connect 1 0 20 1; +#X connect 1 0 23 1; #X connect 2 0 1 0; #X connect 3 0 2 0; #X connect 4 0 5 0; @@ -38,8 +38,8 @@ #X connect 10 0 9 0; #X connect 11 0 1 0; #X connect 12 0 4 0; -#X connect 13 0 20 0; +#X connect 13 0 23 0; #X connect 14 0 10 1; -#X connect 20 0 10 0; -#X connect 23 0 9 0; -#X connect 24 0 0 1; +#X connect 22 0 9 0; +#X connect 23 0 10 0; +#X connect 24 0 23 0; diff --git a/doc/examples/example03.pd b/doc/examples/example03.pd index 90b74c0..0eddd0d 100644 --- a/doc/examples/example03.pd +++ b/doc/examples/example03.pd @@ -1,4 +1,4 @@ -#N canvas 326 208 841 704 10; +#N canvas 141 84 841 685 10; #X obj 68 318 pdp_noise; #X obj 68 85 metro 40; #X obj 68 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 @@ -8,16 +8,16 @@ #X floatatom 240 518 5 0 0; #X obj 68 514 pdp_blur; #X obj 243 499 hsl 128 15 0 1 0 1 empty empty empty -2 -6 0 8 -262144 --1 -1 5600 1; +-1 -1 10100 1; #X floatatom 240 367 5 0 0; #X obj 243 342 hsl 128 15 0 5 0 1 empty empty empty -2 -6 0 8 -262144 --1 -1 500 1; +-1 -1 0 1; #X floatatom 240 587 5 0 0; #X obj 243 567 hsl 128 15 0 1 0 1 empty empty empty -2 -6 0 8 -262144 --1 -1 12700 1; +-1 -1 4100 1; #X floatatom 239 428 5 0 0; #X obj 242 409 hsl 128 15 -5 5 0 1 empty empty empty -2 -6 0 8 -262144 --1 -1 8700 1; +-1 -1 11900 1; #X msg 15 460 reset; #X obj 68 459 pdp_add; #X obj 68 357 pdp_gain; @@ -51,6 +51,11 @@ delay line can be seen as a parallel delay line \, one for each pixel. coupling between the delays is done using a spatial blur effect. the additional temporal filtering isn't necessary \, but it produces a nice additional effect.; +#X obj 534 661 pdp_control; +#X obj 534 684 print; +#X msg 534 637 thread \$1; +#X obj 534 614 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +1; #X connect 0 0 16 0; #X connect 1 0 0 0; #X connect 2 0 1 0; @@ -76,3 +81,6 @@ nice additional effect.; #X connect 25 0 19 0; #X connect 26 0 0 0; #X connect 27 0 0 0; +#X connect 32 0 33 0; +#X connect 34 0 32 0; +#X connect 35 0 34 0; diff --git a/doc/examples/example09.pd b/doc/examples/example09.pd new file mode 100644 index 0000000..2da1b51 --- /dev/null +++ b/doc/examples/example09.pd @@ -0,0 +1,35 @@ +#N canvas 43 348 497 337 10; +#X obj 88 104 pdp_grey2mask; +#X obj 88 148 pdp_gain; +#X obj 88 174 pdp_gain; +#X obj 88 198 pdp_gain; +#X msg 6 130 chanmask 1; +#X msg 6 180 chanmask 4; +#X msg 6 156 chanmask 2; +#X obj 6 103 loadbang; +#X floatatom 208 130 5 0 0; +#X floatatom 208 156 5 0 0; +#X floatatom 208 180 5 0 0; +#X obj 88 234 pdp_xv; +#X obj 88 40 metro 30; +#X obj 88 13 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 88 75 pdp_v4l; +#X text 26 267 a simple colour gradient patch using grey2mask and individual +channel gains (set with the binary chanmask); +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 11 0; +#X connect 4 0 1 0; +#X connect 4 0 6 0; +#X connect 5 0 3 0; +#X connect 6 0 2 0; +#X connect 6 0 5 0; +#X connect 7 0 4 0; +#X connect 8 0 1 1; +#X connect 9 0 2 1; +#X connect 10 0 3 1; +#X connect 12 0 14 0; +#X connect 13 0 12 0; +#X connect 14 0 0 0; diff --git a/doc/examples/example10.pd b/doc/examples/example10.pd new file mode 100644 index 0000000..129209d --- /dev/null +++ b/doc/examples/example10.pd @@ -0,0 +1,55 @@ +#N canvas 147 266 497 337 10; +#X obj 88 104 pdp_grey2mask; +#X msg 6 130 chanmask 1; +#X msg 6 186 chanmask 4; +#X msg 6 158 chanmask 2; +#X obj 6 103 loadbang; +#X floatatom 207 130 5 0 0; +#X floatatom 253 130 5 0 0; +#X floatatom 299 130 5 0 0; +#X obj 88 234 pdp_xv; +#X obj 88 40 metro 30; +#X obj 88 13 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 88 75 pdp_v4l; +#X obj 88 148 pdp_cheby3o; +#X floatatom 345 130 5 0 0; +#X floatatom 207 158 5 0 0; +#X floatatom 253 158 5 0 0; +#X floatatom 299 158 5 0 0; +#X obj 88 176 pdp_cheby3o; +#X floatatom 345 158 5 0 0; +#X floatatom 207 186 5 0 0; +#X floatatom 253 186 5 0 0; +#X floatatom 299 186 5 0 0; +#X obj 88 204 pdp_cheby3o; +#X floatatom 345 186 5 0 0; +#X text 26 267 a more complex colour gradient patch using grey2mask +and individual channel chebychev colour shapers (set with the binary +chanmask); +#X connect 0 0 12 0; +#X connect 1 0 3 0; +#X connect 1 0 12 0; +#X connect 1 0 12 0; +#X connect 2 0 22 0; +#X connect 3 0 2 0; +#X connect 3 0 17 0; +#X connect 4 0 1 0; +#X connect 5 0 12 1; +#X connect 6 0 12 2; +#X connect 7 0 12 3; +#X connect 9 0 11 0; +#X connect 10 0 9 0; +#X connect 11 0 0 0; +#X connect 12 0 17 0; +#X connect 13 0 12 4; +#X connect 14 0 17 1; +#X connect 15 0 17 2; +#X connect 16 0 17 3; +#X connect 17 0 22 0; +#X connect 18 0 17 4; +#X connect 19 0 22 1; +#X connect 20 0 22 2; +#X connect 21 0 22 3; +#X connect 22 0 8 0; +#X connect 23 0 22 4; diff --git a/doc/examples/example11.pd b/doc/examples/example11.pd new file mode 100644 index 0000000..c427e9a --- /dev/null +++ b/doc/examples/example11.pd @@ -0,0 +1,80 @@ +#N canvas 210 529 680 275 10; +#N canvas 0 0 450 300 graph1 0; +#X array mapping 64 float 1; +#A 0 0.0916017 -0.201423 -0.477099 -0.711681 -0.884964 -0.982024 -0.9945 +-0.921318 -0.76878 -0.550026 -0.283897 0.00668462 0.296691 0.561142 +0.777261 0.926433 0.995809 0.979413 0.878658 0.702222 0.465302 0.188305 +-0.104911 -0.389091 -0.639758 -0.835322 -0.958937 -0.999957 -0.954848 +-0.827497 -0.628871 -0.37608 -0.0908956 0.202118 0.477722 0.712179 +0.885295 0.982158 0.994426 0.92104 0.768324 0.54943 0.283212 -0.00739881 +-0.297373 -0.561733 -0.777711 -0.926702 -0.995875 -0.979271 -0.87832 +-0.701718 -0.464675 -0.187609 0.105617 0.389745 0.640304 0.835712 0.959139 +0.999952 0.954637 0.827096 0.628316 0.375418; +#X coords 0 1 63 -1 200 140 1; +#X restore 242 21 graph; +#X msg 50 142 approx mapping; +#X obj 20 86 pdp_t; +#X text 235 165 -1 ----------- 0 ----------- 1; +#X obj 50 115 spigot; +#X obj 87 92 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 20 225 pdp_cheby 10; +#X obj 515 138 tabsend~ mapping; +#X obj 515 112 osc~; +#X floatatom 515 65 5 0 0; +#X floatatom 573 64 5 0 0; +#N canvas 0 0 450 300 fblock 0; +#X obj 36 36 inlet; +#X obj 101 35 inlet; +#X obj 42 196 outlet; +#X obj 104 83 samplerate~; +#X obj 59 158 +; +#X obj 103 144 *; +#X obj 103 59 t b b f; +#X text 200 35 fblock: compute block relative frequencies; +#X text 200 79 right inlet is also "active"; +#X text 201 119 main usage is to compute block synchronous frequencies +; +#X text 200 134 for spectral domain processing; +#X text 201 49 out = left + right * (sys samplerate / blocksize); +#X obj 101 115 / 64; +#X connect 0 0 4 0; +#X connect 1 0 6 0; +#X connect 3 0 12 0; +#X connect 4 0 2 0; +#X connect 5 0 4 1; +#X connect 6 0 4 0; +#X connect 6 1 3 0; +#X connect 6 2 5 1; +#X connect 12 0 5 0; +#X restore 515 89 pd fblock; +#X obj 20 40 metro 40; +#X obj 20 62 pdp_v4l; +#X msg 515 37 0.17; +#X text 236 208 send a signal to a table and use this as an intensity +mapping function in pdp_cheby; +#X obj 20 250 pdp_xv; +#X obj 20 15 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X msg 573 36 3; +#X msg 133 207 chanmask \$1; +#X floatatom 133 185 5 0 0; +#X msg 133 165 1; +#X connect 1 0 6 0; +#X connect 2 0 6 0; +#X connect 2 1 4 0; +#X connect 4 0 1 0; +#X connect 5 0 4 1; +#X connect 6 0 16 0; +#X connect 8 0 7 0; +#X connect 9 0 11 0; +#X connect 10 0 11 1; +#X connect 11 0 8 0; +#X connect 12 0 13 0; +#X connect 13 0 2 0; +#X connect 14 0 9 0; +#X connect 17 0 12 0; +#X connect 18 0 10 0; +#X connect 19 0 6 0; +#X connect 20 0 19 0; +#X connect 21 0 20 0; diff --git a/doc/examples/example12.pd b/doc/examples/example12.pd new file mode 100644 index 0000000..faa2730 --- /dev/null +++ b/doc/examples/example12.pd @@ -0,0 +1,42 @@ +#N canvas 578 52 635 489 10; +#X obj 83 183 metro 40; +#X obj 83 154 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 83 361 pdp_xv; +#X obj 165 299 pdp_loop 50; +#X obj 218 167 f 0; +#X obj 218 198 + 1; +#X obj 218 107 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 247 140 0; +#X obj 165 361 pdp_xv; +#X msg 165 259 store \$1; +#X obj 83 225 pdp_v4l; +#X msg 29 118 open /dev/video1; +#X floatatom 218 230 5 0 0; +#X obj 312 385 pdp_save_png_sequence 50; +#X obj 312 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 29 96 open /dev/video0; +#X text 337 349 <- click to save sequence in /tmp dir; +#X text 247 106 <- click to make a snapshot; +#X text 288 139 <- click to reset recording to loop; +#X text 273 229 <- recorded frame; +#X text 28 27 make loop of snapshots; +#X connect 0 0 10 0; +#X connect 0 0 3 0; +#X connect 1 0 0 0; +#X connect 3 0 8 0; +#X connect 3 0 13 0; +#X connect 4 0 5 0; +#X connect 5 0 4 1; +#X connect 5 0 9 0; +#X connect 5 0 12 0; +#X connect 6 0 4 0; +#X connect 7 0 4 1; +#X connect 9 0 3 0; +#X connect 10 0 2 0; +#X connect 10 0 3 0; +#X connect 11 0 10 0; +#X connect 14 0 13 0; +#X connect 15 0 11 0; diff --git a/doc/examples/example13.pd b/doc/examples/example13.pd new file mode 100644 index 0000000..369c895 --- /dev/null +++ b/doc/examples/example13.pd @@ -0,0 +1,104 @@ +#N canvas 419 114 799 646 10; +#X obj 450 429 pdp_xv; +#X obj 545 76 pdp_control; +#X msg 545 48 thread \$1; +#X obj 545 24 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 134 40 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X msg 471 397 size 640 480; +#X obj 239 393 +; +#X obj 190 432 vsl 15 128 1 0 0 0 empty empty empty 0 -8 0 8 -262144 +-1 -1 0 1; +#X obj 190 393 -; +#X obj 59 386 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 59 401 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 59 416 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 205 432 vsl 15 128 1 0 0 0 empty empty empty 0 -8 0 8 -262144 +-1 -1 0 1; +#X obj 220 432 vsl 15 128 1 0 0 0 empty empty empty 0 -8 0 8 -262144 +-1 -1 0 1; +#X obj 190 366 unpack f f; +#X obj 62 317 unpack f f; +#X obj 68 360 +; +#X obj 45 360 -; +#X obj 151 264 pack f f; +#X obj 215 265 pack f f; +#X msg 295 77 dim 320 240; +#X obj 134 72 metro 40; +#X msg 294 54 dim 640 480; +#X obj 134 100 pdp_v4l; +#X obj 450 366 pdp_zoom; +#X floatatom 450 308 5 0 0; +#X msg 553 311 centerx \$1; +#X floatatom 553 289 5 0 0; +#X floatatom 636 292 5 0 0; +#X msg 635 310 centery \$1; +#X obj 511 197 unpack f f f f; +#X obj 450 287 min; +#X obj 446 252 expr .5/($f1+.02); +#X obj 572 252 expr .5/($f1+.02); +#X msg 450 339 zoomx \$1 \, zoomy \$1; +#X msg 295 8 open /dev/video0; +#X msg 295 30 open /dev/video1; +#X obj 309 244 pack f f f f; +#X obj 134 156 pdp_diff; +#X text 208 156 <- compute difference between current and previous +frame; +#X obj 134 226 pdp_cog_abs_thresh 0.15; +#X text 331 492 using the blob tracker on a difference signal to detect +motion; +#X connect 2 0 1 0; +#X connect 3 0 2 0; +#X connect 4 0 21 0; +#X connect 5 0 0 0; +#X connect 6 0 13 0; +#X connect 8 0 7 0; +#X connect 14 0 12 0; +#X connect 14 0 8 0; +#X connect 14 0 6 0; +#X connect 14 1 8 1; +#X connect 14 1 6 1; +#X connect 15 0 17 0; +#X connect 15 0 16 0; +#X connect 15 0 10 0; +#X connect 15 1 16 1; +#X connect 15 1 17 1; +#X connect 16 0 11 0; +#X connect 17 0 9 0; +#X connect 18 0 15 0; +#X connect 19 0 14 0; +#X connect 20 0 23 0; +#X connect 21 0 23 0; +#X connect 22 0 23 0; +#X connect 23 0 38 0; +#X connect 24 0 0 0; +#X connect 25 0 34 0; +#X connect 26 0 24 0; +#X connect 27 0 26 0; +#X connect 28 0 29 0; +#X connect 29 0 24 0; +#X connect 30 0 27 0; +#X connect 30 1 32 0; +#X connect 30 2 28 0; +#X connect 30 3 33 0; +#X connect 31 0 25 0; +#X connect 32 0 31 0; +#X connect 33 0 31 1; +#X connect 34 0 24 0; +#X connect 35 0 23 0; +#X connect 36 0 23 0; +#X connect 37 0 30 0; +#X connect 38 0 24 0; +#X connect 38 0 40 0; +#X connect 40 1 18 0; +#X connect 40 1 37 0; +#X connect 40 2 19 0; +#X connect 40 2 37 2; +#X connect 40 3 18 1; +#X connect 40 3 37 1; +#X connect 40 4 19 1; +#X connect 40 4 37 3; diff --git a/doc/examples/example14.pd b/doc/examples/example14.pd new file mode 100644 index 0000000..f29e1b2 --- /dev/null +++ b/doc/examples/example14.pd @@ -0,0 +1,54 @@ +#N canvas 621 348 611 467 10; +#X obj 168 329 pdp_xv; +#X obj 168 78 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 168 142 pdp_v4l; +#X obj 168 108 metro 40; +#X msg 265 83 open /dev/video1; +#X floatatom 311 151 5 0 0; +#X obj 168 194 pdp_agc 0.5; +#X floatatom 310 211 5 0 0; +#X obj 168 245 pdp_contrast 0.5; +#X msg 4 157 chanmask \$1; +#X floatatom 4 133 5 0 0; +#X msg 4 104 1; +#X msg 35 104 3; +#X msg 67 104 5; +#X msg 99 104 7; +#X obj 314 192 hsl 128 15 0 1 0 1 empty empty empty -2 -6 0 8 -262144 +-1 -1 12300 1; +#X obj 314 132 hsl 128 15 0 1 0 1 empty empty empty -2 -6 0 8 -262144 +-1 -1 7900 1; +#X msg 265 58 open /dev/video0; +#X floatatom 310 272 5 0 0; +#X obj 314 253 hsl 128 15 0 3 0 1 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 168 298 pdp_saturation 0.5; +#X text 7 79 Y; +#X text 36 78 YCr; +#X text 68 79 YCb; +#X text 98 78 YCrCb; +#X text 25 15 some basic image enhancements; +#X text 13 60 agc color channels; +#X obj 183 166 pdp_flip_lr; +#X connect 1 0 3 0; +#X connect 2 0 27 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 5 0 6 1; +#X connect 6 0 8 0; +#X connect 7 0 8 1; +#X connect 8 0 20 0; +#X connect 9 0 6 0; +#X connect 10 0 9 0; +#X connect 11 0 10 0; +#X connect 12 0 10 0; +#X connect 13 0 10 0; +#X connect 14 0 10 0; +#X connect 15 0 7 0; +#X connect 16 0 5 0; +#X connect 17 0 2 0; +#X connect 18 0 20 1; +#X connect 19 0 18 0; +#X connect 20 0 0 0; +#X connect 27 0 6 0; diff --git a/doc/examples/example15.pd b/doc/examples/example15.pd new file mode 100644 index 0000000..5301fc0 --- /dev/null +++ b/doc/examples/example15.pd @@ -0,0 +1,27 @@ +#N canvas 632 359 559 496 10; +#X obj 127 57 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 127 81 metro 40; +#X obj 148 57 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 126 110 pdp_v4l; +#X msg 229 56 open /dev/video0; +#X msg 228 80 open /dev/video1; +#X obj 126 151 pdp_motion_fade 1; +#X obj 126 174 pdp_contrast 0.16; +#X obj 126 199 pdp_mul; +#X obj 126 224 pdp_gain 22; +#X text 7 2 using motion_fade \, contrast \, mul and gain to get a +motion triggered effect; +#X obj 126 258 pdp_xv; +#X connect 0 0 1 0; +#X connect 1 0 3 0; +#X connect 2 0 1 0; +#X connect 3 0 6 0; +#X connect 4 0 3 0; +#X connect 5 0 3 0; +#X connect 6 0 7 0; +#X connect 7 0 8 1; +#X connect 7 0 8 0; +#X connect 8 0 9 0; +#X connect 9 0 11 0; diff --git a/doc/objects/pdp_abs.pd b/doc/objects/pdp_abs.pd new file mode 100644 index 0000000..eef5a94 --- /dev/null +++ b/doc/objects/pdp_abs.pd @@ -0,0 +1,21 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 296 pdp_gain; +#X msg 128 268 1; +#X text 229 235 absolute value; +#X obj 77 231 pdp_abs; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 10 0; +#X connect 5 0 4 1; +#X connect 6 0 5 0; +#X connect 7 0 3 0; +#X connect 8 0 7 1; +#X connect 10 0 7 0; diff --git a/doc/objects/pdp_add.pd b/doc/objects/pdp_add.pd index 4105dcf..fa5cd1f 100644 --- a/doc/objects/pdp_add.pd +++ b/doc/objects/pdp_add.pd @@ -9,9 +9,15 @@ -1; #X text 229 181 click here; #X obj 77 163 pdp_gain; -#X floatatom 128 135 5 0 0; +#X floatatom 128 135 5 0 0 0 - - -; #X msg 128 109 0.5; #X text 229 283 adds (and saturates) 2 packets; +#X msg 230 246 chanmask \$1; +#X floatatom 230 221 5 0 0 0 - - -; +#X msg 374 131 thread \$1; +#X obj 373 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X obj 377 164 pdp_control; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 2 0 8 0; @@ -22,3 +28,7 @@ #X connect 8 0 5 1; #X connect 9 0 8 1; #X connect 10 0 9 0; +#X connect 12 0 4 0; +#X connect 13 0 12 0; +#X connect 14 0 16 0; +#X connect 15 0 14 0; diff --git a/doc/objects/pdp_and.pd b/doc/objects/pdp_and.pd new file mode 100644 index 0000000..e352b16 --- /dev/null +++ b/doc/objects/pdp_and.pd @@ -0,0 +1,24 @@ +#N canvas 552 356 511 383 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 322 pdp_help_output; +#X obj 121 246 pdp_reg; +#X obj 196 183 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 229 181 click here; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 279 pdp_and; +#X text 229 283 bitwise and; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 7 0; +#X connect 4 0 10 1; +#X connect 5 0 4 0; +#X connect 7 0 10 0; +#X connect 7 0 4 1; +#X connect 8 0 7 1; +#X connect 9 0 8 0; +#X connect 10 0 3 0; diff --git a/doc/objects/pdp_bitdepth.pd b/doc/objects/pdp_bitdepth.pd new file mode 100644 index 0000000..4c5ae11 --- /dev/null +++ b/doc/objects/pdp_bitdepth.pd @@ -0,0 +1,32 @@ +#N canvas 504 211 500 438 10; +#X msg 140 61 start; +#X msg 187 61 stop; +#X obj 140 93 pdp_help_input; +#X obj 140 352 pdp_help_output; +#X obj 140 308 pdp_gain; +#X msg 191 280 1; +#X floatatom 219 209 8 0 0; +#X obj 222 185 hsl 128 15 0 8 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 2500 1; +#X floatatom 238 278 5 0 0; +#X obj 140 243 pdp_bitdepth; +#X text 292 247 set bit depth (0->16); +#X obj 140 158 pdp_gain; +#X msg 191 130 1; +#X floatatom 227 130 5 0 0; +#X msg 32 192 chanmask \$1; +#X floatatom 32 164 5 0 0; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 11 0; +#X connect 4 0 3 0; +#X connect 5 0 4 1; +#X connect 6 0 9 1; +#X connect 7 0 6 0; +#X connect 8 0 4 1; +#X connect 9 0 4 0; +#X connect 11 0 9 0; +#X connect 12 0 11 1; +#X connect 13 0 11 1; +#X connect 14 0 9 0; +#X connect 15 0 14 0; diff --git a/doc/objects/pdp_bitmask.pd b/doc/objects/pdp_bitmask.pd new file mode 100644 index 0000000..c92ab9e --- /dev/null +++ b/doc/objects/pdp_bitmask.pd @@ -0,0 +1,22 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 287 pdp_help_output; +#X obj 77 243 pdp_gain; +#X msg 128 215 1; +#X text 229 182 apply a bitwise mask (16 bit); +#X floatatom 149 144 8 0 0; +#X obj 152 120 hsl 128 15 0 65535 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X floatatom 175 213 5 0 0; +#X obj 77 178 pdp_bitmask; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 10 0; +#X connect 4 0 3 0; +#X connect 5 0 4 1; +#X connect 7 0 10 1; +#X connect 8 0 7 0; +#X connect 9 0 4 1; +#X connect 10 0 4 0; diff --git a/doc/objects/pdp_bq.pd b/doc/objects/pdp_bq.pd index 06c05da..3078c45 100644 --- a/doc/objects/pdp_bq.pd +++ b/doc/objects/pdp_bq.pd @@ -11,13 +11,13 @@ #X msg 28 495 onep \$1; #X floatatom 89 526 5 0 0; #X msg 28 530 twop \$1; -#X obj 85 272 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +#X obj 85 272 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 87 304 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 79 209 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 ; -#X obj 82 244 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +#X obj 82 244 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X msg 28 209 lr \$1; #X msg 28 244 rl \$1; @@ -86,9 +86,12 @@ #X text 264 342 set the filter type:; #X text 137 476 set the filter type:; #X text 538 319 (between 0 and 1 \, 0.5 = nyquist); -#X text 540 333; +#X text 540 333 comment; #X text 540 305 pole frequency; #X msg 100 572 1; +#X msg 457 611 chanmask \$1; +#X floatatom 457 585 5 0 0; +#X text 456 633 binary channel mask; #X connect 0 0 5 1; #X connect 1 0 5 0; #X connect 2 0 5 0; @@ -147,3 +150,5 @@ #X connect 72 0 71 1; #X connect 73 0 72 0; #X connect 82 0 0 0; +#X connect 83 0 5 0; +#X connect 84 0 83 0; diff --git a/doc/objects/pdp_bqt.pd b/doc/objects/pdp_bqt.pd index a2f483e..5076168 100644 --- a/doc/objects/pdp_bqt.pd +++ b/doc/objects/pdp_bqt.pd @@ -47,7 +47,7 @@ #X text 264 342 set the filter type:; #X text 136 192 set the filter type:; #X text 538 319 (between 0 and 1 \, 0.5 = nyquist); -#X text 540 333; +#X text 540 333 comment; #X text 540 305 pole frequency; #X text 37 16 pdp_bqt: a temporal biquad filter; #X text 99 45 try one of the abstractions (pdp_motion_blur and; @@ -55,6 +55,8 @@ #X obj 434 190 pdp_motion_blur; #X obj 558 190 pdp_motion_phase; #X obj 27 499 pdp_bqt; +#X msg 48 312 reset; +#X text 95 313 reset state; #X connect 0 0 1 0; #X connect 1 0 54 0; #X connect 2 0 3 0; @@ -93,3 +95,4 @@ #X connect 52 0 21 0; #X connect 53 0 21 0; #X connect 54 0 39 0; +#X connect 55 0 54 0; diff --git a/doc/objects/pdp_cheby.pd b/doc/objects/pdp_cheby.pd index ada420b..68e24a4 100644 --- a/doc/objects/pdp_cheby.pd +++ b/doc/objects/pdp_cheby.pd @@ -1,47 +1,66 @@ -#N canvas 57 353 672 516 10; -#X msg 81 108 coef 0 \$1; -#X floatatom 113 78 5 0 0; -#X floatatom 180 81 5 0 0; -#X msg 160 109 coef 1 \$1; -#X floatatom 276 78 5 0 0; -#X msg 244 108 coef 2 \$1; -#X floatatom 356 77 5 0 0; -#X msg 324 107 coef 3 \$1; -#X obj 51 372 pdp_cheby 3; -#X floatatom 338 324 5 0 0; -#X msg 340 194 chan 1; -#X text 216 52 coefficients; -#X msg 339 233 chan 0; -#X msg 394 194 chan 2; -#X msg 448 194 chan 3; -#X text 152 363 creation arg: order (nb coefs = order + 1); -#X text 153 379 (default = minimal order = 2); -#X msg 338 274 reset; -#X obj 51 41 pdp_help_input; -#X msg 51 11 start; -#X msg 100 11 stop; -#X obj 51 414 pdp_help_output; -#X text 392 234 all channels; -#X text 391 324 right inlet: number of iterations; -#X text 390 273 set all coefs to 0; -#X msg 338 303 1; -#X text 340 173 select colour channel to be processed; -#X connect 0 0 8 0; +#N canvas 117 219 672 516 10; +#X msg 67 108 coef 0 \$1; +#X floatatom 67 84 5 0 0; +#X floatatom 137 84 5 0 0; +#X msg 137 108 coef 1 \$1; +#X floatatom 206 83 5 0 0; +#X msg 206 108 coef 2 \$1; +#X floatatom 275 84 5 0 0; +#X msg 275 108 coef 3 \$1; +#X floatatom 243 359 5 0 0; +#X text 122 394 creation arg: order (nb coefs = order + 1); +#X text 123 410 (default = minimal order = 2); +#X msg 243 309 reset; +#X obj 21 46 pdp_help_input; +#X msg 21 16 start; +#X msg 70 16 stop; +#X obj 21 445 pdp_help_output; +#X text 296 359 right inlet: number of iterations; +#X text 295 308 set all coefs to 0; +#X msg 243 338 1; +#X msg 243 267 chanmask \$1; +#X floatatom 243 244 5 0 0; +#X text 157 63 set individual coefficients; +#N canvas 0 0 450 300 graph1 0; +#X array mapping 64 float 1; +#A 0 -0.908307 -0.86545 -0.794021 -0.76545 -0.694021 -0.622593 -0.451164 +-0.0511646 0.234549 0.377406 0.427406 0.477406 0.520263 0.534549 0.548835 +0.534549 0.505978 0.477406 0.448835 0.420264 0.348835 0.298835 0.148835 +0.0845496 -0.0511645 -0.151164 -0.236879 -0.322593 -0.436878 -0.436878 +-0.436878 -0.436878 -0.422593 -0.394021 -0.36545 -0.308307 -0.26545 +-0.136879 0.120264 0.291692 0.434549 0.534549 0.591692 0.648835 0.677406 +0.677406 0.663121 0.648835 0.648835 0.634549 0.605978 0.605978 0.605978 +0.605978 0.605978 0.605978 0.634549 0.648835 0.677406 0.705978 0.76312 +0.848835 0.934549 0.977406; +#X coords 0 1 63 -1 200 140 1; +#X restore 427 20 graph; +#X msg 242 217 approx mapping; +#X obj 21 158 pdp_t; +#X text 418 165 -1 ----------- 0 ----------- 1; +#X obj 242 190 spigot; +#X obj 279 167 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X text 361 216 approximate a mapping function; +#X obj 21 403 pdp_cheby 10; +#X connect 0 0 29 0; #X connect 1 0 0 0; #X connect 2 0 3 0; -#X connect 3 0 8 0; +#X connect 3 0 29 0; #X connect 4 0 5 0; -#X connect 5 0 8 0; +#X connect 5 0 29 0; #X connect 6 0 7 0; -#X connect 7 0 8 0; -#X connect 8 0 21 0; -#X connect 9 0 8 1; -#X connect 10 0 8 0; -#X connect 12 0 8 0; -#X connect 13 0 8 0; -#X connect 14 0 8 0; -#X connect 17 0 8 0; +#X connect 7 0 29 0; +#X connect 8 0 29 1; +#X connect 11 0 29 0; +#X connect 12 0 24 0; +#X connect 13 0 12 0; +#X connect 14 0 12 0; #X connect 18 0 8 0; -#X connect 19 0 18 0; -#X connect 20 0 18 0; -#X connect 25 0 9 0; +#X connect 19 0 29 0; +#X connect 20 0 19 0; +#X connect 23 0 29 0; +#X connect 24 0 29 0; +#X connect 24 1 26 0; +#X connect 26 0 23 0; +#X connect 27 0 26 1; +#X connect 29 0 15 0; diff --git a/doc/objects/pdp_cog.pd b/doc/objects/pdp_cog.pd new file mode 100644 index 0000000..70d8ef7 --- /dev/null +++ b/doc/objects/pdp_cog.pd @@ -0,0 +1,32 @@ +#N canvas 683 169 505 377 10; +#X floatatom 146 142 5 0 0; +#X floatatom 146 166 5 0 0; +#X floatatom 146 190 5 0 0; +#X floatatom 146 214 5 0 0; +#X floatatom 146 239 5 0 0; +#X text 32 12 pdp_cog: compute intensity \, center of gravity and standard +deviation. (interpret an image as a gaussian blob).; +#X text 201 215 standard deviation x; +#X text 200 239 standard deviation y; +#X obj 78 50 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 21 236 pdp_help_output; +#X obj 78 73 pdp_help_input; +#X text 200 141 average intensity; +#X text 200 168 center of gravity x; +#X text 200 190 center of gravity y; +#X text 203 47 creation argument is threshold; +#X obj 78 124 pdp_cog; +#X floatatom 375 291 5 0 0; +#X obj 226 317 pdp_cog_abs_thresh 0.1; +#X text 87 342 the same \, but takes the absolute value and performs +a thresholding operation; +#X connect 8 0 10 0; +#X connect 10 0 9 0; +#X connect 10 0 15 0; +#X connect 15 0 0 0; +#X connect 15 1 1 0; +#X connect 15 2 2 0; +#X connect 15 3 3 0; +#X connect 15 4 4 0; +#X connect 16 0 17 1; diff --git a/doc/objects/pdp_control.pd b/doc/objects/pdp_control.pd index fccb5e9..cfe7704 100644 --- a/doc/objects/pdp_control.pd +++ b/doc/objects/pdp_control.pd @@ -1,28 +1,46 @@ -#N canvas 259 276 579 567 10; -#X obj 237 316 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +#N canvas 259 276 910 567 10; +#X obj 143 325 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X obj 237 406 pdp_control; -#X msg 237 357 thread \$1; +#X obj 143 415 pdp_control; +#X msg 143 366 thread \$1; #X obj 48 54 pdp_help_input; #X msg 48 24 start; #X msg 105 24 stop; #X obj 48 205 pdp_help_output; #X obj 48 154 pdp_conv; #X floatatom 117 86 5 0 0; -#X obj 79 350 osc~; -#X floatatom 79 315 5 0 0; -#X obj 79 419 osc~; -#X floatatom 112 391 5 0 0; -#X obj 79 449 dac~; -#X obj 237 445 print; -#X text 276 314 switch thread processing on or of; -#X text 291 446 a pdp_drop message will be sent out; -#X text 291 462 when a package is dropped; +#X obj 46 361 osc~; +#X floatatom 46 326 5 0 0; +#X obj 46 430 osc~; +#X floatatom 79 402 5 0 0; +#X obj 46 460 dac~; +#X obj 143 454 print; +#X text 182 323 switch thread processing on or of; +#X text 197 455 a pdp_drop message will be sent out; +#X text 197 471 when a package is dropped; +#X text 119 155 a convolution object to burn cycles; +#X obj 666 254 pdp_control; +#X msg 666 226 collectgarbage; +#X obj 646 478 pdp_control; #X text 175 82 increase this with thread processing enabled \, no audio -should be dropped. if you do it with thread processing enabled \, increasing -it too much can lock up the machine when real time scheduling is enabled. +should be dropped. if you do it with thread processing disabled \, +increasing it too much can lock up the machine when real time scheduling +is enabled.; +#X msg 646 452 memlimit \$1; +#X msg 688 422 5e+07; +#X msg 615 421 0; +#X text 687 402 50M; +#X text 613 401 off; +#X text 472 178 free all unused packets. pdp's garbage collection is +"lazy" meaning packets will only be freed when the maximum usage limit +is reached.; +#X text 179 25 pdp_control: fine tune the pdp system. (threads & memory). ; -#X text 119 155 a convolution object to burn cycles; +#X text 470 357 set the max memory usage limit for the packet pool. +the default is off (value <= 0).; +#X text 475 511 (this is a safety measure: in pdp it is easy to use +too much memory \, i.e. with delay lines \, which will likely crash +pd); #X connect 0 0 2 0; #X connect 1 0 14 0; #X connect 2 0 1 0; @@ -35,3 +53,7 @@ it too much can lock up the machine when real time scheduling is enabled. #X connect 10 0 9 0; #X connect 11 0 13 0; #X connect 12 0 11 1; +#X connect 20 0 19 0; +#X connect 23 0 21 0; +#X connect 24 0 23 0; +#X connect 25 0 23 0; diff --git a/doc/objects/pdp_convert.pd b/doc/objects/pdp_convert.pd new file mode 100644 index 0000000..498aaa3 --- /dev/null +++ b/doc/objects/pdp_convert.pd @@ -0,0 +1,17 @@ +#N canvas 556 468 575 277 10; +#X obj 46 40 pdp_help_input; +#X msg 46 10 start; +#X msg 95 10 stop; +#X obj 46 225 pdp_help_output; +#X obj 118 69 hdl 15 1 0 2 empty empty empty 0 -6 0 8 -262144 -1 -1 +0; +#X obj 46 90 pdp_route 2; +#X obj 118 154 pdp_convert image/grey/*; +#X text 307 153 convert a packet; +#X connect 0 0 5 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 4 0 5 1; +#X connect 5 0 3 0; +#X connect 5 1 6 0; +#X connect 6 0 3 0; diff --git a/doc/objects/pdp_del.pd b/doc/objects/pdp_del.pd index af16651..607a632 100644 --- a/doc/objects/pdp_del.pd +++ b/doc/objects/pdp_del.pd @@ -1,6 +1,6 @@ #N canvas 414 20 609 368 10; -#X floatatom 107 116 5 0 0; -#X floatatom 64 207 5 0 0; +#X floatatom 107 116 5 0 0 0 - - -; +#X floatatom 64 207 5 0 0 0 - - -; #X obj 20 60 pdp_help_input; #X msg 20 31 start; #X msg 72 30 stop; @@ -15,6 +15,9 @@ #X text 164 165 first creation arg = max delay length; #X text 165 213 second creation arg: initial delay (default = max) ; +#X obj 176 259 pdp_description; +#X obj 176 285 print; +#X msg 339 259 _debug; #X connect 0 0 11 1; #X connect 1 0 5 2; #X connect 2 0 5 0; @@ -24,3 +27,5 @@ #X connect 5 0 6 0; #X connect 7 0 1 0; #X connect 11 0 5 1; +#X connect 11 0 14 0; +#X connect 16 0 11 0; diff --git a/doc/objects/pdp_description.pd b/doc/objects/pdp_description.pd new file mode 100644 index 0000000..f065d83 --- /dev/null +++ b/doc/objects/pdp_description.pd @@ -0,0 +1,28 @@ +#N canvas 338 375 593 300 10; +#X symbolatom 78 197 40 0 0; +#X obj 78 46 pdp_noise; +#X obj 78 23 bng 15 250 50 0 empty empty empty 0 -6 32 8 -262144 -1 +-1; +#X obj 183 44 pdp_noise; +#X obj 183 21 bng 15 250 50 0 empty empty empty 0 -6 32 8 -262144 -1 +-1; +#X obj 183 71 pdp_grey; +#X text 263 139 output packet description as a symbol; +#X obj 288 44 pdp_noise; +#X obj 288 21 bng 15 250 50 0 empty empty empty 0 -6 32 8 -262144 -1 +-1; +#X obj 288 71 pdp_mchp; +#X floatatom 178 171 5 0 0; +#X obj 78 118 pdp_reg; +#X obj 78 142 pdp_description; +#X connect 1 0 11 0; +#X connect 2 0 1 0; +#X connect 3 0 5 0; +#X connect 4 0 3 0; +#X connect 5 0 11 0; +#X connect 7 0 9 0; +#X connect 8 0 7 0; +#X connect 9 0 11 0; +#X connect 11 0 12 0; +#X connect 12 0 0 0; +#X connect 12 1 10 0; diff --git a/doc/objects/pdp_flip_lr.pd b/doc/objects/pdp_flip_lr.pd new file mode 100644 index 0000000..b28c3bd --- /dev/null +++ b/doc/objects/pdp_flip_lr.pd @@ -0,0 +1,11 @@ +#N canvas 504 211 449 178 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 136 pdp_help_output; +#X obj 77 101 pdp_flip_lr; +#X text 222 101 flip left <-> right; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 3 0; diff --git a/doc/objects/pdp_flip_tb.pd b/doc/objects/pdp_flip_tb.pd new file mode 100644 index 0000000..7048a75 --- /dev/null +++ b/doc/objects/pdp_flip_tb.pd @@ -0,0 +1,11 @@ +#N canvas 504 211 449 178 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 136 pdp_help_output; +#X obj 77 101 pdp_flip_tb; +#X text 222 101 flip top <-> bottom; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 3 0; diff --git a/doc/objects/pdp_gain.pd b/doc/objects/pdp_gain.pd index eec7e76..7e3f50b 100644 --- a/doc/objects/pdp_gain.pd +++ b/doc/objects/pdp_gain.pd @@ -1,32 +1,23 @@ -#N canvas 317 409 546 403 10; +#N canvas 444 413 538 379 10; #X msg 91 25 start; #X msg 139 25 stop; #X obj 91 56 pdp_help_input; -#X obj 91 350 pdp_help_output; -#X obj 91 274 pdp_gain; -#X floatatom 142 245 5 0 0; -#X text 201 243 right inlet sets overal gain; -#X msg 127 159 y \$1; -#X msg 176 159 v \$1; -#X msg 224 158 u \$1; -#X floatatom 127 122 5 0 0; -#X floatatom 176 122 5 0 0; -#X floatatom 224 122 5 0 0; -#X text 281 121 set individual channel gains; -#X text 301 144 y: luma; -#X text 301 160 v: chroma red; -#X text 301 175 u: chroma blue; -#X text 201 290 creation argument sets initial gain; -#X text 200 308 (default = 1); -#X text 202 274 pdp_gain clips when overdriven; +#X obj 91 312 pdp_help_output; +#X obj 91 236 pdp_gain; +#X floatatom 142 207 5 0 0; +#X text 201 205 right inlet sets overal gain; +#X text 201 252 creation argument sets initial gain; +#X text 200 270 (default = 1); +#X text 202 236 pdp_gain clips when overdriven; +#X msg 109 124 chanmask \$1; +#X floatatom 109 100 5 0 0; +#X text 203 124 set which channels are processed; +#X text 203 140 using a binary mask. LSB = chan 0; +#X text 203 157 default (any negative number) = all; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 2 0 4 0; #X connect 4 0 3 0; #X connect 5 0 4 1; -#X connect 7 0 4 0; -#X connect 8 0 4 0; -#X connect 9 0 4 0; -#X connect 10 0 7 0; -#X connect 11 0 8 0; -#X connect 12 0 9 0; +#X connect 10 0 4 0; +#X connect 11 0 10 0; diff --git a/doc/objects/pdp_help_input.pd b/doc/objects/pdp_help_input.pd index a4bc76e..4283796 100644 --- a/doc/objects/pdp_help_input.pd +++ b/doc/objects/pdp_help_input.pd @@ -3,9 +3,8 @@ #X text 17 11 this abstraction is used as an input module in most of the documentation patches. change it to reflect your preferred input object.; -#X obj 262 248 inlet; -#X obj 262 276 route start stop; -#X msg 315 309 stop; +#X obj 262 234 inlet; +#X msg 315 324 stop; #X obj 258 672 outlet; #X obj 262 385 metro; #X obj 292 360 nbx 5 14 -1e+37 1e+37 0 1 empty empty empty 0 -6 0 10 @@ -29,11 +28,10 @@ object.; -1; #X obj 262 426 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X msg 492 288 open /somedirectory/mydemo.mov; #X text 520 308 change this to the movie; #X text 519 323 you want to use; #X msg 520 379 loop 1; -#X msg 262 310 bang; +#X msg 262 325 bang; #X text 163 203 for video4linux; #X text 294 201 for quicktime; #X text 156 497 connect here; @@ -41,23 +39,33 @@ object.; #X text 302 497 connect here; #X text 305 511 for quicktime; #X text 308 377 set framerate here; -#X connect 0 0 5 0; -#X connect 2 0 3 0; -#X connect 3 0 25 0; -#X connect 3 1 4 0; -#X connect 4 0 6 0; -#X connect 6 0 20 0; -#X connect 7 0 6 1; -#X connect 8 0 0 0; -#X connect 9 0 19 0; -#X connect 10 0 8 0; -#X connect 11 0 21 0; -#X connect 14 0 0 0; -#X connect 15 0 18 0; -#X connect 18 0 5 0; -#X connect 19 0 10 0; -#X connect 20 0 14 0; -#X connect 21 0 18 0; -#X connect 21 0 24 0; -#X connect 24 0 18 0; -#X connect 25 0 6 0; +#X msg 492 288 open /tmp/test.mov; +#X obj 262 258 route start stop; +#X obj 329 292 select 0; +#X obj 262 292 select 1; +#X msg 40 357 open /dev/video1; +#X connect 0 0 4 0; +#X connect 2 0 32 0; +#X connect 3 0 5 0; +#X connect 5 0 19 0; +#X connect 6 0 5 1; +#X connect 7 0 0 0; +#X connect 8 0 18 0; +#X connect 9 0 7 0; +#X connect 10 0 31 0; +#X connect 13 0 0 0; +#X connect 14 0 17 0; +#X connect 17 0 4 0; +#X connect 18 0 9 0; +#X connect 19 0 13 0; +#X connect 22 0 17 0; +#X connect 23 0 5 0; +#X connect 31 0 17 0; +#X connect 31 0 22 0; +#X connect 32 0 23 0; +#X connect 32 1 3 0; +#X connect 32 2 34 0; +#X connect 33 0 3 0; +#X connect 34 0 23 0; +#X connect 34 1 33 0; +#X connect 35 0 0 0; diff --git a/doc/objects/pdp_help_output.pd b/doc/objects/pdp_help_output.pd index c216ae3..0ed52d5 100644 --- a/doc/objects/pdp_help_output.pd +++ b/doc/objects/pdp_help_output.pd @@ -1,7 +1,14 @@ -#N canvas 482 342 450 300 10; +#N canvas 482 342 510 304 10; #X obj 59 95 inlet; #X obj 59 178 pdp_xv; #X text 17 11 this abstraction is used as an output module in most of the documentation patches. change it to reflect your preferred output object.; +#X obj 232 179 pdp_glx; +#X text 31 201 X11 XVideo output; +#X text 198 199 X11 openGL output; +#X text 60 217 (linux); +#X text 199 214 (linux \, mesa \, osx); +#X msg 106 141 display acer:0; #X connect 0 0 1 0; +#X connect 8 0 1 0; diff --git a/doc/objects/pdp_histo.pd b/doc/objects/pdp_histo.pd new file mode 100644 index 0000000..f99a27e --- /dev/null +++ b/doc/objects/pdp_histo.pd @@ -0,0 +1,36 @@ +#N canvas 594 324 616 432 10; +#X msg 87 208 size \$1; +#X floatatom 87 184 5 0 0; +#N canvas 0 0 450 300 graph2 0; +#X array array1 64 float 0; +#X coords 0 1 63 -1 200 140 1; +#X restore 390 32 graph; +#X obj 127 47 pdp_help_input; +#X obj 127 113 pdp_help_output; +#X obj 127 77 pdp_gain; +#X floatatom 251 50 5 0 0; +#X obj 127 23 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X msg 86 271 array array1; +#X floatatom 155 183 5 0 0; +#X msg 155 207 scale \$1; +#X text 37 355 the size is rounded to the next power of 2; +#X text 36 373 first argument is size \, second is optional scaling +factor.; +#X text 37 338 create a histogram from an image and send to a table +; +#X floatatom 229 183 5 0 0; +#X msg 229 207 samplesize \$1; +#X obj 19 299 pdp_histo array1 64 10; +#X connect 0 0 16 0; +#X connect 1 0 0 0; +#X connect 3 0 5 0; +#X connect 5 0 4 0; +#X connect 5 0 16 0; +#X connect 6 0 5 1; +#X connect 7 0 3 0; +#X connect 8 0 16 0; +#X connect 9 0 10 0; +#X connect 10 0 16 0; +#X connect 14 0 15 0; +#X connect 15 0 16 0; diff --git a/doc/objects/pdp_hthresh.pd b/doc/objects/pdp_hthresh.pd new file mode 100644 index 0000000..6d71925 --- /dev/null +++ b/doc/objects/pdp_hthresh.pd @@ -0,0 +1,26 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 296 pdp_gain; +#X msg 128 268 1; +#X floatatom 160 199 5 0 0; +#X text 234 283 (-t > x > t) -> 0; +#X text 234 248 ( x > t) -> x; +#X text 234 266 (-t > x) -> x; +#X text 233 230 hard threshold; +#X obj 77 231 pdp_hthresh; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 14 0; +#X connect 5 0 4 1; +#X connect 6 0 5 0; +#X connect 7 0 3 0; +#X connect 8 0 7 1; +#X connect 9 0 14 1; +#X connect 14 0 7 0; diff --git a/doc/objects/pdp_loop.pd b/doc/objects/pdp_loop.pd new file mode 100644 index 0000000..b097cd8 --- /dev/null +++ b/doc/objects/pdp_loop.pd @@ -0,0 +1,62 @@ +#N canvas 427 312 733 458 10; +#X obj 32 85 metro 40; +#X obj 17 59 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 152 393 pdp_loop 25; +#X msg 275 109 record; +#X floatatom 83 58 5 0 0; +#X msg 39 58 stop; +#X floatatom 274 363 5 0 0; +#X floatatom 274 338 5 0 0; +#X msg 275 82 store \$1; +#X floatatom 275 57 5 0 0; +#X msg 274 158 stop; +#X obj 152 428 pdp_help_output; +#X obj 152 87 pdp_help_input; +#X msg 152 59 start; +#X msg 199 59 stop; +#X text 365 325 set playback position; +#X text 372 345 hot; +#X text 369 362 cold; +#X text 365 159 stop recording; +#X text 366 107 start recording at position 0; +#X text 365 82 store a single packet at an arbitrary position; +#X text 154 33 source playback; +#X text 16 34 loop playback; +#X text 272 393 creation arg: loop size; +#X msg 275 132 record 10 2; +#X text 365 133 start recording at position 10 \, recording 2 packets +; +#X msg 274 209 loop \$1; +#X obj 274 188 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X text 365 210 looping on/off; +#X msg 274 310 0; +#X msg 274 273 size \$1; +#X floatatom 274 249 5 0 0; +#X text 366 270 set a new loop size. (don't make this too large); +#X msg 561 356 collectgarbage; +#X obj 561 387 pdp_control; +#X msg 546 329 thread 1; +#X connect 0 0 2 0; +#X connect 1 0 0 0; +#X connect 2 0 11 0; +#X connect 3 0 2 0; +#X connect 4 0 0 1; +#X connect 5 0 0 0; +#X connect 6 0 2 1; +#X connect 7 0 2 0; +#X connect 8 0 2 0; +#X connect 9 0 8 0; +#X connect 10 0 2 0; +#X connect 12 0 2 0; +#X connect 13 0 12 0; +#X connect 14 0 12 0; +#X connect 24 0 2 0; +#X connect 26 0 2 0; +#X connect 27 0 26 0; +#X connect 29 0 7 0; +#X connect 30 0 2 0; +#X connect 31 0 30 0; +#X connect 33 0 34 0; +#X connect 35 0 34 0; diff --git a/doc/objects/pdp_mul.pd b/doc/objects/pdp_mul.pd index 596c1cb..24d6461 100644 --- a/doc/objects/pdp_mul.pd +++ b/doc/objects/pdp_mul.pd @@ -1,17 +1,19 @@ #N canvas 224 229 462 390 10; -#X msg 77 38 start; -#X msg 124 38 stop; -#X obj 77 70 pdp_help_input; -#X obj 77 330 pdp_help_output; -#X obj 121 164 pdp_reg; -#X obj 195 127 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +#X msg 130 53 start; +#X msg 177 53 stop; +#X obj 130 85 pdp_help_input; +#X obj 130 345 pdp_help_output; +#X obj 174 179 pdp_reg; +#X obj 248 142 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X text 228 125 click here; -#X obj 77 295 pdp_gain; -#X floatatom 128 267 5 0 0; -#X text 229 201 multiplies 2 packets; -#X obj 77 197 pdp_mul; -#X msg 128 241 2; +#X text 281 140 click here; +#X obj 130 310 pdp_gain; +#X floatatom 181 282 5 0 0; +#X text 282 216 multiplies 2 packets; +#X obj 130 212 pdp_mul; +#X msg 181 256 2; +#X floatatom 40 150 5 0 0; +#X msg 40 177 chanmask \$1; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 2 0 10 0; @@ -22,3 +24,5 @@ #X connect 8 0 7 1; #X connect 10 0 7 0; #X connect 11 0 8 0; +#X connect 12 0 13 0; +#X connect 13 0 10 0; diff --git a/doc/objects/pdp_not.pd b/doc/objects/pdp_not.pd new file mode 100644 index 0000000..c213080 --- /dev/null +++ b/doc/objects/pdp_not.pd @@ -0,0 +1,21 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 231 pdp_not; +#X text 229 235 bitwise not; +#X obj 77 296 pdp_gain; +#X msg 128 268 1; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 7 0; +#X connect 5 0 4 1; +#X connect 6 0 5 0; +#X connect 7 0 9 0; +#X connect 9 0 3 0; +#X connect 10 0 9 1; diff --git a/doc/objects/pdp_or.pd b/doc/objects/pdp_or.pd new file mode 100644 index 0000000..22e91e6 --- /dev/null +++ b/doc/objects/pdp_or.pd @@ -0,0 +1,24 @@ +#N canvas 552 356 511 383 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 322 pdp_help_output; +#X obj 114 246 pdp_reg; +#X obj 196 183 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 229 181 click here; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 279 pdp_or; +#X text 229 283 bitwise or; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 7 0; +#X connect 4 0 10 1; +#X connect 5 0 4 0; +#X connect 7 0 4 1; +#X connect 7 0 10 0; +#X connect 8 0 7 1; +#X connect 9 0 8 0; +#X connect 10 0 3 0; diff --git a/doc/objects/pdp_plasma.pd b/doc/objects/pdp_plasma.pd new file mode 100644 index 0000000..3a9a566 --- /dev/null +++ b/doc/objects/pdp_plasma.pd @@ -0,0 +1,29 @@ +#N canvas 655 0 575 333 10; +#X obj 46 262 pdp_help_output; +#X obj 46 149 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 174 71 dim 320 240; +#X text 270 71 set packet dimensions; +#X msg 174 98 type grey; +#X msg 174 121 type yv12; +#X text 270 100 generate greyscale; +#X text 270 119 generate colour (default); +#X msg 174 152 seed 123; +#X text 270 152 set seed value; +#X text 167 21 pdp_noise creates a random image (with uniform distribution +between -1 and 1) when a bang is received; +#X obj 46 198 pdp_plasma; +#X floatatom 174 176 5 0 0 0 - - -; +#X text 270 176 turbulence; +#X obj 46 241 pdp_reg; +#X obj 113 221 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 1 0 11 0; +#X connect 2 0 11 0; +#X connect 4 0 11 0; +#X connect 5 0 11 0; +#X connect 8 0 11 0; +#X connect 11 0 14 0; +#X connect 12 0 11 1; +#X connect 14 0 0 0; +#X connect 15 0 14 0; diff --git a/doc/objects/pdp_pointcloud.pd b/doc/objects/pdp_pointcloud.pd new file mode 100644 index 0000000..c7c7f47 --- /dev/null +++ b/doc/objects/pdp_pointcloud.pd @@ -0,0 +1,32 @@ +#N canvas 462 571 450 371 10; +#X obj 40 94 pdp_help_input; +#X obj 40 36 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 40 174 pdp_help_output; +#X text 111 11 convert an image to a point cloud; +#X text 111 43 creation argument is number of points; +#X text 111 26 (containing the points with highest intesity); +#X floatatom 168 114 5 0 0; +#X text 219 114 <- nb points; +#X obj 40 140 pdp_pointcloud 10; +#X floatatom 265 151 5 0 0; +#X msg 267 174 nbclusters \$1; +#X obj 180 216 pdp_description; +#X obj 180 243 print; +#X obj 35 296 pdp_xv; +#X obj 39 221 pdp_m_mm A A^T; +#X obj 34 273 pdp_scale 64 64; +#X obj 34 252 pdp_convert image/*/*; +#X connect 0 0 8 0; +#X connect 1 0 0 0; +#X connect 6 0 8 1; +#X connect 8 0 2 0; +#X connect 8 1 11 0; +#X connect 8 1 14 1; +#X connect 8 1 14 0; +#X connect 9 0 10 0; +#X connect 10 0 8 0; +#X connect 11 0 12 0; +#X connect 14 0 16 0; +#X connect 15 0 13 0; +#X connect 16 0 15 0; diff --git a/doc/objects/pdp_positive.pd b/doc/objects/pdp_positive.pd new file mode 100644 index 0000000..5452d2d --- /dev/null +++ b/doc/objects/pdp_positive.pd @@ -0,0 +1,27 @@ +#N canvas 479 219 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X floatatom 128 135 5 0 0; +#X obj 77 296 pdp_gain; +#X msg 145 271 1; +#X obj 77 231 pdp_positive; +#X text 224 230 test positive and return a bitmask; +#X text 225 245 >= 0 -> all one / < 0 -> all zero; +#X text 223 264 to use in conjunction with logic ops; +#X obj 77 268 pdp_xor; +#X obj 277 146 pdp_cheby; +#X obj 77 163 pdp_offset; +#X msg 128 109 -0.5; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 11 1; +#X connect 2 0 13 0; +#X connect 4 0 13 1; +#X connect 5 0 3 0; +#X connect 6 0 5 1; +#X connect 7 0 11 0; +#X connect 11 0 5 0; +#X connect 13 0 7 0; +#X connect 14 0 4 0; diff --git a/doc/objects/pdp_randmix.pd b/doc/objects/pdp_randmix.pd index 75f12fc..6614979 100644 --- a/doc/objects/pdp_randmix.pd +++ b/doc/objects/pdp_randmix.pd @@ -11,6 +11,8 @@ #X text 268 80 click here; #X text 268 159 random crossfade between 2 packets; #X text 268 175 0 = left \, 1 = right; +#X obj 203 125 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 6100 1; #X connect 0 0 7 0; #X connect 1 0 0 1; #X connect 2 0 1 0; @@ -19,3 +21,4 @@ #X connect 4 0 1 1; #X connect 5 0 4 0; #X connect 6 0 4 0; +#X connect 11 0 3 0; diff --git a/doc/objects/pdp_reg.pd b/doc/objects/pdp_reg.pd index 9a78e66..dca00ef 100644 --- a/doc/objects/pdp_reg.pd +++ b/doc/objects/pdp_reg.pd @@ -1,20 +1,38 @@ -#N canvas 623 480 596 300 10; -#X obj 41 171 pdp_reg; -#X obj 41 140 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1 +#N canvas 327 276 676 444 10; +#X obj 41 318 pdp_reg; +#X obj 41 287 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1 -1; #X msg 85 15 start; #X msg 135 15 stop; #X obj 85 53 pdp_help_input; -#X obj 41 240 pdp_help_output; -#X text 113 144 pdp_reg works in the same way as the pd float or int +#X obj 41 359 pdp_help_output; +#X text 121 90 pdp_reg works in the same way as the pd float or int objects; -#X text 263 178 bang: sends stored packet to output; -#X text 263 163 pdp: stores packet and sends to output; -#X text 263 199 pdp: stores a new packet; -#X text 112 164 left intlet (hot):; -#X text 112 199 right intlet (cold):; +#X text 271 124 bang: sends stored packet to output; +#X text 271 109 pdp: stores packet and sends to output; +#X text 271 145 pdp: stores a new packet; +#X text 121 111 left intlet (hot):; +#X text 120 145 right intlet (cold):; +#X msg 122 236 load_png \$1; +#X obj 122 212 openpanel; +#X obj 122 190 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 219 189 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 219 235 save_png \$1; +#X text 331 226 as a png image file.; +#X text 332 211 you can save the contents of the register; +#X obj 219 211 savepanel; +#X msg 219 266 save_png /tmp/snap.png; #X connect 0 0 5 0; #X connect 1 0 0 0; #X connect 2 0 4 0; #X connect 3 0 4 0; #X connect 4 0 0 1; +#X connect 12 0 0 0; +#X connect 13 0 12 0; +#X connect 14 0 13 0; +#X connect 15 0 19 0; +#X connect 16 0 0 0; +#X connect 19 0 16 0; +#X connect 20 0 0 0; diff --git a/doc/objects/pdp_sign.pd b/doc/objects/pdp_sign.pd new file mode 100644 index 0000000..2e3f775 --- /dev/null +++ b/doc/objects/pdp_sign.pd @@ -0,0 +1,25 @@ +#N canvas 479 219 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X floatatom 128 135 5 0 0; +#X obj 77 296 pdp_gain; +#X msg 145 271 1; +#X msg 128 109 -0.5; +#X obj 77 231 pdp_sign; +#X text 239 231 get the sign (-1 \, 1); +#X obj 77 268 pdp_mul; +#X obj 77 163 pdp_gain; +#X obj 173 207 pdp_abs; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 10 1; +#X connect 2 0 11 0; +#X connect 4 0 11 1; +#X connect 5 0 3 0; +#X connect 6 0 5 1; +#X connect 7 0 4 0; +#X connect 8 0 10 0; +#X connect 10 0 5 0; +#X connect 11 0 8 0; diff --git a/doc/objects/pdp_sthresh.pd b/doc/objects/pdp_sthresh.pd new file mode 100644 index 0000000..0267fc5 --- /dev/null +++ b/doc/objects/pdp_sthresh.pd @@ -0,0 +1,26 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 296 pdp_gain; +#X msg 128 268 1; +#X obj 77 231 pdp_sthresh; +#X floatatom 160 199 5 0 0; +#X text 233 230 soft threshold; +#X text 234 283 (-t > x > t) -> 0; +#X text 234 266 (-t > x) -> (x + t); +#X text 234 248 ( x > t) -> (x - t); +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 9 0; +#X connect 5 0 4 1; +#X connect 6 0 5 0; +#X connect 7 0 3 0; +#X connect 8 0 7 1; +#X connect 9 0 7 0; +#X connect 10 0 9 1; diff --git a/doc/objects/pdp_trigger.pd b/doc/objects/pdp_trigger.pd index f8b5461..2cabece 100644 --- a/doc/objects/pdp_trigger.pd +++ b/doc/objects/pdp_trigger.pd @@ -1,14 +1,79 @@ -#N canvas 526 379 575 277 10; +#N canvas 218 0 631 489 10; #X obj 46 40 pdp_help_input; #X msg 46 10 start; #X msg 95 10 stop; -#X obj 46 225 pdp_help_output; -#X obj 46 91 pdp_trigger; -#X obj 118 145 print; -#X text 154 90 outputs a bang on the right output before sending packet -to the left output; +#X obj 46 179 pdp_help_output; +#X obj 46 102 pdp_trigger; +#X text 163 98 default behaviour is to outputs bang on the right output +before sending packet to the left output; +#X obj 118 146 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 45 269 pdp_noise; +#X obj 45 245 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 45 294 pdp_trigger bang pdp bang bang pdp; +#X obj 45 460 print o1; +#X obj 278 326 print o5; +#X obj 161 388 print o3; +#X obj 103 429 print o2; +#X obj 219 354 print o4; +#X text 163 57 pdp_trigger behaves very much like the pd trigger object +; +#X text 162 243 you can give it pdp (p) or bang (b) arguments to send +out packets or bangs from right to left; +#X obj 365 406 pdp_t b p b b p; +#X text 325 386 there is also a short version:; +#X text 142 565 confusing note:; +#X obj 46 575 pdp_noise; +#X obj 46 551 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 46 604 pdp_add; +#X obj 61 746 pdp_noise; +#X obj 61 722 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 61 806 pdp_add; +#X obj 105 776 pdp_gain; +#X text 142 584 you don't need a trigger object if you connect a pdp +object's outlet to only one active inlet.; +#X text 139 657 if an outlet is connected to more than one active inlet +\, you need a trigger object like you would do with standard pd message +objects; +#X obj 285 725 pdp_noise; +#X obj 285 701 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 285 806 pdp_add; +#X obj 343 778 pdp_gain; +#X obj 285 751 pdp_t p p; +#X floatatom 156 750 5 0 0; +#X floatatom 394 750 5 0 0; +#X text 287 829 correct; +#X text 139 852 (even more confusing note: this is because pdp uses +a 3 phase communication protocol.); +#X text 452 459 (scroll down for more); +#X text 48 829 unpredictable; #X connect 0 0 4 0; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 4 0 3 0; -#X connect 4 1 5 0; +#X connect 4 1 6 0; +#X connect 7 0 9 0; +#X connect 8 0 7 0; +#X connect 9 0 10 0; +#X connect 9 1 13 0; +#X connect 9 2 12 0; +#X connect 9 3 14 0; +#X connect 9 4 11 0; +#X connect 20 0 22 0; +#X connect 20 0 22 1; +#X connect 21 0 20 0; +#X connect 23 0 25 0; +#X connect 23 0 26 0; +#X connect 24 0 23 0; +#X connect 26 0 25 1; +#X connect 29 0 33 0; +#X connect 30 0 29 0; +#X connect 32 0 31 1; +#X connect 33 0 31 0; +#X connect 33 1 32 0; +#X connect 34 0 26 1; +#X connect 35 0 32 1; diff --git a/doc/objects/pdp_xor.pd b/doc/objects/pdp_xor.pd new file mode 100644 index 0000000..40366e2 --- /dev/null +++ b/doc/objects/pdp_xor.pd @@ -0,0 +1,28 @@ +#N canvas 552 356 511 383 10; +#X msg 100 45 start; +#X msg 147 45 stop; +#X obj 100 77 pdp_help_input; +#X obj 100 329 pdp_help_output; +#X obj 144 252 pdp_reg; +#X obj 213 204 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 246 202 click here; +#X obj 100 170 pdp_gain; +#X floatatom 151 142 5 0 0; +#X msg 151 116 0.5; +#X obj 100 286 pdp_xor; +#X text 252 290 bitwise xor; +#X msg 11 205 chanmask \$1; +#X floatatom 11 180 5 0 0; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 7 0; +#X connect 4 0 10 1; +#X connect 5 0 4 0; +#X connect 7 0 4 1; +#X connect 7 0 10 0; +#X connect 8 0 7 1; +#X connect 9 0 8 0; +#X connect 10 0 3 0; +#X connect 12 0 10 0; +#X connect 13 0 12 0; diff --git a/doc/objects/pdp_xv.pd b/doc/objects/pdp_xv.pd index dd07488..a0f44a6 100644 --- a/doc/objects/pdp_xv.pd +++ b/doc/objects/pdp_xv.pd @@ -1,36 +1,58 @@ -#N canvas 150 382 708 497 10; -#X obj 29 412 pdp_xv; +#N canvas 238 142 708 744 10; #X msg 132 223 dim 320 240; #X msg 132 246 dim 640 480; -#X text 271 226 dim sets the window dimensions; +#X text 300 227 dim sets the window dimensions; #X msg 132 177 create; #X msg 132 198 destroy; #X text 130 114 pdp_xv ouputs video in a window using the xVideo extension. if your graphics card/driver supports it you can have multiple output windows. if a pdp message is received and a window is not open \, one is created automaticly.; -#X text 271 180 use these messages to explicitly create/destroy the +#X text 230 185 use these messages to explicitly create/destroy the window; -#X msg 134 294 cursor \$1; -#X obj 134 274 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X msg 133 463 cursor \$1; +#X obj 133 443 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X text 270 294 enables/disables cursor in xv window; +#X text 298 464 enables/disables cursor in xv window; #X obj 29 61 pdp_help_input; #X msg 29 25 start; #X msg 78 24 stop; -#X text 269 326 specify the x window display; -#X msg 134 324 display :0; -#X obj 29 448 print; -#X text 133 445 the output channel sends mouse event messages (press/release/drag +#X text 297 496 specify the x window display; +#X msg 133 493 display :0; +#X obj 29 587 print; +#X text 133 584 the output channel sends mouse event messages (press/release/drag and individual p/r/d for each button); -#X connect 0 0 16 0; -#X connect 1 0 0 0; -#X connect 2 0 0 0; -#X connect 4 0 0 0; -#X connect 5 0 0 0; -#X connect 8 0 0 0; -#X connect 9 0 8 0; -#X connect 11 0 0 0; -#X connect 12 0 11 0; -#X connect 13 0 11 0; -#X connect 15 0 0 0; +#X obj 29 551 pdp_xv; +#X msg 132 273 pos 100 100; +#X text 300 273 set window position; +#X msg 132 336 fullscreen; +#X text 298 340 resize to entire screen; +#X text 299 305 set both at once; +#X msg 132 303 posdim 100 300 320 240; +#X msg 131 417 tile 5 5 \$1 \$2; +#X text 297 418 take a part of the screen (for tiling multiple pdp_xv's) +; +#X obj 131 396 pack 0 0; +#X obj 190 396 t b f; +#X floatatom 131 377 5 0 0 0 - - -; +#X floatatom 190 376 5 0 0 0 - - -; +#X connect 0 0 17 0; +#X connect 1 0 17 0; +#X connect 3 0 17 0; +#X connect 4 0 17 0; +#X connect 7 0 17 0; +#X connect 8 0 7 0; +#X connect 10 0 17 0; +#X connect 11 0 10 0; +#X connect 12 0 10 0; +#X connect 14 0 17 0; +#X connect 17 0 15 0; +#X connect 18 0 17 0; +#X connect 20 0 17 0; +#X connect 23 0 17 0; +#X connect 24 0 17 0; +#X connect 26 0 24 0; +#X connect 27 0 26 0; +#X connect 27 1 26 1; +#X connect 28 0 26 0; +#X connect 29 0 27 0; diff --git a/doc/objects/pdp_zthresh.pd b/doc/objects/pdp_zthresh.pd new file mode 100644 index 0000000..df5209b --- /dev/null +++ b/doc/objects/pdp_zthresh.pd @@ -0,0 +1,21 @@ +#N canvas 504 211 500 438 10; +#X msg 77 38 start; +#X msg 124 38 stop; +#X obj 77 70 pdp_help_input; +#X obj 77 340 pdp_help_output; +#X obj 77 163 pdp_gain; +#X floatatom 128 135 5 0 0; +#X msg 128 109 0.5; +#X obj 77 296 pdp_gain; +#X msg 128 268 1; +#X text 233 230 zero threshold ( < 0 -> 0 ); +#X obj 77 231 pdp_zthresh; +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 4 0 10 0; +#X connect 5 0 4 1; +#X connect 6 0 5 0; +#X connect 7 0 3 0; +#X connect 8 0 7 1; +#X connect 10 0 7 0; diff --git a/doc/reference.txt b/doc/reference.txt index dc0ec3d..7635927 100644 --- a/doc/reference.txt +++ b/doc/reference.txt @@ -7,66 +7,139 @@ general purpose pdp modules: pdp_del a packet delay line pdp_reg a packet register pdp_snap takes a snapshot of a packet stream -pdp_trigger sends out a bang message when a packet is recieved +pdp_trigger similar to pd's trigger object pdp_route routes a packet to a specific outlet +pdp_loop a packet loop sampler (packet array) +pdp_description output a symbol describing the packet type +pdp_convert convert between packet types image inputs/outputs: pdp_xv displays images using the xvideo extension +pdp_glx displays images using opengl pdp_v4l reads images from a video4linux device pdp_qt reads quicktime movies image processors: +pdp_abs absolute value pdp_add adds two images +pdp_and bitwize and +pdp_bitdepth set bit depth +pdp_bitmask apply a bit mask pdp_bq spatial biquad filter pdp_bqt temporal biquad filter +pdp_cog gaussian blob estimator pdp_constant fills an image with a constant pdp_conv horizontal/vertical seperable convolution filter pdp_cheby chebyshev color shaper pdp_chrot rotates the chroma components -pdp_gradient converts a greyscale image using a colour palette +pdp_flip_lr flip left <-> right +pdp_flip_tb flip top <-> bottom pdp_grey converts an image to greyscale pdp_grey2mask converts a greyscale image to an image mask +pdp_hthresh hard thresholding pdp_mul multiplies two images -pdp_affine shifts and scales a colour plane pdp_mix crossfade between 2 images pdp_mix2 mixes 2 images after applying a gain to each of them -pdp_randmix crossfades 2 images by taking random pixels pdp_noise a noise generator +pdp_not bitwize not +pdp_or bitwize or +pdp_plasma plasma generator +pdp_pointcloud convert an image to a point cloud +pdp_positive sign function that creates a bitmask +pdp_randmix crossfades 2 images by taking random pixels pdp_rotate tiled rotate -pdp_scope~ a very simple oscilloscope pdp_scale rescale an image -pdp_scan~ phase input scanned synthesis oscillator -pdp_scanxy~ x,y coordinate input scanned synthesis oscillator +pdp_sign sign function +pdp_sthresh soft thresholding pdp_zoom tiled zoom pdp_zrot tiled zoom + rotate +pdp_zthresh zero threshold (x<0 -> 0) +pdp_xor bitwize xor + +dsp objects + +pdp_scope~ a very simple oscilloscope +pdp_scan~ phase input scanned synthesis oscillator +pdp_scanxy~ x,y coordinate input scanned synthesis oscillator + utility abstractions pdp_pps computes the packet rate in packets/sec -image abstractions: +image abstractions +pdp_agc automatic gain control (intensity maximizer) pdp_blur blurs an image pdp_blur_hor horizontal blur pdp_blur_ver vertical blur +pdp_contrast contrast enhancement +pdp_dither a dither effect pdp_phase applies an allpass filter to an image pdp_phase_hor horizontal allpass pdp_phase_ver vertical allpass pdp_motion_blur blurs motion pdp_motion_phase phase shifts motion +pdp_offset add an offset to an image pdp_alledge an all edge detector pdp_conv_emboss emboss pdp_conv_sobel_hor horizontal sobel edge detector pdp_conv_sobel_ver vertical sobel edge detector pdp_conv_sobel_edge sum of squares of hor and ver pdp_saturation change colour saturation +pdp_sub subtract 2 images pdp_invert inverse video +pdp_gain3 set 3 channel gains independently +pdp_gradient converts a greyscale to colour using a colour gradient +pdp_png_to convert a png file (on disk) to a certain packet type +pdp_tag tag a packet (to use it with route) + + +matrix processors + +pdp_m_mv matrix vector multiply +pdp_m_mm matrix matrix multiply +pdp_m_+=mm matrix matrix multiply add +pdp_m_LU compute LU decomposition +pdp_m_LU_inverse compute matrix inverse from LU decomp +pdp_m_LU_solve solve a linear system using LU decomp + +matrix abstractions + +pdp_m_inverse compute matrix inverse + + + + +SEPARATE LIBRARIES: + +cellular automata +(pdp_scaf) + +pdp_ca computes a cellular automaton (as a generator or a filter) +pdp_ca2image convert a CA packet to a greyscale image (obsolete: use pdp_convert) +pdp_image2ca convert an image to a CA packet (black and white) (obsolete: use pdp_convert) + + +3d drawing objects +(pdp_opengl) + +3dp_windowcontext a drawable window +3dp_draw draw objects (cube, sphere, ...) +3dp_view viewing transforms (rotate, translate, ...) +3dp_light light source +3dp_push push a matrix (modelview, texture, ...) +3dp_dlist compile a display list +3dp_snap copies the drawing buffer to a texture packet +3dp_mode set the current matrix mode +3dp_toggle set some opengl state variables + + +3d drawing abstractions (pdp_opengl) -cellular automata (separate lib): +3dp_mouserotate connect to 3dp_windowcontext to rotate the scene +3dp_blend turn on accumulative blending mode -pdp_ca computes a cellular automaton (as a generator or a filter) -pdp_ca2image converts a CA packet to a greyscale image -pdp_image2ca converts an image to a CA packet (black and white) diff --git a/include/pdp.h b/include/pdp.h index b19e7dc..243e18b 100644 --- a/include/pdp.h +++ b/include/pdp.h @@ -23,230 +23,122 @@ #ifndef PDP_H #define PDP_H - -/* header size in bytes */ -#define PDP_HEADER_SIZE 64 - -/* subheader size in bytes */ -#define PDP_SUBHEADER_SIZE 48 +/* header and subheader size in bytes */ +#define PDP_HEADER_SIZE 256 #include <string.h> #include <stdlib.h> + #include "m_pd.h" -#include "pdp_mmx.h" -#include "pdp_imageproc.h" +/* some typedefs */ #include "pdp_types.h" -/* hope this won't conflict with other types */ -#ifndef __cplusplus -typedef int bool; -#define true 1; -#define false 0; -#endif - -/* remark: planar processing ensures (vector assembler) code reusability - for grayscale / rgb(a) / yuv processing. so it's best - to keep away from interleaved formats: deinterleaving - and interleaving can be done in the source/sink modules - (it will probably be very hard to eliminate extra copying - anyway, and this enables the possibility to ensure alignment - and correct (i.e. multiple of 8 or 16) image dimensions) - - all image data is short int (16 bit) - -*/ - - - - -/* image data packet */ -typedef struct -{ - /* standard images */ - unsigned int encoding; /* image encoding (data format ) */ - unsigned int width; /* image width in pixels */ - unsigned int height; /* image height in pixels */ - unsigned int channels; /* number of colour planes if PDP_IMAGE_MCHP */ - - /* sliced image extensions */ /* THIS IS EXPERIMENTAL, DON'T DEPEND ON IT STATYING HERE */ - unsigned int slice_sync; /* slice synchro information */ - unsigned int slice_yoff; /* y offset of the slice in original image */ - unsigned int orig_height; /* height of original image (this is zero for ordinary images) */ - -} t_image; - - -/* image encodings */ -#define PDP_IMAGE_YV12 1 /* 24bbp: 16 bit Y plane followed by 16 bit 2x2 subsampled V and U planes.*/ -#define PDP_IMAGE_GREY 2 /* 16bbp: 16 bit Y plane */ -#define PDP_IMAGE_RGBP 3 /* 48bpp: 16 bit planar RGB */ -#define PDP_IMAGE_MCHP 4 /* generic 16bit multi channel planar */ - -/* slice synchro information */ -#define PDP_IMAGE_SLICE_FIRST (1<<0) -#define PDP_IMAGE_SLICE_LAST (1<<1) -#define PDP_IMAGE_SLICE_BODY (1<<2) +/* the list object */ +#include "pdp_list.h" -/* ascii data packet */ -typedef struct -{ - unsigned int encoding; /* image encoding (data format ) */ - unsigned int width; /* image width in pixels */ - unsigned int height; /* image height in pixels */ -} t_ascii; +/* PDP_IMAGE COMPONENTS */ -/* image encodings */ -#define PDP_ASCII_BW 1 /* 8 bit per character black and white.*/ -#define PDP_ASCII_IBM 2 /* 16 bit per character colour (8 bit character, 8 bit colour, like good old text framebuffers.*/ -#define PDP_ASCII_RGB 3 /* 64 bit per character colour (8 bit character, 3x8 bit RGB */ - -/* -PDP_IMAGE_GREY = PDP_IMAGE_MCHP, channels = 1 -PDP_IMAGE_RGBP = PDP_IMAGE_MCHP, channels = 3 - -remark: only 1 and 2 are implemented at this moment - -*/ - - -/* generic packet subheader */ -//typedef unsigned char t_raw[PDP_SUBHEADER_SIZE]; -typedef unsigned int t_raw; - -/* general pdp header struct */ -typedef struct -{ - unsigned int type; /* datatype of this object */ - unsigned int size; /* datasize including header */ - unsigned int users; /* nb users of this object, readonly if > 1 */ - unsigned int reserved[1]; /* reserved to provide binary compatibility for future extensions */ - - union /* each packet type has a unique subheader */ - { - t_raw raw; /* raw subheader (for extensions unkown to pdp core system) */ - t_image image; /* bitmap image */ - //t_ca ca; /* cellular automaton state data */ - t_ascii ascii; /* ascii packet */ - } info; - -} t_pdp; - -/* pdp data packet types */ -#define PDP_IMAGE 1 /* 16bit signed planar scanline encoded image packet */ -//RESERVED: #define PDP_CA 2 /* 1bit toroidial shifted scanline encoded cellular automaton */ -#define PDP_ASCII 3 /* ascii packet */ +/* header and methods for the built in image packet type */ +#include "pdp_image.h" +/* low level image processing and high level dispatching routines */ +#include "pdp_imageproc.h" +/* low level image conversion routines */ +#include "pdp_llconv.h" -/* pdp specific constants */ -#define PDP_ALIGN 8 +/* low level image resampling routines */ +#include "pdp_resample.h" -/* this needs to be able to grow dynamically, think about it later */ -#define PDP_OBJECT_ARRAY_SIZE 1024 +/* PDP_BITMAP COMPONENTS */ -/* all symbols are C-style */ -#ifdef __cplusplus -extern "C" -{ -#endif +/* header and methods for the built in bitmap packet type */ +#include "pdp_bitmap.h" - //extern t_pdp* pdp_stack[]; - //extern t_symbol* pdp_sym_register_rw; - //extern t_symbol* pdp_sym_register_ro; - //extern t_symbol* pdp_sym_process; -/* setup methods */ -void pdp_init(void); -void pdp_destroy(void); +/* PDP_MATRIX COMPONENTS */ +#include "pdp_matrix.h" -/* object manips */ -extern int pdp_packet_new(unsigned int datatype, unsigned int datasize); /* create a new packet */ -extern t_pdp* pdp_packet_header(int handle); /* get packet header */ -extern void* pdp_packet_data(int handle); /* get packet raw data */ -extern int pdp_packet_copy_ro(int handle); /* get a read only copy */ -extern int pdp_packet_copy_rw(int handle); /* get a read/write copy */ -extern int pdp_packet_clone_rw(int handle); /* get an empty read/write packet of the same type (only copy header) */ -extern void pdp_packet_mark_unused(int handle); /* indicate that you're done with the packet */ -/* +/* PDP SYSTEM COMPONENTS */ -If an owner unregisters a packet, he can still pass it along to clients. More -specificly this is the desired behaviour. It is a simple way to have in place -data processing (if there is only one client) and garbage collection. The first -register call revives the object. +/* packet pool stuff */ +#include "pdp_packet.h" -WARNING: it is an error to call pdp_packet_new inside a pdp packet handler BEFORE -a packet is registered. +/* processing queue object */ +#include "pdp_queue.h" -packet id -1 is the id of an invalid packet. it is not an error to unregister it. -packet id -2 can be used as a bogus id. it is an error to unregister it though. +/* several communication helper methods (pd specific) */ +#include "pdp_comm.h" -*/ +/* type handling subsystem */ +#include "pdp_type.h" +/* dpd command stuff */ +#include "pdp_dpd_command.h" -/* processor queue methods, callable from main pd thread */ -/* warning: only pdp_packet_header and pdp_packet_data are legal inside process routine!! */ -/* add a method to the processing queue */ -void pdp_queue_add(void *owner, void *process, void *callback, int *queue_id); +/* BACKWARDS COMPAT STUFF */ +#include "pdp_compat.h" -/* halt main tread until processing is done */ -void pdp_queue_wait(void); -/* halt main tread until processing is done and remove - callback from queue(for destructors) */ -void pdp_queue_finish(int queue_id); -/* misc signals to pdp */ -void pdp_control_notify_drop(int packet); +#endif +/* -/* helper methods */ + PDP CORE API OVERVIEW -/* send a packet to an outlet */ -void outlet_pdp(t_outlet *out, int packetid); + pdp_packet_* : packet methods, first argument is packet id + new: construct a raw packet (depreciated) + new_*: construct packet of specific type/subtype/... + mark_unused: release + mark_passing: conditional release (release on first copy ro/rw) + copy_ro: readonly (shared) copy + copy_rw: private copy + clone_rw: private copy (copies only meta data, not the content) + header: get the raw header (t_pdp *) + data: get the raw data (void *) + pass_if_valid: send a packet to pd outlet, if it is valid + replace_if_valid delete packet and replace with new one, if new is valid + copy_ro_or_drop: copy readonly, or don't copy if dest slot is full + send drop notify + copy_rw_or_drop: same, but private copy + get_description: retrieve type info + convert_ro: same as copy_ro, but with an automatic conversion matching a type template + convert_rw: same as convert_ro, but producing a private copy -/* if packet is valid, mark it unused and send it to an outlet */ -void pdp_pass_if_valid(t_outlet *outlet, int *packet); + pdp_pool_* : packet pool methods -/* if source packet is valid, release dest packet and move src->dest */ -void pdp_replace_if_valid(int *dpacket, int *spacket); + collect_garbage: manually free all unused resources in packet pool -/* copy_ro if dest packet if invalid, else drop source - (don't copy) + send drop notif to pdp system - returns 1 if dropped, 0 if copied */ -int pdp_packet_copy_ro_or_drop(int *dpacket, int spacket); + pdp_queue_* : processing queue methods -/* copy_rw if dest packit is invalid, else drop source - (don't copy) + send drop notif to pdp system - returns 1 if dropped, zero if copied */ -int pdp_packet_copy_rw_or_drop(int *dpacket, int spacket); + add: add a process method + callback + finish: wait until a specific task is done + wait: wait until processing queue is done + pdp_control_* : central pdp control hub methods -/* check if packets are compatible */ -int pdp_type_compat(int packet0, int packet1); -int pdp_type_compat_image(int packet0, int packet1); + notify_drop: notify that a packet has been dropped -int pdp_type_isvalid_image(int packet); + pdp_type_* : packet type mediator methods + description_match: check if two type templates match + register_conversion: register a type conversion program -/* short cuts to create specific packets */ -int pdp_packet_new_image_yv12(u32 width, u32 height); -int pdp_packet_new_image_grey(u32 width, u32 height); -#ifdef __cplusplus -} -#endif + NOTE: it is advised to derive your module from the pdp base class defined in pdp_base.h + instead of communicating directly with the pdp core -#endif +*/ diff --git a/include/pdp_ascii.h b/include/pdp_ascii.h new file mode 100644 index 0000000..1fde9b4 --- /dev/null +++ b/include/pdp_ascii.h @@ -0,0 +1,39 @@ +/* + * Pure Data Packet header file. ascii packet type. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +#ifndef PDP_H +#define PDP_H + +/* ascii data packet */ +typedef struct +{ + unsigned int encoding; /* image encoding (data format) */ + unsigned int width; /* image width in pixels */ + unsigned int height; /* image height in pixels */ +} t_ascii; + + +/* ascii encodings */ +#define PDP_ASCII_BW 1 /* 8 bit per character black and white.*/ +#define PDP_ASCII_IBM 2 /* 16 bit per character colour (8 bit character, 8 bit colour, like good old text framebuffers.*/ +#define PDP_ASCII_RGB 3 /* 64 bit per character colour (8 bit character, 3x8 bit RGB */ + +#endif diff --git a/include/pdp_base.h b/include/pdp_base.h new file mode 100644 index 0000000..2412e6d --- /dev/null +++ b/include/pdp_base.h @@ -0,0 +1,131 @@ +/* + * Pure Data Packet base class header file. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* + This file contains the specification of the pdp base class. It is derived + from t_object, the basic pd object (like any other pd extern). Have a look + at pdp_add, pdp_gain and pdp_noise to see how to use this. + +*/ + +#include "pdp.h" + +#define MAX_NB_PDP_BASE_INLETS 4 +#define MAX_NB_PDP_BASE_OUTLETS 4 + + + +typedef void (*t_pdp_method)(void *); +typedef void* (*t_pdp_newmethod)(void *); + + +typedef struct +{ + t_object x_obj; + + int b_inlets; // the number of pdp inlets + int b_outlets; // the number of pdp outlets + + // registers to store incoming packets + int b_packet[MAX_NB_PDP_BASE_INLETS]; + int b_packet_next[MAX_NB_PDP_BASE_INLETS]; + t_pdp_symbol *b_type_template[MAX_NB_PDP_BASE_INLETS]; + + int b_queue_id; // task id in process queue (for callback cancelling) + //int b_dropped; // indicate if a packet was dropped during register_rw cycle + + // wil the default (left) active inlet accept pdp messages ? + int b_active_inlet_enabled; + int b_active_inlet_readonly; + + // the process callbacks + t_pdp_method b_process_method; // called in pdp thread + t_pdp_method b_preproc_method; // called before thread (for packet alloc and checking) + t_pdp_method b_postproc_method; // called after thread (for outlet stuff other than default active packet->out0) + + // packet outlets + t_outlet *b_outlet[MAX_NB_PDP_BASE_OUTLETS]; + + u32 b_channel_mask; // channel mask + + int b_thread_enabled; // thread enable switch + + t_pdp_procqueue *b_q; // queue object + +} t_pdp_base; + + + +/* setup base class. call this in your derived class setup method */ +void pdp_base_setup(t_class *c); + + +/* base class constructor/destructor. call this in your base class constructor/destructor */ +void pdp_base_init(void *x); +void pdp_base_free(void *x); + + +/* register processing callbacks */ +void pdp_base_set_process_method(void *x, t_pdp_method m); //process callback (called from pdp thread) +void pdp_base_set_preproc_method(void *x, t_pdp_method m); //pre-process callback (called before process from pd thread) +void pdp_base_set_postproc_method(void *x, t_pdp_method m); //post-process callback (called after process from pd thread) + + +/* configure inlets/outlets */ +void pdp_base_add_pdp_inlet(void *x); +t_outlet *pdp_base_add_pdp_outlet(void *x); +void pdp_base_disable_active_inlet(void *x); //use this for pdp generators +void pdp_base_readonly_active_inlet(void *x); //use this for pdp converters ("out of place" processing) +void pdp_base_add_gen_inlet(void *x, t_symbol *from, t_symbol *to); // generic inlet + + +/* bang method */ +void pdp_base_bang(void *x); + + +/* move delayed passive packets in place */ +void pdp_base_movepassive(void *x); + + + +/* packet manipulation methods + 0 active inlet (left) if enabled + >0 additional pdp inlets created with pdp_base_add_pdp_inlet */ +int pdp_base_get_packet(void *x, int inlet); // get the packet from an inlet +int pdp_base_move_packet(void *x, int inlet); // same as get, but it removes the reference in the base class +void pdp_base_set_packet(void *x, int inlet, int packet); // set (replace) the active packet (will be sent to outlet) + + +/* getters for base class data */ +u32 pdp_base_get_chanmask(void *x); +t_object *pdp_base_get_object(void *x); + + +/* thread control */ +void pdp_base_disable_thread(void *x); + +/* type control */ +void pdp_base_set_type_template(void *x, int inlet, t_pdp_symbol *type_template); + +/* queue control */ +void pdp_base_queue_wait(void *x); +void pdp_base_set_queue(void *x, t_pdp_procqueue *q); +t_pdp_procqueue *pdp_base_get_queue(void *x); diff --git a/include/pdp_bitmap.h b/include/pdp_bitmap.h new file mode 100644 index 0000000..3fddc25 --- /dev/null +++ b/include/pdp_bitmap.h @@ -0,0 +1,96 @@ +/* + * Pure Data Packet system implementation. 8 bit image packet interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* + This file contains methods for the image packets + pdp_packet_new_* methods are several image packet constructors + + It also contains some pdp_type_ methods, for type checking + and conversion. + +*/ + +#ifndef PDP_BITMAP_H +#define PDP_BITMAP_H + + + +/* bitmap data packet */ +typedef struct _bitmap +{ + /* standard images */ + unsigned int encoding; /* image encoding (fourcc data format) */ + unsigned int width; /* image width in pixels */ + unsigned int height; /* image height in pixels */ + unsigned int bpp; /* bits per pixel (0 == standard) */ + +} t_bitmap; + + + +/* supported encodings (fourcc) */ + +/* special */ +#define PDP_BITMAP_RGB 0x32424752 +#define PDP_BITMAP_RGBA 0x41424752 +#define PDP_BITMAP_GREY 0x59455247 + +/* packet yuv */ +#define PDP_BITMAP_YUY2 0x32595559 +#define PDP_BITMAP_UYVY 0x59565955 + +/* planar yuv */ +#define PDP_BITMAP_I420 0x30323449 +#define PDP_BITMAP_YV12 0x32315659 + + +/* all symbols are C style */ +#ifdef __cplusplus +extern "C" +{ +#endif + + + +/* bitmap constructors*/ +int pdp_packet_new_bitmap_yv12(u32 width, u32 height); +int pdp_packet_new_bitmap_grey(u32 width, u32 height); +int pdp_packet_new_bitmap_rgb(u32 width, u32 height); +int pdp_packet_new_bitmap_rgba(u32 width, u32 height); +int pdp_packet_new_bitmap(int type, u32 width, u32 height); + +/* utility methids */ +void pdp_packet_bitmap_flip_top_bottom(int packet); + + +/* get description */ +t_pdp_symbol *pdp_packet_bitmap_get_description(int packet); + +/* get subheader */ +t_bitmap *pdp_packet_bitmap_info(int packet); + +bool pdp_packet_bitmap_isvalid(int packet); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_comm.h b/include/pdp_comm.h new file mode 100644 index 0000000..3b7b7f9 --- /dev/null +++ b/include/pdp_comm.h @@ -0,0 +1,74 @@ +/* + * Pure Data Packet system implementation. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* this file contains misc communication methods */ + +#ifndef PDP_COMM_H +#define PDP_COMM_H + + +/* all symbols are C style */ +#ifdef __cplusplus +extern "C" +{ +#endif + +/* pdp symbols */ +t_symbol *pdp_sym_pdp(void); +t_symbol *pdp_sym_rro(void); +t_symbol *pdp_sym_rrw(void); +t_symbol *pdp_sym_prc(void); +t_symbol *pdp_sym_dpd(void); +t_symbol *pdp_sym_ins(void); +t_symbol *pdp_sym_acc(void); + + +/* utility methods */ + + + +/* if packet is valid, mark it unused and send it to an outlet */ +void pdp_packet_pass_if_valid(t_outlet *outlet, int *packet); + +/* if source packet is valid, release dest packet and move src->dest */ +void pdp_packet_replace_if_valid(int *dpacket, int *spacket); + +/* copy_ro if dest packet if invalid, else drop source + (don't copy) + send drop notif to pdp system + returns 1 if dropped, 0 if copied */ +int pdp_packet_copy_ro_or_drop(int *dpacket, int spacket); +int pdp_packet_convert_ro_or_drop(int *dpacket, int spacket, t_pdp_symbol *type_template); + +/* copy_rw if dest packit is invalid, else drop source + (don't copy) + send drop notif to pdp system + returns 1 if dropped, zero if copied */ +int pdp_packet_copy_rw_or_drop(int *dpacket, int spacket); +int pdp_packet_convert_rw_or_drop(int *dpacket, int spacket, t_pdp_symbol *type_template); + + + + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/include/pdp_compat.h b/include/pdp_compat.h new file mode 100644 index 0000000..2bc948f --- /dev/null +++ b/include/pdp_compat.h @@ -0,0 +1,17 @@ + +/* + please don't use any of these. for backwards compatibility only +*/ + + +#ifndef PDP_COMPAT_H +#define PDP_COMPAT_H + + + + +void pdp_pass_if_valid(t_outlet *outlet, int *packet); +void pdp_replace_if_valid(int *dpacket, int *spacket); + + +#endif diff --git a/include/pdp_config.h b/include/pdp_config.h new file mode 100644 index 0000000..f5f3451 --- /dev/null +++ b/include/pdp_config.h @@ -0,0 +1,77 @@ +/* include/pdp_config.h. Generated by configure. */ +/* include/pdp_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `gsl' library (-lgsl). */ +#define HAVE_LIBGSL 1 + +/* Define to 1 if you have the `gslcblas' library (-lgslcblas). */ +#define HAVE_LIBGSLCBLAS 1 + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* build pdp_glx */ +#define HAVE_PDP_GLX 1 + +/* build png support */ +#define HAVE_PDP_PNG 1 + +/* build pdp_qt */ +#define HAVE_PDP_QT 1 + +/* build pdp_sdl */ +/* #undef HAVE_PDP_SDL */ + +/* build pdp_v4l */ +#define HAVE_PDP_V4L 1 + +/* build pdp_xv */ +#define HAVE_PDP_XV 1 + +/* enable pwc v4l support */ +/* #undef HAVE_PWCV4L */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 diff --git a/include/pdp_config.h.in b/include/pdp_config.h.in index 3ef59a3..1fd0ff6 100644 --- a/include/pdp_config.h.in +++ b/include/pdp_config.h.in @@ -3,12 +3,24 @@ /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the `gsl' library (-lgsl). */ +#undef HAVE_LIBGSL + +/* Define to 1 if you have the `gslcblas' library (-lgslcblas). */ +#undef HAVE_LIBGSLCBLAS + /* Define to 1 if you have the `m' library (-lm). */ #undef HAVE_LIBM /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* build pdp_glx */ +#undef HAVE_PDP_GLX + +/* build png support */ +#undef HAVE_PDP_PNG + /* build pdp_qt */ #undef HAVE_PDP_QT diff --git a/include/pdp_control.h b/include/pdp_control.h new file mode 100644 index 0000000..88c9eb4 --- /dev/null +++ b/include/pdp_control.h @@ -0,0 +1,10 @@ +#ifndef __PDP_CONTROL_H__ +#define __PDP_CONTROL_H__ + +struct _pdp_control; +typedef void (t_pdp_control_method_notify)(struct _pdp_control *x); + +void pdp_control_notify_broadcast(t_pdp_control_method_notify *notify); +void pdp_control_addmethod(t_method m, t_symbol *s); + +#endif diff --git a/include/pdp_dpd_base.h b/include/pdp_dpd_base.h new file mode 100644 index 0000000..233bc63 --- /dev/null +++ b/include/pdp_dpd_base.h @@ -0,0 +1,142 @@ +/* + * Pure Data Packet header file. DPD base class + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* dpd base class for context based processors (for pd-fying standard stack based serial languages) + not all of pdp is used here, but the class is derived from the pdp base class to enable mixing + standard pdp (data flow packet processing) and dpd (context based serial languages) + + dpd is short for "upside down pdp". the name stems from the observation + of opengl code in pd (like in gem) having an upside down feel when looking + through dataflow eyes. i.e.: the target (window context) is on top, while + the objects (geos) are at the bottom connected by a chain of geometric transforms + + the principles of dpd are simple: + + * there is only one main packet, received on the left inlet. + * this packet is called the "context" and is produced by and returned to a top context source/sink + * additional pd messages and pdp packets can be received on the cold inlets + * as opposed to pdp, no copies are made of this context packet, all operations on it are accumulative. + * the protocol is different because fanout is prohibited (so no ro/rw registering) + * the only exception for fanout are inspectors, which have precedence over normal processors + * all processors and inspectors for a single context type must use the pdp thread, to preserve execution order + + +*/ + + + +#include "pdp.h" +#include "pdp_base.h" + +#define PDP_DPD_MAX_CONTEXT_OUTLETS 4 + +typedef struct pdp_dpd_base_struct +{ + t_pdp_base b_base; /* pdp base class */ + + int b_nb_context_outlets; + t_outlet *b_context_outlet[PDP_DPD_MAX_CONTEXT_OUTLETS]; /* dpd outlets */ + int b_outlet_enable[PDP_DPD_MAX_CONTEXT_OUTLETS]; /* dpd outlets */ + t_pdp_method b_accum_method[PDP_DPD_MAX_CONTEXT_OUTLETS]; /* accumulation methods for each outlet */ + t_pdp_method b_accum_callback[PDP_DPD_MAX_CONTEXT_OUTLETS]; /* pd callback methods for each outlet */ + //int b_accum_queue_id[PDP_DPD_MAX_CONTEXT_OUTLETS]; /* accumulator queue id's */ + + t_pdp_method b_inspector_method; /* pdp thread inspector callback */ + t_pdp_method b_inspector_callback; /* main thread inspector callback */ + //int b_inspector_queue_id; + + t_pdp_method b_cleanup_method; /* queued after propagation is done */ + t_pdp_method b_cleanup_callback; /* queued after propagation is done */ + //int b_cleanup_queue_id; + + t_pdp_method b_complete_notify; /* method called after packet output is done */ + t_pdp_newmethod b_command_factory_method; /* command factory method */ + + + int b_context_packet; /* the current context packet */ + + int b_dpd_active_inlet_disabled; + + +} t_pdp_dpd_base; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* bang method (propagate context to outlets & register callbacks) + mainly for context source/sinks + it is not registered as a pd message by default ! */ +void pdp_dpd_base_bang(void *x); + +/* get/set the context packet */ +int pdp_dpd_base_get_context_packet(void *x); +void pdp_dpd_base_set_context_packet(void *x, int p); +int pdp_dpd_base_move_context_packet(void *x); + +/* add a context outlet and it's corresponding accumulation (process) and callback method */ +t_outlet *pdp_dpd_base_add_outlet(void *x, t_pdp_method accum_method, t_pdp_method accum_callback); + +/* add a cleanup callback (called after all propagation is finished) for sources/sinks */ +void pdp_dpd_base_add_cleanup(void *x, t_pdp_method cleanup_method, t_pdp_method accum_callback); + +/* add an inspector callback */ +void pdp_dpd_base_add_inspector(void *x, t_pdp_method inspector_method); + + +/* destructor */ +void pdp_dpd_base_free(void *x); + +/* init method */ +void pdp_dpd_base_init(void *x); + +/* disable dpd active inlet */ +void pdp_dpd_base_disable_active_inlet(void *x); + +/* enable/disable outlet */ +void pdp_dpd_base_enable_outlet(void *x, int outlet, int toggle); + +/* register notify method (called from the end of pdp_dpd_base_bang) */ +void pdp_dpd_base_register_complete_notify(void *x, t_pdp_method method); + +/* register a command init (factory) method + this method should return a command object to place in the queue */ +void pdp_dpd_base_register_command_factory_method(void *x, t_pdp_newmethod command_factory_method); + +/* class setup method */ +void pdp_dpd_base_setup(t_class *class); + +/* add a command to the process queue */ +void pdp_dpd_base_queue_command(void *x, void *c, t_pdp_method process, + t_pdp_method callback, int *id); + + +/* get/set the queue instance (thread) used for scheduling */ +#define pdp_dpd_base_set_queue pdp_base_set_queue +#define pdp_dpd_base_get_queue pdp_base_get_queue +#define pdp_dpd_base_queue_wait pdp_base_queue_wait + + + +#ifdef __cplusplus +} +#endif diff --git a/include/pdp_dpd_command.h b/include/pdp_dpd_command.h new file mode 100644 index 0000000..d1e2824 --- /dev/null +++ b/include/pdp_dpd_command.h @@ -0,0 +1,77 @@ + +/* + * Pure Data Packet header file. DPD command class + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* this object implements a dpd command 'factory and recycling center' */ + +/* a small note on commands & dpd + + dpd uses a different synchronization model than pdp. + + in pdp, objects only pass once the process method in the process thread + has finished. + + in dpd a context packet propagates a context trough an tree of objects, + depth first, following the pd messages. it is possible to send a list of + contexts trough a tree before the actual processing starts. therefore, + each time a context passes trough an object, a new command object (or memento) + needs to be created that saves the state of the rendering context. the command + factory class can be used to create these commands. + + the dpd base class queues a command object and calls the registered method + on the object instead of the dpd object. so a command object is in fact + a delegate of the dpd object in question. + +*/ + + +#ifndef PDP_DPD_COMMAND +#define PDP_DPD_COMMAND + + +/* COMMAND BASE CLASS */ +typedef struct _pdp_dpd_command +{ + struct _pdp_dpd_command *next; + u32 used; + +} t_pdp_dpd_command; + + +/* COMMAND LIST (COMMAND FACTORY) CLASS */ +typedef struct _pdp_dpd_commandfactory +{ + u32 nb_commands; + u32 command_size; + t_pdp_dpd_command *command; +} t_pdp_dpd_commandfactory; + + +/* COMMAND LIST METHODS */ +void pdp_dpd_commandfactory_init(t_pdp_dpd_commandfactory *x, u32 size); +void pdp_dpd_commandfactory_free(t_pdp_dpd_commandfactory *x); +t_pdp_dpd_command *pdp_dpd_commandfactory_get_new_command(t_pdp_dpd_commandfactory *x); + + +/* COMMAND METHODS */ +void pdp_dpd_command_suicide(void *); + + +#endif diff --git a/include/pdp_forth.h b/include/pdp_forth.h new file mode 100644 index 0000000..a53291f --- /dev/null +++ b/include/pdp_forth.h @@ -0,0 +1,192 @@ +/* + * Pure Data Packet header file. Packet processor system + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __PDP_PROCESSOR__ +#define __PDP_PROCESSOR__ + +#include "pdp_list.h" + +/* + +*/ + + +/* + PDP Processor Model + + The model consists of two parts. + + One being the forth system to provide a lowish level description of packet operations, + with a form of polymorphy that enables the system to call the right routines or + provide automatic conversion of packet types. + + Two being the object description language. It describes processors in terms of packet + operations. In fact it is a forth process that sets up the input and output of the + processors, and organizes the local storage into registers. + +*/ + + +/* PDP FORTH (low level stack processors) */ + +/* the error codes for a processor word */ +typedef enum { + e_ok = 0, + e_type, // a recoverable type error (stack untouched) + e_garbled, // a non recoverable error (stack messed up) + e_underflow, // a stack underflow error + e_undef, // an undefined word error + e_internal // an internal error (abort) +} t_pdp_word_error; + +typedef struct _pdp_list t_pdp_stack; + +/* a pdp word operates on a stack containing atoms (floats, ints, symbols, packets) + it should return zero on success and an error value on failure. + whenever a (type) error occurs, the stack should be left untouched (this ensures the system + can try another implementation of the same word. + + the type of the first packet on the stack determines the 'type' of the processor method. + this poses a problem for generating words (i.e pdp_noise or pdp_plasma). in that case + the first word should be a symbol, indicating the type. if the first item is neither + a symbol or a packet, the first word in the word list for the respective word symbol + is called. + + words cannot be removed from the symbol table. (because compiled scripts will have + their addresses stored) however, they can be redefined, since new definitions are + appended to the start of a word list, and upon execution, the first (type) matching word + is called. + + words can be accessed in two ways: + * the central dispatching system, which chooses a word based on it's symbol and + the first item on the stack (a packet's class (or unique type description) or + a symbol describing a type) + * by calling it's code directly. this can be used to optimize (compile) scripts. + + a word may place invalid packets (-1) on the stack and must be robust at receiving + them. this is a way to silently recover from non fatal errors. + + a stack error is always fatal and should abort execution. (e_garbled) + +*/ + +typedef int (*t_pdp_forthword)(t_pdp_stack *); + + +/* a dictionary item is the definition of a word. + if a word is type oblivious, it is a high level word, which means it can operate on any type */ + + +/* a struct describing a forth word implementation */ +typedef struct _pdp_forthword_imp +{ + struct _pdp_symbol *name; // the name of this word + struct _pdp_list *def; // the word definition with symbols (word or immediate symbol), + // pointer (primitive word) or int, float and packet immediates. + struct _pdp_symbol *type; // the type template this low level word operates on (0 == high level word) +} t_pdp_forthword_imp; + +/* a struct describing a forth word specification + one specification can have multiple implementations (for type multiplexing) */ +typedef struct _pdp_forthword_spec +{ + /* name of this forth word */ + struct _pdp_symbol *name; + + /* stack effect */ + int input_size; + int output_size; + + /* index of the stack element to be used for implementation + multiplexing based on the implementation type template */ + int type_index; + + /* a list of implementations for this word */ + t_pdp_list *implementations; + +} t_pdp_forthword_spec; + + + +/* compile a string definition to a list definition */ +t_pdp_list *pdp_forth_compile_def(char *chardef); + + +/* add words to the forth dictionary + if the word is type oblivious, the type index should be -1 and the type symbol NULL */ +void pdp_forthdict_add_word(t_pdp_symbol *name, t_pdp_list *def, int input_size, int output_size, + int type_index, t_pdp_symbol *type); +void pdp_forthdict_add_primitive(t_pdp_symbol *name, t_pdp_forthword w,int input_size, int output_size, + int type_index, t_pdp_symbol *type); +void pdp_forthdict_compile_word(t_pdp_symbol *name, char *chardef, int input_size, int output_size, + int type_index, t_pdp_symbol *type); + + + +/* execute a word definition (a program) or a single symbolic word */ +t_pdp_word_error pdp_forth_execute_def(t_pdp_stack *stack, t_pdp_list *def); +t_pdp_word_error pdp_forth_execute_word(t_pdp_stack *stack, t_pdp_symbol *word); + + +/* PDP PDL (high level processor description language) */ + +/* this uses the forth words to describe a processor: defining inputs and outputs, + preparing the stack, storing intermediates, .. */ + +/* TODO */ + + +void pdp_forth_word_print_debug(t_pdp_symbol *s); + + + + + +/* STACK OPERATIONS */ + + +/* connecting the stack to the world */ +t_pdp_word_error pdp_stack_push_float(t_pdp_stack *, float f); // push thing to tos +t_pdp_word_error pdp_stack_push_int(t_pdp_stack *s, int i); +t_pdp_word_error pdp_stack_push_symbol(t_pdp_stack *s, t_pdp_symbol *x); +t_pdp_word_error pdp_stack_push_packet(t_pdp_stack *s, int p); + +t_pdp_word_error pdp_stack_pop_float(t_pdp_stack *, float *f); // pop thing from tos +t_pdp_word_error pdp_stack_pop_int(t_pdp_stack *, int *i); +t_pdp_word_error pdp_stack_pop_symbol(t_pdp_stack *, t_pdp_symbol **s); +t_pdp_word_error pdp_stack_pop_packet(t_pdp_stack *, int *p); + + +/* stack operations */ + +// DUP SWAP DROP OVER ... +t_pdp_word_error pdp_stack_dup(t_pdp_stack *s); +t_pdp_word_error pdp_stack_swap(t_pdp_stack *s); +t_pdp_word_error pdp_stack_drop(t_pdp_stack *s); +t_pdp_word_error pdp_stack_over(t_pdp_stack *s); + + +/* some util stuff */ +t_pdp_stack *pdp_stack_new(void); +void pdp_stack_free(t_pdp_stack *s); + + + +#endif diff --git a/include/pdp_image.h b/include/pdp_image.h new file mode 100644 index 0000000..f9689d7 --- /dev/null +++ b/include/pdp_image.h @@ -0,0 +1,99 @@ +/* + * Pure Data Packet system implementation. Image packet interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* + This file contains methods for the image packets + pdp_packet_new_* methods are several image packet constructors + + It also contains some pdp_type_ methods, for type checking + and conversion. + +*/ + +#ifndef PDP_IMAGE_H +#define PDP_IMAGE_H + + + +/* image subheader */ +typedef struct _image +{ + /* standard images */ + unsigned int encoding; /* image encoding (data format) */ + unsigned int width; /* image width in pixels */ + unsigned int height; /* image height in pixels */ + unsigned int depth; /* number of colour planes if PDP_IMAGE_MCHP */ + unsigned int chanmask; /* channel bitmask to mask out inactive channels (0 == not used) */ + + /* sliced image extensions */ /* THIS IS EXPERIMENTAL, DON'T DEPEND ON IT */ + unsigned int slice_sync; /* slice synchro information */ + unsigned int slice_yoff; /* y offset of the slice in original image */ + unsigned int orig_height; /* height of original image (this is zero for ordinary images) */ + +} t_image; + + +/* image encodings */ +#define PDP_IMAGE_YV12 1 /* 24bbp: 16 bit Y plane followed by 16 bit 2x2 subsampled V and U planes.*/ +#define PDP_IMAGE_GREY 2 /* 16bbp: 16 bit Y plane */ +#define PDP_IMAGE_MCHP 4 /* generic 16bit multi channel planar (16 bit 3D tensor) */ + +/* slice synchro information */ +#define PDP_IMAGE_SLICE_FIRST (1<<0) +#define PDP_IMAGE_SLICE_LAST (1<<1) +#define PDP_IMAGE_SLICE_BODY (1<<2) + + + +/* all symbols are C style */ +#ifdef __cplusplus +extern "C" +{ +#endif + + + + +/* validate and compat check */ +bool pdp_packet_image_isvalid(int packet); +bool pdp_packet_image_compat(int packet0, int packet1); + +/* short cuts to create specific packets */ +int pdp_packet_new_image(u32 encoding, u32 width, u32 height); +int pdp_packet_new_image_YCrCb(u32 width, u32 height); +int pdp_packet_new_image_grey(u32 width, u32 height); +int pdp_packet_new_image_mchp(u32 width, u32 height, u32 depth); + +#define pdp_packet_new_image_multi pdp_packet_new_image_mchp + +/* get info */ +t_pdp_symbol *pdp_packet_image_get_description(int packet); +t_image *pdp_packet_image_info(int packet); + +/* set props */ +void pdp_packet_image_set_chanmask(int packet, unsigned int chanmask); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_imagebase.h b/include/pdp_imagebase.h new file mode 100644 index 0000000..563b685 --- /dev/null +++ b/include/pdp_imagebase.h @@ -0,0 +1,51 @@ +/* + * Pure Data Packet image processor base class header file. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* + This file contains the specification of the pdp base class. It is derived + from t_object, the basic pd object (like any other pd extern). Have a look + at pdp_add, pdp_gain and pdp_noise to see how to use this. + +*/ + +#include "pdp.h" +#include "pdp_base.h" + + +typedef struct +{ + t_pdp_base x_obj; + u32 b_channel_mask; // channel mask + +} t_pdp_imagebase; + + + +/* setup base class. call this in your derived class setup method */ +void pdp_imagebase_setup(t_class *c); + + +/* base class constructor/destructor. call this in your base class constructor/destructor */ +void pdp_imagebase_init(void *x); +void pdp_imagebase_free(void *x); + +/* getters for image base class data */ +u32 pdp_imagebase_get_chanmask(void *x); diff --git a/include/pdp_imageproc.h b/include/pdp_imageproc.h index 26bcdc6..a1b9de3 100644 --- a/include/pdp_imageproc.h +++ b/include/pdp_imageproc.h @@ -26,12 +26,23 @@ #ifndef PDP_IMAGEPROC_H #define PDP_IMAGEPROC_H -/* + #ifdef __cplusplus extern "C" { #endif -*/ + + + +/* the packet types should be the same for the dispatchers. packet0 is the dominant packet */ + +/* image processing dispatchers */ +void pdp_imageproc_dispatch_1buf(void (*process_routine)(void*, u32, u32, s16*), void *x, u32 chanmask, int packet0); +void pdp_imageproc_dispatch_2buf(void (*process_routine)(void*, u32, u32, s16*, s16 *), void *x, u32 chanmask, int packet0, int packet1); +void pdp_imageproc_dispatch_3buf(void (*process_routine)(void*, u32, u32, s16*, s16 *, s16*), void *x, u32 chanmask, int packet0, int packet1, int packet2); + + + /* get legal image dimensions */ /* this is a fix for the dimension problem */ @@ -45,18 +56,13 @@ u32 pdp_imageproc_legalheight_round_down(int i); /****************************** 16 bit signed (pixel) routines ***************************************/ -#include "pdp_types.h" -//typedef unsigned long u32; -//typedef unsigned long long u64; -//typedef short s16; -//typedef long s32; // mix 2 images void *pdp_imageproc_mix_new(void); void pdp_imageproc_mix_delete(void *x); void pdp_imageproc_mix_setleftgain(void *x, float gain); void pdp_imageproc_mix_setrightgain(void *x, float gain); -void pdp_imageproc_mix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height); +void pdp_imageproc_mix_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); // random mix 2 images // note: random number generator can be platform specific @@ -68,7 +74,7 @@ void *pdp_imageproc_randmix_new(void); void pdp_imageproc_randmix_delete(void *x); void pdp_imageproc_randmix_setthreshold(void *x, float threshold); void pdp_imageproc_randmix_setseed(void *x, float seed); -void pdp_imageproc_randmix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height); +void pdp_imageproc_randmix_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); // produce a random image @@ -77,30 +83,33 @@ void pdp_imageproc_randmix_process(void *x, s16 *image, s16 *image2, u32 width, void *pdp_imageproc_random_new(void); void pdp_imageproc_random_delete(void *x); void pdp_imageproc_random_setseed(void *x, float seed); -void pdp_imageproc_random_process(void *x, s16 *image, u32 width, u32 height); +void pdp_imageproc_random_process(void *x, u32 width, u32 height, s16 *image); + + +// produce a plasma image +// note: random number generator can be platform specific +// however, it should be seeded. (same seed produces the same result) +void *pdp_imageproc_plasma_new(void); +void pdp_imageproc_plasma_delete(void *x); +void pdp_imageproc_plasma_setseed(void *x, float seed); +void pdp_imageproc_plasma_setturbulence(void *x, float seed); +void pdp_imageproc_plasma_process(void *x, u32 width, u32 height, s16 *image); // apply a gain to an image void *pdp_imageproc_gain_new(void); void pdp_imageproc_gain_delete(void *x); void pdp_imageproc_gain_setgain(void *x, float gain); -void pdp_imageproc_gain_process(void *x, s16 *image, u32 width, u32 height); +void pdp_imageproc_gain_process(void *x, u32 width, u32 height, s16 *image); // add two images -void pdp_imageproc_add_process(s16 *image, s16 *image2, u32 width, u32 height); +void pdp_imageproc_add_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); // mul two images -void pdp_imageproc_mul_process(s16 *image, s16 *image2, u32 width, u32 height); - +void pdp_imageproc_mul_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); -// affine transformation (applies gain + adds offset) -void *pdp_imageproc_affine_new(void); -void pdp_imageproc_affine_delete(void *x); -void pdp_imageproc_affine_setgain(void *x, float gain); -void pdp_imageproc_affine_setoffset(void *x, float offset); -void pdp_imageproc_affine_process(void *x, s16 *image, u32 width, u32 height); // 3x1 or 1x3 in place convolution // orientation @@ -112,17 +121,19 @@ void pdp_imageproc_conv_setmin1(void *x, float val); void pdp_imageproc_conv_setzero(void *x, float val); void pdp_imageproc_conv_setplus1(void *x, float val); void pdp_imageproc_conv_setbordercolor(void *x, float intensity); -void pdp_imageproc_conv_process(void *x, s16 *image, u32 width, u32 height, u32 orientation, u32 nbpasses); +void pdp_imageproc_conv_setorientation(void *x, u32 val); +void pdp_imageproc_conv_setnbpasses(void *x, u32 val); +void pdp_imageproc_conv_process(void *x, u32 width, u32 height, s16 *image); -// colour rotation for 2 colour planes +// colour rotation for 2 colour planes ($$$TODO: change interface) // matrix is column encoded void *pdp_imageproc_crot2d_new(void); void pdp_imageproc_crot2d_delete(void *x); void pdp_imageproc_crot2d_setmatrix(void *x, float *matrix); void pdp_imageproc_crot2d_process(void *x, s16 *image, u32 width, u32 height); -// colour rotation for 3 colour planes +// colour rotation for 3 colour planes ($$$TODO: change interface) void *pdp_imageproc_crot3d_new(void); void pdp_imageproc_crot3d_delete(void *x); void pdp_imageproc_crot3d_setmatrix(void *x, float *matrix); @@ -141,14 +152,16 @@ void pdp_imageproc_crot3d_process(void *x, s16 *image, u32 width, u32 height); void *pdp_imageproc_bq_new(void); void pdp_imageproc_bq_delete(void *x); void pdp_imageproc_bq_setcoef(void *x, float *coef); // a0,a1,a2,b0,b1,b2 -void pdp_imageproc_bq_process(void *x, s16 *image, u32 width, u32 height, u32 direction, u32 nbpasses); +void pdp_imageproc_bq_setnbpasses(void *x, u32 nbpasses); +void pdp_imageproc_bq_setdirection(void *x, u32 direction); +void pdp_imageproc_bq_process(void *x, u32 width, u32 height, s16* image); // biquad time -void *pdp_imageproc_bqt_new(void); -void pdp_imageproc_bqt_delete(void *x); -void pdp_imageproc_bqt_setcoef(void *x, float *coef); // a0,a1,a2,b0,b1,b2 -void pdp_imageproc_bqt_process(void *x, s16 *image, s16 *state0, s16 *state1, u32 width, u32 height); +//void *pdp_imageproc_bqt_new(void); +//void pdp_imageproc_bqt_delete(void *x); +//void pdp_imageproc_bqt_setcoef(void *x, float *coef); // a0,a1,a2,b0,b1,b2 +void pdp_imageproc_bqt_process(void *x, u32 width, u32 height, s16 *image, s16 *state0, s16 *state1); @@ -160,7 +173,7 @@ void pdp_imageproc_resample_affinemap_setcentery(void *x, float f); void pdp_imageproc_resample_affinemap_setzoomx(void *x, float f); void pdp_imageproc_resample_affinemap_setzoomy(void *x, float f); void pdp_imageproc_resample_affinemap_setangle(void *x, float f); -void pdp_imageproc_resample_affinemap_process(void *x, s16 *srcimage, s16 *dstimage, u32 width, u32 height); +void pdp_imageproc_resample_affinemap_process(void *x, u32 width, u32 height, s16 *srcimage, s16 *dstimage); @@ -168,14 +181,39 @@ void pdp_imageproc_resample_affinemap_process(void *x, s16 *srcimage, s16 *dstim void *pdp_imageproc_cheby_new(int order); void pdp_imageproc_cheby_delete(void *x); void pdp_imageproc_cheby_setcoef(void *x, u32 n, float f); -void pdp_imageproc_cheby_process(void *x, s16 *image, u32 width, u32 height, u32 iterations); +void pdp_imageproc_cheby_setnbpasses(void *x, u32 n); +void pdp_imageproc_cheby_process(void *x, u32 width, u32 height, s16 *image); + + +//logic ops +void pdp_imageproc_xor_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); +void pdp_imageproc_or_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); +void pdp_imageproc_and_process(void *x, u32 width, u32 height, s16 *image, s16 *image2); +void pdp_imageproc_mask_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_not_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_hardthresh_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_softthresh_process(void *x, u32 width, u32 height, s16 *image); + + +//other stateles operators +void pdp_imageproc_abs_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_zthresh_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_plasma_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_ispositive_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_sign_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_flip_lr_process(void *dummy, u32 width, u32 height, s16 *image); +void pdp_imageproc_flip_tb_process(void *dummy, u32 width, u32 height, s16 *image); + +//set to zero +void pdp_imageproc_zero_process(void *x, u32 width, u32 height, s16 *image); +void pdp_imageproc_constant_process(void *x, u32 width, u32 height, s16 *image); + -/* #ifdef __cplusplus } #endif -*/ + #endif //PDP_IMAGEPROC_H diff --git a/include/pdp_internals.h b/include/pdp_internals.h index 0c580fb..fbd7173 100644 --- a/include/pdp_internals.h +++ b/include/pdp_internals.h @@ -20,7 +20,10 @@ */ -/* this file contains prototypes for "private" pdp methods */ +/* this file contains prototypes for "private" pdp methods. + DON'T CALL THESE FROM OUTSIDE OF PDP! unless you really + know what you are doing. + */ /* pdp system code is not very well organized, this is an @@ -40,8 +43,34 @@ extern "C" //#include <unistd.h> //#include <stdio.h> +/* set/unset main pdp thread usage */ void pdp_queue_use_thread(int t); +/* create a new packet, reuse if possible. + ONLY USE THIS IN A TYPE SPECIFIC CONSTRUCTOR! */ +int pdp_packet_new(unsigned int datatype, unsigned int datasize); + + +/* send a packet to an outlet: it is only legal to call this on a "passing packet" + or a "read only packet". + this means it is illegal to change a packet after you have passed it to others, + since this would mess up all read only references to the packet. +*/ + +/* this seems like a nice place to hide a comment on the notion of read/write in pdp + which packets are writable? all packets with exactly 1 user. this includes all packets + aquired with pdp_packet_*_rw or a constructor, and all packets that are not registered + after being sent out by outlet_pdp. + which packets are readable? all packets */ + +void outlet_pdp(t_outlet *out, int packetid); + +/* send an accumulation (context) packet to an outlet. this is for usage in the dpd + base class. */ +void outlet_dpd(t_outlet *out, int packetid); + + + #ifdef __cplusplus } #endif diff --git a/include/pdp_list.h b/include/pdp_list.h new file mode 100644 index 0000000..ffcf871 --- /dev/null +++ b/include/pdp_list.h @@ -0,0 +1,187 @@ + +/* + * Pure Data Packet header file. List class + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* the pdp list is composed of atoms. + the default atom is a pointer. + lists can be recursed into trees. + + note: all functions that return t_pdp_word and don't take a type argument + obviously don't perform any type checking. if you have heterogenous lists, + you should use atom iterators or direct access. + +*/ + + + +#ifndef PDP_LIST_H +#define PDP_LIST_H + +struct _pdp_list; +struct _pdp_atom; +typedef struct _pdp_list t_pdp_list; +typedef struct _pdp_atom t_pdp_atom; + + + +/* THE LIST OBJECT */ + +typedef enum { + a_undef = 0, + a_pointer, + a_float, + a_int, + a_symbol, + a_packet, + a_list +} t_pdp_word_type; + +typedef union _pdp_word +{ + void* w_pointer; + float w_float; + int w_int; + struct _pdp_symbol* w_symbol; + int w_packet; + struct _pdp_list* w_list; + +} t_pdp_word; + +/* a list element */ +struct _pdp_atom +{ + struct _pdp_atom *next; + t_pdp_word w; + t_pdp_word_type t; +}; + +/* a list container */ +struct _pdp_list +{ + int elements; + t_pdp_atom *first; + t_pdp_atom *last; + +}; + + +/* CONVENTION: trees stacks and lists. + + * all operations with "list" in them operate on flat lists. all the + items contained in the list are either pure atoms (floats, ints, or symbols) + or references (packets, pointers, lists) + + * all operations with "tree" in them, operate on recursive lists (trees) + all sublists of the list (tree) are owned by the parent list, so you can't + build trees from references to other lists. + + * stacks are by definition flat lists, so they can not contains sublists + +*/ + +typedef void (*t_pdp_atom_method)(t_pdp_atom *); +typedef void (*t_pdp_word_method)(t_pdp_word); +typedef void (*t_pdp_pword_method)(t_pdp_word *); +typedef void (*t_pdp_free_method)(void *); + +/* creation / destruction */ +t_pdp_list* pdp_list_new (int elements); +void pdp_list_free (t_pdp_list *l); +void pdp_list_clear (t_pdp_list *l); +void pdp_tree_free (t_pdp_list *l); +void pdp_tree_clear (t_pdp_list *l); + +void pdp_tree_strip_pointers (t_pdp_list *l, t_pdp_free_method f); +void pdp_tree_strip_packets (t_pdp_list *l); + +t_pdp_list* pdp_list_from_cstring (char *chardef, char **nextchar); + + + +/* traversal routines */ +void pdp_list_apply (t_pdp_list *l, t_pdp_atom_method am); +void pdp_tree_apply (t_pdp_list *l, t_pdp_atom_method am); +void pdp_list_apply_word_method (t_pdp_list *l, t_pdp_word_type t, t_pdp_word_method wm); +void pdp_tree_apply_word_method (t_pdp_list *l, t_pdp_word_type t, t_pdp_word_method wm); +void pdp_list_apply_pword_method (t_pdp_list *l, t_pdp_word_type t, t_pdp_pword_method pwm); +void pdp_tree_apply_pword_method (t_pdp_list *l, t_pdp_word_type t, t_pdp_pword_method pwm); + + +/* copy: (reverse) copies a list. */ + +t_pdp_list* pdp_list_copy (t_pdp_list *l); +t_pdp_list* pdp_list_copy_reverse (t_pdp_list *l); +t_pdp_list* pdp_tree_copy (t_pdp_list *l); +t_pdp_list* pdp_tree_copy_reverse (t_pdp_list *l); + + +/* cat: this makes a copy of the second list and adds it at the end of the first one */ +void pdp_list_cat (t_pdp_list *l, t_pdp_list *tail); + +/* information */ +int pdp_list_contains (t_pdp_list *l, t_pdp_word_type t, t_pdp_word w); +int pdp_list_size (t_pdp_list *l); +void pdp_list_print (t_pdp_list *l); + +/* access */ +void pdp_list_add (t_pdp_list *l, t_pdp_word_type t, t_pdp_word w); +void pdp_list_add_back (t_pdp_list *l, t_pdp_word_type t, t_pdp_word w); +void pdp_list_add_to_set (t_pdp_list *l, t_pdp_word_type t, t_pdp_word w); +void pdp_list_remove (t_pdp_list *l, t_pdp_word_type t, t_pdp_word w); + +/* these don't do error checking. out of bound == error */ +t_pdp_word pdp_list_pop (t_pdp_list *l); +t_pdp_word pdp_list_index (t_pdp_list *l, int index); + +/* some aliases */ +#define pdp_list_add_front pdp_list_add +#define pdp_list_push pdp_list_add +#define pdp_list_queue pdp_list_add_end +#define pdp_list_unqueue pdp_list_pop + +/* generic atom iterator */ +#define PDP_ATOM_IN(list,atom) for (atom = list->first ; atom ; atom = atom->next) + +/* fast single type iterators */ + +/* generic */ +#define PDP_WORD_IN(list, atom, word, type) for (atom=list->first ;atom && ((word = atom -> w . type) || 1); atom=atom->next) + +/* type specific */ +#define PDP_POINTER_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_pointer) +#define PDP_INT_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_int) +#define PDP_FLOAT_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_float) +#define PDP_SYMBOL_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_symbol) +#define PDP_PACKET_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_packet) +#define PDP_LIST_IN(list, atom, x) PDP_WORD_IN(list, atom, x, w_list) + + +/* some macros for the pointer type */ + +#define pdp_list_add_pointer(l,p) pdp_list_add(l, a_pointer, ((t_pdp_word)((void *)(p)))) +#define pdp_list_add_back_pointer(l,p) pdp_list_add_back(l, a_pointer, ((t_pdp_word)((void *)(p)))) +#define pdp_list_add_pointer_to_set(l,p) pdp_list_add_to_set(l, a_pointer, ((t_pdp_word)((void *)(p)))) +#define pdp_list_remove_pointer(l,p) pdp_list_remove(l, a_pointer, ((t_pdp_word)((void *)(p)))) +#define pdp_list_contains_pointer(l,p) pdp_list_contains(l, a_pointer, ((t_pdp_word)((void *)(p)))) + + + + +#endif diff --git a/include/pdp_list_macros.h b/include/pdp_list_macros.h new file mode 100644 index 0000000..cb1f49f --- /dev/null +++ b/include/pdp_list_macros.h @@ -0,0 +1,27 @@ +#ifndef __PDP_LIST_MACROS__ +#define __PDP_LIST_MACROS__ + +/* some additional (short named) list macros mainly for manipulationg + argument lists. needs to be included locally. */ + +/* reading a list */ +#define FIRST(l) ((l)->first) +#define SIZE(l) ((l)->elements) + +#define NEXT(a) ((a)->next) +#define N(a) (a = a->next) + +#define FLOAT(a) ((a)->t == a_float ? (a)->w.w_float : 0.0f) +#define PACKET(a) ((a)->t == a_packet ? (a)->w.w_packet : -1) +#define INT(a) ((a)->t == a_int ? (a)->w.w_packet : 0) + + +/* creating a list, and adding stuff to the end (queueing) */ +#define LIST(n) pdp_list_new(n) +#define LFREE(l) pdp_list_free(l) +#define QFLOAT(l, x) pdp_list_add_back(l, a_float, ((t_pdp_word)(float)(x))) +#define QINT(l, x) pdp_list_add_back(l, a_int, ((t_pdp_word)(int)(x))) +#define QPACKET(l, x) pdp_list_add_back(l, a_packet,((t_pdp_word)(int)(x))) + + +#endif diff --git a/include/pdp_llconv.h b/include/pdp_llconv.h index 7b31882..15deda7 100644 --- a/include/pdp_llconv.h +++ b/include/pdp_llconv.h @@ -26,7 +26,8 @@ this is mainly to tuck away "ugly" parts of the code that come up in several places */ - +#ifndef PDP_LLCONV_H +#define PDP_LLCONV_H #include "pdp.h" @@ -58,7 +59,8 @@ enum RIF { RIF_RGBA_P____U8, RIF_RGB__P444_S16, RIF_GREY______S16, - RIF_GREY______U8 + RIF_GREY______U8, + RIF_BGR__P____U8 }; @@ -76,3 +78,6 @@ void pdp_llconv(void *src, int stype, void *dest, int dtype, int w, int h); #ifdef __cplusplus } #endif + + +#endif diff --git a/include/pdp_matrix.h b/include/pdp_matrix.h new file mode 100644 index 0000000..22a33bb --- /dev/null +++ b/include/pdp_matrix.h @@ -0,0 +1,94 @@ +/* + * Pure Data Packet system implementation. matrix packet interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef PDP_MATRIX_H +#define PDP_MATRIX_H + +#include <stdio.h> +#include <gsl/gsl_block.h> +#include <gsl/gsl_vector.h> +#include <gsl/gsl_matrix.h> +#include <gsl/gsl_blas.h> +#include <gsl/gsl_linalg.h> + +#include "pdp_types.h" + +#define gsl_rows size1 +#define gsl_columns size2 + +typedef struct _matrix +{ + /* meta data */ + u32 type; /* float/double real/complex */ + u32 rows; + u32 columns; + + /* gsl structures: these will be cast to the correct type on use */ + gsl_block block; /* gsl block meta data */ + gsl_vector vector; /* gsl vector meta data */ + gsl_matrix matrix; /* gsl matrix meta data */ + gsl_permutation perm; /* permutation data for storing an LU decomposition */ + int signum; /* sign of permutation matrix */ + + +} t_matrix; + +#define PDP_MATRIX 7 + +#define PDP_MATRIX_TYPE_RFLOAT 1 +#define PDP_MATRIX_TYPE_CFLOAT 2 +#define PDP_MATRIX_TYPE_RDOUBLE 3 +#define PDP_MATRIX_TYPE_CDOUBLE 4 + +int pdp_packet_matrix_isvalid(int p); +int pdp_packet_matrix_isvector(int p); +int pdp_packet_matrix_ismatrix(int p); + +int pdp_packet_new_matrix(u32 rows, u32 columns, u32 type); +int pdp_packet_new_matrix_product_result(CBLAS_TRANSPOSE_t TransA, CBLAS_TRANSPOSE_t TransB, int pA, int pB); +void pdp_packet_matrix_setzero(int p); + + +/* getters: returns 0 if type is incorrect */ +void *pdp_packet_matrix_get_gsl_matrix(int p, u32 type); +void *pdp_packet_matrix_get_gsl_vector(int p, u32 type); +int pdp_packet_matrix_get_type(int p); + + +/* type transparent matrix operations */ + +/* blas wrappers */ + +/* C += scale op(A) op(B) */ +int pdp_packet_matrix_blas_mm(CBLAS_TRANSPOSE_t TransA, CBLAS_TRANSPOSE_t TransB, + int pA, int pB, int pC, + float scale_r, float scale_i); +/* c += scale op(A) b */ +int pdp_packet_matrix_blas_mv(CBLAS_TRANSPOSE_t TransA, + int pA, int pb, int pc, + float scale_r, float scale_i); + +/* other gsl wrappers */ +int pdp_packet_matrix_LU(int p_matrix); +int pdp_packet_matrix_LU_to_inverse(int p_matrix); +int pdp_packet_matrix_LU_solve(int p_matrix, int p_vector); + + +#endif diff --git a/include/pdp_packet.h b/include/pdp_packet.h new file mode 100644 index 0000000..6a98c8c --- /dev/null +++ b/include/pdp_packet.h @@ -0,0 +1,222 @@ +/* + * Pure Data Packet system implementation: Packet Manager Interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* + + This file contains the pdp packet manager interface specification. + + It is an implementation of the "Object Pool" pattern with lazy instantiation + and lazy destruction. + + The pool is a growable array. It can only grow larger. Packets are represented + by an integer, which is an index in this array. + + The standard "pure" packets (the ones which use a flat memory buffer) have recovery + for resource depletion (main memory). If an out of memory condition is met + on allocation of a new package, the garbage collector kicks in and frees unused + packets until the out of memory condition is solved. Since an out of memory + condition can be fatal for other parts of the program, pdp also supports a + memory limit, to ensure some kind of safety margin. + + The "not so pure" packets should resolve resource conflicts in their own factory method, + since the constructor is responsible for allocating external resources. The standard + way to do this is to allocate a packet, free it's resources and allocate a new packet + until the resource allocation succeeds. Especially for these kinds of packets, the + pdp pool supports an explicit reuse method. This returns a valid packet if it can reuse + one (based on the high level type description). + + Packets that don't have memory managing methods defined in the packet class + (Standard packets) are treated as a header concatenated with a flat memory buffer, and + can be copied and cloned without problems. So, if a packet contains pointers to other + data or code, it can't be a pure packet. + + The interface to the packet manager contains the following managing methods: + + * pdp_packet_new: create a new packet or reuse a previous one + * pdp_packet_mark_passing: conditionally release a packet (for passing to other objects) + * pdp_packet_unmark_passing: turn a conditionally released packet back to normal (i.e. before deletion) + * pdp_packet_mark_unused: release a packet + * pdp_packet_copy_ro: register a packet for read only use + * pdp_packet_copy_rw: register a packet for read/write use (this creates a copy if necessary) + * pdp_packet_clone_rw: create a new packet using a template, but don't copy the data + + And two methods for raw data access + + * pdp_packet_header: retreive the header of the packet + * pdp_packet_data: retreive the data buffer of the packet (only for static packets) + + All the methods declared in this header are supposed to be thread safe, so you + can call them from the pd and pdp thread. + +*/ + +#ifndef PDP_PACKET_H +#define PDP_PACKET_H + +/* all symbols are C-style */ +#ifdef __cplusplus +extern "C" +{ +#endif + + + + //typedef int (*t_pdp_attribute_method)(struct _pdp_list *); +typedef int (*t_pdp_factory_method)(t_pdp_symbol *); + + +#if 0 + +/* packet class attribute (method) */ +typedef struct _pdp_attribute +{ + t_pdp_symbol *name; + t_pdp_attribute_method method; + + /* problem: do we support argument type checking ?? + this seems to be better solved in a "spec doc" or a central place + where "reserved" methods can be defined. */ + + /* if null this means the input or output list can be anything */ + struct _pdp_list *in_spec; // template for the input list (including default arguments) + struct _pdp_list *out_spec; // template for the output list +} t_pdp_attribute; + +#endif + +/* packet class header */ +typedef struct _pdp_class +{ + /* packet manips: non-pure data packets (using external resources) must define these */ + t_pdp_packet_method1 reinit; /* reuse method for pdp_packet_new() */ + t_pdp_packet_method2 clone; /* init from template for pdp_packet_clone_rw() */ + t_pdp_packet_method2 copy; /* init & copy from template for pdp_packet_copy_rw() */ + t_pdp_packet_method1 cleanup; /* free packet's resources (to be used by the garbage collector) */ + + t_pdp_symbol *type; /* type template for packet class */ + t_pdp_factory_method create; /* the constructor */ + //struct _pdp_list *attributes; /* list of attributes (packet methods) */ +}t_pdp_class; + + +/* packet object header */ +struct _pdp +{ + /* meta info */ + unsigned int type; /* main datatype of this object */ + t_pdp_symbol *desc; /* high level type description (sort of a mime type) */ + unsigned int size; /* datasize including header */ + unsigned int flags; /* packet flags */ + + /* reference count */ + unsigned int users; /* nb users of this object, readonly if > 1 */ + unsigned int *refloc; /* location of reference to packet for passing packets */ + + /* class object */ + t_pdp_class *theclass; /* if zero, the packet is a pure packet (just data, no member functions) */ + + u32 pad[9]; /* reserved to provide binary compatibility for future extensions */ + + union /* each packet type has a unique subheader */ + { + t_raw raw; /* raw subheader (for extensions unkown to pdp core system) */ + t_image image; /* (nonstandard internal) 16 bit signed planar bitmap image format */ + t_bitmap bitmap; /* (standard) bitmap image (fourcc coded) */ + //t_ca ca; /* cellular automaton state data */ + //t_ascii ascii; /* ascii packet */ + } info; + +}; + + +/* pdp data packet type id */ +#define PDP_IMAGE 1 /* 16bit signed planar scanline encoded image packet */ +//RESERVED: #define PDP_CA 2 /* 1bit toroidial shifted scanline encoded cellular automaton */ +//RESERVED: #define PDP_ASCII 3 /* ascii packet */ +//RESERVED: #define PDP_TEXTURE 4 /* opengl texture object */ +//RESERVED: #define PDP_3DCONTEXT 5 /* opengl render context */ +#define PDP_BITMAP 6 /* 8bit image packet (fourcc coded??) */ +//RESERVED: #define PDP_MATRIX 7 /* floating point/double matrix/vector packet (from gsl) */ + +/* PACKET FLAGS */ + +#define PDP_FLAG_DONOTCOPY (1<<0) /* don't copy the packet on register_rw, instead return an invalid packet */ + + +/* class methods */ +t_pdp_class *pdp_class_new(t_pdp_symbol *type, t_pdp_factory_method create); + +#if 0 +void pdp_class_addmethod(t_pdp_class *c, t_pdp_symbol *name, t_pdp_attribute_method method, + struct _pdp_list *in_spec, struct _pdp_list *out_spec); +#endif + +/* packet factory method + registration */ +int pdp_factory_newpacket(t_pdp_symbol *type); + +#if 0 +/* send a message to a packet (packet polymorphy) + this returns NULL on failure, or a return list + the return list should be freed by the caller */ + +int pdp_packet_op(t_pdp_symbol *operation, struct _pdp_list *stack); +#endif + +/* debug */ +void pdp_packet_print_debug(int packet); + + +/* hard coded packet methods */ +int pdp_packet_copy_ro(int handle); /* get a read only copy */ +int pdp_packet_copy_rw(int handle); /* get a read/write copy */ +int pdp_packet_clone_rw(int handle); /* get an empty read/write packet of the same type (only copy header) */ +void pdp_packet_mark_unused(int handle); /* indicate that you're done with the packet */ +void pdp_packet_mark_passing(int *phandle); /* mark a packet as passing */ +void pdp_packet_unmark_passing(int packet); /* unmark a packet as passing (i.e. before marking unused) */ +void pdp_packet_delete(int packet); /* like mark_unused, but really delete when refcount == 0 */ + +t_pdp* pdp_packet_header(int handle); /* get packet header */ +void* pdp_packet_subheader(int handle); /* get packet subheader */ +void* pdp_packet_data(int handle); /* get packet raw data */ + +int pdp_packet_compat(int packet0, int packet1); +int pdp_packet_reuse(t_pdp_symbol *description); +int pdp_packet_brandnew(unsigned int datatype, unsigned int datasize); /* create a new packet, don't reuse */ + +int pdp_packet_writable(int packet); /* returns true if packet is writable */ +void pdp_packet_replace_with_writable(int *packet); /* replaces a packet with a writable copy */ +void pdp_packet_mark_unused_atomic(int *handle); /* mark unused + set reference to -1 (for thread synchro) */ + + +/* pool stuff */ +int pdp_pool_collect_garbage(void); /* free all unused packets */ +void pdp_pool_set_max_mem_usage(int max); /* set max mem usage */ + +/* a wrapper around malloc and free to keep track of pdp's memory usage */ +void *pdp_alloc(int size); +void pdp_dealloc(void *stuff); + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_png.h b/include/pdp_png.h new file mode 100644 index 0000000..5aae4c7 --- /dev/null +++ b/include/pdp_png.h @@ -0,0 +1,28 @@ +/* + * Pure Data Packet header file. png glue code. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __PDP_PNG_H__ +#define __PDP_PNG_H__ + +int pdp_packet_bitmap_save_png_file(int packet, char *filename); +int pdp_packet_bitmap_from_png_file(char *filename); + + +#endif diff --git a/include/pdp_queue.h b/include/pdp_queue.h new file mode 100644 index 0000000..81a6b7e --- /dev/null +++ b/include/pdp_queue.h @@ -0,0 +1,115 @@ +/* + * Pure Data Packet - processor queue interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +#ifndef PDP_QUEUE_H +#define PDP_QUEUE_H + +/********************* general purpose pd process queue class *********************/ + +typedef void (*t_pdpmethod)(void *client); + +/* the process queue data record */ +typedef struct process_queue_struct +{ + void *x_owner; /* the object we are dealing with */ + t_pdpmethod x_process; /* the process method */ + t_pdpmethod x_callback; /* the function to be called when finished */ + int *x_queue_id; /* place to store the queue id for task */ +} t_process_queue_item; + + +/* a pd process queue object */ +typedef struct _pd_queue +{ + /* clock members */ + t_clock *pdp_clock; + double deltime; + + /* some bookkeeping vars */ + long long ticks; + long long packets; + + /* queue members */ + t_process_queue_item *q; /* queue */ + int mask; + int head; /* last entry in queue + 1 */ + int tail; /* first entry in queque */ + int curr; /* the object currently processed in other thread */ + + /* pthread vars */ + pthread_mutex_t mut; + pthread_cond_t cond_dataready; + pthread_cond_t cond_processingdone; + pthread_t thread_id; + + /* toggle for thread usage */ + int use_thread; + +} t_pdp_procqueue; + + +/* all symbols are C-style */ +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_procqueue_wait(t_pdp_procqueue *q); +void pdp_procqueue_finish(t_pdp_procqueue *q, int index); +void pdp_procqueue_add(t_pdp_procqueue *q, void *owner, void *process, void *callback, int *queue_id); +void pdp_procqueue_use_thread(t_pdp_procqueue* q, int t); +void pdp_procqueue_init(t_pdp_procqueue *q, double milliseconds, int logsize); + +/********************* interface to pdp process queue singleton *********************/ + +/* processor queue methods, callable from main pd thread */ + +/* get the default queue */ +t_pdp_procqueue *pdp_queue_get_queue(void); + + + +#if 1 + +/* add a method to the processing queue */ +void pdp_queue_add(void *owner, void *process, void *callback, int *queue_id); + +/* halt main tread until processing is done */ +void pdp_queue_wait(void); + +/* halt main tread until processing is done and remove + callback from queue(for destructors) */ +void pdp_queue_finish(int queue_id); + +#endif + + +/* misc signals to pdp */ +void pdp_control_notify_drop(int packet); + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_resample.h b/include/pdp_resample.h index 2865cac..8876bfa 100644 --- a/include/pdp_resample.h +++ b/include/pdp_resample.h @@ -39,7 +39,7 @@ void pdp_resample_zoom_tiled_bilin(s16 *src_image, s16 *dst_image, s32 w, s32 h, /* power of 2 resamplers */ void pdp_resample_halve(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h); - +void pdp_resample_double(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h); diff --git a/include/pdp_type.h b/include/pdp_type.h new file mode 100644 index 0000000..ea8da47 --- /dev/null +++ b/include/pdp_type.h @@ -0,0 +1,177 @@ +/* + * Pure Data Packet system implementation. Type handling interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* COMMENTS + +Since version 0.11 all packets have an (optional) high level type description. +This can be thought of as their mime type. It has several uses: + +* automatic type conversion +* better reuse strategy for non pure packets +* debugging + +The description is text-encoded, in the following form: + +type/subtype/subsubtype/.. + +This is implemented using t_pdp_symbol. + +Type descriptors can have wildcards. This is to give some freedom to a desired +type conversion. The following are all compatible: + +*/ + +// image/grey/320x240 +// image/*/320x240 +// image/*/* + +/* + +From a user pov, the type conversion is centralized. A single object (pdp_convert) +can do most of the conversions. + +Type conversion implementation has to be done decentralized. It is subdivided into +two steps: inter-type and intra-type conversions. + +Intra-type is the full responsability of each type implementation and can be handled +in a decentralized way (at linkage the type central intra-converter is registered +at the pdp framework. + +Inter-type conversion is harder to do decentralized, therefore each new type should +provide some conversions to the basic built in types. (internal image, bitmap or matrix +types. + +The point of this whole business is to + +* enable automatic conversion from anything to a desired type for operators that combine objects. + i.e. pdp_add but receive incompatible objects. +* enable manual anything to anything conversion using a pdp_convert object, i.e. have a consistent + packet conversion api for users. + + +The solution is type conversion programs. A program's behaviour is specified as follows: + +* the program is registered with a source and destination (result) template +* it is passed a packet and a destination template +* it can assume the source packet complies to the program's registerd source template +* it should convert the packet to a packet that will comply to it's registered destination template +* if for some reason a conversion fails, an invalid packet (handle == -1) should be returned + +about type templates: + +* they are hierarchical, with subtypes separated by a '/' character +* they can contain a wildcard '*', meaning that a certain level in the type hierarchy is: + - a don't care value, when the wildcard is used + -> as a destination template in a requested conversion + -> as a source template in a conversion program's specification + - uspecified, when the wildcard is used + -> as a destination template in a conversion program's specification + + + +NOTE: + + a wildcard can't be used in a source template for a conversion request + this assymetry requires there be 2 kinds of template matching mechanisms: + + - source type description (without wildcards) to conversion program source template matching + - destination type description (with wildcards) to conversion program destination template matching + + since a packet's type description cannot have wildcards, a symmetric matching (both sides have + wildcards) can be used for matching. + +*/ + + + +/* + +implementation: + +there are 2 lists with conversion progams: +* the global list, containing all registered programs. +* the cached list, containing all recently used registered programs, or combinations thereof + +if there is no cached, perfectly matching rule, a new one will be created, and added to +the head of the conversion list. + +all conversion methods should keep their hands off the source packet. it is treated as readonly. +this is to ensure a more flexible operation (i.e. be able to put the conversion at the register_ro +level) + + +TODO: add a breadth first search algorithm to do multiple stage conversion. + +*/ + +#ifndef PDP_TYPE_H +#define PDP_TYPE_H + +/* the conversion method accepts a packet (which is freed) and a destination wildcard + and produces a new packet, or the invalid packet if the conversion failed */ +typedef int (*t_pdp_conversion_method)(int, t_pdp_symbol *); + +/* a conversion program is alist of conversion methods */ +typedef t_pdp_list t_pdp_conversion_program; + +/* a conversion has source and dest wildcards, and a conversion program */ +typedef struct _pdp_conversion +{ + t_pdp_symbol *src_pattern; // source type pattern + t_pdp_symbol *dst_pattern; // destination type pattern + t_pdp_conversion_program *program; // the conversion program for this conversion +} t_pdp_conversion; + +/* all symbols are C style */ +#ifdef __cplusplus +extern "C" +{ +#endif + +/* pdp_packet methods */ +t_pdp_symbol *pdp_packet_get_description(int packet); +int pdp_packet_convert_ro(int packet, t_pdp_symbol *dest_pattern); +int pdp_packet_convert_rw(int packet, t_pdp_symbol *dest_pattern); + + +/* pdp_conversion_program methods */ +void pdp_conversion_program_free(t_pdp_conversion_program *program); +t_pdp_conversion_program *pdp_conversion_program_new(t_pdp_conversion_method method, ...); +t_pdp_conversion_program *pdp_conversion_program_copy(t_pdp_conversion_program *program); +void pdp_conversion_program_add(t_pdp_conversion_program *program, t_pdp_conversion_program *tail); + +/* pdp_type (central type object) methods */ +int pdp_type_description_match(t_pdp_symbol *description, t_pdp_symbol *pattern); +void pdp_type_register_conversion (t_pdp_symbol *src_pattern, t_pdp_symbol *dst_pattern, t_pdp_conversion_program *program); +void pdp_type_register_cached_conversion (t_pdp_symbol *src_pattern, t_pdp_symbol *dst_pattern, t_pdp_conversion_program *program); + + //t_pdp_symbol *pdp_type_gendesc(char *desc); //generate a type description (with description list attached) +t_pdp_list *pdp_type_to_list(t_pdp_symbol *type); + +/* pdp's (threadsafe) symbol */ +t_pdp_symbol *pdp_gensym(char *s); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_type.h_old b/include/pdp_type.h_old new file mode 100644 index 0000000..d588e7f --- /dev/null +++ b/include/pdp_type.h_old @@ -0,0 +1,180 @@ +/* + * Pure Data Packet system implementation. Type handling interface + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* COMMENTS + +Since version 0.11 all packets have an (optional) high level type description. +This can be thought of as their mime type. It has several uses: + +* automatic type conversion +* better reuse strategy for non pure packets +* debugging + +The description is text-encoded, in the following form: + +type/subtype/subsubtype/.. + +This is implemented using t_pdp_symbol. + +Type descriptors can have wildcards. This is to give some freedom to a desired +type conversion. The following are all compatible: + +*/ + +// image/grey/320x240 +// image/*/320x240 +// image/*/* + +/* + +From a user pov, the type conversion is centralized. A single object (pdp_convert) +can do most of the conversions. + +Type conversion implementation has to be done decentralized. It is subdivided into +two steps: inter-type and intra-type conversions. + +Intra-type is the full responsability of each type implementation and can be handled +in a decentralized way (at linkage the type central intra-converter is registered +at the pdp framework. + +Inter-type conversion is harder to do decentralized, therefore each new type should +provide some conversions to the basic built in types. (internal image, bitmap or matrix +types. + +The point of this whole business is to + +* enable automatic conversion from anything to a desired type for operators that combine objects. + i.e. pdp_add but receive incompatible objects. +* enable manual anything to anything conversion using a pdp_convert object, i.e. have a consistent + package conversion api for users. + + +The solution is type conversion programs. A program's behaviour is specified as follows: + +* the program is registered with a source and destination (result) template +* it is passed a packet and a destination template +* it can assume the source packet complies to the program's registerd source template +* it should convert the packet to a packet that will comply to it's registered destination template +* if for some reason a conversion fails, an invalid packet (handle == -1) should be returned + +about type templates: + +* they are hierarchical, with subtypes separated by a '/' character +* they can contain a wildcard '*', meaning that a certain level in the type hierarchy is: + - a don't care value, when the wildcard is used + -> as a destination template in a requested conversion + -> as a source template in a conversion program's specification + - uspecified, when the wildcard is used + -> as a destination template in a conversion program's specification + + + +NOTE: + + a wildcard can't be used in a source template for a conversion request + this assymetry requires there be 2 kinds of template matching mechanisms: + + - source type description (without wildcards) to conversion program source template matching + - destination type description (with wildcards) to conversion program destination template matching + + since a packet's type description cannot have wildcards, a symmetric matching (both sides have + wildcards) can be used for matching. + +*/ + + + +/* + +implementation: + +there are 2 lists with conversion progams: +* the global list, containing all registered programs. +* the cached list, containing all recently used registered programs, or combinations thereof + +if there is no cached, perfectly matching rule, a new one will be created, and added to +the head of the conversion list. + +all conversion methods should keep their hand's off the source packet. it is treated as readonly. +this is to ensure a more flexible operation (i.e. be able to put the conversion at the register_ro +level) this will need a bit more logic in running the conversion program though.. + + +*/ + +#ifndef PDP_TYPE_H +#define PDP_TYPE_H + +/* the conversion method accepts a packet (which is freed) and a destination wildcard + and produces a new packet, or the invalid packet if the conversion failed */ +typedef int (*t_pdp_conversion_method)(int, t_pdp_symbol *); + +/* a conversion program is alist of conversion methods */ +typedef struct _pdp_conversion_program +{ + t_pdp_conversion_method method; // conversion method + struct _pdp_conversion_program *next; // next method in program +} t_pdp_conversion_program; + +/* a conversion has source and dest wildcards, and a conversion program */ +typedef struct _pdp_conversion +{ + t_pdp_symbol *src_pattern; // source type pattern + t_pdp_symbol *dst_pattern; // destination type pattern + t_pdp_conversion_program *program; // the conversion program for this conversion + struct _pdp_conversion *next; // next conversion program record +} t_pdp_conversion; + +/* all symbols are C style */ +#ifdef __cplusplus +extern "C" +{ +#endif + +/* pdp_packet methods */ +t_pdp_symbol *pdp_packet_get_description(int packet); +int pdp_packet_convert_ro(int packet, t_pdp_symbol *dest_pattern); +int pdp_packet_convert_rw(int packet, t_pdp_symbol *dest_pattern); + + +/* pdp_conversion_program methods */ +void pdp_conversion_program_free(t_pdp_conversion_program *program); +t_pdp_conversion_program *pdp_conversion_program_new(t_pdp_conversion_method method, ...); +t_pdp_conversion_program *pdp_conversion_program_copy(t_pdp_conversion_program *program); +void pdp_conversion_program_add(t_pdp_conversion_program *program, t_pdp_conversion_program *tail); + +/* pdp_type (central type object) methods */ +int pdp_type_description_match(t_pdp_symbol *description, t_pdp_symbol *pattern); +void pdp_type_register_conversion (t_pdp_symbol *src_pattern, t_pdp_symbol *dst_pattern, t_pdp_conversion_program *program); +void pdp_type_register_cached_conversion (t_pdp_symbol *src_pattern, t_pdp_symbol *dst_pattern, t_pdp_conversion_program *program); + + //t_pdp_symbol *pdp_type_gendesc(char *desc); //generate a type description (with description list attached) +t_pdp_list *pdp_type_to_list(t_pdp_symbol *type); + +/* pdp's (threadsafe) symbol */ +t_pdp_symbol *pdp_gensym(char *s); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/pdp_types.h b/include/pdp_types.h index 32ab03f..59fc0d2 100644 --- a/include/pdp_types.h +++ b/include/pdp_types.h @@ -19,6 +19,7 @@ * */ +/* some typedefs and utility classes */ #ifndef PDP_TYPES_H #define PDP_TYPES_H @@ -33,4 +34,62 @@ typedef unsigned short u16; typedef unsigned long u32; typedef unsigned long long u64; + +#ifndef __cplusplus +typedef int bool; +#define true 1; +#define false 0; +#endif + + +typedef struct _pdp t_pdp; +typedef void (*t_pdp_packet_method1)(t_pdp *); /* dst */ +typedef void (*t_pdp_packet_method2)(t_pdp *, t_pdp *); /* dst, src */ + + +/* + The pdp symbol type manages the pdp name space. It maps + gives a symbol to something in a certain name space: + + * packet classes + * forth words + * processor instances + * type description lists (for accelerating type matching) + + symbols have an infinite lifespan, so this is also true + for things attached to it. + +*/ + +/* the pdp symbol type */ +typedef struct _pdp_symbol +{ + /* the symbol name */ + char *s_name; + + /* the items this symbol is associated to in different namespaces */ + struct _pdp_forthword_spec *s_word_spec; // a forth word + struct _pdp_list *s_processor; // an atom processor object + struct _pdp_class *s_class; // packet class + struct _pdp_list *s_type; // a type description + + struct _pdp_symbol *s_next; + +} t_pdp_symbol; + +static inline void _pdp_symbol_clear_namespaces(t_pdp_symbol *s) +{ + s->s_word_spec = 0; + s->s_processor = 0; + s->s_class = 0; + s->s_type = 0; +} + + + +/* generic packet subheader */ +//typedef unsigned char t_raw[PDP_SUBHEADER_SIZE]; +typedef unsigned int t_raw; + + #endif diff --git a/include/pdp_xwindow.h b/include/pdp_xwindow.h new file mode 100644 index 0000000..f578daf --- /dev/null +++ b/include/pdp_xwindow.h @@ -0,0 +1,147 @@ + +/* + * Pure Data Packet header file: xwindow glue code + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +// x stuff +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/extensions/Xv.h> +#include <X11/extensions/Xvlib.h> +#include "pdp.h" + +// image formats for communication with the X Server +#define FOURCC_YV12 0x32315659 /* YV12 YUV420P */ +#define FOURCC_YUV2 0x32595559 /* YUV2 YUV422 */ +#define FOURCC_I420 0x30323449 /* I420 Intel Indeo 4 */ + +/* TODO: finish this */ + +/* remarks: + this class does not own the display connection */ + + + + +/* x window class */ +typedef struct _pdp_xwindow +{ + Display *dpy; + int screen; + Window win; + GC gc; + Atom WM_DELETE_WINDOW; + + + int winwidth; + int winheight; + int winxoffset; + int winyoffset; + + int initialized; + int autocreate; + t_symbol *dragbutton; + + float cursor; + +} t_pdp_xwindow; + +/* cons */ +void pdp_xwindow_init(t_pdp_xwindow *b); + +/* des */ +void pdp_xwindow_free(t_pdp_xwindow *b); + +/* fullscreen message */ +void pdp_xwindow_fullscreen(t_pdp_xwindow *xwin); + +/* resize window */ +void pdp_xwindow_resize(t_pdp_xwindow *b, int width, int height); + +/* resize window */ +void pdp_xwindow_moveresize(t_pdp_xwindow *b, int xoffset, int yoffset, int width, int height); + +/* fill a tile of the screen */ +void pdp_xwindow_tile(t_pdp_xwindow *xwin, int x_tiles, int y_tiles, int i, int j); + +/* move window */ +void pdp_xwindow_move(t_pdp_xwindow *xwin, int xoffset, int yoffset); + +/* receive events */ +void pdp_xwindow_send_events(t_pdp_xwindow *b, t_outlet *outlet); + +/* enable/disable cursor */ +void pdp_xwindow_cursor(t_pdp_xwindow *b, t_floatarg f); + +/* create xwindow. return code != NULL on succes */ +int pdp_xwindow_create_on_display(t_pdp_xwindow *b, Display *dpy); + +/* close window */ +void pdp_xwindow_close(t_pdp_xwindow *b); + + + +/* xvideo class */ +typedef struct _pdp_xvideo +{ + + Display *dpy; + int screen; + Window win; + + int xv_format; + int xv_port; + + XvImage *xvi; + unsigned char *data; + unsigned int width; + unsigned int height; + int last_encoding; + + int initialized; + +} t_pdp_xvideo; + + +/* cons */ +void pdp_xvideo_init(t_pdp_xvideo *x); + +/* des */ +void pdp_xvideo_free(t_pdp_xvideo* x); + + +/* open an xv port (and create XvImage) */ +int pdp_xvideo_open_on_display(t_pdp_xvideo *x, Display *dpy); + +/* close xv port (and delete XvImage */ +void pdp_xvideo_close(t_pdp_xvideo* x); + +/* display a packet */ +void pdp_xvideo_display_packet(t_pdp_xvideo *x, t_pdp_xwindow *w, int packet); + + +#if 0 +/* xwindow event handler */ +typedef struct _pdp_xwin_handler +{ + t_pdp_xwindow *win; + t_outlet *outlet; +} +#endif diff --git a/include/pwc-ioctl.h b/include/pwc-ioctl.h index 19b267a..4977036 100644 --- a/include/pwc-ioctl.h +++ b/include/pwc-ioctl.h @@ -1,7 +1,7 @@ #ifndef PWC_IOCTL_H #define PWC_IOCTL_H -/* (C) 2001 Nemosoft Unv. webcam@smcc.demon.nl +/* (C) 2001-2002 Nemosoft Unv. webcam@smcc.demon.nl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* +/* This is pwc-ioctl.h belonging to PWC 8.6 */ + +/* Changes 2001/08/03 Alvarado Added ioctl constants to access methods for changing white balance and red/blue gains @@ -52,6 +54,14 @@ #define PWC_FPS_SNAPSHOT 0x00400000 + +struct pwc_probe +{ + char name[32]; + int type; +}; + + /* pwc_whitebalance.mode values */ #define PWC_WB_INDOOR 0 #define PWC_WB_OUTDOOR 1 @@ -63,9 +73,9 @@ Set mode to one of the PWC_WB_* values above. *red and *blue are the respective gains of these colour components inside the camera; range 0..65535 - When mode == PWC_WB_MANUAL, manual_red and manual_blue are set or read; + When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read; otherwise undefined. - read_red and read_blue are read-only. + 'read_red' and 'read_blue' are read-only. */ struct pwc_whitebalance @@ -75,12 +85,23 @@ struct pwc_whitebalance int read_red, read_blue; /* R/O */ }; +/* + 'control_speed' and 'control_delay' are used in automatic whitebalance mode, + and tell the camera how fast it should react to changes in lighting, and + with how much delay. Valid values are 0..65535. +*/ +struct pwc_wb_speed +{ + int control_speed; + int control_delay; + +}; /* Used with VIDIOCPWC[SG]LED */ struct pwc_leds { - int led_on; /* Led on-time; range = 0..255 */ - int led_off; /* */ + int led_on; /* Led on-time; range = 0..25000 */ + int led_off; /* Led off-time; range = 0..25000 */ }; @@ -104,6 +125,19 @@ struct pwc_leds /* Get preferred compression quality */ #define VIDIOCPWCGCQUAL _IOR('v', 195, int) + + /* This is a probe function; since so many devices are supported, it + becomes difficult to include all the names in programs that want to + check for the enhanced Philips stuff. So in stead, try this PROBE; + it returns a structure with the original name, and the corresponding + Philips type. + To use, fill the structure with zeroes, call PROBE and if that succeeds, + compare the name with that returned from VIDIOCGCAP; they should be the + same. If so, you can be assured it is a Philips (OEM) cam and the type + is valid. + */ +#define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe) + /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */ #define VIDIOCPWCSAGC _IOW('v', 200, int) /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */ @@ -115,9 +149,28 @@ struct pwc_leds #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance) #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance) - /* Turn LED on/off ; int range 0..65535 */ + /* Auto WB speed */ +#define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed) +#define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed) + + /* LEDs on/off/blink; int range 0..65535 */ #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds) - /* Get state of LED; int range 0..65535 */ #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds) + /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */ +#define VIDIOCPWCSCONTOUR _IOW('v', 206, int) +#define VIDIOCPWCGCONTOUR _IOR('v', 206, int) + + /* Backlight compensation; 0 = off, otherwise on */ +#define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int) +#define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int) + + /* Flickerless mode; = 0 off, otherwise on */ +#define VIDIOCPWCSFLICKER _IOW('v', 208, int) +#define VIDIOCPWCGFLICKER _IOR('v', 208, int) + + /* Dynamic noise reduction; 0 off, 3 = high noise reduction */ +#define VIDIOCPWCSDYNNOISE _IOW('v', 209, int) +#define VIDIOCPWCGDYNNOISE _IOR('v', 209, int) + #endif diff --git a/modules/Makefile b/modules/Makefile index 09a9ce3..dfafb76 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -1,18 +1,20 @@ -current: all_modules +# build subdirs +current: + make -C generic + make -C image_basic + make -C image_io + make -C image_special + make -C matrix_basic + make -C test -include ../Makefile.config - -PDP_MOD = pdp_add.o pdp_reg.o pdp_conv.o \ - pdp_mix.o pdp_affine.o pdp_del.o pdp_mul.o pdp_randmix.o \ - pdp_snap.o pdp_trigger.o pdp_bq.o pdp_noise.o pdp_gradient.o \ - pdp_route.o pdp_gain.o pdp_grey.o pdp_chrot.o pdp_scope.o \ - pdp_scale.o pdp_zoom.o pdp_scan.o pdp_cheby.o pdp_scanxy.o \ - pdp_grey2mask.o pdp_constant.o pdp_slice_cut.o pdp_slice_glue.o - -# build portable and optional modules -all_modules: $(PDP_MOD) $(PDP_OPTMOD) clean: + make -C generic clean + make -C image_basic clean + make -C image_io clean + make -C image_special clean + make -C matrix_basic clean + make -C test clean rm -f *~ rm -f *.o diff --git a/modules/README b/modules/README index 537ff2d..54f816c 100644 --- a/modules/README +++ b/modules/README @@ -7,27 +7,24 @@ There are 3 kinds of pdp messages: [pdp register_rw <packet_id>] [pdp process] -An object can receive a packet by catching the 3 kinds of messages: +Together they form the pdp protocol. An object can receive a packet +by catching the 3 kinds of messages: When a register_ro message is received, the object can call -pdp_packet_copy_ro(packet) to reseve a read only copy for itself. -The only operations on the packet at that time are read only -operations. +pdp_packet_copy_ro(packet) to reserve a read only copy for itself. The same goes for handling the register_rw message. You can reserve a read/write copy by using pdp_packet_copy_rw(packet) When a process message is received, the object is allowed to start -processing the data. - -In the register_ro or register_rw phases, the object can inspect -the packet to see if it wants to register it (using pdp_packet_header -and pdp_packet_data operations) but it is not allowed to allocate other objects -in that phase. This is only allowed in the process phase. (or after -the receiving packet is registerd.) - -An object can send out a pdp message using the outlet_pdp(outlet, packet) -function. This sends out these 3 messages in sequence. It is best to -unregister a packet using pdp_packet_mark_unused(packet) before sending it out, -if it is no longer used by the sending object. This eliminates one extra -copy operation on the data. +processing the packet data end send the resulting packet(s) out. + +To send out a packet, use the pdp_packet_pass_if_valid(outlet, &packet) +method. It passes a packet, and sets the reference to -1 (the undefined +packet id). + + +If you want to write pdp externs, consider using the pdp_base object +to derive your object from. Have a look at pdp_add, pdp_gain, pdp_noise +to see how to do this. + diff --git a/modules/pdp_add.c b/modules/pdp_add.c deleted file mode 100644 index 9bf8c13..0000000 --- a/modules/pdp_add.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - -typedef struct pdp_add_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; // packet outlet - - int x_packet0; // current hot packet (left inlet) - int x_packet1; // current cold packet (right inlet) - int x_packet1next; // next cold packet (right inlet) - int x_queue_id; // task id in process queue (for callback cancelling) - int x_dropped; // indicate if a packet was dropped during register_rw cycle - -} t_pdp_add; - - - -static void pdp_add_process_yv12(t_pdp_add *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - - // set hight so it includes the chroma frames - h = h + (h>>1); - - pdp_imageproc_add_process((short int*)data0, (short int*)data1, w, h); - - - return; -} - -static void pdp_add_process_grey(t_pdp_add *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - pdp_imageproc_add_process((short int*)data0, (short int*)data1, w, h); - - - return; -} - -static void pdp_add_process(t_pdp_add *x) -{ - int encoding; - - /* check if image data packets are compatible */ - if (pdp_type_compat_image(x->x_packet0, x->x_packet1)){ - - /* dispatch to process thread */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_add_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_add_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } -} - -/* this method is called after the thread has finished processing */ -static void pdp_add_sendpacket(t_pdp_add *x) -{ - - /* unregister (mark unused) packet and propagate if packet is valid */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); - -} - -static void pdp_add_input_0(t_pdp_add *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* if a cold packet was received in the meantime - swap it in, else keep the old one */ - - pdp_replace_if_valid(&x->x_packet1, &x->x_packet1next); - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_add_process, pdp_add_sendpacket, &x->x_queue_id); - } -} - -static void pdp_add_input_1(t_pdp_add *x, t_symbol *s, t_floatarg f) -{ - /* store the packet and trow away - the old one, if there is any */ - - int p = (int)f; - - if(s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet1next, p); - -} - - - - - -static void pdp_add_free(t_pdp_add *x) -{ - /* remove process method from queue before deleting data */ - pdp_queue_finish(x->x_queue_id); - - /* delete stuff */ - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); - pdp_packet_mark_unused(x->x_packet1next); - -} - -t_class *pdp_add_class; - - - -void *pdp_add_new(void) -{ - t_pdp_add *x = (t_pdp_add *)pd_new(pdp_add_class); - - /* init in/out */ - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - /* init pdp vars */ - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_packet1next = -1; - x->x_queue_id = -1; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_add_setup(void) -{ - - - pdp_add_class = class_new(gensym("pdp_add"), (t_newmethod)pdp_add_new, - (t_method)pdp_add_free, sizeof(t_pdp_add), 0, A_NULL); - - - class_addmethod(pdp_add_class, (t_method)pdp_add_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_add_class, (t_method)pdp_add_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_affine.c b/modules/pdp_affine.c deleted file mode 100644 index 06d41ac..0000000 --- a/modules/pdp_affine.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" - - -typedef struct pdp_affine_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_queue_id; - int x_dropped; // indicate if a packet was dropped during register_rw cycle - - int x_channel; - - void *x_affine; - -} t_pdp_affine; - - - -static void pdp_affine_process_yv12(t_pdp_affine *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - unsigned int v_offset = size; - unsigned int u_offset = size + (size >> 2) ; - unsigned int i,j; - - short int * idata = (short int *)data0; - int ch = x->x_channel; - - if((ch == 0) || (ch==1)) pdp_imageproc_affine_process(x->x_affine, &idata[0], w, h); - if((ch == 0) || (ch==2)) pdp_imageproc_affine_process(x->x_affine, &idata[v_offset], w>>1, h>>1); - if((ch == 0) || (ch==3)) pdp_imageproc_affine_process(x->x_affine, &idata[u_offset], w>>1, h>>1); - - return; - - -} - -static void pdp_affine_process_grey(t_pdp_affine *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - short int * idata = (short int *)data0; - int ch = x->x_channel; - - if((ch == 0) || (ch==1)) pdp_imageproc_affine_process(x->x_affine, &idata[0], w, h); - - return; - - -} - -static void pdp_affine_process(t_pdp_affine *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_affine_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_affine_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_affine_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont pdp_affine_process */ - - } - } - -} - -static void pdp_affine_sendpacket(t_pdp_affine *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_affine_input_0(t_pdp_affine *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_affine_process, pdp_affine_sendpacket, &x->x_queue_id); - } - -} - - - -static void pdp_affine_gain(t_pdp_affine *x, t_floatarg f) -{ - pdp_imageproc_affine_setgain(x->x_affine, f); - -} - -static void pdp_affine_offset(t_pdp_affine *x, t_floatarg f) -{ - pdp_imageproc_affine_setoffset(x->x_affine, f); -} - -static void pdp_affine_channel(t_pdp_affine *x, t_floatarg f) -{ - int ch = (int)f; - - - if ((ch < 1) || (ch > 3)) ch = 0; - - x->x_channel = ch; - - -} -static void pdp_affine_free(t_pdp_affine *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_affine_delete(x->x_affine); - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_affine_class; - - - -void *pdp_affine_new(t_floatarg f) -{ - t_pdp_affine *x = (t_pdp_affine *)pd_new(pdp_affine_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("gain")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("offset")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - x->x_affine = pdp_imageproc_affine_new(); - - pdp_affine_gain(x, 1.0f); - pdp_affine_offset(x, 0.0f); - pdp_affine_channel(x, f); - - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_affine_setup(void) -{ - - - pdp_affine_class = class_new(gensym("pdp_affine"), (t_newmethod)pdp_affine_new, - (t_method)pdp_affine_free, sizeof(t_pdp_affine), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_affine_class, (t_method)pdp_affine_gain, gensym("gain"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_affine_class, (t_method)pdp_affine_offset, gensym("offset"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_affine_class, (t_method)pdp_affine_channel, gensym("chan"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_affine_class, (t_method)pdp_affine_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_bq.c b/modules/pdp_bq.c deleted file mode 100644 index b7c33c2..0000000 --- a/modules/pdp_bq.c +++ /dev/null @@ -1,698 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" -#include <math.h> - -/* computes a transfer function: - * - * b0 + b1 z^(-1) + b2 z^(-2) - * T(z) = -------------------------- - * 1 + a1 z^(-1) + a2 z^(-2) - * - * TODO: think about scaling. - */ - - -/* - * TODO: - * add another time processing class - * add methods for separate horizontal/vertical filters - */ - - -typedef struct pdp_bq_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - //_outlet *x_outlet1; - //t_outlet *x_outlet2; - - /* pass through packet */ - int x_packet0; - - /* state packets for bqt */ - int x_packet1; - int x_packet2; - - int x_dropped; - int x_queue_id; - - unsigned int x_nbpasses; - - /* single direction */ - unsigned int x_direction; - - bool x_reset_on_formatchange; - - - void *x_biquad; - - float x_coefs_a[3]; // a0, -a1, -a2 - float x_coefs_b[3]; // b0, b1, b2 - float x_state_u[2]; // u0, u1 - float x_state_u_save[2]; // u0, u1 (for reset) - -} t_pdp_bq; - - -/************************* COEFFICIENT METHODS ****************************/ - -static void pdp_bq_a0(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[0] = f;} -static void pdp_bq_a1(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[1] = -f;} -static void pdp_bq_a2(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[2] = -f;} - -static void pdp_bq_b0(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[0] = f;} -static void pdp_bq_b1(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[1] = f;} -static void pdp_bq_b2(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[2] = f;} - -static void pdp_bq_u0(t_pdp_bq *x, t_floatarg f){x->x_state_u_save[0] = f;} -static void pdp_bq_u1(t_pdp_bq *x, t_floatarg f){x->x_state_u_save[1] = f;} - - -static void pdp_bq_setcoefs(t_pdp_bq *x, - float a0, float a1, float a2, - float b0, float b1, float b2) -{ - pdp_bq_a0(x,a0); - pdp_bq_a1(x,a1); - pdp_bq_a2(x,a2); - pdp_bq_b0(x,b0); - pdp_bq_b1(x,b1); - pdp_bq_b2(x,b2); - pdp_imageproc_bq_setcoef(x->x_biquad, x->x_coefs_a); -} - -static void pdp_bq_setstate(t_pdp_bq *x, float u0, float u1) -{ - pdp_bq_u0(x,u0); - pdp_bq_u1(x,u1); - pdp_imageproc_bq_setcoef(x->x_biquad, x->x_coefs_a); -} - - - -/* reso lowpass */ -static void pdp_bq_lpf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) -{ - float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; - w = 2.0 * M_PI * f; - cs = cos(w); - sn = sin(w); - - alpha = sn*sinh(1.0f/(2.0f*Q)); - b0 = (1.0 - cs)/2.0; - b1 = 1.0 - cs; - b2 = (1.0 - cs)/2.0; - a0 = (1.0 + alpha); - a1 = -2.0*cs; - a2 = 1.0 - alpha; - - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); - -} - -/* reso highpass */ -static void pdp_bq_hpf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) -{ - float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; - w = 2.0 * M_PI * f; - cs = cos(w); - sn = sin(w); - - alpha = sn*sinh(1.0f/(2.0f*Q)); - - b0 = (1.0 + cs)/2.0; - b1 = -1.0 - cs; - b2 = (1.0 + cs)/2.0; - a0 = (1.0 + alpha); - a1 = -2.0*cs; - a2 = 1.0 - alpha; - - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); - -} - - -/* reso allpass */ -static void pdp_bq_apf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) -{ - float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; - w = 2.0 * M_PI * f; - cs = cos(w); - sn = sin(w); - - alpha = sn*sinh(1.0f/(2.0f*Q)); - - b0 = (1.0 - alpha); - b1 = -2.0 * cs; - b2 = (1.0 + alpha); - a0 = (1.0 + alpha); - a1 = -2.0*cs; - a2 = 1.0 - alpha; - - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); -} - -/* reso band stop (notch) */ -static void pdp_bq_bsf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) -{ - float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; - w = 2.0 * M_PI * f; - cs = cos(w); - sn = sin(w); - - alpha = sn*sinh(1.0f/(2.0f*Q)); - - b0 = 1.0; - b1 = -2.0 * cs; - b2 = 1.0; - a0 = (1.0 + alpha); - a1 = -2.0*cs; - a2 = 1.0 - alpha; - - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); - -} - -static void pdp_bq_onep(t_pdp_bq *x, t_floatarg f) -{ - float a0,a1,a2,b0,b1,b2; - - if (f>1.0f) f = 1.0f; - if (f<0.0f) f = 0.0f; - - a0 = 1.0f; - a1 = -(1.0f - f); - a2 = 0.0f; - b0 = f; - b1 = 0.0f; - b2 = 0.0f; - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); -} - -static void pdp_bq_twop(t_pdp_bq *x, t_floatarg f) -{ - float f1; - float a0,a1,a2,b0,b1,b2; - - if (f>1.0) f = 1.0; - if (f<0.0) f = 0.0; - - f1 = 1.0 - f; - - a0 = 1.0f; - a1 = -2.0f*f1; - a2 = f1*f1; - b0 = f*f; - b1 = 0.0f; - b2 = 0.0f; - - pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); -} - - - - - -/************************* PROCESS METHODS ****************************/ - - -static void pdp_bqt_process_yv12(t_pdp_bq *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - t_pdp *header2 = pdp_packet_header(x->x_packet2); - - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - void *data2 = pdp_packet_data (x->x_packet2); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - h = h + (h>>1); - - pdp_imageproc_bqt_process(x->x_biquad, (short int*)data0, (short int*)data1, (short int *)data2, w, h); - - return; -} - - - -static void pdp_bqt_process_grey(t_pdp_bq *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - t_pdp *header2 = pdp_packet_header(x->x_packet2); - - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - void *data2 = pdp_packet_data (x->x_packet2); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - pdp_imageproc_bqt_process(x->x_biquad, (short int*)data0, (short int*)data1, (short int *)data2, w, h); - - return; -} - - - - -static void pdp_bq_process_yv12(t_pdp_bq *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - unsigned int v_offset = size; - unsigned int u_offset = size + (size >> 2); - - unsigned int nbp = x->x_nbpasses; - - short int * idata = (short int *)data0; - - pdp_imageproc_bq_process(x->x_biquad, idata, w, h, x->x_direction, nbp); - pdp_imageproc_bq_process(x->x_biquad, idata + v_offset, w>>1, h>>1, x->x_direction, nbp); - pdp_imageproc_bq_process(x->x_biquad, idata + u_offset, w>>1, h>>1, x->x_direction, nbp); - - return; -} - - -static void pdp_bq_process_grey(t_pdp_bq *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int nbp = x->x_nbpasses; - - short int * idata = (short int *)data0; - pdp_imageproc_bq_process(x->x_biquad, idata, w, h, x->x_direction, nbp); - - return; - -} - - -static void pdp_bqt_process(t_pdp_bq *x) -{ - int encoding; - - /* image data packets are compatible, this is ensured in the pdp method */ - /* when the hot packet is received */ - - /* process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_bqt_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_bqt_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - -} - - -static void pdp_bq_process(t_pdp_bq *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_bq_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_bq_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - -static void pdp_bqt_reset(t_pdp_bq *x) -{ - t_pdp* header1 = pdp_packet_header(x->x_packet1); - t_pdp* header2 = pdp_packet_header(x->x_packet2); - void *data1 = pdp_packet_data(x->x_packet1); - void *data2 = pdp_packet_data(x->x_packet1); - unsigned int w,h,nbpixels,count; - - if (!(header1 && header2)) return; - if (header1->type != PDP_IMAGE) return; - - w = header1->info.image.width; - h = header1->info.image.height; - nbpixels = w*h; - - post("pdp_bqt: resetting state"); - switch (header1->info.image.encoding){ - case PDP_IMAGE_YV12: - count = (nbpixels + nbpixels >> 1) << 1; - bzero(data1, count); - bzero(data2, count); - break; - case PDP_IMAGE_GREY: - count = (nbpixels) << 1; - bzero(data1, count); - bzero(data2, count); - break; - default: - break; - } - -} - - - -/************************* INPUT HANDLERS ****************************/ - -static void pdp_bq_sendpacket(t_pdp_bq *x) -{ - - /* output state packets for those that are interested */ - //if(x->x_packet2 != -1) outlet_pdp(x->x_outlet2, x->x_packet2); - //if(x->x_packet1 != -1) outlet_pdp(x->x_outlet1, x->x_packet1); - - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_bq_input_0(t_pdp_bq *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* add the process method and callback to the process queue */ - pdp_queue_add(x, pdp_bq_process, pdp_bq_sendpacket, &x->x_queue_id); - } - -} - - - -static void pdp_bqt_input_0(t_pdp_bq *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* check if state packets are compatible */ - if (!( (pdp_type_compat_image(x->x_packet0, x->x_packet1)) - && (pdp_packet_header(x->x_packet0)->info.image.encoding - == pdp_packet_header(x->x_packet1)->info.image.encoding))){ - - - /* if not, create new state packets by copying the input packets */ - post("pdp_bqt: created new state packets"); - pdp_packet_mark_unused(x->x_packet1); - pdp_packet_mark_unused(x->x_packet2); - x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); - x->x_packet2 = pdp_packet_clone_rw(x->x_packet0); - - /* reset */ - if (x->x_reset_on_formatchange) pdp_bqt_reset(x); - } - - /* add the process method and callback to the process queue */ - pdp_queue_add(x, pdp_bqt_process, pdp_bq_sendpacket, &x->x_queue_id); - } - -} - - - -/************************* CONFIG METHODS ****************************/ - - -static void pdp_bq_passes(t_pdp_bq *x, t_floatarg f) -{ - int passes = (int)f; - passes = passes < 0 ? 0 : passes; - x->x_nbpasses = passes; - -} - -static void pdp_bq_lr(t_pdp_bq *x, t_floatarg f) -{ - if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT; - if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT; -} - -static void pdp_bq_rl(t_pdp_bq *x, t_floatarg f) -{ - if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT; - if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT; -} -static void pdp_bq_tb(t_pdp_bq *x, t_floatarg f) -{ - if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM; - if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM; -} - -static void pdp_bq_bt(t_pdp_bq *x, t_floatarg f) -{ - if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP; - if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP; -} - - -static void pdp_bq_hor(t_pdp_bq *x, t_floatarg f) -{ - pdp_bq_lr(x, f); - pdp_bq_rl(x, f); -} -static void pdp_bq_ver(t_pdp_bq *x, t_floatarg f) -{ - pdp_bq_tb(x, f); - pdp_bq_bt(x, f); -} - - - -/************************* DES/CONSTRUCTORS ****************************/ - -static void pdp_bq_free(t_pdp_bq *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_bq_delete(x->x_biquad); - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); - pdp_packet_mark_unused(x->x_packet2); - -} - - -void pdp_bq_init(t_pdp_bq *x) -{ - - - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_packet2 = -1; - - x->x_queue_id = -1; - - x->x_nbpasses = 1; - x->x_reset_on_formatchange = true; - - x->x_biquad = pdp_imageproc_bq_new(); - - - pdp_bq_setstate(x, 0.0f, 0.0f); - pdp_bq_onep(x, 0.1f); - -} - - - -/* class pointers */ - -t_class *pdp_bq_class; /* biquad spacial processing */ -t_class *pdp_bqt_class; /* biquad time processing */ - -void *pdp_bq_new(void) -{ - t_pdp_bq *x = (t_pdp_bq *)pd_new(pdp_bq_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("passes")); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - pdp_bq_init(x); - return (void *)x; -} - -void *pdp_bqt_new(void) -{ - t_pdp_bq *x = (t_pdp_bq *)pd_new(pdp_bqt_class); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - //x->x_outlet1 = outlet_new(&x->x_obj, &s_anything); - //x->x_outlet2 = outlet_new(&x->x_obj, &s_anything); - pdp_bq_init(x); - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - - - - - -/************************* CLASS CONSTRUCTORS ****************************/ - - -void pdp_bq_setup(void) -{ - - /* setup spatial processing class */ - - pdp_bq_class = class_new(gensym("pdp_bq"), (t_newmethod)pdp_bq_new, - (t_method)pdp_bq_free, sizeof(t_pdp_bq), 0, A_NULL); - - - class_addmethod(pdp_bq_class, (t_method)pdp_bq_passes, gensym("passes"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_hor, gensym("hor"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_ver, gensym("ver"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_tb, gensym("tb"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_bt, gensym("bt"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_lr, gensym("lr"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_rl, gensym("rl"), A_FLOAT, A_NULL); - - - - /* raw coefficient methods */ - class_addmethod(pdp_bq_class, (t_method)pdp_bq_a1, gensym("a1"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_a2, gensym("a2"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_b0, gensym("b0"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_b1, gensym("b1"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_b2, gensym("b2"), A_FLOAT, A_NULL); - //class_addmethod(pdp_bq_class, (t_method)pdp_bq_u1, gensym("u1"), A_FLOAT, A_NULL); - //class_addmethod(pdp_bq_class, (t_method)pdp_bq_u2, gensym("u2"), A_FLOAT, A_NULL); - - /* real pole filters */ - class_addmethod(pdp_bq_class, (t_method)pdp_bq_onep, gensym("onep"), A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_twop, gensym("twop"), A_FLOAT, A_NULL); - - /* resonnant pole filters */ - class_addmethod(pdp_bq_class, (t_method)pdp_bq_lpf, gensym("lpf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_hpf, gensym("hpf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_apf, gensym("apf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bq_class, (t_method)pdp_bq_bsf, gensym("bsf"), A_FLOAT, A_FLOAT, A_NULL); - - - class_addmethod(pdp_bq_class, (t_method)pdp_bq_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - - - - - - - - /* setup time processing class */ - pdp_bqt_class = class_new(gensym("pdp_bqt"), (t_newmethod)pdp_bqt_new, - (t_method)pdp_bq_free, sizeof(t_pdp_bq), 0, A_NULL); - - - /* raw coefficient methods */ - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_a1, gensym("a1"), A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_a2, gensym("a2"), A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_b0, gensym("b0"), A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_b1, gensym("b1"), A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_b2, gensym("b2"), A_FLOAT, A_NULL); - //class_addmethod(pdp_bqt_class, (t_method)pdp_bq_u1, gensym("u1"), A_FLOAT, A_NULL); - //class_addmethod(pdp_bqt_class, (t_method)pdp_bq_u2, gensym("u2"), A_FLOAT, A_NULL); - - /* real pole filters */ - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_onep, gensym("onep"), A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_twop, gensym("twop"), A_FLOAT, A_NULL); - - /* resonnant pole filters */ - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_lpf, gensym("lpf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_hpf, gensym("hpf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_apf, gensym("apf"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_bqt_class, (t_method)pdp_bq_bsf, gensym("bsf"), A_FLOAT, A_FLOAT, A_NULL); - - /* control */ - class_addmethod(pdp_bqt_class, (t_method)pdp_bqt_reset, gensym("reset"), A_NULL); - - - - /* pdp */ - class_addmethod(pdp_bqt_class, (t_method)pdp_bqt_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - - - - - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_cheby.c b/modules/pdp_cheby.c deleted file mode 100644 index 4ba32a3..0000000 --- a/modules/pdp_cheby.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" - - -typedef struct pdp_cheby_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_queue_id; - int x_dropped; // indicate if a packet was dropped during register_rw cycle - - int x_channel; - - void *x_cheby; - - int x_iterations; - int x_order; - -} t_pdp_cheby; - - - -static void pdp_cheby_process_yv12(t_pdp_cheby *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - unsigned int v_offset = size; - unsigned int u_offset = size + (size >> 2) ; - unsigned int i,j; - - short int * idata = (short int *)data0; - int ch = x->x_channel; - - if((ch == 0) || (ch==1)) pdp_imageproc_cheby_process(x->x_cheby, &idata[0], w, h, x->x_iterations ); - if((ch == 0) || (ch==2)) pdp_imageproc_cheby_process(x->x_cheby, &idata[v_offset], w>>1, h>>1, x->x_iterations); - if((ch == 0) || (ch==3)) pdp_imageproc_cheby_process(x->x_cheby, &idata[u_offset], w>>1, h>>1, x->x_iterations); - - return; - - -} - -static void pdp_cheby_process_grey(t_pdp_cheby *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - short int * idata = (short int *)data0; - int ch = x->x_channel; - - if((ch == 0) || (ch==1)) pdp_imageproc_cheby_process(x->x_cheby, &idata[0], w, h, x->x_iterations); - - return; - - -} - -static void pdp_cheby_process(t_pdp_cheby *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_cheby_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_cheby_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_cheby_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont pdp_cheby_process */ - - } - } - -} - -static void pdp_cheby_sendpacket(t_pdp_cheby *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_cheby_input_0(t_pdp_cheby *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_cheby_process, pdp_cheby_sendpacket, &x->x_queue_id); - } - -} - - - -static void pdp_cheby_coef(t_pdp_cheby *x, t_floatarg c, t_floatarg f) -{ - pdp_imageproc_cheby_setcoef(x->x_cheby, (int)c, f); -} - -static void pdp_cheby_reset(t_pdp_cheby *x) -{ - int i; - for (i = 0; i <= x->x_order; i++) - pdp_imageproc_cheby_setcoef(x->x_cheby, i, 0); -} - -static void pdp_cheby_channel(t_pdp_cheby *x, t_floatarg f) -{ - int ch = (int)f; - if ((ch < 1) || (ch > 3)) ch = 0; - x->x_channel = ch; -} - -static void pdp_cheby_iterations(t_pdp_cheby *x, t_floatarg f) -{ - int i = (int)f; - if (i<0) i = 0; - x->x_iterations = i; - -} -static void pdp_cheby_free(t_pdp_cheby *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_cheby_delete(x->x_cheby); - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_cheby_class; - - - -void *pdp_cheby_new(t_floatarg f) -{ - t_pdp_cheby *x = (t_pdp_cheby *)pd_new(pdp_cheby_class); - int order = (int)(f); - - if (order < 2) order = 2; - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("iterations")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - x->x_cheby = pdp_imageproc_cheby_new(order); - - // default: process all channels - x->x_channel = 0; - x->x_iterations = 1; - x->x_order = order; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_cheby_setup(void) -{ - - - pdp_cheby_class = class_new(gensym("pdp_cheby"), (t_newmethod)pdp_cheby_new, - (t_method)pdp_cheby_free, sizeof(t_pdp_cheby), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_coef, gensym("coef"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_iterations, gensym("iterations"), A_FLOAT, A_NULL); - class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_channel, gensym("chan"), A_FLOAT, A_NULL); - class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_reset, gensym("reset"), A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_chrot.c b/modules/pdp_chrot.c deleted file mode 100644 index 5181195..0000000 --- a/modules/pdp_chrot.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" -#include <math.h> - - -typedef struct pdp_chrot_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_queue_id; - int x_dropped; // indicate if a packet was dropped during register_rw cycle - - int x_channel; - - float x_matrix[4]; - - void *x_crot2d; - -} t_pdp_chrot; - - - -static void pdp_chrot_process_yv12(t_pdp_chrot *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - unsigned int v_offset = size; - - short int * idata = (short int *)data0; - - - /* color rotation for 2 colour planes */ - pdp_imageproc_crot2d_process(x->x_crot2d, idata + v_offset, w>>1, h>>1); - - - return; - - -} - -static void pdp_chrot_process(t_pdp_chrot *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_chrot_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_chrot_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - break; - - default: - break; - /* don't know the type, so dont pdp_chrot_process */ - - } - } - -} - -static void pdp_chrot_sendpacket(t_pdp_chrot *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_chrot_input_0(t_pdp_chrot *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_chrot_process, pdp_chrot_sendpacket, &x->x_queue_id); - } - -} - - -static void pdp_chrot_setelement(t_pdp_chrot *x, int element, float f) -{ - x->x_matrix[element] = f; - -} - -static void pdp_chrot_angle_radians(t_pdp_chrot *x, t_floatarg angle) -{ - float c = cos(angle); - float s = sin(angle); - - pdp_chrot_setelement(x, 0, c); - pdp_chrot_setelement(x, 1, s); - pdp_chrot_setelement(x, 2, -s); - pdp_chrot_setelement(x, 3, c); - - pdp_imageproc_crot2d_setmatrix(x->x_crot2d, x->x_matrix); -} - -static void pdp_chrot_angle_degrees(t_pdp_chrot *x, t_floatarg angle) -{ - pdp_chrot_angle_radians(x, (angle * (M_PI / 180.f))); - -} - -static void pdp_chrot_free(t_pdp_chrot *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_crot2d_delete(x->x_crot2d); - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_chrot_class; - - - -void *pdp_chrot_new(t_floatarg f) -{ - t_pdp_chrot *x = (t_pdp_chrot *)pd_new(pdp_chrot_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("angle")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - x->x_crot2d = pdp_imageproc_crot2d_new(); - pdp_chrot_angle_radians(x, 0.0f); - - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_chrot_setup(void) -{ - - - pdp_chrot_class = class_new(gensym("pdp_chrot"), (t_newmethod)pdp_chrot_new, - (t_method)pdp_chrot_free, sizeof(t_pdp_chrot), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_chrot_class, (t_method)pdp_chrot_angle_degrees, gensym("angle"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_chrot_class, (t_method)pdp_chrot_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_constant.c b/modules/pdp_constant.c deleted file mode 100644 index c9a1e61..0000000 --- a/modules/pdp_constant.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - - -typedef struct pdp_constant_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_queue_id; - - int x_pdp_image_type; - - unsigned int x_width; - unsigned int x_height; - - s8 x_fillbyte; - -} t_pdp_constant; - - - -void pdp_constant_type(t_pdp_constant *x, t_symbol *s) -{ - if (gensym("yv12") == s) {x->x_pdp_image_type = PDP_IMAGE_YV12; return;} - if (gensym("grey") == s) {x->x_pdp_image_type = PDP_IMAGE_GREY; return;} - - x->x_pdp_image_type = -1; - -} - - -void pdp_constant_value(t_pdp_constant *x, t_floatarg f) -{ - if (f>1.0f) f = 1.0f; - if (f<-1.0f) f = -1.0f; - - x->x_fillbyte = (s8)(0x7f * f); - -} - - - -static void pdp_constant_createpacket_yv12(t_pdp_constant *x) -{ - /* create new packet */ - x->x_packet0 = pdp_packet_new_image_yv12(x->x_width, x->x_height); - -} - -static void pdp_constant_generate_yv12(t_pdp_constant *x) -{ - short int *data; - unsigned int w = x->x_width; - unsigned int h = x->x_height; - - data = (short int *) pdp_packet_data(x->x_packet0); - - memset(data, x->x_fillbyte, (w*h + ((w*h)>>2)) * sizeof(s16)); - - - return; - -} - -static void pdp_constant_createpacket_grey(t_pdp_constant *x) -{ - /* create new packet */ - x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height); - -} - -static void pdp_constant_generate_grey(t_pdp_constant *x) -{ - unsigned int w = x->x_width; - unsigned int h = x->x_height; - short int *data = (short int *) pdp_packet_data(x->x_packet0); - - data = (short int *) pdp_packet_data(x->x_packet0); - - memset(data, x->x_fillbyte, (w*h) * sizeof(s16)); - - return; -} - -static void pdp_constant_sendpacket(t_pdp_constant *x, t_floatarg w, t_floatarg h) -{ - /* propagate if valid */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - - -static void pdp_constant_bang(t_pdp_constant *x) -{ - - int encoding; - - /* if we have an active packet, don't do anything */ - if (-1 != x->x_packet0) return; - - switch(x->x_pdp_image_type){ - - case PDP_IMAGE_YV12: - pdp_constant_createpacket_yv12(x); // don't create inside thread!!! - pdp_queue_add(x, pdp_constant_generate_yv12, pdp_constant_sendpacket, &x->x_queue_id); - break; - - case PDP_IMAGE_GREY: - pdp_constant_createpacket_grey(x); // don't create inside thread!!! - pdp_queue_add(x, pdp_constant_generate_grey, pdp_constant_sendpacket, &x->x_queue_id); - break; - - default: - break; - - } - - - /* release the packet */ - - -} - -static void pdp_constant_dim(t_pdp_constant *x, t_floatarg w, t_floatarg h) -{ - x->x_width = pdp_imageproc_legalwidth((int)w); - x->x_height = pdp_imageproc_legalheight((int)h); - //post("dims %d %d", x->x_width, x->x_height); -} - - -static void pdp_constant_free(t_pdp_constant *x) -{ - - /* remove callback from process queue */ - pdp_queue_finish(x->x_queue_id); - - - /* tidy up */ - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_constant_class; - - - - -void *pdp_constant_new(void) -{ - int i; - - t_pdp_constant *x = (t_pdp_constant *)pd_new(pdp_constant_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("value")); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_width = 320; - x->x_height = 240; - - pdp_constant_value(x, 0.0f); - - pdp_constant_type(x, gensym("yv12")); - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - - -void pdp_constant_setup(void) -{ - - - pdp_constant_class = class_new(gensym("pdp_constant"), (t_newmethod)pdp_constant_new, - (t_method)pdp_constant_free, sizeof(t_pdp_constant), 0, A_NULL); - - class_addmethod(pdp_constant_class, (t_method)pdp_constant_value, gensym("value"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_constant_class, (t_method)pdp_constant_type, gensym("type"), A_SYMBOL, A_NULL); - class_addmethod(pdp_constant_class, (t_method)pdp_constant_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_constant_class, (t_method)pdp_constant_bang, gensym("bang"), A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_conv.c b/modules/pdp_conv.c deleted file mode 100644 index 885b86b..0000000 --- a/modules/pdp_conv.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" - - -typedef struct pdp_conv_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - - int x_packet0; - int x_dropped; - int x_queue_id; - - unsigned int x_nbpasses; - bool x_horizontal; - bool x_vertical; - - void *x_convolver_hor; - void *x_convolver_ver; - -} t_pdp_conv; - - - -static void pdp_conv_process_yv12(t_pdp_conv *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - unsigned int v_offset = size; - unsigned int u_offset = size + (size >> 2) ; - - - unsigned int i,j; - unsigned int nbpasses = x->x_nbpasses; - - short int * idata = (short int *)data0; - - int orient; - - - - - orient = PDP_IMAGEPROC_CONV_VERTICAL; - if (x->x_vertical){ - pdp_imageproc_conv_process(x->x_convolver_ver, idata, w, h, orient, nbpasses); - pdp_imageproc_conv_process(x->x_convolver_ver, idata+v_offset, w>>1, h>>1, orient, nbpasses); - pdp_imageproc_conv_process(x->x_convolver_ver, idata+u_offset, w>>1, h>>1, orient, nbpasses); - } - - - - orient = PDP_IMAGEPROC_CONV_HORIZONTAL; - if (x->x_horizontal){ - pdp_imageproc_conv_process(x->x_convolver_hor, idata, w, h, orient, nbpasses); - pdp_imageproc_conv_process(x->x_convolver_hor, idata+v_offset, w>>1, h>>1, orient, nbpasses); - pdp_imageproc_conv_process(x->x_convolver_hor, idata+u_offset, w>>1, h>>1, orient, nbpasses); - } - - - return; - - -} -static void pdp_conv_process_grey(t_pdp_conv *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - - - unsigned int i,j; - unsigned int nbpasses = x->x_nbpasses; - - short int * idata = (short int *)data0; - - int orient; - - if (x->x_vertical){ - orient = PDP_IMAGEPROC_CONV_VERTICAL; - pdp_imageproc_conv_process(x->x_convolver_ver, idata, w, h, orient, nbpasses); - } - - if (x->x_horizontal){ - orient = PDP_IMAGEPROC_CONV_HORIZONTAL; - pdp_imageproc_conv_process(x->x_convolver_hor, idata, w, h, orient, nbpasses); - } - - -} - -static void pdp_conv_process(t_pdp_conv *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_conv_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_conv_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_conv_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - -static void pdp_conv_sendpacket(t_pdp_conv *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_conv_input_0(t_pdp_conv *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_conv_process, pdp_conv_sendpacket, &x->x_queue_id); - } - -} - - - - -static void pdp_conv_passes(t_pdp_conv *x, t_floatarg f) -{ - int passes = (int)f; - passes = passes < 0 ? 0 : passes; - x->x_nbpasses = passes; - -} -static void pdp_conv_hor(t_pdp_conv *x, t_floatarg f) -{ - int hor = (int)f; - x->x_horizontal = (hor != 0); - -} -static void pdp_conv_ver(t_pdp_conv *x, t_floatarg f) -{ - int ver = (int)f; - x->x_vertical = (ver != 0); -} -static void pdp_conv_free(t_pdp_conv *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_conv_delete(x->x_convolver_hor); - pdp_imageproc_conv_delete(x->x_convolver_ver); - pdp_packet_mark_unused(x->x_packet0); - -} - -/* setup hmask */ - -static void pdp_conv_hleft(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setmin1(x->x_convolver_hor, f); - -} -static void pdp_conv_hmiddle(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setzero(x->x_convolver_hor, f); -} -static void pdp_conv_hright(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setplus1(x->x_convolver_hor, f); -} - -static void pdp_conv_hmask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) -{ - pdp_conv_hleft(x, l); - pdp_conv_hmiddle(x, m); - pdp_conv_hright(x, r); -} - -static void pdp_conv_vtop(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setmin1(x->x_convolver_ver, f); -} -static void pdp_conv_vmiddle(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setzero(x->x_convolver_ver, f); - -} -static void pdp_conv_vbottom(t_pdp_conv *x, t_floatarg f) -{ - pdp_imageproc_conv_setplus1(x->x_convolver_ver, f); -} - -static void pdp_conv_vmask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) -{ - pdp_conv_vtop(x, l); - pdp_conv_vmiddle(x, m); - pdp_conv_vbottom(x, r); -} - - -static void pdp_conv_mask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) -{ - pdp_conv_hmask(x, l, m, r); - pdp_conv_vmask(x, l, m, r); -} - -t_class *pdp_conv_class; - - - -void *pdp_conv_new(void) -{ - t_pdp_conv *x = (t_pdp_conv *)pd_new(pdp_conv_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("passes")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_nbpasses = 1; - x->x_horizontal = true; - x->x_vertical = true; - - x->x_convolver_hor = pdp_imageproc_conv_new(); - x->x_convolver_ver = pdp_imageproc_conv_new(); - - pdp_imageproc_conv_setbordercolor(x->x_convolver_hor, 0); - pdp_imageproc_conv_setbordercolor(x->x_convolver_ver, 0); - - pdp_conv_mask(x, .25,.5,.25); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_conv_setup(void) -{ - - - pdp_conv_class = class_new(gensym("pdp_conv"), (t_newmethod)pdp_conv_new, - (t_method)pdp_conv_free, sizeof(t_pdp_conv), 0, A_NULL); - - - class_addmethod(pdp_conv_class, (t_method)pdp_conv_passes, gensym("passes"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_hor, gensym("hor"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_ver, gensym("ver"), A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_conv_class, (t_method)pdp_conv_hleft, gensym("hleft"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_hmiddle, gensym("hmiddle"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_hright, gensym("hright"), A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_conv_class, (t_method)pdp_conv_vtop, gensym("vtop"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_vmiddle, gensym("vmiddle"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_vbottom, gensym("vbottom"), A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_conv_class, (t_method)pdp_conv_vmask, gensym("vmask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_hmask, gensym("hmask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_conv_class, (t_method)pdp_conv_mask, gensym("mask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - - class_addmethod(pdp_conv_class, (t_method)pdp_conv_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_del.c b/modules/pdp_del.c deleted file mode 100644 index 50813e3..0000000 --- a/modules/pdp_del.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_del_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - t_outlet **x_outlet; - - int *x_packet; - int x_order; - int x_head; - int x_delay; -} t_pdp_del; - - - - - -static void pdp_del_input_0(t_pdp_del *x, t_symbol *s, t_floatarg f) -{ - int in; - int out; - int packet; - - - /* if this is a register_ro message or register_rw message, register with packet factory */ - /* if this is a process message, start the processing + propagate stuff to outputs */ - - if (s == gensym("register_ro")){ - in = (x->x_head % x->x_order); - //post("pdp_del: marking unused packed id=%d on loc %d", x->x_packet[0], in); - pdp_packet_mark_unused(x->x_packet[in]); - packet = pdp_packet_copy_ro((int)f); - x->x_packet[in] = packet; - //post("pdp_del: writing packed id=%d on loc %d", packet, in); - } - else if (s == gensym("process")){ - out = (((x->x_head + x->x_delay)) % x->x_order); - packet = x->x_packet[out]; - - if (-1 != packet){ - //post("pdp_del: packet %d has id %d", out, packet); - pdp_packet_mark_unused(packet); - outlet_pdp(x->x_outlet0, packet); - x->x_packet[out] = -1; - } - else { - //post("pdp_del: packet %d is empty", out); - } - x->x_head = (x->x_head + x->x_order - 1) % x->x_order; - } - - -} - - - - - -static void pdp_del_delay(t_pdp_del *x, t_floatarg fdel) -{ - int del = (int)fdel; - if (del < 0) del = 0; - if (del >= x->x_order) del = x->x_order - 1; - - x->x_delay = del; - -} - -static void pdp_del_reset(t_pdp_del *x) -{ - int i; - for (i=0; i<x->x_order; i++) { - pdp_packet_mark_unused(x->x_packet[i]); - x->x_packet[i] = -1; - } - x->x_head = 0; - -} - -static void pdp_del_free(t_pdp_del *x) -{ - pdp_del_reset(x); - free (x->x_packet); -} - -t_class *pdp_del_class; - - - -void *pdp_del_new(t_floatarg forder, t_floatarg fdel) -{ - int order = (int)forder; - int del; - int logorder; - int i; - t_pdp_del *x = (t_pdp_del *)pd_new(pdp_del_class); - - del = order; - order++; - - if (del < 0) del = 0; - if (order <= 2) order = 2; - - //post("pdp_del: order = %d", order); - - x->x_order = order; - x->x_packet = (int *)malloc(sizeof(int)*order); - for(i=0; i<order; i++) x->x_packet[i] = -1; - x->x_delay = del; - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("delay")); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_del_setup(void) -{ - - - pdp_del_class = class_new(gensym("pdp_del"), (t_newmethod)pdp_del_new, - (t_method)pdp_del_free, sizeof(t_pdp_del), 0, A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_del_class, (t_method)pdp_del_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_del_class, (t_method)pdp_del_delay, gensym("delay"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_del_class, (t_method)pdp_del_reset, gensym("reset"), A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_gain.c b/modules/pdp_gain.c deleted file mode 100644 index a334656..0000000 --- a/modules/pdp_gain.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - - -typedef struct pdp_gain_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - - int x_packet0; - int x_dropped; - int x_queue_id; - - void *x_gain_y; - void *x_gain_v; - void *x_gain_u; - -} t_pdp_gain; - - - -static void pdp_gain_process_yv12(t_pdp_gain *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - short int * idata = (short int *)data0; - unsigned int size = w*h; - - pdp_imageproc_gain_process(x->x_gain_y, idata, w, h); - pdp_imageproc_gain_process(x->x_gain_u, idata + size, w>>1, h>>1); - pdp_imageproc_gain_process(x->x_gain_v, idata + size + (size>>2) , w>>1, h>>1); - - - return; - - -} -static void pdp_gain_process_grey(t_pdp_gain *x) -{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - void *data0 = pdp_packet_data (x->x_packet0); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int size = w*h; - short int * idata = (short int *)data0; - - pdp_imageproc_gain_process(x->x_gain_y, idata, w, h); - - return; - - -} - -static void pdp_gain_process(t_pdp_gain *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_gain_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_gain_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_gain_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - -static void pdp_gain_sendpacket(t_pdp_gain *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_gain_input_0(t_pdp_gain *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_gain_process, pdp_gain_sendpacket, &x->x_queue_id); - } - -} - - - - -static void pdp_gain_gainy(t_pdp_gain *x, t_floatarg f) -{ - pdp_imageproc_gain_setgain(x->x_gain_y, f); -} - -static void pdp_gain_gainv(t_pdp_gain *x, t_floatarg f) -{ - pdp_imageproc_gain_setgain(x->x_gain_v, f); -} - -static void pdp_gain_gainu(t_pdp_gain *x, t_floatarg f) -{ - pdp_imageproc_gain_setgain(x->x_gain_u, f); -} - -static void pdp_gain_gain(t_pdp_gain *x, t_floatarg f) -{ - pdp_gain_gainy(x, f); - pdp_gain_gainv(x, f); - pdp_gain_gainu(x, f); - -} - - - -t_class *pdp_gain_class; - - - -void pdp_gain_free(t_pdp_gain *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_gain_delete(x->x_gain_y); - pdp_imageproc_gain_delete(x->x_gain_u); - pdp_imageproc_gain_delete(x->x_gain_v); -} - -void *pdp_gain_new(t_floatarg f) -{ - t_pdp_gain *x = (t_pdp_gain *)pd_new(pdp_gain_class); - - - /* no arg, or zero -> gain = 1 */ - if (f==0.0f) f = 1.0f; - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("gain")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - x->x_gain_y = pdp_imageproc_gain_new(); - x->x_gain_u = pdp_imageproc_gain_new(); - x->x_gain_v = pdp_imageproc_gain_new(); - pdp_gain_gain(x, f); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_gain_setup(void) -{ - - - pdp_gain_class = class_new(gensym("pdp_gain"), (t_newmethod)pdp_gain_new, - (t_method)pdp_gain_free, sizeof(t_pdp_gain), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_gain_class, (t_method)pdp_gain_gain, gensym("gain"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_gain_class, (t_method)pdp_gain_gainy, gensym("y"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_gain_class, (t_method)pdp_gain_gainu, gensym("v"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_gain_class, (t_method)pdp_gain_gainv, gensym("u"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_gain_class, (t_method)pdp_gain_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_gradient.c b/modules/pdp_gradient.c deleted file mode 100644 index 3af2a84..0000000 --- a/modules/pdp_gradient.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct yv12_palette_struct -{ - short int y; - short int u; - short int v; -} t_yv12_palette; - -typedef struct pdp_gradient_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_dropped; - int x_queue_id; - - t_yv12_palette x_palette[512]; - -} t_pdp_gradient; - - -unsigned int float2fixed(float f) -{ - f *= 0x8000; - if(f>0x7fff) f = 0x7fff; - if(f<-0x7fff) f = -0x7fff; - return (short int)f; -} - -static void pdp_gradient_yuv_index(t_pdp_gradient *x, - t_floatarg index, - t_floatarg y, - t_floatarg u, - t_floatarg v) -{ - int i = ((int)index) & 511; - x->x_palette[i].y = float2fixed(y); - x->x_palette[i].u = float2fixed(u); - x->x_palette[i].v = float2fixed(v); -} - -static void pdp_gradient_yuv(t_pdp_gradient *x, - t_floatarg y, - t_floatarg u, - t_floatarg v) -{ - int i; - float inc = 1.0f / 256.0f; - float frac = -1.0f; - for(i=-256; i<256; i++) { - pdp_gradient_yuv_index(x, i, frac*y, frac*u, frac*v); - frac += inc; - } -} - -static void pdp_gradient_rgb_index(t_pdp_gradient *x, - t_floatarg index, - t_floatarg r, - t_floatarg g, - t_floatarg b) -{ - float y,u,v; - - - y = 0.299f * r + 0.587f * g + 0.114f * b; - u = (r-y) * 0.713f; - v = (b-y) * 0.565f; - - pdp_gradient_yuv_index(x, index, y,u,v); -} - -static void pdp_gradient_rgb(t_pdp_gradient *x, - t_floatarg r, - t_floatarg g, - t_floatarg b) -{ - int i; - float inc = 1.0f / 256.0f; - float frac = -1.0f; - for(i=-256; i<256; i++) { - pdp_gradient_rgb_index(x, i, frac*r, frac*g, frac*b); - frac += inc; - } -} - -/* -static void pdp_gradient_hsv_index(t_pdp_gradient *x, - t_floatarg index, - t_floatarg h, - t_floatarg s, - t_floatarg v) -{ - float r,g,b; - - r = h; - g = s; - b = v; - - pdp_gradient_rgb_index(x, index, r,g,b); -} - -static void pdp_gradient_hsv(t_pdp_gradient *x, - t_floatarg h, - t_floatarg s, - t_floatarg v) -{ - int i; - float inc = 1.0f / 256.0f; - float frac = -1.0f; - for(i=-256; i<256; i++) { - pdp_gradient_hsv_index(x, i, h, s, frac*v); - frac += inc; - } -} -*/ - -static void pdp_gradient_process_grey(t_pdp_gradient *x) -{ - t_pdp *header = pdp_packet_header(x->x_packet0); - short int *data = (short int *)pdp_packet_data (x->x_packet0); - t_pdp *newheader = 0; - short int *newdata = 0; - int newpacket = -1; - - unsigned int w = header->info.image.width; - unsigned int h = header->info.image.height; - - unsigned int size = w*h; - unsigned int totalnbpixels = size; - unsigned int u_offset = size; - unsigned int v_offset = size + (size>>2); - - unsigned int row, col; - - newpacket = pdp_packet_new(PDP_IMAGE, (size + (size>>1))<<1); - newheader = pdp_packet_header(newpacket); - newdata = (short int *)pdp_packet_data(newpacket); - - newheader->info.image.encoding = PDP_IMAGE_YV12; - newheader->info.image.width = w; - newheader->info.image.height = h; - - /* convert every pixel according to palette */ - for(row=0; row < size; row += (w<<1)){ - for(col=0; col < w; col += 2){ - short int u_acc, v_acc; - short int grey; - - /* top left pixel */ - grey = ((data[row+col])>>7) & 511; - newdata[row+col] = x->x_palette[grey].y; - u_acc = (x->x_palette[grey].u)>>2; - v_acc = (x->x_palette[grey].v)>>2; - - /* top right pixel */ - grey = ((data[row+col+1])>>7) & 511; - newdata[row+col+1] = x->x_palette[grey].y; - u_acc += (x->x_palette[grey].u)>>2; - v_acc += (x->x_palette[grey].v)>>2; - - /* bottom left pixel */ - grey = ((data[row+col+w])>>7) & 511; - newdata[row+col+w] = x->x_palette[grey].y; - u_acc += (x->x_palette[grey].u)>>2; - v_acc += (x->x_palette[grey].v)>>2; - - /* bottom right pixel */ - grey = ((data[row+col+w+1])>>7) & 511; - newdata[row+col+w+1] = x->x_palette[grey].y; - u_acc += (x->x_palette[grey].u)>>2; - v_acc += (x->x_palette[grey].v)>>2; - - /* store uv comp */ - newdata[u_offset + (row>>2) + (col>>1)] = u_acc; - newdata[v_offset + (row>>2) + (col>>1)] = v_acc; - } - } - - - - /* delete source packet and replace with new packet */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = newpacket; - return; -} - -static void pdp_gradient_process_yv12(t_pdp_gradient *x) -{ - /* pdp_gradient_process only the luminance channel */ - pdp_gradient_process_grey(x); -} - - - -static void pdp_gradient_process(t_pdp_gradient *x) -{ - int encoding; - t_pdp *header = 0; - - /* check if image data packets are compatible */ - if ( (header = pdp_packet_header(x->x_packet0)) - && (PDP_IMAGE == header->type)){ - - /* pdp_gradient_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_gradient_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_gradient_process_grey(x); - break; - - default: - /* don't know the type, so dont pdp_gradient_process */ - - break; - } - } -} - -static void pdp_gradient_sendpacket(t_pdp_gradient *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_gradient_input_0(t_pdp_gradient *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - - /* add the process method and callback to the process queue */ - // since the process method creates a packet, this is not processed in the thread - // $$$TODO: fix this - //pdp_queue_add(x, pdp_gradient_process, pdp_gradient_sendpacket, &x->x_queue_id); - pdp_gradient_process(x); - pdp_gradient_sendpacket(x); - } - -} - - - -static void pdp_gradient_free(t_pdp_gradient *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_gradient_class; - - - -void *pdp_gradient_new(void) -{ - int i; - - t_pdp_gradient *x = (t_pdp_gradient *)pd_new(pdp_gradient_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - for (i=-256; i<256; i++){ - x->x_palette[i&511].y = i << 7; - x->x_palette[i&511].u = (-i) << 6; - x->x_palette[i&511].v = (i) << 5; - } - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_gradient_setup(void) -{ - - - pdp_gradient_class = class_new(gensym("pdp_gradient"), (t_newmethod)pdp_gradient_new, - (t_method)pdp_gradient_free, sizeof(t_pdp_gradient), 0, A_NULL); - - - class_addmethod(pdp_gradient_class, (t_method)pdp_gradient_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_gradient_class, (t_method)pdp_gradient_yuv, gensym("yuv"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_gradient_class, (t_method)pdp_gradient_rgb, gensym("rgb"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - // class_addmethod(pdp_gradient_class, (t_method)pdp_gradient_hsv, gensym("hsv"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_grey.c b/modules/pdp_grey.c deleted file mode 100644 index 0626ea9..0000000 --- a/modules/pdp_grey.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_grey_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - - int x_packet0; - -} t_pdp_grey; - - - -static void pdp_grey_process(t_pdp_grey *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *headernew; - int newpacket; - int w; - int h; - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* pdp_grey_process inputs and write into active inlet */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - w = header0->info.image.width; - h = header0->info.image.height; - newpacket = pdp_packet_new(PDP_IMAGE, w*h*2); - headernew = pdp_packet_header(newpacket); - headernew->info.image.encoding = PDP_IMAGE_GREY; - headernew->info.image.width = w; - headernew->info.image.height = h; - memcpy(pdp_packet_data(newpacket), pdp_packet_data(x->x_packet0), 2*w*h); - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = newpacket; - break; - - case PDP_IMAGE_GREY: - /* just pass along */ - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - -static void pdp_grey_sendpacket(t_pdp_grey *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_grey_input_0(t_pdp_grey *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0)){ - - pdp_grey_process(x); - pdp_grey_sendpacket(x); - } - -} - - - - -short int pdp_grey_fixedpoint(float f) -{ - - float min = (float)-0x7fff; - float max = (float)0x7fff; - f *= (float)0x100; - if (f>max) f = max; - if (f<min) f = min; - - return (short int)f; - -} - - -t_class *pdp_grey_class; - - - -void pdp_grey_free(t_pdp_grey *x) -{ -} - -void *pdp_grey_new(t_floatarg f) -{ - t_pdp_grey *x = (t_pdp_grey *)pd_new(pdp_grey_class); - - - /* no arg, or zero -> gain = 1 */ - if (f==0.0f) f = 1.0f; - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("gain")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_grey_setup(void) -{ - - - pdp_grey_class = class_new(gensym("pdp_grey"), (t_newmethod)pdp_grey_new, - (t_method)pdp_grey_free, sizeof(t_pdp_grey), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_grey_class, (t_method)pdp_grey_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_grey2mask.c b/modules/pdp_grey2mask.c deleted file mode 100644 index af6a99f..0000000 --- a/modules/pdp_grey2mask.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* this module converts a greyscale image or the luma channel of a colour image - to a colour image intensity mask, usable for multiplication */ - -#include "pdp.h" -#include "pdp_resample.h" - -typedef struct pdp_grey2mask_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_dropped; - int x_queue_id; - - -} t_pdp_grey2mask; - - - -static void pdp_grey2mask_process_grey(t_pdp_grey2mask *x) -{ - t_pdp *header = pdp_packet_header(x->x_packet0); - short int *data = (short int *)pdp_packet_data (x->x_packet0); - t_pdp *newheader = 0; - short int *newdata = 0; - int newpacket = -1; - - unsigned int w = header->info.image.width; - unsigned int h = header->info.image.height; - - unsigned int size = w*h; - unsigned int totalnbpixels = size; - unsigned int u_offset = size; - unsigned int v_offset = size + (size>>2); - - unsigned int row, col; - - newpacket = pdp_packet_new(PDP_IMAGE, (size + (size>>1))<<1); - newheader = pdp_packet_header(newpacket); - newdata = (short int *)pdp_packet_data(newpacket); - - newheader->info.image.encoding = PDP_IMAGE_YV12; - newheader->info.image.width = w; - newheader->info.image.height = h; - - - /* copy luma channel */ - memcpy(newdata, data, size * sizeof(s16)); - - /* subsample luma -> chroma channel */ - pdp_resample_halve(data, newdata+u_offset, w, h); - - /* copy this to the other chroma channel */ - memcpy(newdata+v_offset, newdata+u_offset, (size>>2)*sizeof(s16)); - - /* delete source packet and replace with new packet */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = newpacket; - return; -} - -static void pdp_grey2mask_process_yv12(t_pdp_grey2mask *x) -{ - /* process only the luminance channel */ - pdp_grey2mask_process_grey(x); -} - - - -static void pdp_grey2mask_process(t_pdp_grey2mask *x) -{ - int encoding; - t_pdp *header = 0; - - /* check if image data packets are compatible */ - if ( (header = pdp_packet_header(x->x_packet0)) - && (PDP_IMAGE == header->type)){ - - /* pdp_grey2mask_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_grey2mask_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_grey2mask_process_grey(x); - break; - - default: - /* don't know the type, so dont pdp_grey2mask_process */ - - break; - } - } -} - -static void pdp_grey2mask_sendpacket(t_pdp_grey2mask *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_grey2mask_input_0(t_pdp_grey2mask *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_ro")) x->x_dropped = pdp_packet_copy_ro_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - - /* add the process method and callback to the process queue */ - - //pdp_queue_add(x, pdp_grey2mask_process, pdp_grey2mask_sendpacket, &x->x_queue_id); - // since the process method creates a packet, this is not processed in the thread - // $$$TODO: fix this - pdp_grey2mask_process(x); - pdp_grey2mask_sendpacket(x); - } - -} - - - -static void pdp_grey2mask_free(t_pdp_grey2mask *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_grey2mask_class; - - - -void *pdp_grey2mask_new(void) -{ - int i; - - t_pdp_grey2mask *x = (t_pdp_grey2mask *)pd_new(pdp_grey2mask_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_packet0 = -1; - x->x_queue_id = -1; - - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_grey2mask_setup(void) -{ - - - pdp_grey2mask_class = class_new(gensym("pdp_grey2mask"), (t_newmethod)pdp_grey2mask_new, - (t_method)pdp_grey2mask_free, sizeof(t_pdp_grey2mask), 0, A_NULL); - - - class_addmethod(pdp_grey2mask_class, (t_method)pdp_grey2mask_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_mix.c b/modules/pdp_mix.c deleted file mode 100644 index 9602c4b..0000000 --- a/modules/pdp_mix.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_mix_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - t_outlet *x_outlet1; - - int x_packet0; // hot packet - int x_packet1; // cold packet - int x_packet1next; // next cold packet - int x_dropped; - - int x_queue_id; // identifier of method in the processing queue - - void *x_mixer; - - int x_extrapolate; - -} t_pdp_mix; - - - -static void pdp_mix_process_yv12(t_pdp_mix *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - - h = h + (h>>1); - pdp_imageproc_mix_process(x->x_mixer,(short int*)data0, (short int*)data1, w, h); - - return; - - - -} - -static void pdp_mix_process_grey(t_pdp_mix *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - pdp_imageproc_mix_process(x->x_mixer,(short int*)data0, (short int*)data1, w, h); - - return; - - - -} - -static void pdp_mix_process(t_pdp_mix *x) -{ - int encoding; - - /* check if image data packets are compatible */ - if (pdp_type_compat_image(x->x_packet0, x->x_packet1)){ - - /* dispatch to process thread */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_mix_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_mix_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont pdp_mix_process */ - - } - } - -} - -static void pdp_mix_sendpacket(t_pdp_mix *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_mix_input_0(t_pdp_mix *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* if a cold packet was received in the meantime - swap it in, else keep the old one */ - - pdp_replace_if_valid(&x->x_packet1, &x->x_packet1next); - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_mix_process, pdp_mix_sendpacket, &x->x_queue_id); - } - -} - -static void pdp_mix_input_1(t_pdp_mix *x, t_symbol *s, t_floatarg f) -{ - /* store the packet and drop - the old one, if there is any */ - - if(s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet1next, (int)f); - -} - - - -static void pdp_mix_mix(t_pdp_mix *x, t_floatarg f) -{ - float f2; - if (!x->x_extrapolate){ - if (f < 0.0f) f = 0.0f; - if (f > 1.0f) f = 1.0f; - } - - f2 = (1.0f - f); - pdp_imageproc_mix_setleftgain(x->x_mixer, f2); - pdp_imageproc_mix_setrightgain(x->x_mixer, f); - -} - -static void pdp_mix_mix1(t_pdp_mix *x, t_floatarg f) -{ - pdp_imageproc_mix_setleftgain(x->x_mixer, f); - -} -static void pdp_mix_mix2(t_pdp_mix *x, t_floatarg f2) -{ - pdp_imageproc_mix_setrightgain(x->x_mixer, f2); -} - -static void pdp_mix_extrapolate(t_pdp_mix *x, t_floatarg f) -{ - if (f == 0.0f) x->x_extrapolate = 0; - if (f == 1.0f) x->x_extrapolate = 1; -} - - -static void pdp_mix_free(t_pdp_mix *x) -{ - /* remove the method from the queue before deleting stuff */ - pdp_queue_finish(x->x_queue_id); - - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); - pdp_packet_mark_unused(x->x_packet1next); - - pdp_imageproc_mix_delete(x->x_mixer); -} - -t_class *pdp_mix_class; -t_class *pdp_mix2_class; - - -void *pdp_mix_common_init(t_pdp_mix *x) -{ - int i; - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_packet1next = -1; - x->x_queue_id = -1; - x->x_extrapolate = 0; - - - x->x_mixer = pdp_imageproc_mix_new(); - pdp_mix_mix(x, 0.0f); - - - return (void *)x; -} - - -void *pdp_mix_new(t_floatarg mix) -{ - t_pdp_mix *x = (t_pdp_mix *)pd_new(pdp_mix_class); - pdp_mix_common_init(x); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("mix")); - if (mix == 0.0f) mix = 0.5f; - pdp_mix_mix(x, mix); - return (void *)x; -} - -void *pdp_mix2_new(t_floatarg mix1, t_floatarg mix2) -{ - t_pdp_mix *x = (t_pdp_mix *)pd_new(pdp_mix2_class); - pdp_mix_common_init(x); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("mix1")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("mix2")); - if ((mix1 == 0.0f) && (mix2 == 0.0f)) mix1 = mix2 = 0.5f; - pdp_mix_mix1(x, mix1); - pdp_mix_mix2(x, mix2); - return (void *)x; -} - -#ifdef __cplusplus -extern "C" -{ -#endif - - - -void pdp_mix_setup(void) -{ - - - pdp_mix_class = class_new(gensym("pdp_mix"), (t_newmethod)pdp_mix_new, - (t_method)pdp_mix_free, sizeof(t_pdp_mix), 0, A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_mix_class, (t_method)pdp_mix_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix_class, (t_method)pdp_mix_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix_class, (t_method)pdp_mix_mix, gensym("mix"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix_class, (t_method)pdp_mix_extrapolate, gensym("extrapolate"), A_DEFFLOAT, A_NULL); - - pdp_mix2_class = class_new(gensym("pdp_mix2"), (t_newmethod)pdp_mix2_new, - (t_method)pdp_mix_free, sizeof(t_pdp_mix), 0, A_DEFFLOAT, A_DEFFLOAT, A_NULL); - - class_addmethod(pdp_mix2_class, (t_method)pdp_mix_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix2_class, (t_method)pdp_mix_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix2_class, (t_method)pdp_mix_mix1, gensym("mix1"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix2_class, (t_method)pdp_mix_mix2, gensym("mix2"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mix2_class, (t_method)pdp_mix_extrapolate, gensym("extrapolate"), A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_mul.c b/modules/pdp_mul.c deleted file mode 100644 index 822a862..0000000 --- a/modules/pdp_mul.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_mul_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - t_outlet *x_outlet1; - - int x_packet0; - int x_packet1; - int x_packet1next; - int x_queue_id; - int x_dropped; - -} t_pdp_mul; - - -static void pdp_mul_process_yv12(t_pdp_mul *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - // set hight so it includes the chroma frames - h = h + (h>>1); - - pdp_imageproc_mul_process((short int*)data0, (short int*)data1, w, h); - - return; - - - -} -static void pdp_mul_process_grey(t_pdp_mul *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - - pdp_imageproc_mul_process((short int*)data0, (short int*)data1, w, h); - - return; -} - -static void pdp_mul_process(t_pdp_mul *x) -{ - int encoding; - - /* check if image data packets are compatible */ - if (pdp_type_compat_image(x->x_packet0, x->x_packet1)){ - - /* pdp_mul_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_mul_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_mul_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont pdp_mul_process */ - - } - } -} - -static void pdp_mul_sendpacket(t_pdp_mul *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_mul_input_0(t_pdp_mul *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* if a cold packet was received in the meantime - swap it in, else keep the old one */ - - pdp_replace_if_valid(&x->x_packet1, &x->x_packet1next); - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_mul_process, pdp_mul_sendpacket, &x->x_queue_id); - } - -} - -static void pdp_mul_input_1(t_pdp_mul *x, t_symbol *s, t_floatarg f) -{ - /* store the packet and drop - the old one, if there is any */ - - if(s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet1next, (int)f); - -} - - - - - - - -static void pdp_mul_free(t_pdp_mul *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); - -} - -t_class *pdp_mul_class; - - - -void *pdp_mul_new(void) -{ - t_pdp_mul *x = (t_pdp_mul *)pd_new(pdp_mul_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_packet1next = -1; - x->x_queue_id = -1; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_mul_setup(void) -{ - - - pdp_mul_class = class_new(gensym("pdp_mul"), (t_newmethod)pdp_mul_new, - (t_method)pdp_mul_free, sizeof(t_pdp_mul), 0, A_NULL); - - - - class_addmethod(pdp_mul_class, (t_method)pdp_mul_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_mul_class, (t_method)pdp_mul_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_noise.c b/modules/pdp_noise.c deleted file mode 100644 index 84f4a72..0000000 --- a/modules/pdp_noise.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - - -typedef struct pdp_noise_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - void *x_noisegen; - - int x_packet0; - int x_queue_id; - - int x_pdp_image_type; - - unsigned int x_width; - unsigned int x_height; - -} t_pdp_noise; - - - -void pdp_noise_type(t_pdp_noise *x, t_symbol *s) -{ - if (gensym("yv12") == s) {x->x_pdp_image_type = PDP_IMAGE_YV12; return;} - if (gensym("grey") == s) {x->x_pdp_image_type = PDP_IMAGE_GREY; return;} - - x->x_pdp_image_type = -1; - -} - - -void pdp_noise_random(t_pdp_noise *x, t_floatarg seed) -{ - if (seed == 0.0f) seed = (float)random(); - pdp_imageproc_random_setseed(x->x_noisegen, seed); - -} - - - -static void pdp_noise_createpacket_yv12(t_pdp_noise *x) -{ - /* create new packet */ - x->x_packet0 = pdp_packet_new_image_yv12(x->x_width, x->x_height); - - /* seed the 16 bit rng with a new random number from the clib */ - pdp_noise_random(x, 0.0f); -} - -static void pdp_noise_generate_yv12(t_pdp_noise *x) -{ - short int *data; - unsigned int w = x->x_width; - unsigned int h = x->x_height; - - h = h + (h>>1); - - data = (short int *) pdp_packet_data(x->x_packet0); - - pdp_noise_random(x, 0.0f); - pdp_imageproc_random_process(x->x_noisegen, data, w, h); - - return; - -} - -static void pdp_noise_createpacket_grey(t_pdp_noise *x) -{ - /* create new packet */ - x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height); - - /* seed the 16 bit rng with a new random number from the clib */ - pdp_noise_random(x, 0.0f); -} - -static void pdp_noise_generate_grey(t_pdp_noise *x) -{ - unsigned int w = x->x_width; - unsigned int h = x->x_height; - short int *data = (short int *) pdp_packet_data(x->x_packet0); - - data = (short int *) pdp_packet_data(x->x_packet0); - - pdp_noise_random(x, 0.0f); - pdp_imageproc_random_process(x->x_noisegen, data, w, h); - - - return; -} - -static void pdp_noise_sendpacket(t_pdp_noise *x, t_floatarg w, t_floatarg h) -{ - /* propagate if valid */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - - -static void pdp_noise_bang(t_pdp_noise *x) -{ - - int encoding; - - /* if we have an active packet, don't do anything */ - if (-1 != x->x_packet0) return; - - switch(x->x_pdp_image_type){ - - case PDP_IMAGE_YV12: - pdp_noise_createpacket_yv12(x); // don't create inside thread!!! - pdp_queue_add(x, pdp_noise_generate_yv12, pdp_noise_sendpacket, &x->x_queue_id); - break; - - case PDP_IMAGE_GREY: - pdp_noise_createpacket_grey(x); // don't create inside thread!!! - pdp_queue_add(x, pdp_noise_generate_grey, pdp_noise_sendpacket, &x->x_queue_id); - break; - - default: - break; - - } - - - /* release the packet */ - - -} - -static void pdp_noise_dim(t_pdp_noise *x, t_floatarg w, t_floatarg h) -{ - x->x_width = pdp_imageproc_legalwidth((int)w); - x->x_height = pdp_imageproc_legalheight((int)h); - //post("dims %d %d", x->x_width, x->x_height); -} - - -static void pdp_noise_free(t_pdp_noise *x) -{ - - /* remove callback from process queue */ - pdp_queue_finish(x->x_queue_id); - - - /* tidy up */ - pdp_packet_mark_unused(x->x_packet0); - pdp_imageproc_random_delete(x->x_noisegen); - -} - -t_class *pdp_noise_class; - - - - -void *pdp_noise_new(void) -{ - int i; - - t_pdp_noise *x = (t_pdp_noise *)pd_new(pdp_noise_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_width = 320; - x->x_height = 240; - - x->x_noisegen = pdp_imageproc_random_new(); - - pdp_noise_random(x, 0.0f); - - pdp_noise_type(x, gensym("yv12")); - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - - -void pdp_noise_setup(void) -{ - - - pdp_noise_class = class_new(gensym("pdp_noise"), (t_newmethod)pdp_noise_new, - (t_method)pdp_noise_free, sizeof(t_pdp_noise), 0, A_NULL); - - class_addmethod(pdp_noise_class, (t_method)pdp_noise_random, gensym("seed"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_noise_class, (t_method)pdp_noise_type, gensym("type"), A_SYMBOL, A_NULL); - class_addmethod(pdp_noise_class, (t_method)pdp_noise_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_noise_class, (t_method)pdp_noise_bang, gensym("bang"), A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_qt.c b/modules/pdp_qt.c deleted file mode 100644 index 8ed633d..0000000 --- a/modules/pdp_qt.c +++ /dev/null @@ -1,949 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -#include "pdp.h" -#include "pdp_llconv.h" -#include <quicktime/lqt.h> -#include <quicktime/colormodels.h> - - -#define min(x,y) ((x<y)?(x):(y)) - - - -#define FREE(x) {if (x) {free(x); x=0;} else post("free null pointer");} - - -/* debug macro */ -//#define DEBUG_MSG_ENABLED - -#ifdef DEBUG_MSG_ENABLED - -#define DEBUG_MSG(EXP)\ -fprintf (stderr, "mark start: [" #EXP "], on line %d\n", __LINE__);\ - EXP \ -fprintf (stderr, "mark end: [" #EXP "], on line %d\n", __LINE__); - -#else -#define DEBUG_MSG(EXP) EXP -#endif - -typedef struct pdp_qt_struct -{ - t_object x_obj; - t_float x_f; - - float x_gain; - - - t_symbol *x_name; // this is our name - int x_istilde; // 0==pdp_qt / 1==pdp_qt~ - int x_syncaudio; - - - /* clock object */ - t_clock *x_clock; - int x_counter; - int x_queue_id; - - /* audio outlets */ - t_outlet *x_outleft; - t_outlet *x_outright; - - /* message outlets */ - t_outlet *x_outlet0; - t_outlet *x_outlet1; - t_outlet *x_outlet2; - - /* pdp data */ - int x_packet0; - - /* toggles */ - int x_loop; - int x_autoplay; - - /* qt data */ - unsigned char ** x_qt_rows; // pointer array to rows / colour planes - float ** x_qt_audiochans; // pointer array to audio channel buffers - unsigned char * x_qt_frame; - quicktime_t *x_qt; - int x_qt_cmodel; - - //t_pdp_qt_data *x_state_data; - - /* audio data */ - int x_chunk_current; - float *x_chunk_buf; - float *x_chunk[2][2]; - int x_chunk_used[2]; // marks if chunk is used or not - int x_chunk_size; - int x_chunk_pos; - - /* global state */ - int x_initialized; - int x_frame; - int x_frame_thread; - int x_process_in_thread; - - - /* audio info */ - int x_audio_tracks; // ==0 means audio not available - int x_audio_channels; - long x_audio_samplerate; - long x_audio_length; - - /* video info */ - int x_video_tracks; // ==0 means video not available - float x_video_framerate; - long x_video_length; - unsigned int x_video_width; - unsigned int x_video_height; - - -} t_pdp_qt; - - -static void pdp_qt_bang(t_pdp_qt *x); - -static void pdp_qt_close(t_pdp_qt *x) -{ - /* disable clock */ - clock_unset(x->x_clock); - pdp_queue_finish(x->x_queue_id); - - if (x->x_initialized){ - /* close file */ - quicktime_close(x->x_qt); - x->x_initialized = 0; - - - /* free video data */ - if (x->x_video_tracks){ - FREE(x->x_qt_frame); - FREE(x->x_qt_rows); - x->x_video_tracks = 0; - //x->x_qt_rows = 0; - //x->x_qt_frame = 0; - } - - /* free audio data */ - if (x->x_audio_tracks){ - x->x_chunk_used[0] = 0; - x->x_chunk_used[1] = 0; - FREE(x->x_chunk_buf); - FREE(x->x_qt_audiochans); - x->x_audio_tracks = 0; - //x->x_qt_audiochans = 0; - //x->x_chunk_buf = 0; - x->x_chunk[0][0] = 0; - x->x_chunk[0][1] = 0; - x->x_chunk[1][0] = 0; - x->x_chunk[1][1] = 0; - } - - - } - - -} - -void pdp_qt_create_pdp_packet(t_pdp_qt *x) -{ - t_pdp *header; - - - /* round to next legal size */ - /* if size is illegal, image distortion will occur */ - u32 w = pdp_imageproc_legalwidth(x->x_video_width); - u32 h = pdp_imageproc_legalheight(x->x_video_height); - - - int nbpixels = w * h; - int packet_size = (nbpixels + (nbpixels >> 1)) << 1; - - - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_new(PDP_IMAGE, packet_size); - header = pdp_packet_header(x->x_packet0); - - //header->info.image.encoding = (x->x_qt_cmodel == BC_RGB888) ? PDP_IMAGE_GREY : PDP_IMAGE_YV12; - header->info.image.encoding = PDP_IMAGE_YV12; - header->info.image.width = w; - header->info.image.height = h; -} - - - - -static void pdp_qt_open(t_pdp_qt *x, t_symbol *name) -{ - unsigned int size; - unsigned int i; - unsigned int chunk_bytesize; - - post("%s: opening %s", x->x_name->s_name, name->s_name); - - - /* close previous one */ - pdp_qt_close(x); - - - /* check if qt file */ - if(0 == quicktime_check_sig(name->s_name)){ - post("%s: ERROR: not a quicktime file", x->x_name->s_name); - goto exit; - } - - /* open */ - DEBUG_MSG(x->x_qt = quicktime_open(name->s_name, 1, 0);) - if (!(x->x_qt)){ - post("%s: ERROR: can't open file", x->x_name->s_name); - goto exit; - } - - /* check video */ - x->x_video_tracks = 0; - if (quicktime_has_video(x->x_qt)) { - x->x_video_framerate = quicktime_frame_rate (x->x_qt, 0); - x->x_video_length = quicktime_video_length (x->x_qt, 0); - x->x_video_width = quicktime_video_width (x->x_qt, 0); - x->x_video_height = quicktime_video_height (x->x_qt, 0); - post("%s: video stream found (%dx%d pixels, %0.00f fps, %d frames, %s codec)", - x->x_name->s_name, x->x_video_width, x->x_video_height, x->x_video_framerate, - x->x_video_length, quicktime_video_compressor(x->x_qt, 0)); - x->x_video_tracks = quicktime_video_tracks(x->x_qt); - - } - - - /* check audior */ - x->x_audio_tracks = 0; - if (quicktime_has_audio(x->x_qt)) { - x->x_audio_tracks = quicktime_audio_tracks (x->x_qt); - //x->x_audio_channels = quicktime_track_channels (x->x_qt, 0); - x->x_audio_channels = lqt_total_channels (x->x_qt); - x->x_audio_samplerate = quicktime_sample_rate (x->x_qt, 0); - x->x_audio_length = quicktime_audio_length (x->x_qt, 0); - x->x_chunk_size = (int)((float)x->x_audio_samplerate / x->x_video_framerate); - post("%s: audio stream found (%d channels, %d Hz, %d samples, chunksize %d)", - x->x_name->s_name, x->x_audio_channels, x->x_audio_samplerate, x->x_audio_length, x->x_chunk_size); - } - - /* check if video codec is supported */ - if (x->x_video_tracks){ - if (!quicktime_supported_video(x->x_qt,0)) { - post("%s: WARNING: unsupported video codec",x->x_name->s_name); - x->x_video_tracks = 0; - } - } - - /* check if audio codec is supported */ - if (x->x_audio_tracks){ - if (!quicktime_supported_audio(x->x_qt,0)) { - post("%s: WARNING: unsupported audio codec", x->x_name->s_name); - x->x_audio_tracks = 0; - } - } - - - - /* check which colormodel to use */ - if (x->x_video_tracks){ - - if (quicktime_reads_cmodel(x->x_qt,BC_YUV420P,0)){ - post("%s: using colormodel YUV420P", x->x_name->s_name); - x->x_qt_cmodel = BC_YUV420P; - } - else if (quicktime_reads_cmodel(x->x_qt,BC_YUV422,0)){ - post("%s: using colormodel YUV422", x->x_name->s_name); - x->x_qt_cmodel = BC_YUV422; - } - else if (quicktime_reads_cmodel(x->x_qt,BC_RGB888,0)){ - post("%s: using colormodel RGB888", x->x_name->s_name); - x->x_qt_cmodel = BC_RGB888; - } - else { - post("%s: WARNING: can't find a usable colour model", x->x_name->s_name); - x->x_video_tracks = 0; - } - - } - - - - /* no video == errors */ - if (!x->x_video_tracks) { - post("%s: ERROR: no usable video stream found.", x->x_name->s_name); - goto exit_close; - } - - - /* initialize video data structures */ - if (x->x_video_tracks){ - - /* allocate enough space for all supported colormodels (24bpp)*/ - x->x_frame = 0; - x->x_qt_frame = (unsigned char*)malloc(x->x_video_width * x->x_video_height * 3); - x->x_qt_rows = (unsigned char **)malloc(sizeof(unsigned char *) * x->x_video_height); - size = x->x_video_width * x->x_video_height; - - switch(x->x_qt_cmodel){ - case BC_YUV420P: - /* planar with u&v 2x2 subsampled */ - x->x_qt_rows[0] = &x->x_qt_frame[0]; - x->x_qt_rows[2] = &x->x_qt_frame[size]; - x->x_qt_rows[1] = &x->x_qt_frame[size + (size>>2)]; - break; - - case BC_YUV422: - /* packed with u&v 2x subsampled (lines) */ - /* later on we will convert this to planar */ - for(i=0; i< x->x_video_height; i++) x->x_qt_rows[i] = &x->x_qt_frame[i * x->x_video_width * 2]; - break; - - case BC_RGB888: - /* packed rgb */ - /* later on we will convert this to planar */ - for(i=0; i< x->x_video_height; i++) x->x_qt_rows[i] = &x->x_qt_frame[i * x->x_video_width * 3]; - break; - - default: - post("%s: error on init: unkown colour model",x->x_name->s_name); - break; - } - - DEBUG_MSG(quicktime_set_cmodel(x->x_qt, x->x_qt_cmodel);) - pdp_qt_create_pdp_packet(x); - outlet_float(x->x_outlet2, (float)quicktime_video_length(x->x_qt,0)); - - } - - /* initialize audio data structures */ - if (x->x_audio_tracks){ - x->x_chunk_pos = 0; - x->x_chunk_current = 0; - - chunk_bytesize = sizeof(float)*x->x_chunk_size; - x->x_chunk_buf = (float *)malloc(chunk_bytesize * 4); - memset(x->x_chunk_buf, 0, chunk_bytesize * 4); - x->x_chunk[0][0] = x->x_chunk_buf; - x->x_chunk[0][1] = x->x_chunk_buf + x->x_chunk_size ; - x->x_chunk[1][0] = x->x_chunk_buf + x->x_chunk_size * 2; - x->x_chunk[1][1] = x->x_chunk_buf + x->x_chunk_size * 3; - x->x_chunk_used[0] = 0; - x->x_chunk_used[1] = 0; - x->x_syncaudio = x->x_istilde; //sync on audio if this is a tilde object - - DEBUG_MSG(if (x->x_audio_channels == 0) exit(1);) - x->x_qt_audiochans = (float **)malloc(x->x_audio_channels * sizeof(float **)); - memset(x->x_qt_audiochans, 0, x->x_audio_channels * sizeof(float **)); - } - else { - x->x_syncaudio = 0; - } - - - /* everything went well */ - x->x_initialized = 1; - - /* start playback if outplay is on */ - if(x->x_autoplay) clock_delay(x->x_clock, 1000.0L / (double)x->x_video_framerate); - - /* brag about success */ - post("%s: %s opened", x->x_name->s_name, name->s_name); - - return; - - /* error exits */ - - exit_close: - DEBUG_MSG(quicktime_close(x->x_qt);) - - exit: - x->x_initialized = 0; - x->x_audio_tracks = 0; - x->x_video_tracks = 0; - return; - -} - - -//static void pdp_qt_setposition(t_pdp_qt *x, int pos) -//{ -// x->x_frame = pos; -// DEBUG_MSG(if(x->x_video_tracks) quicktime_set_video_position(x->x_qt, pos, 0);) -// DEBUG_MSG(if(x->x_audio_tracks) quicktime_set_audio_position(x->x_qt, pos * x->x_chunk_size, 0);) -// -//} - - -static void pdp_qt_bangaudio(t_pdp_qt *x) -{ - int lefterr=0; - int righterr=0; - int err=0; - int sample = 0; - int remaining = 0; - int readamount = 0; - - - - if (!x->x_initialized){ - //post("pdp_qt: no qt file opened"); - return; - } - - - if (!x->x_audio_tracks){ - //post("pdp_qt: no audio stream present"); - return; - } - - - - //DEBUG_MSG(sample = quicktime_audio_position(x->x_qt,0);) - - - // if the active chunk is unused, clear it and mark it used - if (!x->x_chunk_used[x->x_chunk_current]){ - //post("%s: clearing unused active chunk",x->x_name->s_name); - - - - //probably this is the !@#%&*(*)&!$() bug - //memset(x->x_chunk[0][x->x_chunk_current], 0, sizeof(float)*2*x->x_chunk_size); - //memset(x->x_chunk[1][x->x_chunk_current], 0, sizeof(float)*2*x->x_chunk_size); - - memset(x->x_chunk[0][x->x_chunk_current], 0, sizeof(float) * x->x_chunk_size); - memset(x->x_chunk[1][x->x_chunk_current], 0, sizeof(float) * x->x_chunk_size); - - - - - x->x_chunk_used[x->x_chunk_current] = 1; - } - - // compute the remaining time - DEBUG_MSG(remaining = (int ) ( quicktime_audio_length(x->x_qt, 0) - quicktime_audio_position(x->x_qt, 0) );) - readamount = min(remaining, x->x_chunk_size); - if (!readamount) return; - - - // if the inactive chunk is unused, fill it with the current frame's audio data and mark it used - if (!x->x_chunk_used[!x->x_chunk_current]){ - switch(x->x_audio_channels){ - case 1: - x->x_qt_audiochans[0] = x->x_chunk[0][!x->x_chunk_current]; - x->x_qt_audiochans[1] = 0; - DEBUG_MSG(err = lqt_decode_audio(x->x_qt, NULL, x->x_qt_audiochans, readamount);) - break; - default: - x->x_qt_audiochans[0] = x->x_chunk[0][!x->x_chunk_current]; - x->x_qt_audiochans[1] = x->x_chunk[1][!x->x_chunk_current]; - DEBUG_MSG(err = lqt_decode_audio(x->x_qt, NULL, x->x_qt_audiochans, readamount);) - break; - } - x->x_chunk_used[!x->x_chunk_current] = 1; - } - // if it is used, something went wrong with sync - else{ - //post("%s: dropping audio chunk %d.",x->x_name->s_name, x->x_frame_thread); - } - - - if (err) post("%s: error decoding audio",x->x_name->s_name, x->x_frame_thread); - - // ensure audio pointer points to next frame's data - //DEBUG_MSG(quicktime_set_audio_position(x->x_qt, sample + readamount, 0);) - -} - - - - -static void pdp_qt_bangvideo(t_pdp_qt *x) -{ - unsigned int w, h, nbpixels, packet_size, i,j; - unsigned int *source, *dest; - unsigned int uoffset, voffset; - short int* data; - t_pdp* header; - - // check if we want greyscale output or not - //int grey = (x->x_qt_cmodel == BC_RGB888); - - static short int gain[4] = {0x7fff, 0x7fff, 0x7fff, 0x7fff}; - - if ((!x->x_initialized) || (!x->x_video_tracks)){ - //post("pdp_qt: no qt file opened"); - return; - } - - w = x->x_video_width; - h = x->x_video_height; - nbpixels = x->x_video_width * x->x_video_height; - - header = pdp_packet_header(x->x_packet0); - data = (short int *) pdp_packet_data(x->x_packet0); - - - DEBUG_MSG(lqt_decode_video(x->x_qt, x->x_qt_rows, 0);) - - - switch(x->x_qt_cmodel){ - case BC_YUV420P: - pdp_llconv(x->x_qt_frame, RIF_YVU__P411_U8, data, RIF_YVU__P411_S16, x->x_video_width, x->x_video_height); - break; - - case BC_YUV422: - pdp_llconv(x->x_qt_frame, RIF_YUYV_P____U8, data, RIF_YVU__P411_S16, x->x_video_width, x->x_video_height); - break; - - case BC_RGB888: - pdp_llconv(x->x_qt_frame, RIF_RGB__P____U8, data, RIF_YVU__P411_S16, x->x_video_width, x->x_video_height); - break; - - default: - post("%s: error on decode: unkown colour model",x->x_name->s_name); - break; - } - - - -} - -static void pdp_qt_sendpacket(t_pdp_qt *x) -{ - if (x->x_packet0 != -1){ - //pdp_packet_mark_unused(x->x_packet0); - outlet_pdp(x->x_outlet0, x->x_packet0); - //x->x_packet0 = -1; - } -} - - -static void pdp_qt_thread_bang(t_pdp_qt *x) -{ - // set audio position - if(x->x_video_tracks) quicktime_set_video_position(x->x_qt, x->x_frame_thread, 0); - - // bang video - pdp_qt_bangvideo(x); - - // if it's a tilde object, bang audio - if (x->x_istilde && x->x_audio_tracks){ - quicktime_set_audio_position(x->x_qt, x->x_frame_thread * x->x_chunk_size, 0); - pdp_qt_bangaudio(x); - } - -} - - -static void pdp_qt_bang(t_pdp_qt *x) -{ - int length, pos; - - /* return if not initialized */ - if (!x->x_initialized) return; - - //length = quicktime_video_length(x->x_qt,0); - //pos = quicktime_video_position(x->x_qt,0); - length = x->x_video_length; - pos = x->x_frame; - - - /* check bounds */ - if (x->x_loop){ - pos = x->x_frame % length; - if (pos < 0) pos += length; - } - else{ - if (pos < 0) pos = 0; - if (pos >= length) pos = length - 1; - } - - /* store next frame for access in thread */ - x->x_frame_thread = pos; - - - // if autoplay is on and we do not have audio synchro - // set clock to play next frame - if (x->x_autoplay && !x->x_syncaudio) clock_delay(x->x_clock, 1000.0L / (double)x->x_video_framerate); - - - // make sure prev decode is finished don't drop frames in this one - pdp_queue_finish(x->x_queue_id); - x->x_queue_id = -1; - - /* only decode new stuff if previous is done */ - if (-1 == x->x_queue_id){ - // send the current frame number to outlet - outlet_float(x->x_outlet1, (float)pos); - - //pdp_qt_setposition(x, pos); - - // start process method - if (x->x_process_in_thread) pdp_queue_add(x, pdp_qt_thread_bang, pdp_qt_sendpacket, &x->x_queue_id); - else { - pdp_qt_thread_bang(x); - pdp_qt_sendpacket(x); - } - } - // advance frame - x->x_frame = pos + 1; - - - // send the packet - //pdp_qt_sendpacket(x); -} - - - -//static void pdp_qt_getaudiochunk(t_pdp_qt *x, int channel) -//{ -// if (!x->x_audio_tracks) return; -// quicktime_decode_audio(x->x_qt, NULL, x->x_chunk[channel][x->x_chunk_current], x->x_chunk_size<<1, channel); -// -//} - -static void pdp_qt_loop(t_pdp_qt *x, t_floatarg loop) -{ - int loopi = (int)loop; - x->x_loop = !(loopi == 0); -} - -static void pdp_qt_autoplay(t_pdp_qt *x, t_floatarg play) -{ - int playi = (int)play; - x->x_autoplay = !(playi == 0); - - - // reset clock if autoplay is off - if (!x->x_autoplay) clock_unset(x->x_clock); - - -} - - - -static void pdp_qt_frame_cold(t_pdp_qt *x, t_floatarg frameindex) -{ - int frame = (int)frameindex; - //int length; - - - x->x_frame = frame; - - //if (!(x->x_initialized)) return; - - //length = quicktime_video_length(x->x_qt,0); - - //frame = (frame >= length) ? length-1 : frame; - //frame = (frame < 0) ? 0 : frame; - - //pdp_qt_setposition(x, frame); -} - -static void pdp_qt_frame(t_pdp_qt *x, t_floatarg frameindex) -{ - pdp_qt_frame_cold(x, frameindex); - pdp_qt_bang(x); -} - -static void pdp_qt_stop(t_pdp_qt *x) -{ - pdp_qt_autoplay(x, 0); -} - -static void pdp_qt_continue(t_pdp_qt *x) -{ - pdp_qt_autoplay(x, 1); - pdp_qt_bang(x); -} - - -static void pdp_qt_play(t_pdp_qt *x){ - pdp_qt_frame_cold(x, 0); - pdp_qt_continue(x); -} - - - - -static void pdp_qt_importaudio(t_pdp_qt *x, t_symbol *array, t_floatarg channel) -{ - int c = (int)channel; - t_garray *g; - int vecsize; - int sample; - float *f; - int i; - - /* if there's no audio, there's nothing to export */ - if (!x->x_audio_tracks) return; - - /* check audio channel */ - if ((c < 0) || (c >= x->x_audio_channels)) return; - - /* check if array exists */ - if (!(g = (t_garray *)pd_findbyclass(array, garray_class))){ - pd_error(x, "%s: no such table", array->s_name); - return; - } - - post("%s: importing audio channel %d into array %s", x->x_name->s_name, c, array->s_name); - - - // make sure decode is finished - pdp_queue_finish(x->x_queue_id); - x->x_queue_id = -1; - - - /* resize array */ - garray_resize(g, x->x_audio_length); - - /* for sanity's sake let's clear the save-in-patch flag here */ - garray_setsaveit(g, 0); - garray_getfloatarray(g, &vecsize, &f); - - /* if the resize failed, garray_resize reported the error */ - if (vecsize != x->x_audio_length){ - pd_error(x, "array resize failed"); - return; - } - - /* save pointer in file */ - DEBUG_MSG(sample = quicktime_audio_position(x->x_qt, 0);) - DEBUG_MSG(quicktime_set_audio_position(x->x_qt, 0, 0);) - - /* transfer the audio file to the end of the array */ - DEBUG_MSG(quicktime_decode_audio(x->x_qt, NULL, f, vecsize, c);) - - /* restore pointer in file */ - DEBUG_MSG(quicktime_set_audio_position(x->x_qt, sample, 0);) - - -} - - - -static t_int *pdp_qt_perform(t_int *w) -{ - t_pdp_qt *x = (t_pdp_qt *)w[1]; - t_float *out0 = (t_float *)w[2]; - t_float *out1 = (t_float *)w[3]; - t_int n = (t_int)w[4]; - - t_int xfer_samples; - if (!x->x_initialized || !x->x_audio_tracks) goto zero; - - while(1){ - // check current chunk - if (!x->x_chunk_used[x->x_chunk_current]) goto zero; - - - // transfer from chunk to output - xfer_samples = min(n, x->x_chunk_size - x->x_chunk_pos); - - //x->x_audio_channels = 1; - - if (x->x_audio_channels == 1){ - memcpy(out0, x->x_chunk[0][x->x_chunk_current] + x->x_chunk_pos, sizeof(float)*xfer_samples); - memcpy(out1, x->x_chunk[0][x->x_chunk_current] + x->x_chunk_pos, sizeof(float)*xfer_samples); - } - else { - memcpy(out0, x->x_chunk[0][x->x_chunk_current] + x->x_chunk_pos, sizeof(float)*xfer_samples); - memcpy(out1, x->x_chunk[1][x->x_chunk_current] + x->x_chunk_pos, sizeof(float)*xfer_samples); - } - out0 += xfer_samples; - out1 += xfer_samples; - n -= xfer_samples; - x->x_chunk_pos += xfer_samples; - - - // check if chunk is finished, if so mark unused, swap buffers and set clock - if (x->x_chunk_size == x->x_chunk_pos){ - x->x_chunk_used[x->x_chunk_current] = 0; - x->x_chunk_pos = 0; - x->x_chunk_current ^= 1; - if (x->x_autoplay) clock_delay(x->x_clock, 0L); - } - - // if chunk is not finished, the output buffer is full - else{ - goto exit; - } - - } - - - zero: - // fill the rest of the output with zeros - memset(out0, 0, sizeof(float)*n); - memset(out1, 0, sizeof(float)*n); - - exit: - return(w+5); -} - -static void pdp_qt_dsp(t_pdp_qt *x, t_signal **sp) -{ - dsp_add(pdp_qt_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); - -} - -static void pdp_qt_process_in_thread(t_pdp_qt *x, t_float f) -{ - - int t = (f != 0.0f); - - x->x_process_in_thread = t; - - post("pdp_qt: thread processing switched %d", t ? "on" : "off"); - -} - -static void pdp_qt_tick(t_pdp_qt *x) -{ - - // bang audio/video - pdp_qt_bang(x); -} - -static void pdp_qt_free(t_pdp_qt *x) -{ - clock_unset(x->x_clock); - pdp_qt_close(x); - clock_free(x->x_clock); - //free (x->x_state_data); - -} - - - -t_class *pdp_qt_class; -t_class *pdp_qt_tilde_class; - - -void pdp_qt_init_common(t_pdp_qt *x) -{ - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("frame_cold")); - - /* add common outlets */ - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_outlet1 = outlet_new(&x->x_obj, &s_float); - x->x_outlet2 = outlet_new(&x->x_obj, &s_float); - - /* init */ - x->x_gain = 1.0f; - x->x_process_in_thread = 0; - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_initialized = 0; - x->x_audio_tracks = 0; - x->x_video_tracks = 0; - x->x_loop = 0; - x->x_autoplay = 0; - x->x_chunk[0][0] = 0; - x->x_chunk[0][1] = 0; - x->x_chunk[1][0] = 0; - x->x_chunk[1][1] = 0; - - /* initialize clock object */ - x->x_clock = clock_new(x, (t_method)pdp_qt_tick); - - - - -} - -void *pdp_qt_new(void) -{ - t_pdp_qt *x = (t_pdp_qt *)pd_new(pdp_qt_class); - x->x_name = gensym("pdp_qt"); - x->x_istilde = 0; - pdp_qt_init_common(x); - return (void *)x; -} - -void *pdp_qt_tilde_new(void) -{ - t_pdp_qt *x = (t_pdp_qt *)pd_new(pdp_qt_tilde_class); - x->x_name = gensym("pdp_qt"); - x->x_istilde = 1; - - pdp_qt_init_common(x); - - /* add outlets to the right so pdp_qt~ can replace pdp_qt without breaking a patch */ - x->x_outleft = outlet_new(&x->x_obj, &s_signal); - x->x_outright = outlet_new(&x->x_obj, &s_signal); - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_qt_setup_common(t_class *class) -{ - class_addmethod(class, (t_method)pdp_qt_bang, gensym("bang"), A_NULL); - class_addmethod(class, (t_method)pdp_qt_close, gensym("close"), A_NULL); - class_addmethod(class, (t_method)pdp_qt_open, gensym("open"), A_SYMBOL, A_NULL); - class_addmethod(class, (t_method)pdp_qt_autoplay, gensym("autoplay"), A_DEFFLOAT, A_NULL); - class_addmethod(class, (t_method)pdp_qt_stop, gensym("stop"), A_NULL); - class_addmethod(class, (t_method)pdp_qt_play, gensym("play"), A_NULL); - class_addmethod(class, (t_method)pdp_qt_continue, gensym("cont"), A_NULL); - class_addmethod(class, (t_method)pdp_qt_loop, gensym("loop"), A_DEFFLOAT, A_NULL); - class_addfloat (class, (t_method)pdp_qt_frame); - class_addmethod(class, (t_method)pdp_qt_frame_cold, gensym("frame_cold"), A_FLOAT, A_NULL); - class_addmethod(class, (t_method)pdp_qt_process_in_thread, gensym("thread"), A_FLOAT, A_NULL); - class_addmethod(class, (t_method)pdp_qt_importaudio, gensym("importaudio"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(class, (t_method)pdp_qt_importaudio, gensym("dump"), A_SYMBOL, A_DEFFLOAT, A_NULL); -} - -void pdp_qt_setup(void) -{ - - /* plain class */ - pdp_qt_class = class_new(gensym("pdp_qt"), (t_newmethod)pdp_qt_new, - (t_method)pdp_qt_free, sizeof(t_pdp_qt), 0, A_NULL); - pdp_qt_setup_common(pdp_qt_class); - - - /* tilde class */ - pdp_qt_tilde_class = class_new(gensym("pdp_qt~"), (t_newmethod)pdp_qt_tilde_new, - (t_method)pdp_qt_free, sizeof(t_pdp_qt), 0, A_NULL); - pdp_qt_setup_common(pdp_qt_tilde_class); - - class_addmethod(pdp_qt_tilde_class, (t_method)pdp_qt_dsp, gensym("dsp"), 0); -} - -#ifdef __cplusplus -} -#endif - - diff --git a/modules/pdp_randmix.c b/modules/pdp_randmix.c deleted file mode 100644 index 3ffea27..0000000 --- a/modules/pdp_randmix.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_randmix_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - int x_packet1; - int x_packet1next; - int x_queue_id; - int x_dropped; - - void *x_randmixer; - -} t_pdp_randmix; - - -void pdp_randmix_random(t_pdp_randmix *x, t_floatarg seed) -{ - pdp_imageproc_randmix_setseed(x->x_randmixer, seed); -} - - - -static void pdp_randmix_process_yv12(t_pdp_randmix *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - h = h + (h>>1); - - pdp_imageproc_randmix_process(x->x_randmixer, (short int*)data0, (short int*)data1, w, h); - - return; - - - -} - -static void pdp_randmix_process_grey(t_pdp_randmix *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - pdp_imageproc_randmix_process(x->x_randmixer, (short int*)data0, (short int*)data1, w, h); - - return; - -} - -static void pdp_randmix_process(t_pdp_randmix *x) -{ - - int encoding; - - /* check if image data packets are compatible */ - if (pdp_type_compat_image(x->x_packet0, x->x_packet1)){ - - /* pdp_randmix_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_randmix_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_randmix_process_grey(x); - break; - - default: - break; - /* don't know the type, so dont pdp_randmix_process */ - - } - } - -} - -static void pdp_randmix_sendpacket(t_pdp_randmix *x) -{ - /* unregister and propagate if valid packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - -static void pdp_randmix_input_0(t_pdp_randmix *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_rw_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* if a cold packet was received in the meantime - swap it in, else keep the old one */ - - pdp_replace_if_valid(&x->x_packet1, &x->x_packet1next); - - - /* add the process method and callback to the process queue */ - - pdp_queue_add(x, pdp_randmix_process, pdp_randmix_sendpacket, &x->x_queue_id); - } - -} - -static void pdp_randmix_input_1(t_pdp_randmix *x, t_symbol *s, t_floatarg f) -{ - /* store the packet and drop - the old one, if there is any */ - - if(s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet1next, (int)f); - -} - - - - - -static void pdp_randmix_threshold(t_pdp_randmix *x, t_floatarg f) -{ - pdp_imageproc_randmix_setthreshold(x->x_randmixer, f); - -} - - - -static void pdp_randmix_free(t_pdp_randmix *x) -{ - pdp_queue_finish(x->x_queue_id); - - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); - - pdp_imageproc_randmix_delete(x->x_randmixer); - -} - -t_class *pdp_randmix_class; - - -void *pdp_randmix_new(void) -{ - int i; - - t_pdp_randmix *x = (t_pdp_randmix *)pd_new(pdp_randmix_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("threshold")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_packet1next = -1; - x->x_queue_id = -1; - - x->x_randmixer = pdp_imageproc_randmix_new(); - - pdp_randmix_threshold(x, 0.5f); - pdp_randmix_random(x, 0.0f); - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - - -void pdp_randmix_setup(void) -{ - - - pdp_randmix_class = class_new(gensym("pdp_randmix"), (t_newmethod)pdp_randmix_new, - (t_method)pdp_randmix_free, sizeof(t_pdp_randmix), 0, A_NULL); - - class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_threshold, gensym("threshold"), A_DEFFLOAT, A_NULL); - class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_random, gensym("seed"), A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_reg.c b/modules/pdp_reg.c deleted file mode 100644 index e3aa721..0000000 --- a/modules/pdp_reg.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - -typedef struct pdp_reg_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - -} t_pdp_reg; - - -static void pdp_reg_bang(t_pdp_reg *x) -{ - - if (-1 != x->x_packet0) outlet_pdp(x->x_outlet0, x->x_packet0); - -} - - - -static void pdp_reg_input_0(t_pdp_reg *x, t_symbol *s, t_floatarg f) -{ - - /* if this is a register_ro message or register_rw message, register with packet factory */ - - /* if this is a process message, start the processing + propagate stuff to outputs */ - - if (s == gensym("register_ro")){ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_copy_ro((int)f); - //post("in0ro: requested %d, got %d", (int)f, x->x_packet0); - } - else if (s == gensym("process")){ - pdp_reg_bang(x); - - } - - -} - - -static void pdp_reg_input_1(t_pdp_reg *x, t_symbol *s, t_floatarg f) -{ - - /* if this is a register_ro message or register_rw message, register with packet factory */ - - /* if this is a process message, start the processing + propagate stuff to outputs */ - - if (s == gensym("register_ro")){ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_copy_ro((int)f); - //post("in0ro: requested %d, got %d", (int)f, x->x_packet0); - } - -} - - - -static void pdp_reg_free(t_pdp_reg *x) -{ - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_reg_class; - - - -void *pdp_reg_new(void) -{ - t_pdp_reg *x = (t_pdp_reg *)pd_new(pdp_reg_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_reg_setup(void) -{ - - - pdp_reg_class = class_new(gensym("pdp_reg"), (t_newmethod)pdp_reg_new, - (t_method)pdp_reg_free, sizeof(t_pdp_reg), 0, A_NULL); - - - class_addmethod(pdp_reg_class, (t_method)pdp_reg_bang, gensym("bang"), A_NULL); - - class_addmethod(pdp_reg_class, (t_method)pdp_reg_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_reg_class, (t_method)pdp_reg_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_route.c b/modules/pdp_route.c deleted file mode 100644 index 02197ad..0000000 --- a/modules/pdp_route.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - -// dynamic ???? -#define PDP_ROUTE_MAX_NB_OUTLETS 100 - -typedef struct pdp_route_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet[PDP_ROUTE_MAX_NB_OUTLETS]; - - int x_nb_outlets; - int x_route; - int x_route_next; - - -} t_pdp_route; - - -static void pdp_route_input_0(t_pdp_route *x, t_symbol *s, t_floatarg f) -{ - t_atom atom[2]; - t_symbol *pdp = gensym("pdp"); - - - /* trigger on register_ro */ - if (s == gensym("register_ro")){ - x->x_route = x->x_route_next; - } - - /* propagate the pdp message */ - SETSYMBOL(atom+0, s); - SETFLOAT(atom+1, f); - outlet_anything(x->x_outlet[x->x_route], pdp, 2, atom); - -} - -static void pdp_route_route(t_pdp_route *x, t_floatarg f) -{ - int route = (int)f; - - if (route < 0) route = 0; - if (route >= x->x_nb_outlets) route = x->x_nb_outlets - 1; - - x->x_route_next = route; - -} - - - -static void pdp_route_free(t_pdp_route *x) -{ - -} - -t_class *pdp_route_class; - - - -void *pdp_route_new(t_floatarg f) -{ - int nboutlets = (int)f; - int i; - - t_pdp_route *x = (t_pdp_route *)pd_new(pdp_route_class); - - - if (nboutlets < 2) nboutlets = 2; - if (nboutlets >= PDP_ROUTE_MAX_NB_OUTLETS) nboutlets = PDP_ROUTE_MAX_NB_OUTLETS - 1; - - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("route")); - - x->x_nb_outlets = nboutlets; - x->x_route = 0; - x->x_route_next = 0; - - for (i=0; i<nboutlets; i++) - x->x_outlet[i] = outlet_new(&x->x_obj, &s_anything); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_route_setup(void) -{ - - - pdp_route_class = class_new(gensym("pdp_route"), (t_newmethod)pdp_route_new, - (t_method)pdp_route_free, sizeof(t_pdp_route), 0, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_route_class, (t_method)pdp_route_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_route_class, (t_method)pdp_route_route, gensym("route"), A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_scale.c b/modules/pdp_scale.c deleted file mode 100644 index 82c5257..0000000 --- a/modules/pdp_scale.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_resample.h" - - - -typedef struct pdp_scale_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - - int x_packet0; - int x_packet1; - int x_dropped; - int x_queue_id; - - unsigned int x_width; - unsigned int x_height; - int x_quality; - - -} t_pdp_scale; - - -static void pdp_scale_process_yv12(t_pdp_scale *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int src_w = header0->info.image.width; - unsigned int src_h = header0->info.image.height; - - unsigned int dst_w = header1->info.image.width; - unsigned int dst_h = header1->info.image.height; - - short int *src_image = (short int *)data0; - short int *dst_image = (short int *)data1; - - unsigned int src_size = src_w*src_h; - unsigned int src_voffset = src_size; - unsigned int src_uoffset = src_size + (src_size>>2); - - unsigned int dst_size = dst_w*dst_h; - unsigned int dst_voffset = dst_size; - unsigned int dst_uoffset = dst_size + (dst_size>>2); - - if (x->x_quality){ - pdp_resample_scale_bilin(src_image, dst_image, src_w, src_h, dst_w, dst_h); - pdp_resample_scale_bilin(src_image+src_voffset, dst_image+dst_voffset, src_w>>1, src_h>>1, dst_w>>1, dst_h>>1); - pdp_resample_scale_bilin(src_image+src_uoffset, dst_image+dst_uoffset, src_w>>1, src_h>>1, dst_w>>1, dst_h>>1); - } - else{ - pdp_resample_scale_nn(src_image, dst_image, src_w, src_h, dst_w, dst_h); - pdp_resample_scale_nn(src_image+src_voffset, dst_image+dst_voffset, src_w>>1, src_h>>1, dst_w>>1, dst_h>>1); - pdp_resample_scale_nn(src_image+src_uoffset, dst_image+dst_uoffset, src_w>>1, src_h>>1, dst_w>>1, dst_h>>1); - } - - return; -} - -static void pdp_scale_process_grey(t_pdp_scale *x) -{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int src_w = header0->info.image.width; - unsigned int src_h = header0->info.image.height; - - unsigned int dst_w = header1->info.image.width; - unsigned int dst_h = header1->info.image.height; - - short int *src_image = (short int *)data0; - short int *dst_image = (short int *)data1; - - if (x->x_quality) pdp_resample_scale_bilin(src_image, dst_image, src_w, src_h, dst_w, dst_h); - else pdp_resample_scale_nn(src_image, dst_image, src_w, src_h, dst_w, dst_h); - - return; - - -} - -static void pdp_scale_sendpacket(t_pdp_scale *x) -{ - /* delete source packet */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1; - - /* unregister and propagate if valid dest packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet1); -} - -static void pdp_scale_process(t_pdp_scale *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - /* if dims are equal, just send the packet */ - if ((header0->info.image.width == x->x_width) - && (header0->info.image.height == x->x_height)){ - x->x_packet1 = x->x_packet0; - x->x_packet0 = -1; - pdp_scale_sendpacket(x); - return; - } - - /* type hub */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - x->x_packet1 = pdp_packet_new_image_yv12(x->x_width, x->x_height); - pdp_queue_add(x, pdp_scale_process_yv12, pdp_scale_sendpacket, &x->x_queue_id); - break; - - case PDP_IMAGE_GREY: - x->x_packet1 = pdp_packet_new_image_grey(x->x_width, x->x_height); - pdp_queue_add(x, pdp_scale_process_grey, pdp_scale_sendpacket, &x->x_queue_id); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - - - -static void pdp_scale_input_0(t_pdp_scale *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_ro_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* add the process method and callback to the process queue */ - pdp_scale_process(x); - - } - -} - - - - -static void pdp_scale_width(t_pdp_scale *x, t_floatarg f) -{ - int i = (int)f; - if (i < 32) i = 32; - x->x_width = i; -} - -static void pdp_scale_height(t_pdp_scale *x, t_floatarg f) -{ - int i = (int)f; - if (i < 32) i = 32; - x->x_height = i; -} - - -static void pdp_scale_dim(t_pdp_scale *x, t_floatarg w, t_floatarg h) -{ - pdp_scale_width(x, w); - pdp_scale_height(x, h); -} - -static void pdp_scale_quality(t_pdp_scale *x, t_floatarg f) -{ - if (f==0) x->x_quality = 0; - if (f==1) x->x_quality = 1; -} - - -t_class *pdp_scale_class; - - - -void pdp_scale_free(t_pdp_scale *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); -} - -void *pdp_scale_new(t_floatarg fw, t_floatarg fh) -{ - t_pdp_scale *x = (t_pdp_scale *)pd_new(pdp_scale_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_queue_id = -1; - - if ((fw != 0.0f) && (fh != 0.0f)) pdp_scale_dim(x, fw, fh); - else pdp_scale_dim(x, 320, 240); - - pdp_scale_quality(x, 1); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_scale_setup(void) -{ - - - pdp_scale_class = class_new(gensym("pdp_scale"), (t_newmethod)pdp_scale_new, - (t_method)pdp_scale_free, sizeof(t_pdp_scale), 0, A_DEFFLOAT, A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_scale_class, (t_method)pdp_scale_quality, gensym("quality"), A_FLOAT, A_NULL); - class_addmethod(pdp_scale_class, (t_method)pdp_scale_width, gensym("width"), A_FLOAT, A_NULL); - class_addmethod(pdp_scale_class, (t_method)pdp_scale_height, gensym("height"), A_FLOAT, A_NULL); - class_addmethod(pdp_scale_class, (t_method)pdp_scale_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_scale_class, (t_method)pdp_scale_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_scan.c b/modules/pdp_scan.c deleted file mode 100644 index 49a985c..0000000 --- a/modules/pdp_scan.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_mmx.h" -#include <math.h> - -#define PDP_SCAN_COSTABLE_SIZE 1024 -static float pdp_cos[PDP_SCAN_COSTABLE_SIZE]; - -typedef struct pdp_scan_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - t_outlet *x_outlet1; - - float x_centerx; - float x_centery; - float x_sizeh; - float x_sizev; - - int x_packet0; - int x_packet1; - - int x_interpolate; - - -} t_pdp_scan; - - -static t_int *pdp_scan_perform(t_int *w) -{ - - t_pdp_scan *x = (t_pdp_scan *)(w[1]); - t_int n = (t_int)(w[2]); - t_float *in = (float *)(w[3]); - t_float *out = (float *)(w[4]); - - - /* check if valid image */ - if (-1 == x->x_packet0){ - while (n--) *out++ = 0; - return (w+5); - } - else{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - short int *data0 = (short int *)pdp_packet_data (x->x_packet0); - short int *data1 = (short int *)pdp_packet_data (x->x_packet1); - int width = (float)header0->info.image.width; - float widthm1 = (float)header0->info.image.width - 1; - float heightm1 = (float)header0->info.image.height - 1; - int i; - - float scale = 1.0f / 32767.0f; - - if (x->x_interpolate && (-1 != x->x_packet1)){ - float a_old = 1.0f; - float a_new = 0.0f; - float a_inc = 1.0f / (float)n; - float old, new; - - while(n--){ - float phase = *in++; - int iphase = (int)(phase * PDP_SCAN_COSTABLE_SIZE); - float c = pdp_cos[iphase & (PDP_SCAN_COSTABLE_SIZE - 1)]; - float s = pdp_cos[(iphase - (PDP_SCAN_COSTABLE_SIZE>>1)) & (PDP_SCAN_COSTABLE_SIZE - 1)]; - int xxx = (int)((x->x_centerx + x->x_sizeh * c) * widthm1); - int yyy = (int)((x->x_centery + x->x_sizev * c) * heightm1); - int offset = yyy*width+xxx; - new = ((float)(data0[offset])) * scale; - old = ((float)(data1[offset])) * scale; - *out++ = a_old * old + a_new * new; - a_new += a_inc; - a_old -= a_inc; - } - - pdp_packet_mark_unused(x->x_packet1); - x->x_packet1 = -1; - } - else{ - while(n--){ - float phase = *in++; - int iphase = (int)(phase * PDP_SCAN_COSTABLE_SIZE); - float c = pdp_cos[iphase & (PDP_SCAN_COSTABLE_SIZE - 1)]; - float s = pdp_cos[(iphase - (PDP_SCAN_COSTABLE_SIZE>>1)) & (PDP_SCAN_COSTABLE_SIZE - 1)]; - int xxx = (int)((x->x_centerx + x->x_sizeh * c) * widthm1); - int yyy = (int)((x->x_centery + x->x_sizev * c) * heightm1); - *out++ = ((float)(data0[yyy*width+xxx])) * scale; - } - } - - return (w+5); - - } -} - - - - -static void pdp_scan_input_0(t_pdp_scan *x, t_symbol *s, t_floatarg f) -{ - int packet = (int)f; - - /* register */ - if (s== gensym("register_ro")){ - t_pdp *header = pdp_packet_header(packet); - if (!header) return; - if (PDP_IMAGE != header->type) return; - if ((header->info.image.encoding != PDP_IMAGE_YV12) && (header->info.image.encoding != PDP_IMAGE_GREY)) return; - - /* replace if not compatible or we are not interpolating */ - if (!x->x_interpolate || (!pdp_type_compat_image(x->x_packet0, packet))){ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_copy_ro(packet); - } - /* otherwize keep the old one */ - else{ - pdp_packet_mark_unused(x->x_packet1); - x->x_packet1 = x->x_packet0; - x->x_packet0 = pdp_packet_copy_ro(packet); - } - } - - /* pass packet */ - if (s== gensym("process")){ - //if (-1 != x->x_packet0) outlet_pdp (x->x_outlet0, x->x_packet0); - } - - -} - - - - -static void pdp_scan_dsp (t_pdp_scan *x, t_signal **sp) -{ - dsp_add(pdp_scan_perform, 4, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); - -} - - -static void pdp_scan_interpolate(t_pdp_scan *x, t_floatarg f) -{ - if (0.0 == f){ - x->x_interpolate = 0; - pdp_packet_mark_unused(x->x_packet1); - } - if (1.0 == f) x->x_interpolate = 1; -} - -static void pdp_scan_free(t_pdp_scan *x) -{ - pdp_packet_mark_unused(x->x_packet0); -} - - -t_class *pdp_scan_class; - - - -void *pdp_scan_new(void) -{ - t_pdp_scan *x = (t_pdp_scan *)pd_new(pdp_scan_class); - - - //x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_outlet1 = outlet_new(&x->x_obj, &s_signal); - x->x_packet0 = -1; - x->x_packet1 = -1; - - x->x_centerx = 0.5f; - x->x_centery = 0.5f; - x->x_sizeh = 0.3; - x->x_sizev = 0.3; - - pdp_scan_interpolate(x, 0); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_scan_setup(void) -{ - int i; - for (i=0; i<PDP_SCAN_COSTABLE_SIZE; i++) - pdp_cos[i] = cos((double)(i) * 2 * M_PI / PDP_SCAN_COSTABLE_SIZE); - - - pdp_scan_class = class_new(gensym("pdp_scan~"), (t_newmethod)pdp_scan_new, - (t_method)pdp_scan_free, sizeof(t_pdp_scan), 0, A_NULL); - - CLASS_MAINSIGNALIN(pdp_scan_class, t_pdp_scan, x_f); - - class_addmethod(pdp_scan_class, (t_method)pdp_scan_interpolate, gensym("interpolate"), A_FLOAT, A_NULL); - class_addmethod(pdp_scan_class, (t_method)pdp_scan_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_scan_class, (t_method)pdp_scan_dsp, gensym("dsp"), A_NULL); - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_scanxy.c b/modules/pdp_scanxy.c deleted file mode 100644 index 84efd84..0000000 --- a/modules/pdp_scanxy.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include <math.h> - -typedef struct pdp_scanxy_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - t_outlet *x_outlet1; - - int x_packet0; - int x_packet1; - - int x_interpolate; - - -} t_pdp_scanxy; - - -static t_int *pdp_scanxy_perform(t_int *w) -{ - - t_pdp_scanxy *x = (t_pdp_scanxy *)(w[1]); - t_int n = (t_int)(w[2]); - t_float *inx = (float *)(w[3]); - t_float *iny = (float *)(w[4]); - t_float *out = (float *)(w[5]); - - - /* check if valid image */ - if (-1 == x->x_packet0){ - while (n--) *out++ = 0; - return (w+6); - } - else{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - short int *data0 = (short int *)pdp_packet_data (x->x_packet0); - short int *data1 = (short int *)pdp_packet_data (x->x_packet1); - int width = (float)header0->info.image.width; - int height = (float)header0->info.image.height; - int i; - - float scale = 1.0f / 32767.0f; - float scalein = 0x10000; - - if (x->x_interpolate && (-1 != x->x_packet1)){ - float a_old = 1.0f; - float a_new = 0.0f; - float a_inc = 1.0f / (float)n; - float old, new; - - while(n--){ - int xxx = ((((int)(scalein * *inx++)) & 0xffff) * width) >> 16; - int yyy = ((((int)(scalein * *iny++)) & 0xffff) * height) >> 16; - int offset = yyy*width+xxx; - new = ((float)(data0[offset])) * scale; - old = ((float)(data1[offset])) * scale; - *out++ = a_old * old + a_new * new; - a_new += a_inc; - a_old -= a_inc; - } - - pdp_packet_mark_unused(x->x_packet1); - x->x_packet1 = -1; - } - else{ - while(n--){ - int xxx = ((((int)(scalein * *inx++)) & 0xffff) * width) >> 16; - int yyy = ((((int)(scalein * *iny++)) & 0xffff) * height) >> 16; - int offset = yyy*width+xxx; - *out++ = ((float)(data0[offset])) * scale; - } - } - - return (w+6); - - } -} - - - - -static void pdp_scanxy_input_0(t_pdp_scanxy *x, t_symbol *s, t_floatarg f) -{ - int packet = (int)f; - - /* register */ - if (s== gensym("register_ro")){ - t_pdp *header = pdp_packet_header(packet); - if (!header) return; - if (PDP_IMAGE != header->type) return; - if ((header->info.image.encoding != PDP_IMAGE_YV12) && (header->info.image.encoding != PDP_IMAGE_GREY)) return; - - /* replace if not compatible or we are not interpolating */ - if (!x->x_interpolate || (!pdp_type_compat_image(x->x_packet0, packet))){ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_copy_ro(packet); - } - /* otherwize keep the old one */ - else{ - pdp_packet_mark_unused(x->x_packet1); - x->x_packet1 = x->x_packet0; - x->x_packet0 = pdp_packet_copy_ro(packet); - } - } - - /* pass packet */ - if (s== gensym("process")){ - //if (-1 != x->x_packet0) outlet_pdp (x->x_outlet0, x->x_packet0); - } - - -} - - - - -static void pdp_scanxy_dsp (t_pdp_scanxy *x, t_signal **sp) -{ - dsp_add(pdp_scanxy_perform, 5, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec); - -} - - -static void pdp_scanxy_interpolate(t_pdp_scanxy *x, t_floatarg f) -{ - if (0.0 == f){ - x->x_interpolate = 0; - pdp_packet_mark_unused(x->x_packet1); - } - if (1.0 == f) x->x_interpolate = 1; -} - -static void pdp_scanxy_free(t_pdp_scanxy *x) -{ - pdp_packet_mark_unused(x->x_packet0); -} - - -t_class *pdp_scanxy_class; - - - -void *pdp_scanxy_new(void) -{ - t_pdp_scanxy *x = (t_pdp_scanxy *)pd_new(pdp_scanxy_class); - - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - x->x_outlet1 = outlet_new(&x->x_obj, &s_signal); - x->x_packet0 = -1; - x->x_packet1 = -1; - - pdp_scanxy_interpolate(x, 0); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_scanxy_setup(void) -{ - - pdp_scanxy_class = class_new(gensym("pdp_scanxy~"), (t_newmethod)pdp_scanxy_new, - (t_method)pdp_scanxy_free, sizeof(t_pdp_scanxy), 0, A_NULL); - - CLASS_MAINSIGNALIN(pdp_scanxy_class, t_pdp_scanxy, x_f); - - class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_interpolate, gensym("interpolate"), A_FLOAT, A_NULL); - class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_dsp, gensym("dsp"), A_NULL); - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_scope.c b/modules/pdp_scope.c deleted file mode 100644 index 6c0f5c0..0000000 --- a/modules/pdp_scope.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include <string.h> - -#define BUFSIZE 2048 - -typedef struct pdp_scope_data -{ - short int random_seed[4]; - -}t_pdp_scope_data; - -typedef struct pdp_scope_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - t_pdp_scope_data *x_data; - int x_packet0; - int x_queue_id; - - int x_pdp_image_type; - - unsigned int x_width; - unsigned int x_height; - - float *x_buffer; - int x_needle; - - -} t_pdp_scope; - - - -void pdp_scope_type(t_pdp_scope *x, t_symbol *s) -{ - if (gensym("yv12") == s) {x->x_pdp_image_type = PDP_IMAGE_YV12; return;} - if (gensym("grey") == s) {x->x_pdp_image_type = PDP_IMAGE_GREY; return;} - - x->x_pdp_image_type = -1; - -} - - - - - -static void pdp_scope_createpacket_yv12(t_pdp_scope *x) -{ - t_pdp *header; - - unsigned int w = x->x_width; - unsigned int h = x->x_height; - - unsigned int size = w*h; - unsigned int totalnbpixels = size + (size >> 1); - unsigned int packet_size = totalnbpixels << 1; - - x->x_packet0 = pdp_packet_new(PDP_IMAGE, packet_size); - header = pdp_packet_header(x->x_packet0); - - header->info.image.encoding = PDP_IMAGE_YV12; - header->info.image.width = w; - header->info.image.height = h; - - memset(pdp_packet_data(x->x_packet0), 0, packet_size); - -} - -static void pdp_scope_generate_yv12(t_pdp_scope *x) -{ - unsigned int w = x->x_width; - unsigned int h = x->x_height; - unsigned int size = w*h; - unsigned int totalnbpixels = size + (size >> 1); - short int *data = (short int *) pdp_packet_data(x->x_packet0); - - unsigned int i; - int offset = x->x_needle; - int val; - unsigned int y; - float fh2 = (float)(h/2); - - for (i=0; i<w; i++){ - y = (h/2) + (int)(fh2 * -x->x_buffer[(offset - w + i) & (BUFSIZE - 1)]); - if (y>=h) y = h-1; - - data[i + y*w] = 0x7fff; - } - - return; - -} - -static void pdp_scope_createpacket_grey(t_pdp_scope *x) -{ - t_pdp *header; - short int *data; - - unsigned int w = x->x_width; - unsigned int h = x->x_height; - - unsigned int size = w*h; - unsigned int totalnbpixels = size; - unsigned int packet_size = totalnbpixels << 1; - - /* create new packet */ - x->x_packet0 = pdp_packet_new(PDP_IMAGE, packet_size); - - - header = pdp_packet_header(x->x_packet0); - data = (short int *) pdp_packet_data(x->x_packet0); - - header->info.image.encoding = PDP_IMAGE_GREY; - header->info.image.width = w; - header->info.image.height = h; - - memset(pdp_packet_data(x->x_packet0), 0, packet_size); - -} - -static void pdp_scope_generate_grey(t_pdp_scope *x) -{ - unsigned int w = x->x_width; - unsigned int h = x->x_height; - unsigned int totalnbpixels = x->x_width * x->x_height; - short int *data = (short int *) pdp_packet_data(x->x_packet0); - - unsigned int i; - int offset = x->x_needle; - int val; - unsigned int y; - float fh2 = (float)(h/2); - - for (i=0; i<w; i++){ - y = (h/2) + (int)(fh2 * -x->x_buffer[(offset - w + i) & (BUFSIZE - 1)]); - if (y>=h) y = h-1; - - data[i + y*w] = 0x7fff; - } - - return; -} - -static void pdp_scope_sendpacket(t_pdp_scope *x) -{ - /* propagate if valid */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); -} - - -static void pdp_scope_bang(t_pdp_scope *x) -{ - - int encoding; - - /* if we have an active packet, don't do anything */ - if (-1 != x->x_packet0) return; - - switch(x->x_pdp_image_type){ - - case PDP_IMAGE_YV12: - pdp_scope_createpacket_yv12(x); // don't create inside thread!!! - pdp_scope_generate_yv12(x); - pdp_scope_sendpacket(x); - //pdp_queue_add(x, pdp_scope_generate_yv12, pdp_scope_sendpacket, &x->x_queue_id); - break; - - case PDP_IMAGE_GREY: - pdp_scope_createpacket_grey(x); // don't create inside thread!!! - pdp_scope_generate_grey(x); - pdp_scope_sendpacket(x); - //pdp_queue_add(x, pdp_scope_generate_grey, pdp_scope_sendpacket, &x->x_queue_id); - break; - - default: - break; - - } - - - /* release the packet */ - -} - - -static void pdp_scope_dim(t_pdp_scope *x, t_floatarg w, t_floatarg h) -{ - if (w<32.0f) w = 32.0f; - if (h<32.0f) h = 32.0f; - - x->x_width = (unsigned int)w; - x->x_height = (unsigned int)h; -} - - -static void pdp_scope_free(t_pdp_scope *x) -{ - - /* remove callback from process queue */ - pdp_queue_finish(x->x_queue_id); - - - /* tidy up */ - pdp_packet_mark_unused(x->x_packet0); - free(x->x_data); - -} -static t_int *pdp_scope_perform(t_int *w) -{ - - - t_float *in = (float *)(w[3]); - t_pdp_scope *x = (t_pdp_scope *)(w[1]); - t_int n = (t_int)(w[2]); - t_int i; - - t_int offset = x->x_needle; - - for (i=0; i<n; i++) - x->x_buffer[(offset+i)&(BUFSIZE-1)] = in[i]; - - x->x_needle = (offset + n ) & (BUFSIZE - 1); - - return (w+4); - -} -static void pdp_scope_dsp(t_pdp_scope *x, t_signal **sp) -{ - dsp_add(pdp_scope_perform, 3, x, sp[0]->s_n, sp[0]->s_vec); - -} - -t_class *pdp_scope_class; - - - - -void *pdp_scope_new(void) -{ - int i; - - t_pdp_scope *x = (t_pdp_scope *)pd_new(pdp_scope_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_width = 320; - x->x_height = 240; - x->x_f = 0.0; - - x->x_data = (t_pdp_scope_data *)malloc(sizeof(t_pdp_scope_data)); - - pdp_scope_type(x, gensym("yv12")); - - x->x_buffer = (float *)malloc(sizeof(float) * BUFSIZE); - x->x_needle = 0; - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - - -void pdp_scope_setup(void) -{ - - - pdp_scope_class = class_new(gensym("pdp_scope~"), (t_newmethod)pdp_scope_new, - (t_method)pdp_scope_free, sizeof(t_pdp_scope), 0, A_NULL); - - CLASS_MAINSIGNALIN(pdp_scope_class, t_pdp_scope, x_f); - - class_addmethod(pdp_scope_class, (t_method)pdp_scope_type, gensym("type"), A_SYMBOL, A_NULL); - class_addmethod(pdp_scope_class, (t_method)pdp_scope_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_scope_class, (t_method)pdp_scope_bang, gensym("bang"), A_NULL); - class_addmethod(pdp_scope_class, (t_method)pdp_scope_dsp, gensym("dsp"), 0); -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_sdl.c b/modules/pdp_sdl.c deleted file mode 100644 index d30ef84..0000000 --- a/modules/pdp_sdl.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) 2003 by martin pi <pi@attacksyour.net> - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - -pdp sdl output - -DONE: - -TODO: - * close window (event) - * fullscreen chose resolution - * event handling in different object (and look at mplayer for that!) - -*/ - - -#include <stdio.h> -//#include <unistd.h> -//#include <sys/ipc.h> -//#include <sys/shm.h> - -#include <SDL/SDL.h> - -//#include <quicktime/lqt.h> -//#include <quicktime/colormodels.h> - -#include "pdp.h" -#include "pdp_llconv.h" - - -/* initial image dimensions */ -#define PDP_SDL_W 320 -#define PDP_SDL_H 240 - - -typedef struct pdp_sdl_struct { - t_object x_obj; - t_float x_f; - - int x_packet0; - int x_queue_id; - - SDL_Surface *x_sdl_surface; - SDL_Overlay *x_sdl_overlay; - SDL_Rect x_sdl_rect; - - int x_xid; - - Uint32 x_sdl_format; - - int x_winwidth; - int x_winheight; - - unsigned int x_width; - unsigned int x_height; - int x_last_encoding; - int x_cursor; - - int x_initialized; - int x_backfromthread; - - int x_fullscreen; - -} t_pdp_sdl; - -static SDL_Surface *pdp_sdl_getSurface(int xid, char* title, int width, int height, int bits, int fullscreenflag, int cursorflag) { - Uint32 flags; - int size,i; - SDL_Surface *screen; - char SDL_hack[32]; - - /* next lines from gstreamer plugin sdlvideosink */ - if (xid < 0) unsetenv("SDL_WINDOWID"); - else { - sprintf(SDL_hack, "%d", xid); - setenv("SDL_WINDOWID", SDL_hack, 1); - } - - /* Initialize SDL */ - if (!SDL_WasInit(SDL_INIT_VIDEO)) { - if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) { - post("SDL: Initializing of SDL failed: %s.\n", SDL_GetError()); - return NULL; - } - /* ignore events :: only keys and wm_quit */ - for ( i=SDL_NOEVENT; i<SDL_NUMEVENTS; ++i ) - if( !(i & (SDL_KEYDOWN|SDL_VIDEORESIZE)) ) - SDL_EventState(i, SDL_IGNORE); - - - } - -/* -gem : SDL_OPENGL|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT|SDL_OPENGLBLIT; -working: SDL_ANYFORMAT|SDL_RESIZABLE|SDL_RLEACCEL; -*/ - flags = SDL_SWSURFACE | SDL_RESIZABLE; -// flags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT|SDL_RLEACCEL; - if ( fullscreenflag>0 ) { - flags |= SDL_FULLSCREEN|SDL_DOUBLEBUF; - } - - screen = SDL_SetVideoMode(width, height, bits, flags); - if ( screen == NULL ) { - post("Couldn't set video mode: %s\n", SDL_GetError()); - return NULL; - } - - SDL_WM_SetCaption (title, title); - - SDL_ShowCursor(cursorflag); - - return screen; -} - -static SDL_Surface *pdp_sdl_recreateSurface(SDL_Surface *old, int xid, char* title, int width, int height, int bits, int fullscreenflag, int cursorflag) { - SDL_Surface *new = pdp_sdl_getSurface(xid, title, width, height, bits, fullscreenflag, cursorflag); - if (new != NULL) SDL_FreeSurface(old); - return new; -} - -static inline void pdp_sdl_getOverlay(t_pdp_sdl* x) { - x->x_sdl_overlay = SDL_CreateYUVOverlay(x->x_width, x->x_height, x->x_sdl_format, x->x_sdl_surface); -} - -static inline void pdp_sdl_freeOverlay(t_pdp_sdl* x) { - SDL_FreeYUVOverlay(x->x_sdl_overlay); -} - -static int pdp_sdl_drawImage(t_pdp_sdl* x, t_image *image, short int *pixels) { - - unsigned int width = image->width; - unsigned int height = image->height; - int encoding = image->encoding; - unsigned int* uintdata; - int i; - - - /* 8bit y fulscale and 8bit u,v 2x2 subsampled */ - //static short int gain[4] = {0x0100, 0x0100, 0x0100, 0x0100}; - int nbpixels = width * height; - long size = (width * height + (((width>>1)*(height>>1))<<1)); - - /* check if xvimage needs to be recreated */ - if ((width != x->x_width) || (height != x->x_height)){ - post("pdp_xv: replace image"); - x->x_width = width; - x->x_height = height; - pdp_sdl_freeOverlay(x); - pdp_sdl_getOverlay(x); - } - - SDL_LockYUVOverlay(x->x_sdl_overlay); - if (pixels) { - pdp_llconv(pixels,RIF_YVU__P411_S16, (Uint8 *)(* x->x_sdl_overlay->pixels), RIF_YVU__P411_U8, x->x_width, x->x_height); - } else bzero((Uint8 *)(* x->x_sdl_overlay->pixels), size); - SDL_UnlockYUVOverlay(x->x_sdl_overlay); - - return 1; -} - -static void pdp_sdl_fullscreen(t_pdp_sdl *x, t_floatarg f); - -static inline void pdp_sdl_recreate(t_pdp_sdl *x) { - x->x_sdl_surface = pdp_sdl_recreateSurface(x->x_sdl_surface, x->x_xid,"pdp-sdl", x->x_winwidth, x->x_winheight, 16, x->x_fullscreen,x->x_cursor); -} - -static int pdp_sdl_create(t_pdp_sdl *x) { - if (x->x_initialized){ - return 0; - } - x->x_initialized = 0; - - x->x_sdl_surface = pdp_sdl_getSurface(x->x_xid, "pdp-sdl", x->x_winwidth, x->x_winheight, 16, x->x_fullscreen,x->x_cursor); - if (x->x_sdl_surface != NULL) { - pdp_sdl_getOverlay(x); - if (x->x_sdl_overlay != NULL) { - x->x_sdl_rect.x = 0; - x->x_sdl_rect.y = 0; - x->x_sdl_rect.w = x->x_winwidth; - x->x_sdl_rect.h = x->x_winheight; - x->x_initialized = 1; - post("created successfully"); - } - } - x->x_backfromthread = 1; - - return x->x_initialized; -} - -static void pdp_sdl_destroy(t_pdp_sdl *x); -static void pdp_sdl_resize(t_pdp_sdl *x,t_floatarg,t_floatarg); - -static void pdp_sdl_checkEvents(t_pdp_sdl *x) { - Uint8 *keys; - SDL_Event event; - - if (SDL_PollEvent(&event)!=1) return; - - switch( event.type ){ - case SDL_KEYDOWN: - case SDL_KEYUP: - keys = SDL_GetKeyState(NULL); - - if(keys[SDLK_UP]) { post("up"); } - if(keys[SDLK_DOWN]) { post("down"); } - - if(keys[SDLK_ESCAPE]) pdp_sdl_fullscreen(x,0); - break; - - case SDL_QUIT: - pdp_sdl_destroy(x); - break; - case SDL_VIDEORESIZE: - pdp_sdl_resize(x,(t_floatarg)event.resize.w,(t_floatarg)event.resize.h); - break; - default: - break; - } - - -} - -static void pdp_sdl_bang(t_pdp_sdl *x); - -static void pdp_sdl_process(t_pdp_sdl *x) -{ - t_pdp *header = pdp_packet_header(x->x_packet0); - void *data = pdp_packet_data (x->x_packet0); - - - if (!x->x_backfromthread) return; - - /* check if window is initialized */ - if (!(x->x_initialized)){ - if (!pdp_sdl_create(x)) return; - } - - /* check for pending sdl events */ - pdp_sdl_checkEvents(x); - - /* check data packet */ - if (!(header)) { - post("pdp_sdl: invalid packet header"); - return; - } - if (PDP_IMAGE != header->type) { - post("pdp_sdl: packet is not a PDP_IMAGE"); - return; - } - if (header->info.image.encoding != PDP_IMAGE_YV12) { - post("pdp_sdl: packet is not a PDP_IMAGE_YV12"); - return; - } - - /* copy the packet to the sdlimage */ - pdp_sdl_drawImage(x, &header->info.image, (short int *)data); - - /* display the new image */ - pdp_sdl_bang(x); -} - -static void pdp_sdl_destroy(t_pdp_sdl *x) { - if (x->x_initialized){ - pdp_sdl_freeOverlay(x); - SDL_FreeSurface(x->x_sdl_surface); - x->x_initialized = 0; - SDL_Quit(); - } -} - -static void pdp_sdl_random(t_pdp_sdl *x) { - unsigned int i; - long *intdata = (long *)(* x->x_sdl_overlay->pixels); - SDL_LockYUVOverlay(x->x_sdl_overlay); - for(i=0; i<x->x_width*x->x_height/4; i++) intdata[i]=random(); - SDL_UnlockYUVOverlay(x->x_sdl_overlay); -} - -/* redisplays image */ -static void pdp_sdl_bang_thread(t_pdp_sdl *x) { - if (SDL_DisplayYUVOverlay(x->x_sdl_overlay, &(* x).x_sdl_rect) <0) - post("pdp_sdl: __LINE__ cannot display"); -} - -static void pdp_sdl_bang_callback(t_pdp_sdl *x) -{ - x->x_backfromthread = 1; - - /* release the packet if there is one */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1;} - -static void pdp_sdl_bang(t_pdp_sdl *x) { - - /* if previous queued method returned - schedule a new one, else ignore */ - if (x->x_backfromthread) { - x->x_backfromthread = 0; - pdp_queue_add(x, pdp_sdl_bang_thread, pdp_sdl_bang_callback, &x->x_queue_id); - } -} - -static void pdp_sdl_input_0(t_pdp_sdl *x, t_symbol *s, t_floatarg f) { - - if (s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet0, (int)f); - if (s == gensym("process")) pdp_sdl_process(x); - -} - -static void pdp_sdl_resize(t_pdp_sdl* x, t_floatarg width, t_floatarg height) { - - if (x->x_initialized && (!x->x_fullscreen) && (width>0) && (height>0)) { - post("should get %d/%d",(int)width,(int) height); - x->x_winwidth=(int)width; - x->x_winheight=(int)height; - pdp_sdl_recreate(x); - } -} - - -static void pdp_sdl_fullscreen(t_pdp_sdl *x, t_floatarg f) { - if (f == x->x_fullscreen) return; - - x->x_fullscreen = (f != 0.0f); - x->x_cursor=0; - - pdp_sdl_recreate(x); -} - -static void pdp_sdl_cursor(t_pdp_sdl *x, t_floatarg f) { - if (f == x->x_cursor) return; - - x->x_cursor = (f != 0.0f); - SDL_ShowCursor(x->x_cursor); -} - - -/* sets new target window */ - -static void pdp_sdl_win(t_pdp_sdl *x, t_floatarg *f) { - pdp_queue_finish(x->x_queue_id); - x->x_queue_id = -1; - x->x_xid = (int)f; - pdp_sdl_recreate(x); -} - -/* be very carefule not to set DGA fro here! */ -/* use export SDL_VIDEODRIVER=dga (or equivalent for your shell) instead */ - -static void pdp_sdl_renderer(t_pdp_sdl *x, t_symbol *s) { - char SDL_hack[32]; - - pdp_sdl_destroy(x); - - /* next lines from gstreamer plugin sdlvideosink */ - unsetenv("SDL_VIDEODRIVER"); - - sprintf(SDL_hack, "%s", s->s_name); - setenv("SDL_VIDEODRIVER", SDL_hack, 1); - - pdp_sdl_create(x); -} - -static void pdp_sdl_free(t_pdp_sdl *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_sdl_destroy(x); - pdp_packet_mark_unused(x->x_packet0); -// SDL_Quit(); -} - -static void pdp_sdl_listmodes(const char* title, Uint32 flags) { - SDL_Rect ** modes; - int i; - - /* Get available modes */ - modes = SDL_ListModes(NULL, flags); - - /* Check is there are any modes available */ - if(modes == (SDL_Rect **)0){ - printf("%s : No modes available!", title); - return; - } - - /* Check if our resolution is restricted */ - if(modes == (SDL_Rect **)-1){ - post("%s : All resolutions available.", title); - } else { - /* Print valid modes */ - for(i=0;modes[i];++i) - post("%s : %d x %d", title, modes[i]->w, modes[i]->h); - } - -} - -static void pdp_sdl_modes(t_pdp_sdl *x) { - pdp_sdl_listmodes("FULL|HWSURF|||||||||||||||||||||||||", SDL_FULLSCREEN|SDL_HWSURFACE); - pdp_sdl_listmodes("HWSURF|RESIZ|ASYNC|HWACCEL||||||||||", SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); - pdp_sdl_listmodes("HWSURF|RESIZ|ASYNC|HWACCEL|FULL|DBUF", SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_FULLSCREEN|SDL_DOUBLEBUF); - pdp_sdl_listmodes("OPENGL|DBUF|HWSURF|ANYF|GLBLIT||||||", SDL_OPENGL|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT|SDL_OPENGLBLIT); - pdp_sdl_listmodes("ANYF|RESIZ|RLEA|||||||||||||||||||||", SDL_ANYFORMAT|SDL_RESIZABLE|SDL_RLEACCEL); -} - -static void pdp_sdl_info(t_pdp_sdl *x) { - const SDL_VideoInfo *narf; - post("\nSDL video info: note that this only works under dga mode\n"); - narf = SDL_GetVideoInfo(); - post("Is it possible to create hardware surfaces?\t\thw_available=%d",narf->hw_available); - post("Is there a window manager available?\t\t\twm_available=%d",narf->wm_available); - post("Are hardware to hardware blits accelerated?\t\tblit_hw=%d",narf->blit_hw); - post("Are hardware to hardware colorkey blits accelerated?\tblit_hw_CC=%d",narf->blit_hw_CC); - post("Are hardware to hardware alpha bits accelerated?\tblit_hw_A=%d",narf->blit_hw_A); - post("Are software to hardware blits accelerated?\t\tblit_sw=%d",narf->blit_sw); - post("Are software to hardware colorkey blits accelerated?\tblit_sw_CC=%d",narf->blit_sw_CC); - post("Are software to hardware alpha blits accelerated?\tblit_sw_A=%d",narf->blit_sw_A); - post("Are color fills accelerated?\t\t\t\tblit_fill=%d",narf->blit_fill); - post("Total amount of video_mem: %d",narf->video_mem); - -} - -t_class *pdp_sdl_class; - -void *pdp_sdl_new(void) { - - - t_pdp_sdl *x = (t_pdp_sdl *)pd_new(pdp_sdl_class); - - x->x_packet0 = -1; - x->x_queue_id = -1; - - x->x_sdl_surface = NULL; - x->x_sdl_overlay = NULL; - x->x_sdl_format = SDL_YV12_OVERLAY; - - x->x_winwidth = PDP_SDL_W; - x->x_winheight = PDP_SDL_H; - - x->x_width = PDP_SDL_W; - x->x_height = PDP_SDL_H; - - x->x_backfromthread = 1; - x->x_initialized = 0; - - x->x_fullscreen = 0; - x->x_cursor=1; - - x->x_xid = -1; - - pdp_sdl_create(x); - - return (void *)x; -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_sdl_setup(void) -{ - - - pdp_sdl_class = class_new(gensym("pdp_sdl"), (t_newmethod)pdp_sdl_new, - (t_method)pdp_sdl_free, sizeof(t_pdp_sdl), 0, A_NULL); - - - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_bang, gensym("bang"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_random, gensym("random"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_create, gensym("create"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_info, gensym("info"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_modes, gensym("modes"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_destroy, gensym("destroy"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_destroy, gensym("close"), A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("size"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_fullscreen, gensym("fullscreen"), A_FLOAT, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_cursor, gensym("cursor"), A_FLOAT, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_win, gensym("window"), A_FLOAT, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_renderer, gensym("renderer"), A_SYMBOL, A_NULL); - class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif - diff --git a/modules/pdp_slice_cut.c b/modules/pdp_slice_cut.c deleted file mode 100644 index 0d689ea..0000000 --- a/modules/pdp_slice_cut.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* this module converts a greyscale image or the luma channel of a colour image - to a colour image intensity mask, usable for multiplication */ - -#include "pdp.h" -#include "pdp_resample.h" -#include "pdp_imageproc.h" - -typedef struct pdp_slice_cut_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - //int x_dropped; - //int x_queue_id; - - unsigned int x_slice_height; - - -} t_pdp_slice_cut; - - - -static void pdp_slice_cut_process_grey(t_pdp_slice_cut *x) -{ - t_pdp *header = pdp_packet_header(x->x_packet0); - short int *data = (short int *)pdp_packet_data (x->x_packet0); - t_pdp *newheader = 0; - short int *newdata = 0; - int newpacket = -1; - - unsigned int w = header->info.image.width; - unsigned int h = header->info.image.height; - - unsigned int size = w*h; - unsigned int height_left = h; - unsigned int slice_height = 0; - unsigned int slice_yoffset = 0; - unsigned int slice_offset = 0; - unsigned int slice_size_bytes = 0; - - #define min(x,y) (((x)<(y)) ? (x) : (y)) - - while(height_left){ - - /* compute slice size */ - slice_height = min(x->x_slice_height, height_left); - height_left -= slice_height; - slice_size_bytes = (w << 1) * slice_height; - - /* create new slice packet */ - newpacket = pdp_packet_new(PDP_IMAGE, slice_size_bytes); - newheader = pdp_packet_header(newpacket); - newdata = (s16*)pdp_packet_data(newpacket); - - newheader->info.image.encoding = PDP_IMAGE_GREY; - newheader->info.image.width = w; - newheader->info.image.height = slice_height; - - newheader->info.image.orig_height = h; - newheader->info.image.slice_yoff = slice_yoffset; - - if (slice_height + height_left == h) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_FIRST; - else if (height_left == 0) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_LAST; - else newheader->info.image.slice_sync = PDP_IMAGE_SLICE_BODY; - - /* copy slice data */ - memcpy(newdata, data+slice_offset, slice_size_bytes); - - /* unregister and propagate if valid packet */ - pdp_packet_mark_unused(newpacket); - outlet_pdp(x->x_outlet0, newpacket); - - /* advance pointer stuff */ - slice_offset += (slice_size_bytes>>1); - slice_yoffset += slice_height; - - } - - - - /* delete source packet when finished */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1; - return; -} - -static void pdp_slice_cut_process_yv12(t_pdp_slice_cut *x) -{ - - t_pdp *header = pdp_packet_header(x->x_packet0); - short int *data = (short int *)pdp_packet_data (x->x_packet0); - t_pdp *newheader = 0; - short int *newdata = 0; - int newpacket = -1; - - unsigned int w = header->info.image.width; - unsigned int h = header->info.image.height; - - unsigned int size = w*h; - unsigned int height_left = h; - unsigned int slice_height = 0; - unsigned int sequence_number = 0; - unsigned int slice_offset = 0; - unsigned int slice_yoffset = 0; - unsigned int slice_size_bytes = 0; - unsigned int slice_size = 0; - - #define min(x,y) (((x)<(y)) ? (x) : (y)) - - while(height_left){ - - /* compute slice size */ - slice_height = min(x->x_slice_height, height_left); - height_left -= slice_height; - slice_size = w * slice_height; - slice_size_bytes = slice_size << 1; - - /* create new slice packet */ - newpacket = pdp_packet_new(PDP_IMAGE, slice_size_bytes + (slice_size_bytes >> 1)); - newheader = pdp_packet_header(newpacket); - newdata = (s16*)pdp_packet_data(newpacket); - newheader->info.image.encoding = PDP_IMAGE_YV12; - newheader->info.image.width = w; - newheader->info.image.height = slice_height; - newheader->info.image.orig_height = h; - newheader->info.image.slice_yoff = slice_yoffset; - - if (slice_height + height_left == h) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_FIRST; - else if (height_left == 0) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_LAST; - else newheader->info.image.slice_sync = PDP_IMAGE_SLICE_BODY; - - - /* copy slice data */ - memcpy(newdata, - data + slice_offset, - slice_size_bytes); - - memcpy(newdata + slice_size, - data + size + (slice_offset>>2), - slice_size_bytes>>2); - - memcpy(newdata + slice_size + (slice_size >> 2), - data + size + (size >> 2) + (slice_offset >> 2), - slice_size_bytes>>2); - - /* unregister and propagate if valid packet */ - pdp_packet_mark_unused(newpacket); - outlet_pdp(x->x_outlet0, newpacket); - - /* advance pointer stuff */ - slice_offset += (slice_size_bytes>>1); - slice_yoffset += slice_height; - - } - - - - /* delete source packet when finished */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1; - return; - -} - - - -static void pdp_slice_cut_process(t_pdp_slice_cut *x) -{ - int encoding; - t_pdp *header = 0; - - - /* check if image data packets are compatible */ - if ( (header = pdp_packet_header(x->x_packet0)) - && (PDP_IMAGE == header->type)){ - - /* pdp_slice_cut_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_slice_cut_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_slice_cut_process_grey(x); - break; - - default: - /* don't know the type, so dont pdp_slice_cut_process */ - - break; - } - } -} - -static void pdp_slice_cut_input_0(t_pdp_slice_cut *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_ro")) x->x_packet0 = pdp_packet_copy_ro(p); - if ((s == gensym("process")) && (-1 != x->x_packet0)) pdp_slice_cut_process(x); - -} - - - -static void pdp_slice_cut_height(t_pdp_slice_cut *x, t_floatarg f) -{ - int i = (int)f; - x->x_slice_height = pdp_imageproc_legalheight(i); - post("pdp_slice: height set to %d", x->x_slice_height); - -} -static void pdp_slice_cut_forceheight(t_pdp_slice_cut *x, t_floatarg f) -{ - int i = (int)f; - if (i<1) i = 1; - x->x_slice_height = i; - post("pdp_slice: WARNING: forceheight is a debug message. setting this to an abritrary"); - post("pdp_slice: WARNING: value can crash pdp. set it to a multiple of 2 and only use pixel"); - post("pdp_slice: WARNING: operations (no convolution or biquad) in the mmx version."); - post("pdp_slice: height forced to %d", x->x_slice_height); - -} - - -static void pdp_slice_cut_free(t_pdp_slice_cut *x) -{ - pdp_packet_mark_unused(x->x_packet0); -} - -t_class *pdp_slice_cut_class; - - - -void *pdp_slice_cut_new(void) -{ - int i; - - t_pdp_slice_cut *x = (t_pdp_slice_cut *)pd_new(pdp_slice_cut_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_packet0 = -1; - //x->x_queue_id = -1; - - x->x_slice_height = 8; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_slice_cut_setup(void) -{ - - - pdp_slice_cut_class = class_new(gensym("pdp_slice_cut"), (t_newmethod)pdp_slice_cut_new, - (t_method)pdp_slice_cut_free, sizeof(t_pdp_slice_cut), 0, A_NULL); - - - class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_height, gensym("height"), A_FLOAT, A_NULL); - class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_forceheight, gensym("forceheight"), A_FLOAT, A_NULL); - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_slice_glue.c b/modules/pdp_slice_glue.c deleted file mode 100644 index 601bd32..0000000 --- a/modules/pdp_slice_glue.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* this module converts a greyscale image or the luma channel of a colour image - to a colour image intensity mask, usable for multiplication */ - -#include "pdp.h" -#include "pdp_resample.h" - -typedef struct pdp_slice_glue_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; //input packet - int x_packet1; //output packet - -} t_pdp_slice_glue; - - - -static void pdp_slice_glue_process_grey(t_pdp_slice_glue *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - short int *data0 = (short int *)pdp_packet_data (x->x_packet0); - short int *data1 = (short int *)pdp_packet_data (x->x_packet1); - - - unsigned int offset = header0->info.image.width * header0->info.image.slice_yoff; - unsigned int slice_size = header0->info.image.width * header0->info.image.height; - - memcpy(data1 + offset, data0, slice_size << 1); - - - return; -} - -static void pdp_slice_glue_process_yv12(t_pdp_slice_glue *x) -{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - short int *data0 = (short int *)pdp_packet_data (x->x_packet0); - short int *data1 = (short int *)pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - unsigned int dw = header1->info.image.width; - unsigned int dh = header1->info.image.height; - unsigned int dsize = dh*dw; - - unsigned int offset = w * header0->info.image.slice_yoff; - unsigned int slice_size = w * h; - - memcpy(data1 + offset, data0, slice_size << 1); - memcpy(data1 + dsize + (offset >> 2), data0 + slice_size, slice_size >> 1); - memcpy(data1 + dsize + (dsize >>2) + (offset>>2), data0 + slice_size + (slice_size >> 2), slice_size >> 1); - - - return; - -} - - - -static void pdp_slice_glue_process(t_pdp_slice_glue *x) -{ - int encoding; - int newpacket; - t_pdp *header = 0; - t_pdp *dest_header = 0; - - - /* check if the packet is a valid slice packet */ - /* if not pass it along */ - if (!((header = pdp_packet_header(x->x_packet0)) && - (PDP_IMAGE == header->type) && (header->info.image.orig_height))) goto passalong; - - /* if this is the first slice of a sequence, or we don't have a dest packet yet */ - /* create a new destination packet */ - if ((x->x_packet1 == -1) || (header->info.image.slice_sync & PDP_IMAGE_SLICE_FIRST)){ - pdp_packet_mark_unused(x->x_packet1); - x->x_packet1 = pdp_packet_new(PDP_IMAGE, ((header->size - PDP_HEADER_SIZE) / header->info.image.height) - * header->info.image.orig_height); - dest_header = pdp_packet_header(x->x_packet1); - dest_header->info.image.encoding = header->info.image.encoding; - dest_header->info.image.width = header->info.image.width; - dest_header->info.image.height = header->info.image.orig_height; - } - - /* if this is a body or last slice, it has to be compatible with the current dest packet */ - /* else ignore it */ - else{ - dest_header = pdp_packet_header(x->x_packet1); - if (!((dest_header->info.image.encoding == header->info.image.encoding) && - ((dest_header->info.image.width == header->info.image.width)))) goto dispose; - } - - /* now we have a dest packet and the source packet is compatible with it, so copy the data */ - - - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - - case PDP_IMAGE_YV12: - pdp_slice_glue_process_yv12(x); - break; - - case PDP_IMAGE_GREY: - pdp_slice_glue_process_grey(x); - break; - - default: - /* don't know the type, so dont pdp_slice_glue_process */ - - break; - } - - /* if the source packet was a final slice, pass on the constructed packet */ - if (header->info.image.slice_sync & PDP_IMAGE_SLICE_LAST){ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet1); - } - - - /* processing is done so we delete the source packet */ - dispose: - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1; - return; - - - passalong: - pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); - return; - -} - -static void pdp_slice_glue_input_0(t_pdp_slice_glue *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - - if (s== gensym("register_ro")) x->x_packet0 = pdp_packet_copy_ro(p); - if ((s == gensym("process")) && (-1 != x->x_packet0)) pdp_slice_glue_process(x); - -} - - - - -static void pdp_slice_glue_free(t_pdp_slice_glue *x) -{ - pdp_packet_mark_unused(x->x_packet0); -} - -t_class *pdp_slice_glue_class; - - - -void *pdp_slice_glue_new(void) -{ - int i; - - t_pdp_slice_glue *x = (t_pdp_slice_glue *)pd_new(pdp_slice_glue_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_packet0 = -1; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_slice_glue_setup(void) -{ - - - pdp_slice_glue_class = class_new(gensym("pdp_slice_glue"), (t_newmethod)pdp_slice_glue_new, - (t_method)pdp_slice_glue_free, sizeof(t_pdp_slice_glue), 0, A_NULL); - - - class_addmethod(pdp_slice_glue_class, (t_method)pdp_slice_glue_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_snap.c b/modules/pdp_snap.c deleted file mode 100644 index 3ed0da2..0000000 --- a/modules/pdp_snap.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - -typedef struct pdp_snap_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - int x_packet0; - bool x_snapnext; - -} t_pdp_snap; - - -static void pdp_snap_bang(t_pdp_snap *x) -{ - - if (-1 != x->x_packet0) - outlet_pdp(x->x_outlet0, x->x_packet0); - -} - - - - -static void pdp_snap_input_1(t_pdp_snap *x, t_symbol *s, t_floatarg f) -{ - - /* if this is a register_ro message or register_rw message, register with packet factory */ - - /* if this is a process message, start the processing + propagate stuff to outputs */ - - if (s == gensym("register_ro")){ - if(x->x_snapnext) { - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = pdp_packet_copy_ro((int)f); - x->x_snapnext = false; - } - } - -} - -static void pdp_snap_snap(t_pdp_snap *x) -{ - x->x_snapnext = true; -} - -static void pdp_snap_free(t_pdp_snap *x) -{ - pdp_packet_mark_unused(x->x_packet0); - -} - -t_class *pdp_snap_class; - - - -void *pdp_snap_new(void) -{ - t_pdp_snap *x = (t_pdp_snap *)pd_new(pdp_snap_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1")); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_packet0 = -1; - x->x_snapnext = false; - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_snap_setup(void) -{ - - - pdp_snap_class = class_new(gensym("pdp_snap"), (t_newmethod)pdp_snap_new, - (t_method)pdp_snap_free, sizeof(t_pdp_snap), 0, A_NULL); - - - class_addmethod(pdp_snap_class, (t_method)pdp_snap_bang, gensym("bang"), A_NULL); - class_addmethod(pdp_snap_class, (t_method)pdp_snap_snap, gensym("snap"), A_NULL); - - class_addmethod(pdp_snap_class, (t_method)pdp_snap_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_trigger.c b/modules/pdp_trigger.c deleted file mode 100644 index e131438..0000000 --- a/modules/pdp_trigger.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" - - - - - -typedef struct pdp_trigger_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - t_outlet *x_outlet1; - int x_packet; - - -} t_pdp_trigger; - - - - -static void pdp_trigger_input_0(t_pdp_trigger *x, t_symbol *s, t_floatarg f) -{ - t_atom atom[2]; - t_symbol *pdp = gensym("pdp"); - - - /* trigger on register_ro */ - if (s == gensym("register_ro")){ - outlet_bang(x->x_outlet1); - - } - - /* propagate the pdp message */ - SETSYMBOL(atom+0, s); - SETFLOAT(atom+1, f); - outlet_anything(x->x_outlet0, pdp, 2, atom); - -} - - - -static void pdp_trigger_free(t_pdp_trigger *x) -{ - -} - -t_class *pdp_trigger_class; - - - -void *pdp_trigger_new(void) -{ - t_pdp_trigger *x = (t_pdp_trigger *)pd_new(pdp_trigger_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_outlet1 = outlet_new(&x->x_obj, &s_bang); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_trigger_setup(void) -{ - - - pdp_trigger_class = class_new(gensym("pdp_trigger"), (t_newmethod)pdp_trigger_new, - (t_method)pdp_trigger_free, sizeof(t_pdp_trigger), 0, A_NULL); - - class_addmethod(pdp_trigger_class, (t_method)pdp_trigger_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_v4l.c b/modules/pdp_v4l.c deleted file mode 100644 index f1195c3..0000000 --- a/modules/pdp_v4l.c +++ /dev/null @@ -1,757 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -#include "pdp_config.h" -#include "pdp.h" -#include "pdp_llconv.h" -#include "pdp_imageproc.h" -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/time.h> -#include <linux/types.h> -#include <linux/videodev.h> -#include <sys/mman.h> -#include <sched.h> -#include <pthread.h> - -// dont open any more after a set number -// of failed attempts -// this is to prevent locks on auto-open -// is reset when manually opened or closed -#define PDP_XV_RETRIES 10 - -#ifdef HAVE_PWCV4L -#include "pwc-ioctl.h" -#endif - - -#define DEVICENO 0 -#define NBUF 2 -#define COMPOSITEIN 1 - - - - -typedef struct pdp_v4l_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - bool x_initialized; - bool x_auto_open; - - unsigned int x_width; - unsigned int x_height; - int x_channel; - unsigned int x_norm; - int x_freq; - - unsigned int x_framerate; - - struct video_tuner x_vtuner; - struct video_picture x_vpicture; - struct video_buffer x_vbuffer; - struct video_capability x_vcap; - struct video_channel x_vchannel; - struct video_audio x_vaudio; - struct video_mbuf x_vmbuf; - struct video_mmap x_vmmap[NBUF]; - struct video_window x_vwin; - int x_tvfd; - int x_frame; - unsigned char *x_videobuf; - int x_skipnext; - int x_mytopmargin, x_mybottommargin; - int x_myleftmargin, x_myrightmargin; - - t_symbol *x_device; - t_symbol *x_image_type; - //int x_pdp_image_type; - int x_v4l_palette; - - pthread_t x_thread_id; - int x_continue_thread; - int x_frame_ready; - int x_only_new_frames; - int x_last_frame; - - - int x_open_retry; - - u32 x_minwidth; - u32 x_maxwidth; - u32 x_minheight; - u32 x_maxheight; - - -} t_pdp_v4l; - - - - - -static void pdp_v4l_close(t_pdp_v4l *x) -{ - /* close the v4l device and dealloc buffer */ - - void *dummy; - - /* terminate thread if there is one */ - if(x->x_continue_thread){ - x->x_continue_thread = 0; - pthread_join (x->x_thread_id, &dummy); - } - - - if (x->x_tvfd >= 0) - { - close(x->x_tvfd); - x->x_tvfd = -1; - } - - if (x->x_initialized){ - munmap(x->x_videobuf, x->x_vmbuf.size); - x->x_initialized = false; - } - -} - -static void pdp_v4l_close_manual(t_pdp_v4l *x) -{ - x->x_open_retry = PDP_XV_RETRIES; - pdp_v4l_close(x); - -} - -static void pdp_v4l_close_error(t_pdp_v4l *x) -{ - pdp_v4l_close(x); - if(x->x_open_retry) x->x_open_retry--; -} - - -static void pdp_v4l_pwc_init(t_pdp_v4l *x) -{ - /* todo add detection code for pwc */ - -#ifdef HAVE_PWCV4L - - if(ioctl(x->x_tvfd, VIDIOCPWCRUSER)){ - perror("pdp_v4l: pwc: VIDIOCPWCRUSER"); - goto closit; - } - - if (ioctl(x->x_tvfd, VIDIOCGWIN, &x->x_vwin)){ - perror("pdp_v4l: pwc: VIDIOCGWIN"); - goto closit; - } - - - - if (x->x_vwin.flags & PWC_FPS_MASK){ - post("pdp_v4l: pwc: framerate: %d", (x->x_vwin.flags & PWC_FPS_MASK) >> PWC_FPS_SHIFT); - post("pdp_v4l: pwc: setting framerate to %d", x->x_framerate); - x->x_vwin.flags &= PWC_FPS_MASK; - x->x_vwin.flags |= (x->x_framerate << PWC_FPS_SHIFT); - if (ioctl(x->x_tvfd, VIDIOCSWIN, &x->x_vwin)){ - perror("pdp_v4l: pwc: VIDIOCSWIN"); - goto closit; - } - if (ioctl(x->x_tvfd, VIDIOCGWIN, &x->x_vwin)){ - perror("pdp_v4l: pwc: VIDIOCGWIN"); - goto closit; - } - post("pdp_v4l: pwc: framerate: %d", (x->x_vwin.flags & PWC_FPS_MASK) >> PWC_FPS_SHIFT); - - } - - - return; - - - - closit: - pdp_v4l_close_error(x); - return; - -#else - post("pdp_v4l: additional pwc support disabled"); - return; -#endif -} - -static void pdp_v4l_sync_frame(t_pdp_v4l* x){ - /* grab frame */ - if (ioctl(x->x_tvfd, VIDIOCSYNC, &x->x_vmmap[x->x_frame].frame) < 0){ - perror("pdp_v4l: VIDIOCSYNC"); - pdp_v4l_close(x); - return; - } -} - -static void pdp_v4l_capture_frame(t_pdp_v4l* x){ - if (ioctl(x->x_tvfd, VIDIOCMCAPTURE, &x->x_vmmap[x->x_frame]) < 0){ - if (errno == EAGAIN) - post("pdp_v4l: can't sync (no video source?)\n"); - else - perror("pdp_v4l: VIDIOCMCAPTURE"); - if (ioctl(x->x_tvfd, VIDIOCMCAPTURE, &x->x_vmmap[x->x_frame]) < 0) - perror("pdp_v4l: VIDIOCMCAPTURE2"); - - post("pdp_v4l: frame %d %d, format %d, width %d, height %d", - x->x_frame, x->x_vmmap[x->x_frame].frame, x->x_vmmap[x->x_frame].format, - x->x_vmmap[x->x_frame].width, x->x_vmmap[x->x_frame].height); - - pdp_v4l_close(x); - return; - } -} - - -static void *pdp_v4l_thread(void *voidx) -{ - t_pdp_v4l *x = ((t_pdp_v4l *)voidx); - - - /* flip buffers */ - x->x_frame ^= 0x1; - - /* capture with a double buffering scheme */ - while (x->x_continue_thread){ - - /* schedule capture command for next frame */ - pdp_v4l_capture_frame(x); - - /* wait until previous capture is ready */ - x->x_frame ^= 0x1; - pdp_v4l_sync_frame(x); - - /* setup pointers for main thread */ - x->x_frame_ready = 1; - x->x_last_frame = x->x_frame; - - } - - return 0; -} - -static void pdp_v4l_setlegaldim(t_pdp_v4l *x, int xx, int yy); - -static void pdp_v4l_open(t_pdp_v4l *x, t_symbol *name) -{ - /* open a v4l device and allocate a buffer */ - - unsigned int size; - int i; - - unsigned int width, height; - - - /* if already opened -> close */ - if (x->x_initialized) pdp_v4l_close(x); - - - /* exit if retried too much */ - if (!x->x_open_retry){ - post("pdp_v4l: retry count reached zero for %s", name->s_name); - post("pdp_v4l: try to open manually"); - return; - } - - post("pdp_v4l: opening %s", name->s_name); - - x->x_device = name; - - if ((x->x_tvfd = open(name->s_name, O_RDWR)) < 0) - { - post("pdp_v4l: error:"); - perror(name->s_name); - goto closit; - } - - - if (ioctl(x->x_tvfd, VIDIOCGCAP, &x->x_vcap) < 0) - { - perror("get capabilities"); - goto closit; - } - - post("pdp_v4l: cap: name %s type %d channels %d maxw %d maxh %d minw %d minh %d", - x->x_vcap.name, x->x_vcap.type, x->x_vcap.channels, x->x_vcap.maxwidth, x->x_vcap.maxheight, - x->x_vcap.minwidth, x->x_vcap.minheight); - - x->x_minwidth = pdp_imageproc_legalwidth(x->x_vcap.minwidth); - x->x_maxwidth = pdp_imageproc_legalwidth_round_down(x->x_vcap.maxwidth); - x->x_minheight = pdp_imageproc_legalheight(x->x_vcap.minheight); - x->x_maxheight = pdp_imageproc_legalheight_round_down(x->x_vcap.maxheight); - - - if (ioctl(x->x_tvfd, VIDIOCGPICT, &x->x_vpicture) < 0) - { - perror("VIDIOCGCAP"); - goto closit; - } - - post("pdp_v4l: picture: brightness %d depth %d palette %d", - x->x_vpicture.brightness, x->x_vpicture.depth, x->x_vpicture.palette); - - /* get channel info */ - for (i = 0; i < x->x_vcap.channels; i++) - { - x->x_vchannel.channel = i; - if (ioctl(x->x_tvfd, VIDIOCGCHAN, &x->x_vchannel) < 0) - { - perror("VDIOCGCHAN"); - goto closit; - } - post("pdp_v4l: channel %d name %s type %d flags %d", - x->x_vchannel.channel, x->x_vchannel.name, - x->x_vchannel.type, x->x_vchannel.flags); - } - - /* switch to the desired channel */ - if (x->x_channel < 0) x->x_channel = 0; - if (x->x_channel >= x->x_vcap.channels) x->x_channel = x->x_vcap.channels - 1; - - x->x_vchannel.channel = x->x_channel; - if (ioctl(x->x_tvfd, VIDIOCGCHAN, &x->x_vchannel) < 0) - { - perror("pdp_v4l: warning: VDIOCGCHAN"); - post("pdp_v4l: cant change to channel %d",x->x_channel); - - // ignore error - // goto closit; - } - else{ - post("pdp_v4l: switched to channel %d", x->x_channel); - } - - x->x_vchannel.norm = x->x_norm; - if (ioctl(x->x_tvfd, VIDIOCSCHAN, &x->x_vchannel) < 0) - { - perror("pdp_v4l: warning: VDIOCSCHAN"); - post("pdp_v4l: cant change to norm %d",x->x_norm); - - // ignore error - // goto closit; - } - - if (x->x_freq > 0){ - if (ioctl(x->x_tvfd, VIDIOCSFREQ, &x->x_freq) < 0) - perror ("couldn't set frequency :"); - } - - - - - /* get mmap numbers */ - if (ioctl(x->x_tvfd, VIDIOCGMBUF, &x->x_vmbuf) < 0) - { - perror("pdp_v4l: VIDIOCGMBUF"); - goto closit; - } - post("pdp_v4l: buffer size %d, frames %d, offset %d %d", x->x_vmbuf.size, - x->x_vmbuf.frames, x->x_vmbuf.offsets[0], x->x_vmbuf.offsets[1]); - if (!(x->x_videobuf = (unsigned char *) - mmap(0, x->x_vmbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, x->x_tvfd, 0))) - { - perror("pdp_v4l: mmap"); - goto closit; - } - - pdp_v4l_setlegaldim(x, x->x_width, x->x_height); - width = x->x_width; - height = x->x_height; - - for (i = 0; i < NBUF; i++) - { - //x->x_vmmap[i].format = VIDEO_PALETTE_YUV420P; - //x->x_vmmap[i].format = VIDEO_PALETTE_UYVY; - x->x_vmmap[i].width = width; - x->x_vmmap[i].height = height; - x->x_vmmap[i].frame = i; - } - - - //goto test; - - //try yuv planar format - x->x_v4l_palette = VIDEO_PALETTE_YUV420P; - for (i = 0; i < NBUF; i++) x->x_vmmap[i].format = x->x_v4l_palette; - if (ioctl(x->x_tvfd, VIDIOCMCAPTURE, &x->x_vmmap[x->x_frame]) < 0) - { - if (errno == EAGAIN) - post("pdp_v4l: can't sync (no video source?)"); - } - else{ - post("pdp_v4l: using VIDEO_PALETTE_YUV420P"); - goto capture_ok; - } - - - //try VIDEO_PALETTE_YUV422 format - x->x_v4l_palette = VIDEO_PALETTE_YUV422; - for (i = 0; i < NBUF; i++) x->x_vmmap[i].format = x->x_v4l_palette; - if (ioctl(x->x_tvfd, VIDIOCMCAPTURE, &x->x_vmmap[x->x_frame]) < 0) - { - if (errno == EAGAIN) - post("pdp_v4l: can't sync (no video source?)"); - } - else{ - post("pdp_v4l: using VIDEO_PALETTE_YUV422"); - goto capture_ok; - } - - - test: - - //try rgb packed format - x->x_v4l_palette = VIDEO_PALETTE_RGB24; - for (i = 0; i < NBUF; i++) x->x_vmmap[i].format = x->x_v4l_palette; - if (ioctl(x->x_tvfd, VIDIOCMCAPTURE, &x->x_vmmap[x->x_frame]) < 0) - { - if (errno == EAGAIN) - post("pdp_v4l: can't sync (no video source?)"); - } - else{ - post("pdp_v4l: using VIDEO_PALETTE_RGB24"); - goto capture_ok; - } - - - // none of the formats are supported - perror("pdp_v4l: VIDIOCMCAPTURE: format not supported"); - goto closit; - - - capture_ok: - - post("pdp_v4l: frame %d %d, format %d, width %d, height %d", - x->x_frame, x->x_vmmap[x->x_frame].frame, x->x_vmmap[x->x_frame].format, - x->x_vmmap[x->x_frame].width, x->x_vmmap[x->x_frame].height); - - x->x_width = width; - x->x_height = height; - - post("pdp_v4l: Opened video connection (%dx%d)",x->x_width,x->x_height); - - - /* do some pwc specific inits */ - pdp_v4l_pwc_init(x); - - - x->x_initialized = true; - - /* create thread */ - x->x_continue_thread = 1; - x->x_frame_ready = 0; - pthread_create(&x->x_thread_id, 0, pdp_v4l_thread, x); - - return; - closit: - pdp_v4l_close_error(x); - -} - -static void pdp_v4l_open_manual(t_pdp_v4l *x, t_symbol *name) -{ - x->x_open_retry = PDP_XV_RETRIES; - pdp_v4l_open(x, name); -} - - -static void pdp_v4l_channel(t_pdp_v4l *x, t_float f) -{ - int channel = (float)f; - - if (x->x_initialized){ - pdp_v4l_close(x); - x->x_channel = channel; - pdp_v4l_open(x, x->x_device); - } - else - x->x_channel = channel; -} - - -static void pdp_v4l_freq(t_pdp_v4l *x, t_float f) -{ - int freq = (int)f; - - x->x_freq = freq; - if (x->x_freq > 0){ - if (ioctl(x->x_tvfd, VIDIOCSFREQ, &x->x_freq) < 0) - perror ("couldn't set frequency :"); - else {post("pdp_v4l: tuner frequency: %f MHz", f / 16.0f);} - } - -} - -static void pdp_v4l_freqMHz(t_pdp_v4l *x, t_float f) -{ - pdp_v4l_freq(x, f*16.0f); -} - - -static void pdp_v4l_bang(t_pdp_v4l *x) -{ - - /* if initialized, grab a frame and output it */ - - unsigned int w,h,nbpixels,packet_size,plane1,plane2; - unsigned char *newimage; - int object,length,pos,i,encoding; - t_pdp* header; - short int * data; - - - static short int gain[4] = {0x7fff, 0x7fff, 0x7fff, 0x7fff}; - - if (!(x->x_initialized)){ - post("pdp_v4l: no device opened"); - - if (x->x_auto_open){ - post("pdp_v4l: attempting auto open"); - pdp_v4l_open(x, x->x_device); - if (!(x->x_initialized)){ - post("pdp_v4l: auto open failed"); - return; - } - } - - else return; - } - - - /* do nothing if there is no frame ready */ - if((!x->x_frame_ready) && (x->x_only_new_frames)) return; - x->x_frame_ready = 0; - - /* get the address of the "other" frame */ - newimage = x->x_videobuf + x->x_vmbuf.offsets[x->x_last_frame]; - - /* create new packet */ - w = x->x_width; - h = x->x_height; - - nbpixels = w * h; - -/* - switch(x->x_pdp_image_type){ - case PDP_IMAGE_GREY: - packet_size = nbpixels << 1; - break; - case PDP_IMAGE_YV12: - packet_size = (nbpixels + (nbpixels >> 1)) << 1; - break; - default: - packet_size = 0; - post("pdp_v4l: internal error"); - } -*/ - - packet_size = (nbpixels + (nbpixels >> 1)) << 1; - - - plane1 = nbpixels; - plane2 = nbpixels + (nbpixels>>2); - - object = pdp_packet_new(PDP_IMAGE, packet_size); - header = pdp_packet_header(object); - data = (short int *) pdp_packet_data(object); - - //header->info.image.encoding = x->x_pdp_image_type; - header->info.image.encoding = PDP_IMAGE_YV12; - header->info.image.width = w; - header->info.image.height = h; - - /* read from the "other" frame */ - newimage = x->x_videobuf + x->x_vmbuf.offsets[x->x_frame ^ 0x1]; - - - /* convert data to pdp packet */ - - switch(x->x_v4l_palette){ - case VIDEO_PALETTE_YUV420P: - pdp_llconv(newimage, RIF_YUV__P411_U8, data, RIF_YVU__P411_S16, w, h); - break; - - case VIDEO_PALETTE_RGB24: - pdp_llconv(newimage, RIF_RGB__P____U8, data, RIF_YVU__P411_S16, w, h); - break; - - case VIDEO_PALETTE_YUV422: - pdp_llconv(newimage, RIF_YUYV_P____U8, data, RIF_YVU__P411_S16, w, h); - break; - - - default: - post("pdp_v4l: unsupported palette"); - break; - } - -/* - if (PDP_IMAGE_YV12 == x->x_pdp_image_type){ - pixel_unpack_u8s16_y(&newimage[0], data, nbpixels>>3, x->x_state_data->gain); - pixel_unpack_u8s16_uv(&newimage[plane1], &data[plane2], nbpixels>>5, x->x_state_data->gain); - pixel_unpack_u8s16_uv(&newimage[plane2], &data[plane1], nbpixels>>5, x->x_state_data->gain); - } -*/ - //x->x_v4l_palette = VIDEO_PALETTE_YUV420P; - //x->x_v4l_palette = VIDEO_PALETTE_RGB24; - -/* - - else if(PDP_IMAGE_GREY == x->x_pdp_image_type){ - pixel_unpack_u8s16_y(&newimage[0], data, nbpixels>>3, x->x_state_data->gain); - } -*/ - //post("pdp_v4l: mark unused %d", object); - - pdp_packet_mark_unused(object); - outlet_pdp(x->x_outlet0, object); - - -} - - -static void pdp_v4l_setlegaldim(t_pdp_v4l *x, int xx, int yy) -{ - - unsigned int w,h; - - w = pdp_imageproc_legalwidth((int)xx); - h = pdp_imageproc_legalheight((int)yy); - - w = (w < x->x_maxwidth) ? w : x->x_maxwidth; - w = (w > x->x_minwidth) ? w : x->x_minwidth; - - h = (h < x->x_maxheight) ? h : x->x_maxheight; - h = (h > x->x_minheight) ? h : x->x_minheight; - - x->x_width = w; - x->x_height = h; -} - -static void pdp_v4l_dim(t_pdp_v4l *x, t_floatarg xx, t_floatarg yy) -{ - if (x->x_initialized){ - pdp_v4l_close(x); - pdp_v4l_setlegaldim(x, (int)xx, (int)yy); - pdp_v4l_open(x, x->x_device); - - } - else{ - pdp_v4l_setlegaldim(x, (int)xx, (int)yy); - } -} - - -static void pdp_v4l_free(t_pdp_v4l *x) -{ - pdp_v4l_close(x); -} - -t_class *pdp_v4l_class; - - - -void *pdp_v4l_new(void) -{ - t_pdp_v4l *x = (t_pdp_v4l *)pd_new(pdp_v4l_class); - - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - x->x_initialized = false; - - - x->x_tvfd = -1; - x->x_frame = 0; - x->x_last_frame = 0; - - x->x_framerate = 27; - - x->x_auto_open = true; - x->x_device = gensym("/dev/video0"); - - x->x_continue_thread = 0; - x->x_only_new_frames = 1; - - x->x_width = 320; - x->x_height = 240; - -// pdp_v4l_type(x, gensym("yv12")); - - - x->x_open_retry = PDP_XV_RETRIES; - - x->x_channel = 0; - x->x_freq = -1; //don't set freq by default - - x->x_minwidth = pdp_imageproc_legalwidth(0); - x->x_maxwidth = pdp_imageproc_legalwidth_round_down(0x7fffffff); - x->x_minheight = pdp_imageproc_legalheight(0); - x->x_maxheight = pdp_imageproc_legalheight_round_down(0x7fffffff); - - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_v4l_setup(void) -{ - - - pdp_v4l_class = class_new(gensym("pdp_v4l"), (t_newmethod)pdp_v4l_new, - (t_method)pdp_v4l_free, sizeof(t_pdp_v4l), 0, A_NULL); - - - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_bang, gensym("bang"), A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_close_manual, gensym("close"), A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_open_manual, gensym("open"), A_SYMBOL, A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_channel, gensym("channel"), A_FLOAT, A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_freq, gensym("freq"), A_FLOAT, A_NULL); - class_addmethod(pdp_v4l_class, (t_method)pdp_v4l_freqMHz, gensym("freqMHz"), A_FLOAT, A_NULL); - - - -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/pdp_xv.c b/modules/pdp_xv.c deleted file mode 100644 index fde5409..0000000 --- a/modules/pdp_xv.c +++ /dev/null @@ -1,646 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - -pdp xvideo output - -*/ - -// x stuff -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <X11/extensions/Xv.h> -#include <X11/extensions/Xvlib.h> - -// image formats for communication with the X Server -#define FOURCC_YV12 0x32315659 /* YV12 YUV420P */ -#define FOURCC_YUV2 0x32595559 /* YUV2 YUV422 */ -#define FOURCC_I420 0x30323449 /* I420 Intel Indeo 4 */ - -// pdp stuff -#include "pdp.h" -#include "pdp_llconv.h" - - -/* initial image dimensions */ -#define PDP_XV_W 320 -#define PDP_XV_H 240 - -#define PDP_XV_AUTOCREATE_RETRY 10 - - -typedef struct pdp_xv_struct -{ - t_object x_obj; - t_float x_f; - t_outlet *x_outlet; - - int x_packet0; - int x_queue_id; - t_symbol *x_display; - - Display *x_dpy; - int x_screen; - Window x_win; - GC x_gc; - Atom x_WM_DELETE_WINDOW; - - int x_xv_format; - int x_xv_port; - - int x_winwidth; - int x_winheight; - - XvImage *x_xvi; - unsigned char *x_data; - unsigned int x_width; - unsigned int x_height; - int x_last_encoding; - - int x_initialized; - int x_autocreate; - - float x_cursor; - t_symbol *x_dragbutton; - - -} t_pdp_xv; - - -static int xv_init(t_pdp_xv *x) -{ - unsigned int ver, rel, req, ev, err, i, j; - unsigned int adaptors; - int formats; - XvAdaptorInfo *ai; - - if (Success != XvQueryExtension(x->x_dpy,&ver,&rel,&req,&ev,&err)) return 0; - - /* find + lock port */ - if (Success != XvQueryAdaptors(x->x_dpy,DefaultRootWindow(x->x_dpy),&adaptors,&ai)) - return 0; - for (i = 0; i < adaptors; i++) { - if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) { - for (j=0; j < ai[i].num_ports; j++){ - if (Success != XvGrabPort(x->x_dpy,ai[i].base_id+j,CurrentTime)) { - //fprintf(stderr,"INFO: Xvideo port %ld on adapter %d: is busy, skipping\n",ai[i].base_id+j, i); - } - else { - x->x_xv_port = ai[i].base_id + j; - goto breakout; - } - } - } - } - - - breakout: - - XFree(ai); - if (0 == x->x_xv_port) return 0; - post("pdp_xv: grabbed port %d on adaptor %d", x->x_xv_port, i); - return 1; -} - - -void pdp_xv_create_xvimage(t_pdp_xv *x) -{ - - long size = (x->x_width * x->x_height + (((x->x_width>>1)*(x->x_height>>1))<<1)); - //post("create xvimage %d %d", x->x_width, x->x_height); - x->x_data = (unsigned char *)malloc(size); - x->x_xvi = XvCreateImage(x->x_dpy, x->x_xv_port, x->x_xv_format, (char *)x->x_data, x->x_width, x->x_height); - x->x_last_encoding = -1; - if ((!x->x_xvi) || (!x->x_data)) post ("ERROR CREATING XVIMAGE"); - //post("created xvimag data:%x xvi:%x",x->x_data,x->x_xvi); - -} - -void pdp_xv_destroy_xvimage(t_pdp_xv *x) -{ - if(x->x_data) free(x->x_data); - if (x->x_xvi) XFree(x->x_xvi); - x->x_xvi = 0; - x->x_data = 0; -} - - -static void pdp_xv_cursor(t_pdp_xv *x, t_floatarg f) -{ - if (!x->x_initialized) return; - - if (f == 0) { - static char data[1] = {0}; - - Cursor cursor; - Pixmap blank; - XColor dummy; - - blank = XCreateBitmapFromData(x->x_dpy, x->x_win, data, 1, 1); - cursor = XCreatePixmapCursor(x->x_dpy, blank, blank, &dummy, - &dummy, 0, 0); - XFreePixmap(x->x_dpy, blank); - XDefineCursor(x->x_dpy, x->x_win,cursor); - } - else - XUndefineCursor(x->x_dpy, x->x_win); - - x->x_cursor = f; -} - - -static void pdp_xv_destroy(t_pdp_xv* x) -{ - XEvent e; - - if (x->x_initialized){ - XFreeGC(x->x_dpy, x->x_gc); - XDestroyWindow(x->x_dpy, x->x_win); - while(XPending(x->x_dpy)) XNextEvent(x->x_dpy, &e); - XvUngrabPort(x->x_dpy, x->x_xv_port, CurrentTime); - pdp_xv_destroy_xvimage(x); - XCloseDisplay(x->x_dpy); - x->x_initialized = false; - - } - -} - -static void pdp_xv_resize(t_pdp_xv* x, t_floatarg width, t_floatarg height) -{ - if (x->x_initialized && (width>0) && (height>0)){ - XResizeWindow(x->x_dpy, x->x_win, (unsigned int)width, (unsigned int)height); - XFlush(x->x_dpy); - } -} - -static void pdp_xv_create(t_pdp_xv* x) -{ - unsigned int *uintdata = (unsigned int *)(x->x_data); - XEvent e; - unsigned int i; - - - if( x->x_initialized ){ - //post("pdp_xv: window already created"); - return; - } - - if (NULL == (x->x_dpy = XOpenDisplay(x->x_display->s_name))){ - post("pdp_xv: cant open display %s\n",x->x_display->s_name); - x->x_initialized = false; - return; - } - - /* init xvideo */ - if (xv_init(x)){ - - pdp_xv_create_xvimage(x); - - } - - else { - /* clean up mess */ - post("pdp_xv: ERROR: no xv port available. closing display."); - XCloseDisplay(x->x_dpy); - x->x_initialized = false; - return; - } - - - /* create a window */ - x->x_screen = DefaultScreen(x->x_dpy); - - - x->x_win = XCreateSimpleWindow( - x->x_dpy, - RootWindow(x->x_dpy, x->x_screen), 0, 0, x->x_winwidth, x->x_winheight, 0, - BlackPixel(x->x_dpy, x->x_screen), - BlackPixel(x->x_dpy, x->x_screen)); - - - /* enable handling of close window event */ - x->x_WM_DELETE_WINDOW = XInternAtom(x->x_dpy, "WM_DELETE_WINDOW", True); - (void)XSetWMProtocols(x->x_dpy, x->x_win, &x->x_WM_DELETE_WINDOW, 1); - - if(!(x->x_win)){ - /* clean up mess */ - post("pdp_xv: could not create window\n"); - post("pdp_xv: unlocking xv port"); - XvUngrabPort(x->x_dpy, x->x_xv_port, CurrentTime); - post("pdp_xv: freeing xvimage"); - pdp_xv_destroy_xvimage(x); - post("pdp_xv: closing display"); - XCloseDisplay(x->x_dpy); - x->x_initialized = false; - return; - } - - /* select input events */ - XSelectInput(x->x_dpy, x->x_win, StructureNotifyMask - | ButtonPressMask | ButtonReleaseMask | MotionNotify | ButtonMotionMask); - - - XMapWindow(x->x_dpy, x->x_win); - - x->x_gc = XCreateGC(x->x_dpy, x->x_win, 0, 0); - - for(;;){ - XNextEvent(x->x_dpy, &e); - if (e.type == MapNotify) break; - } - - - /* we're done initializing */ - x->x_initialized = true; - - /* disable/enable cursor */ - pdp_xv_cursor(x, x->x_cursor); - -} - -void pdp_xv_copy_xvimage(t_pdp_xv *x, t_image *image, short int* data) -{ - unsigned int width = image->width; - unsigned int height = image->height; - int encoding = image->encoding; - unsigned int* uintdata; - int i; - - - /* 8bit y fulscale and 8bit u,v 2x2 subsampled */ - //static short int gain[4] = {0x0100, 0x0100, 0x0100, 0x0100}; - long size = (width * height + (((width>>1)*(height>>1))<<1)); - int nbpixels = width * height; - - /* check if xvimage needs to be recreated */ - if ((width != x->x_width) || (height != x->x_height)){ - //post("pdp_xv: replace image"); - x->x_width = width; - x->x_height = height; - pdp_xv_destroy_xvimage(x); - pdp_xv_create_xvimage(x); - } - - - /* data holds a 16bit version of a the xvimage, so it needs to be converted */ - - - - if (data) { - /* convert 16bit -> 8bit */ - if(PDP_IMAGE_YV12 == encoding){ - pdp_llconv(data,RIF_YVU__P411_S16, x->x_data, RIF_YVU__P411_U8, x->x_width, x->x_height); - x->x_last_encoding = PDP_IMAGE_YV12; - } - if(PDP_IMAGE_GREY == encoding){ - pdp_llconv(data,RIF_GREY______S16, x->x_data, RIF_GREY______U8, x->x_width, x->x_height); - if (PDP_IMAGE_GREY != x->x_last_encoding) { - post("pdp_xv: switching to greyscale"); - /* clear u&v planes if necessary */ - uintdata = (unsigned int *)&x->x_data[nbpixels]; - for(i=0; i < nbpixels>>3; i++) uintdata[i]=0x80808080; - } - x->x_last_encoding = PDP_IMAGE_GREY; - - } - } - else bzero(x->x_data, size); - - - -} - -static int pdp_xv_try_autocreate(t_pdp_xv *x) -{ - - if (x->x_autocreate){ - post("pdp_xv: autocreate window"); - pdp_xv_create(x); - if (!(x->x_initialized)){ - x->x_autocreate--; - if (!x->x_autocreate){ - post ("pdp_xv: autocreate failed %d times: disabled", PDP_XV_AUTOCREATE_RETRY); - post ("pdp_xv: send [autocreate 1] message to re-enable"); - return 0; - } - } - else return 1; - - } - return 0; -} - -static void pdp_xv_bang(t_pdp_xv *x); - -static void pdp_xv_process(t_pdp_xv *x) -{ - t_pdp *header = pdp_packet_header(x->x_packet0); - void *data = pdp_packet_data (x->x_packet0); - - - if (-1 != x->x_queue_id) return; - - /* check if window is initialized */ - if (!(x->x_initialized)){ - if (!pdp_xv_try_autocreate(x)) return; - } - - /* check data packet */ - if (!(header)) { - post("pdp_xv: invalid packet header"); - return; - } - if (PDP_IMAGE != header->type) { - post("pdp_xv: packet is not a PDP_IMAGE"); - return; - } - if ((PDP_IMAGE_YV12 != header->info.image.encoding) - && (PDP_IMAGE_GREY != header->info.image.encoding)) { - post("pdp_xv: packet is not a PDP_IMAGE_YV12/GREY"); - return; - } - - /* copy the packet to the xvimage */ - pdp_xv_copy_xvimage(x, &header->info.image, (short int *)data); - - - /* display the new image */ - pdp_xv_bang(x); - - -} - - -static void pdp_xv_random(t_pdp_xv *x) -{ - unsigned int i; - long *intdata = (long *)(x->x_data); - for(i=0; i<x->x_width*x->x_height/4; i++) intdata[i]=random(); -} - - -/* redisplays image */ -static void pdp_xv_bang_thread(t_pdp_xv *x) -{ - - unsigned int i; - XEvent e; - XConfigureEvent *ce = (XConfigureEvent *)&e; - XButtonEvent *be = (XButtonEvent *)&e; - XMotionEvent *me = (XMotionEvent *)&e; - float inv_x, inv_y; - t_symbol *s; - t_atom atom[2]; - char nextdrag[]="drag0"; - char b='0'; - - inv_x = 1.0f / (float)(x->x_winwidth); - inv_y = 1.0f / (float)(x->x_winheight); - - while (XPending(x->x_dpy)){ - - XNextEvent(x->x_dpy, &e); - - switch(e.type){ - case ConfigureNotify: - x->x_winwidth = ce->width; - x->x_winheight = ce->height; - inv_x = 1.0f / (float)(x->x_winwidth); - inv_y = 1.0f / (float)(x->x_winheight); - break; - - case ClientMessage: - if ((Atom)e.xclient.data.l[0] == x->x_WM_DELETE_WINDOW) { - post("pdp_xv: button disabled, please send a \"close\" message to close the window"); - //destroy = 1; - } - break; - - case ButtonPress: - //post("pdp_xv: press %f %f", inv_x * (float)be->x, inv_y * (float)be->y); - SETFLOAT(atom+0,inv_x * (float)be->x); - SETFLOAT(atom+1,inv_y * (float)be->y); - outlet_anything(x->x_outlet, gensym("press"), 2, atom); - switch(be->button){ - case Button1: outlet_anything(x->x_outlet, gensym("press1"), 2, atom); b='1'; break; - case Button2: outlet_anything(x->x_outlet, gensym("press2"), 2, atom); b='2'; break; - case Button3: outlet_anything(x->x_outlet, gensym("press3"), 2, atom); b='3'; break; - case Button4: outlet_anything(x->x_outlet, gensym("press4"), 2, atom); b='4'; break; - case Button5: outlet_anything(x->x_outlet, gensym("press5"), 2, atom); b='5'; break; - default: break; - } - nextdrag[4]=b; - x->x_dragbutton = gensym(nextdrag); - break; - - case ButtonRelease: - //post("pdp_xv: release %f %f", inv_x * (float)be->x, inv_y * (float)be->y); - SETFLOAT(atom+0,inv_x * (float)be->x); - SETFLOAT(atom+1,inv_y * (float)be->y); - outlet_anything(x->x_outlet, gensym("release"), 2, atom); - switch(be->button){ - case Button1: outlet_anything(x->x_outlet, gensym("release1"), 2, atom); break; - case Button2: outlet_anything(x->x_outlet, gensym("release2"), 2, atom); break; - case Button3: outlet_anything(x->x_outlet, gensym("release3"), 2, atom); break; - case Button4: outlet_anything(x->x_outlet, gensym("release4"), 2, atom); break; - case Button5: outlet_anything(x->x_outlet, gensym("release5"), 2, atom); break; - default: break; - } - - break; - case MotionNotify: - //post("pdp_xv: drag %f %f", inv_x * (float)be->x, inv_y * (float)be->y); - SETFLOAT(atom+0,inv_x * (float)be->x); - SETFLOAT(atom+1,inv_y * (float)be->y); - outlet_anything(x->x_outlet, gensym("drag"), 2, atom); - outlet_anything(x->x_outlet, x->x_dragbutton, 2, atom); - break; - - default: - //post("pdp_xv: unknown event"); - break; - } - - } - - // THIS SEEMS TO CRASH ON VERY LARGE IMAGES.. - //post("start"); - //post("XvPutImage xvi:%x",x->x_xvi); - XvPutImage(x->x_dpy,x->x_xv_port,x->x_win,x->x_gc,x->x_xvi, - 0,0,x->x_width,x->x_height, 0,0,x->x_winwidth,x->x_winheight); - //post("XFlush"); - XFlush(x->x_dpy); - - //post("end"); - - - - -} - -static void pdp_xv_bang_callback(t_pdp_xv *x) -{ - /* release the packet if there is one */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1;} - -static void pdp_xv_bang(t_pdp_xv *x) -{ - - /* check if window is initialized */ - if (!(x->x_initialized)){ - if (!pdp_xv_try_autocreate(x)) return; - } - - - /* if previous queued method returned - schedule a new one, else ignore */ - if (-1 == x->x_queue_id) { - pdp_queue_add(x, pdp_xv_bang_thread, pdp_xv_bang_callback, &x->x_queue_id); - } - -} - -static void pdp_xv_input_0(t_pdp_xv *x, t_symbol *s, t_floatarg f) -{ - - if (s == gensym("register_ro")) pdp_packet_copy_ro_or_drop(&x->x_packet0, (int)f); - if (s == gensym("process")) pdp_xv_process(x); - -} - - -static void pdp_xv_vga(t_pdp_xv *x) -{ - pdp_xv_resize(x, 640, 480); -} - -static void pdp_xv_autocreate(t_pdp_xv *x, t_floatarg f) -{ - if (f != 0.0f) x->x_autocreate = PDP_XV_AUTOCREATE_RETRY; - else x->x_autocreate = 0; -} - -static void pdp_xv_display(t_pdp_xv *x, t_symbol *s) -{ - pdp_queue_finish(x->x_queue_id); - x->x_queue_id = -1; - x->x_display = s; - if (x->x_initialized){ - pdp_xv_destroy(x); - pdp_xv_create(x); - } -} - - - -static void pdp_xv_free(t_pdp_xv *x) -{ - pdp_queue_finish(x->x_queue_id); - - pdp_xv_destroy(x); - pdp_packet_mark_unused(x->x_packet0); -} - -t_class *pdp_xv_class; - - - -void *pdp_xv_new(void) -{ - t_pdp_xv *x = (t_pdp_xv *)pd_new(pdp_xv_class); - x->x_outlet = outlet_new(&x->x_obj, &s_anything); - - - x->x_packet0 = -1; - x->x_queue_id = -1; - x->x_display = gensym(":0"); - - - x->x_dpy = 0; - x->x_screen = -1; - - x->x_xv_format = FOURCC_YV12; - x->x_xv_port = 0; - - x->x_winwidth = PDP_XV_W; - x->x_winheight = PDP_XV_H; - - x->x_width = PDP_XV_W; - x->x_height = PDP_XV_H; - - x->x_data = 0; - x->x_xvi = 0; - - x->x_initialized = 0; - pdp_xv_autocreate(x,1); - x->x_last_encoding = -1; - - x->x_cursor = 0; - x->x_dragbutton = gensym("drag1"); - - //pdp_xv_create(x); - - return (void *)x; -} - - - - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_xv_setup(void) -{ - - - pdp_xv_class = class_new(gensym("pdp_xv"), (t_newmethod)pdp_xv_new, - (t_method)pdp_xv_free, sizeof(t_pdp_xv), 0, A_NULL); - - - class_addmethod(pdp_xv_class, (t_method)pdp_xv_bang, gensym("bang"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_random, gensym("random"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_create, gensym("open"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_create, gensym("create"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_autocreate, gensym("autocreate"), A_FLOAT, A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_destroy, gensym("destroy"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_destroy, gensym("close"), A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_resize, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_resize, gensym("size"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_display, gensym("display"), A_SYMBOL, A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - class_addmethod(pdp_xv_class, (t_method)pdp_xv_cursor, gensym("cursor"), A_FLOAT, A_NULL); - - /* some shortcuts for the lazy */ - class_addmethod(pdp_xv_class, (t_method)pdp_xv_vga, gensym("vga"), A_NULL); - -} - -#ifdef __cplusplus -} -#endif - - diff --git a/modules/pdp_zoom.c b/modules/pdp_zoom.c deleted file mode 100644 index c89efb1..0000000 --- a/modules/pdp_zoom.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include "pdp.h" -#include "pdp_resample.h" - - - -typedef struct pdp_zoom_struct -{ - t_object x_obj; - t_float x_f; - - t_outlet *x_outlet0; - - - int x_packet0; - int x_packet1; - int x_dropped; - int x_queue_id; - - void *x_zoom; - - int x_quality; //not used - - -} t_pdp_zoom; - - -static void pdp_zoom_process_yv12(t_pdp_zoom *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - short int *src_image = (short int *)data0; - short int *dst_image = (short int *)data1; - - unsigned int size = w * h; - unsigned int voffset = size; - unsigned int uoffset = size + (size>>2); - - pdp_imageproc_resample_affinemap_process(x->x_zoom, src_image, dst_image, w, h); - pdp_imageproc_resample_affinemap_process(x->x_zoom, src_image+voffset, dst_image+voffset, w>>1, h>>1); - pdp_imageproc_resample_affinemap_process(x->x_zoom, src_image+uoffset, dst_image+uoffset, w>>1, h>>1); - - - return; -} - -static void pdp_zoom_process_grey(t_pdp_zoom *x) -{ - - t_pdp *header0 = pdp_packet_header(x->x_packet0); - t_pdp *header1 = pdp_packet_header(x->x_packet1); - void *data0 = pdp_packet_data (x->x_packet0); - void *data1 = pdp_packet_data (x->x_packet1); - - unsigned int w = header0->info.image.width; - unsigned int h = header0->info.image.height; - - short int *src_image = (short int *)data0; - short int *dst_image = (short int *)data1; - - pdp_imageproc_resample_affinemap_process(x->x_zoom, src_image, dst_image, w, h); - - return; - -} - -static void pdp_zoom_sendpacket(t_pdp_zoom *x) -{ - /* delete source packet */ - pdp_packet_mark_unused(x->x_packet0); - x->x_packet0 = -1; - - /* unregister and propagate if valid dest packet */ - pdp_pass_if_valid(x->x_outlet0, &x->x_packet1); -} - -static void pdp_zoom_process(t_pdp_zoom *x) -{ - t_pdp *header0 = pdp_packet_header(x->x_packet0); - - /* check data packets */ - - if ((header0) && (PDP_IMAGE == header0->type)){ - - - /* type hub */ - switch(header0->info.image.encoding){ - - case PDP_IMAGE_YV12: - x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); - pdp_queue_add(x, pdp_zoom_process_yv12, pdp_zoom_sendpacket, &x->x_queue_id); - break; - - case PDP_IMAGE_GREY: - x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); - pdp_queue_add(x, pdp_zoom_process_grey, pdp_zoom_sendpacket, &x->x_queue_id); - break; - - default: - break; - /* don't know the type, so dont process */ - - } - } - -} - - - - -static void pdp_zoom_input_0(t_pdp_zoom *x, t_symbol *s, t_floatarg f) -{ - - int p = (int)f; - int passes, i; - - if (s== gensym("register_rw")) x->x_dropped = pdp_packet_copy_ro_or_drop(&x->x_packet0, p); - - - if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ - - /* add the process method and callback to the process queue */ - pdp_zoom_process(x); - - } - -} - - - - -static void pdp_zoom_zoom_x(t_pdp_zoom *x, t_floatarg f) -{ - pdp_imageproc_resample_affinemap_setzoomx(x->x_zoom, f); -} - -static void pdp_zoom_angle(t_pdp_zoom *x, t_floatarg f) -{ - pdp_imageproc_resample_affinemap_setangle(x->x_zoom, f); -} - -static void pdp_zoom_zoom_y(t_pdp_zoom *x, t_floatarg f) -{ - pdp_imageproc_resample_affinemap_setzoomy(x->x_zoom, f); -} - -static void pdp_zoom_zoom(t_pdp_zoom *x, t_floatarg f) -{ - pdp_zoom_zoom_x(x, f); - pdp_zoom_zoom_y(x, f); -} - -static void pdp_zoom_center_x(t_pdp_zoom *x, t_floatarg f) -{ - pdp_imageproc_resample_affinemap_setcenterx(x->x_zoom, f); -} - -static void pdp_zoom_center_y(t_pdp_zoom *x, t_floatarg f) -{ - pdp_imageproc_resample_affinemap_setcentery(x->x_zoom, f); -} -static void pdp_zoom_center(t_pdp_zoom *x, t_floatarg fx, t_floatarg fy) -{ - pdp_zoom_center_x(x, fx); - pdp_zoom_center_y(x, fy); -} - -// not used -static void pdp_zoom_quality(t_pdp_zoom *x, t_floatarg f) -{ - if (f==0) x->x_quality = 0; - if (f==1) x->x_quality = 1; -} - - -t_class *pdp_zoom_class; - - - -void pdp_zoom_free(t_pdp_zoom *x) -{ - pdp_queue_finish(x->x_queue_id); - pdp_imageproc_resample_affinemap_delete(x->x_zoom); - pdp_packet_mark_unused(x->x_packet0); - pdp_packet_mark_unused(x->x_packet1); -} - - -void pdp_zoom_init_common(t_pdp_zoom *x) -{ - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - x->x_packet0 = -1; - x->x_packet1 = -1; - x->x_queue_id = -1; - - x->x_zoom = pdp_imageproc_resample_affinemap_new(); - - //quality is not used: all routines are "high quality" bilinear - //pdp_zoom_quality(x, 1); - pdp_zoom_center_x(x, 0.5f); - pdp_zoom_center_y(x, 0.5f); - -} - - -void *pdp_zoom_new(t_floatarg zoom) -{ - t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("zoom")); - - pdp_zoom_init_common(x); - - if (zoom == 0.0f) zoom = 1.0f; - pdp_zoom_zoom(x, zoom); - pdp_zoom_angle(x, 0.0f); - - return (void *)x; -} - -void *pdp_zrot_new(t_floatarg zoom, t_floatarg angle) -{ - t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("zoom")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("angle")); - - pdp_zoom_init_common(x); - - if (zoom == 0.0f) zoom = 1.0f; - pdp_zoom_zoom(x, zoom); - pdp_zoom_angle(x, angle); - - return (void *)x; -} - -void *pdp_rotate_new(t_floatarg angle) -{ - t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class); - - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("angle")); - - pdp_zoom_init_common(x); - pdp_zoom_zoom(x, 1.0f); - pdp_zoom_angle(x, angle); - - return (void *)x; -} - - -#ifdef __cplusplus -extern "C" -{ -#endif - - -void pdp_zoom_setup(void) -{ - - pdp_zoom_class = class_new(gensym("pdp_zoom"), (t_newmethod)pdp_zoom_new, - (t_method)pdp_zoom_free, sizeof(t_pdp_zoom), 0, A_DEFFLOAT, A_NULL); - - class_addcreator((t_newmethod)pdp_zrot_new, gensym("pdp_zrot"), A_DEFFLOAT, A_DEFFLOAT, A_NULL); - class_addcreator((t_newmethod)pdp_rotate_new, gensym("pdp_rotate"), A_DEFFLOAT, A_NULL); - - - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_quality, gensym("quality"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center_x, gensym("centerx"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center_y, gensym("centery"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center, gensym("center"), A_FLOAT, A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom_x, gensym("zoomx"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom_y, gensym("zoomy"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom, gensym("zoom"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_angle, gensym("angle"), A_FLOAT, A_NULL); - class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); - -} - -#ifdef __cplusplus -} -#endif diff --git a/pdp-config.1 b/pdp-config.1 new file mode 100644 index 0000000..b65dbbd --- /dev/null +++ b/pdp-config.1 @@ -0,0 +1,87 @@ +.\" This -*- nroff -*- file has been generated from +.\" DocBook SGML with docbook-to-man on Debian GNU/Linux. +...\" +...\" transcript compatibility for postscript use. +...\" +...\" synopsis: .P! <file.ps> +...\" +.de P! +\\&. +.fl \" force out current output buffer +\\!%PB +\\!/showpage{}def +...\" the following is from Ken Flowers -- it prevents dictionary overflows +\\!/tempdict 200 dict def tempdict begin +.fl \" prolog +.sy cat \\$1\" bring in postscript file +...\" the following line matches the tempdict above +\\!end % tempdict % +\\!PE +\\!. +.sp \\$2u \" move below the image +.. +.de pF +.ie \\*(f1 .ds f1 \\n(.f +.el .ie \\*(f2 .ds f2 \\n(.f +.el .ie \\*(f3 .ds f3 \\n(.f +.el .ie \\*(f4 .ds f4 \\n(.f +.el .tm ? font overflow +.ft \\$1 +.. +.de fP +.ie !\\*(f4 \{\ +. ft \\*(f4 +. ds f4\" +' br \} +.el .ie !\\*(f3 \{\ +. ft \\*(f3 +. ds f3\" +' br \} +.el .ie !\\*(f2 \{\ +. ft \\*(f2 +. ds f2\" +' br \} +.el .ie !\\*(f1 \{\ +. ft \\*(f1 +. ds f1\" +' br \} +.el .tm ? font underflow +.. +.ds f1\" +.ds f2\" +.ds f3\" +.ds f4\" +'\" t +.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n +.TH "PDP" "1" +.SH "NAME" +pdp \(em script to get information about the installed version of PDP +.SH "SYNOPSIS" +.PP +\fBpdp\fP [\fB--version\fP] [\fB--cflags\fP] [\fB--libdir\fP] +.SH "DESCRIPTION" +.PP +\fBpdp\fP is a tool that is used to configure to determine the compiler and linker flags that should be used to compile and links modules that use PDP. + +.SH "OPTIONS" +.PP +\fBpdp\fP accepts the following options: +.IP "\fB--version\fP " 10 +Print the currently installed version of PDP on the standard output. +.IP "\fB--cflags\fP " 10 +Print the compiler flags that are necessary to compile a PDP module. +.IP "\fB--libdir\fP " 10 +Print the linker flags that are necessary to link a PDP module. +.SH "SEE ALSO" +.PP +pd (1). +.SH "AUTHOR" +.PP +This manual page was written by Pablo Martín caedes@sindominio.net for +the \fBDebian\fP system (but may be used by others). Permission is +granted to copy, distribute and/or modify this document under +the terms of the GNU Free Documentation +License, Version 1.1 or any later version published by the Free +Software Foundation; with no Invariant Sections, no Front-Cover +Texts and no Back-Cover Texts. +...\" created by instant / docbook-to-man, Thu 14 Aug 2003, 15:18 diff --git a/scaf/COPYING b/scaf/COPYING deleted file mode 100644 index 7f87ef8..0000000 --- a/scaf/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR PDP.LICENSE, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) 19yy <name of author> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/scaf/Makefile b/scaf/Makefile deleted file mode 100644 index 783b459..0000000 --- a/scaf/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -include Makefile.config - -all: pdp_scaf.pd_linux - -pdp_scaf_all: - make -C include - make -C compiler - make -C rules - make -C pdp - -clean: - rm -f *~ - rm -f pdp_scaf.pd_linux - make -C include clean - make -C compiler clean - make -C rules clean - make -C pdp clean - -mrproper: clean - rm -rf configure - rm -rf Makefile.config - rm -rf config.status - rm -rf config.log - rm -rf autom4te.cache - -pdp_scaf.pd_linux: pdp_scaf_all - rm -f pdp_scaf.pd_linux - gcc -export_dynamic -shared -o pdp_scaf.pd_linux pdp/*.o $(PDP_CA_LIBS) - -install: all - install -d $(prefix)/lib/scaf - install -m 755 compiler/scafc $(prefix)/bin - install -m 755 compiler/scafc.pl $(prefix)/lib/scaf - install -m 644 compiler/kernel.scaf $(prefix)/lib/scaf - install -m 644 compiler/scafmacro.s $(prefix)/lib/scaf - install -m 644 compiler/optim.rules $(prefix)/lib/scaf - install -m 755 rules/carules.scafo $(prefix)/lib/scaf/default.scafo - #Check if pd is installed in $(prefix)/lib/pd. - #If this fails the pdp_scaf lib and the docs won't be installed. - test -d $(prefix)/lib/pd - install -m 755 pdp_scaf.pd_linux $(prefix)/lib/pd/externs - install -m 644 doc/*.pd $(prefix)/lib/pd/doc/5.reference diff --git a/scaf/Makefile.config.in b/scaf/Makefile.config.in deleted file mode 100644 index 12927d3..0000000 --- a/scaf/Makefile.config.in +++ /dev/null @@ -1,30 +0,0 @@ -# build flags - -# define the include paths here if configure can't find them -# PDP_CFLAGS=-I/somehere/pdp/include -# PD_CFLAGS=-I/somewhere/pd/src - - -prefix=@prefix@ -PDP_CA_INCLUDE = @CPPFLAGS@ -PDP_CA_LIBS = @LIBS@ -DEFAULT_RULES_LIB = @DEFAULT_RULES_LIB@ -PDP_CA_AFLAGS = -#--gstabs -PDP_CA_CFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -ffast-math \ - -Wall -W -Wstrict-prototypes -Werror \ - -Wno-unused -Wno-parentheses -Wno-switch -g $(PDP_CFLAGS) $(PD_CFLAGS) \ - -DPDP_CA_RULES_LIB=\"$(DEFAULT_RULES_LIB)\" -# -Wshadow - -# compiler and assembler -#CC = gcc-3.2 -#CC = gcc -#AS = as - -# build rules - -.c.o: - $(CC) $(PDP_CA_CFLAGS) $(PDP_CA_INCLUDE) $(PDP_CA_DEFS) -o $*.o -c $*.c -.s.o: - $(AS) -o $*.o $*.s $(PDP_CA_AFLAGS) diff --git a/scaf/README b/scaf/README deleted file mode 100644 index e71d1c9..0000000 --- a/scaf/README +++ /dev/null @@ -1,92 +0,0 @@ -PDP_SCAF for pdp v0.7 -Cellular Automata modules for PDP - -Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -The GNU Public Licence can be found in the file COPYING - - ------------------------------------------------------------------- - -This is a pdp extension lib that contains modules for cellular -automata built on a (very) minimal forth-like virtual system -(scaf - simple cellular automaton forth) to define update rules. a -compiler is included to produce scafo object code that can be -dynamically loaded into the pdp_ca module. so it is possible to -add/change rules without restarting pd (note however you need to close -all lib files before the dynamic loader reloads the lib). see -scaf/README for details. - - -pdp_ca2image and pdp_image2ca are included for conversion between -CA packets and image packets. (pdp_ca2image produces greyscale -images) - -Have a look at the patches in test/ for some crude docs. The file -README.scaf contains some more info on the internals. - - -Requirements: - -* pd -* pdp -* linux -* perl for the forth compiler -* an intel/amd processor that supports MMX - - -Building: - -./configure -make -make install - -If you don't have both libraries in the same dir and want to keep -it that way, hardcode the paths in Makefile.config.in and run -configure. You need to do "make install" to install the scaf compiler -"scafc" and the default ruleset. This is to be able to load plain -(text) rule files and have the default rules loaded when you create -a pdp_ca object. - -Using: - -add "-lib <SCAF_DIR>/pdp_scaf" to the pd command line after the -"-lib <PDP_DIR>/pdp" part. - - - -launch pd with the options -lib $PDP_DIR/pdp -path $PDP_DIR/abstractions - -Directory structure: - -include/ header files -pdp/ pdp external code -compiler/ forth system code -test/ some test patches (cryptic doc) -rules/ ca rule libraries - - - -Please let me know if you discover a bug or think something doesn't work -right. Code, documentation or example patches are more than welcome of -course. - -Have Fun, - -Tom - -last modified: 2003/01/12 diff --git a/scaf/README.scaf b/scaf/README.scaf deleted file mode 100644 index 0035899..0000000 --- a/scaf/README.scaf +++ /dev/null @@ -1,98 +0,0 @@ -SCAF - simple cellular automaton forth - -scaf is a virtual machine / forth environment for binary arithmic -tailored to 2D 1 cell neighbourhood cellular automata. - -scaf is a compiled language. programs run inside a "feeder" -(sort of operating system if you want) - -the feeder is responsable for loading/storing CA cells -from/to memory. data in memory is organized as a scanline -encoded toroidial bitplane (lsb = left). to simplify the feeder -and the stack machine, the top left corner of the rectangular grid -of pixels will shift down every processing step. this enables -to keep a cell neighbourhood in a couple of registers. - -the stack machine has the following architecture: -CA stack: (%esi), TOS: %mm0 (32x2 cells. lsb = top left) -CA horizon: (%edi) (64x4 cells. (%edi) = top row. lsb = left) - -scratch register: %mm1, %mm2 -bitmask register: %mm3 = 0xffffffffffffffff - -4 bit counter: %mm4-%mm7 - -the stack size / organization is not known to the stack machine. -it can be thought of as operating on a 3x3 cell neightbourhood. -the only purpose of the forth program is to determine the CA local update rule. - -the machine is supposed to be very minimal. no looping control. -no adressing modes. no conditional code. so recursion is not allowed -(no way to stop it) there are 9 words to load the cell neigbourhood -on the stack. the rest is just logic and stack manips. - -the counter can be used for counting neighbourhood cells, like in the -game of life. the zero test and sign bit can be used for comparisons. -there are kernel words for loading constants into the counter register, -and for communication between stack and register. - -the horizon is limited to 3x3, however it can be easily extended to -32x3. extending it further than that would require a redesign of the -forth + feeder. - - -HOW TO CREATE NEW CA RULES - -edit scaf/modules/carules.scaf or create your own source lib and add -the name to the scaf/modules/Makefile. type make in scaf/modules -to compile. if you get error messages from the assembler saying things -like - - Error: no such instruction: `xxx' - - or - Error: invalid character '_' in mnemonic - -this means there are undefined words in your source file. since not -all characters are allowed in an asm file, the offending characters are -converted to _SOMETHINGELSE_ - -if you are stuck somewhere, just look at the output of scaf.pl on -your .scaf file to determine where the problem is. - -words that can be accessed from inside pdp_ca have to start with the -prefix rule_ and have to leave a single item on the data stack (the return -value) other rules can have all the stack effect you want, but for safety -reasons they can't be accessed from within pdp_ca. - - - -FORTH SYSTEM CODE - -the forth system is made up of the following files: - -kernel.scaf: a collection of forth kernel words -scafmacro.s: a set of asm macro definitions used in kernel.scaf -optim.rules: some substitution rules to eliminate redundant - stack manipulations - -scaf.pl: the compiler - -scaf.pl is run like this: - -scaf.pl -Isystemdir source.scaf - -if the -I switch is left out, the current directory is searched -for the system files. the compiler produces an assembler source -that includes scafmacro.s on standard output. - -the code it produces is relatively fast. it only uses and/or/xor -and shift mmx instructions. it's not optimal use of silicon but -it's pretty fast given what's possible. the feeder routine could -be improved though. - -porting to another platform would require a rewrite of scafmacro.s -the rest can be reused. if the target machine has 64 bit registers -(or if you can emulate this one using more registers) porting is -relatively easy. for larger registers a small change needs to -be made to the feeder routine in pdp_ca.c diff --git a/scaf/TODO b/scaf/TODO deleted file mode 100644 index bbeebec..0000000 --- a/scaf/TODO +++ /dev/null @@ -1,3 +0,0 @@ -* add decimating to pdp_ca2image -* clean up library -* add translation option to pdp_ca (modify so horizontal shifts by 1 are possible) diff --git a/scaf/configure.ac b/scaf/configure.ac deleted file mode 100644 index 4b15a18..0000000 --- a/scaf/configure.ac +++ /dev/null @@ -1,53 +0,0 @@ -AC_INIT(pdp/pdp_ca_system.c) -AC_PROG_CC -AC_HEADER_STDC - -dnl default install prefix is /usr/local -if test $prefix == "NONE"; -then - prefix=/usr/local -fi - -AC_PATH_PROG(PDP_CONFIG,pdp-config,"no", $PATH) - -AC_CHECK_LIB(m,sin) -AC_CHECK_LIB(dl,dlopen,, echo libdl not found. sorry... || exit 1) - - -TOPSRC=`pwd` -PARENT=`dirname $TOPSRC` - -dnl if pdp-config is found use it to get the cflags -if ! test $PDP_CONFIG == "no" -then - PDP_CPPFLAGS=`$PDP_CONFIG --cflags` - -dnl if not, check in the parent dir (in case we are distributed with the pdp package) -elif test -f $PARENT/include/pdp.h -then - PDP_CPPFLAGS="-I$PARENT/include" -fi - -CPPFLAGS="$CPPFLAGS $PDP_CPPFLAGS" -AC_CHECK_HEADER(m_pd.h,,PD_OK=no) -AC_CHECK_HEADER(pdp.h,,PDP_OK=no) - -if test PD_OK == "no"; -then - echo "WARNING: m_pd.h not found. Is PD installed? - echo "WARNING: You can ignore this warning if you have set the PD_CFLAGS manually in Makefile.config.in -fi - -if test PDP_OK == "no"; -then - echo "WARNING: pdp.h not found. Is PDP installed? - echo "WARNING: You can ignore this warning if you have set the PDP_CFLAGS manually in Makefile.config.in -fi - -CPPFLAGS="$CPPFLAGS $PDFLAGS $PDPFLAGS -I$TOPSRC/include" - -DEFAULT_RULES_LIB=$prefix/lib/scaf/default.scafo; -AC_SUBST(DEFAULT_RULES_LIB) - -AC_CONFIG_FILES(Makefile.config) -AC_OUTPUT diff --git a/system/Makefile b/system/Makefile deleted file mode 100644 index 227e72e..0000000 --- a/system/Makefile +++ /dev/null @@ -1,30 +0,0 @@ - -OBJECTS = pdp.o pdp_ut.o pdp_packet.o pdp_type.o pdp_queue.o pdp_comm.o \ - pdp_control.o pdp_llconv.o pdp_resample.o - -OBJECTS_MMX = pdp_imageproc_mmx.o pdp_llconv_mmx.o -OBJECTS_PORTABLE = pdp_imageproc_portable.o pdp_llconv_portable.o - - - -include ../Makefile.config - -all: $(PDP_TARGET) common_objects - - -linux_mmx: $(OBJECTS_MMX) - make -C mmx - -linux: $(OBJECTS_PORTABLE) - -darwin: $(OBJECTS_PORTABLE) - -pdp_main_clean: - rm -f pdp.o - -common_objects: pdp_main_clean $(OBJECTS) - -clean: - rm -f *~ - rm -f *.o - make -C mmx clean diff --git a/system/Makefile.linux b/system/Makefile.linux deleted file mode 100644 index 96660f7..0000000 --- a/system/Makefile.linux +++ /dev/null @@ -1,2 +0,0 @@ -platform_targets: pdp_imageproc_portable.o pdp_llconv_portable.o - diff --git a/system/Makefile.linux_mmx b/system/Makefile.linux_mmx deleted file mode 100644 index a646e5e..0000000 --- a/system/Makefile.linux_mmx +++ /dev/null @@ -1,4 +0,0 @@ -platform_subtree: - make -C mmx - -platform_targets: pdp_imageproc_mmx.o pdp_llconv_mmx.o platform_subtree diff --git a/system/pdp.c b/system/pdp.c deleted file mode 100644 index 5475c8d..0000000 --- a/system/pdp.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Pure Data Packet system implementation: setup code - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include "pdp_config.h" -#include "pdp.h" -#include <stdio.h> - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - - - -/* module setup declarations (all C-style) */ - -/* pdp system / internal stuff */ -void pdp_packet_setup(void); -void pdp_ut_setup(void); -void pdp_queue_setup(void); -void pdp_control_setup(void); - -/* pdp modules */ -void pdp_xv_setup(void); -void pdp_add_setup(void); -void pdp_mul_setup(void); -void pdp_mix_setup(void); -void pdp_randmix_setup(void); -void pdp_qt_setup(void); -void pdp_v4l_setup(void); -void pdp_reg_setup(void); -void pdp_conv_setup(void); -void pdp_bq_setup(void); -void pdp_affine_setup(void); -void pdp_del_setup(void); -void pdp_snap_setup(void); -void pdp_trigger_setup(void); -void pdp_route_setup(void); -void pdp_noise_setup(void); -void pdp_gradient_setup(void); -void pdp_gain_setup(void); -void pdp_grey_setup(void); -void pdp_chrot_setup(void); -void pdp_scope_setup(void); -void pdp_scale_setup(void); -void pdp_zoom_setup(void); -void pdp_scan_setup(void); -void pdp_scanxy_setup(void); -void pdp_sdl_setup(void); -void pdp_cheby_setup(void); -void pdp_grey2mask_setup(void); -void pdp_constant_setup(void); -void pdp_slice_cut_setup(void); -void pdp_slice_glue_setup(void); - - - -/* library setup routine */ -void pdp_setup(void){ - - /* babble */ - post ("PDP: pure data packet"); - -#ifdef PDP_VERSION - fprintf(stderr, "PDP: version " PDP_VERSION "\n"); -#endif - - - /* setup pdp system */ - pdp_packet_setup(); - pdp_queue_setup(); - pdp_control_setup(); - - /* setup utility toolkit */ - pdp_ut_setup(); - - /* setup pdp modules*/ - pdp_add_setup(); - pdp_mul_setup(); - pdp_mix_setup(); - pdp_randmix_setup(); - pdp_reg_setup(); - pdp_conv_setup(); - pdp_bq_setup(); - pdp_affine_setup(); - pdp_del_setup(); - pdp_snap_setup(); - pdp_trigger_setup(); - pdp_route_setup(); - pdp_noise_setup(); - pdp_gradient_setup(); - pdp_gain_setup(); - pdp_grey_setup(); - pdp_chrot_setup(); - pdp_scope_setup(); - pdp_scale_setup(); - pdp_zoom_setup(); - pdp_scan_setup(); - pdp_scanxy_setup(); - pdp_cheby_setup(); - pdp_grey2mask_setup(); - pdp_constant_setup(); - - - /* experimental stuff */ - pdp_slice_cut_setup(); - pdp_slice_glue_setup(); - - - /* optional modules */ - -#ifdef HAVE_PDP_QT - pdp_qt_setup(); -#endif - -#ifdef HAVE_PDP_XV - pdp_xv_setup(); -#endif - -#ifdef HAVE_PDP_SDL - pdp_sdl_setup(); -#endif - -#ifdef HAVE_PDP_V4L - pdp_v4l_setup(); -#endif - -} - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_comm.c b/system/pdp_comm.c deleted file mode 100644 index 80cbaaa..0000000 --- a/system/pdp_comm.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Pure Data Packet system implementation. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* this file contains misc communication methods */ - - -#include "pdp.h" -#include "pdp_internals.h" -#include <stdio.h> - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - - -/************** packet management and communication convenience functions ************/ - -/* send a packet to an outlet */ -void outlet_pdp(t_outlet *out, int packetid) -{ - t_atom atom[2]; - t_symbol *s = gensym("pdp"); - t_symbol *rro = gensym("register_ro"); - t_symbol *rrw = gensym("register_rw"); - t_symbol *proc = gensym("process"); - - - SETFLOAT(atom+1, (float)packetid); - - SETSYMBOL(atom+0, rro); - outlet_anything(out, s, 2, atom); - - SETSYMBOL(atom+0, rrw); - outlet_anything(out, s, 2, atom); - - /* this is not really necessary, it can be triggered by the rw message */ - SETSYMBOL(atom+0, proc); - outlet_anything(out, s, 1, atom); - -} - - -/* unregister a packet and send it to an outlet */ -void -pdp_pass_if_valid(t_outlet *outlet, int *packet) -{ - if (-1 != *packet){ - pdp_packet_mark_unused(*packet); - outlet_pdp(outlet, *packet); - *packet = -1; - } -} - -void -pdp_replace_if_valid(int *dpacket, int *spacket) -{ - if (-1 != *spacket){ - pdp_packet_mark_unused(*dpacket); - *dpacket = *spacket; - *spacket = -1; - } - -} - - -int -pdp_packet_copy_ro_or_drop(int *dpacket, int spacket) -{ - int drop = 0; - if (*dpacket == -1) *dpacket = pdp_packet_copy_ro(spacket); - else { - /* send a notification there is a dropped packet */ - pdp_control_notify_drop(spacket); - drop = 1; - } - return drop; -} - - -int -pdp_packet_copy_rw_or_drop(int *dpacket, int spacket) -{ - int drop = 0; - if (*dpacket == -1) *dpacket = pdp_packet_copy_rw(spacket); - else { - /* send a notification there is a dropped packet */ - pdp_control_notify_drop(spacket); - drop = 1; - } - return drop; -} - - - - - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_control.c b/system/pdp_control.c deleted file mode 100644 index 1053f6d..0000000 --- a/system/pdp_control.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Pure Data Packet system implementation: control object - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* this is an actual pd class that is used for communication with the - pdp framework */ - -#include "pdp.h" -#include "pdp_internals.h" -#include <stdio.h> - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - - - -static long dropped_packets; - -static t_class* pdp_control_class; - - -/* pdp control instance data */ - -struct pdp_control_struct; -typedef struct pdp_control_struct -{ - t_object x_obj; - t_outlet *x_outlet0; - struct pdp_control_struct *x_next; - -} t_pdp_control; - -typedef void (t_pdp_control_method_notify)(t_pdp_control *x); - - -static t_pdp_control *pdp_control_list; - -static void pdp_control_info(t_pdp_control *x) -{ -} - -static void pdp_control_thread(t_pdp_control *x, t_floatarg f) -{ - int t = (int)f; - - if (t){ - post("pdp_control: pdp is now using its own processing thread"); - pdp_queue_use_thread(1); - } - else { - post("pdp_control: pdp is now using the main pd thread"); - pdp_queue_use_thread(0); - } -} - - -static void pdp_control_send_drop_message(t_pdp_control *x) -{ - t_atom atom[1]; - t_symbol *s = gensym("pdp_drop"); - - SETFLOAT(atom+0, (float)dropped_packets); - outlet_anything(x->x_outlet0, s, 1, atom); -} - - -static void pdp_control_free(t_pdp_control *x) -{ - /* remove from linked list */ - t_pdp_control *curr = pdp_control_list; - if (pdp_control_list == x) pdp_control_list = x->x_next; - else while (curr){ - if (curr->x_next == x) { - curr->x_next = x->x_next; - break; - } - else { - curr = curr->x_next; - } - - } -} - - -static void *pdp_control_new(void) -{ - t_pdp_control *x = (t_pdp_control *)pd_new(pdp_control_class); - x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); - - /* add to list */ - x->x_next = pdp_control_list; - pdp_control_list = x; - return x; -} - -/************************* class methods ***************************************/ - - -void pdp_control_setup(void) -{ - - pdp_control_list = 0; - dropped_packets = 0; - - /* setup pd class data */ - pdp_control_class = class_new(gensym("pdp_control"), (t_newmethod)pdp_control_new, - (t_method)pdp_control_free, sizeof(t_pdp_control), 0, A_NULL); - - - class_addmethod(pdp_control_class, (t_method)pdp_control_info, gensym("info"), A_NULL); - class_addmethod(pdp_control_class, (t_method)pdp_control_thread, gensym("thread"), A_DEFFLOAT, A_NULL); -} - - - -void pdp_control_notify_broadcast(t_pdp_control_method_notify *notify) -{ - t_pdp_control *curr = pdp_control_list; - while (curr){ - (*notify)(curr); - curr = curr->x_next; - } -} - - - -/************************* notify class methods *************************/ - -void pdp_control_notify_drop(int packet) -{ - dropped_packets++; - - /* send drop notify to controller class instances */ - pdp_control_notify_broadcast(pdp_control_send_drop_message); - //post("dropped packet"); -} - - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_imageproc_mmx.c b/system/pdp_imageproc_mmx.c deleted file mode 100644 index fde790f..0000000 --- a/system/pdp_imageproc_mmx.c +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Pure Data Packet. c wrapper for mmx image processing routines. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* this is a c wrapper around platform specific (mmx) code */ -#include <stdlib.h> -#include <math.h> -#include "pdp_mmx.h" -#include "pdp_imageproc.h" -#include "m_pd.h" - -/* round image dims to next multiple of 8 */ -u32 pdp_imageproc_legalwidth(int i) -{ - if (i>1024) return 1024; - if (i>0) return ((((i-1)>>3)+1)<<3); - return 8; - -} - -u32 pdp_imageproc_legalheight(int i) -{ - if (i>1024) return 1024; - if (i>0) return ((((i-1)>>3)+1)<<3); - return 8; -} -u32 pdp_imageproc_legalwidth_round_down(int i) -{ - if (i>1024) return 1024; - if (i>8) return ((i>>3)<<3); - return 8; - -} - -u32 pdp_imageproc_legalheight_round_down(int i) -{ - if (i>1024) return 1024; - if (i>8) return ((i>>3)<<3); - return 8; -} - -// utility stuff -inline static s16 float2fixed(float f) -{ - if (f > 1) f = 1; - if (f < -1) f = -1; - f *= 0x7fff; - return (s16)f; -} - -inline static void setvec(s16 *v, float f) -{ - s16 a = float2fixed(f); - v[0] = a; - v[1] = a; - v[2] = a; - v[3] = a; -} - - - -// add two images -void pdp_imageproc_add_process(s16 *image, s16 *image2, u32 width, u32 height) -{ - unsigned int totalnbpixels = width * height; - pixel_add_s16(image, image2, totalnbpixels>>2); -} - -// mul two images -void pdp_imageproc_mul_process(s16 *image, s16 *image2, u32 width, u32 height) -{ - unsigned int totalnbpixels = width * height; - pixel_mul_s16(image, image2, totalnbpixels>>2); -} - -// mix 2 images -void *pdp_imageproc_mix_new(void){return malloc(8*sizeof(s16));} -void pdp_imageproc_mix_delete(void *x) {free (x);} -void pdp_imageproc_mix_setleftgain(void *x, float gain){setvec((s16 *)x, gain);} -void pdp_imageproc_mix_setrightgain(void *x, float gain){setvec((s16 *)x + 4, gain);} -void pdp_imageproc_mix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - unsigned int totalnbpixels = width * height; - pixel_mix_s16(image, image2, totalnbpixels>>2, d, d+4); -} - - -// random mix 2 images -void *pdp_imageproc_randmix_new(void){return malloc(8*sizeof(s16));} -void pdp_imageproc_randmix_delete(void *x) {free (x);} -void pdp_imageproc_randmix_setthreshold(void *x, float threshold){setvec((s16 *)x, 2*threshold-1);} -void pdp_imageproc_randmix_setseed(void *x, float seed) -{ - s16 *d = (s16 *)x; - srandom((u32)seed); - d[4] = (s16)random(); - d[5] = (s16)random(); - d[6] = (s16)random(); - d[7] = (s16)random(); - -} -void pdp_imageproc_randmix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - unsigned int totalnbpixels = width * height; - pixel_randmix_s16(image, image2, totalnbpixels>>2, d+4, d); -} - -// affine transformation (applies gain + adds offset) -void *pdp_imageproc_affine_new(void){return malloc(8*sizeof(s16));} -void pdp_imageproc_affine_delete(void *x){free(x);} -void pdp_imageproc_affine_setgain(void *x, float gain){setvec((s16 *)x, gain);} -void pdp_imageproc_affine_setoffset(void *x, float offset){setvec((s16 *)x+4, offset);} -void pdp_imageproc_affine_process(void *x, s16 *image, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - pixel_affine_s16(image, (width*height)>>2, d, d+4); -} - -// 3x1 or 1x3 in place convolution -// orientation -void *pdp_imageproc_conv_new(void){return(malloc(16*sizeof(s16)));} -void pdp_imageproc_conv_delete(void *x){free(x);} -void pdp_imageproc_conv_setmin1(void *x, float val){setvec((s16 *)x, val);} -void pdp_imageproc_conv_setzero(void *x, float val){setvec((s16 *)x+4, val);} -void pdp_imageproc_conv_setplus1(void *x, float val){setvec((s16 *)x+8, val);} -void pdp_imageproc_conv_setbordercolor(void *x, float val){setvec((s16 *)x+12, val);} -void pdp_imageproc_conv_process(void *x, s16 *image, u32 width, u32 height, u32 orientation, u32 nbp) -{ - s16 *d = (s16 *)x; - u32 i,j; - - if (orientation == PDP_IMAGEPROC_CONV_HORIZONTAL) - { - for(i=0; i<width*height; i+=width) - for (j=0; j<nbp; j++) - pixel_conv_hor_s16(image+i, width>>2, d+12, d); - } - - else - { - for (j=0; j<nbp; j++) - for(i=0; i<width; i +=4) pixel_conv_ver_s16(image+i, height, width, d+12, d); - } - - - -} - -// apply a gain to an image -void *pdp_imageproc_gain_new(void){return(malloc(8*sizeof(s16)));} -void pdp_imageproc_gain_delete(void *x){free(x);} -void pdp_imageproc_gain_setgain(void *x, float gain) -{ - /* convert float to s16 + shift */ - s16 *d = (s16 *)x; - s16 g; - int i; - float sign; - int shift = 0; - - sign = (gain < 0) ? -1 : 1; - gain *= sign; - - /* max shift = 16 */ - for(i=0; i<=16; i++){ - if (gain < 0x4000){ - gain *= 2; - shift++; - } - else break; - } - - gain *= sign; - g = (s16) gain; - - //g = 0x4000; - //shift = 14; - - d[0]=g; - d[1]=g; - d[2]=g; - d[3]=g; - d[4]=(s16)shift; - d[5]=0; - d[6]=0; - d[7]=0; -} -void pdp_imageproc_gain_process(void *x, s16 *image, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - pixel_gain_s16(image, (width*height)>>2, d, (u64 *)(d+4)); -} - -// colour rotation for 2 colour planes -void *pdp_imageproc_crot2d_new(void){return malloc(16*sizeof(s16));} -void pdp_imageproc_crot2d_delete(void *x){free(x);} -void pdp_imageproc_crot2d_setmatrix(void *x, float *matrix) -{ - s16 *d = (s16 *)x; - setvec(d, matrix[0]); - setvec(d+4, matrix[1]); - setvec(d+8, matrix[2]); - setvec(d+12, matrix[3]); -} -void pdp_imageproc_crot2d_process(void *x, s16 *image, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - pixel_crot2d_s16(image, width*height >> 2, d); -} - -// biquad and biquad time -void *pdp_imageproc_bq_new(void){return malloc((5+2+2)*4*sizeof(s16));}//5xcoef, 2xstate, 2xsavestate -void pdp_imageproc_bq_delete(void *x){free(x);} -void pdp_imageproc_bq_setcoef(void *x, float *coef) // a0,-a1,-a2,b0,b1,b2,u0,u1 -{ - s16 *d = (s16 *)x; - float ia0 = 1.0f / coef[0]; - - /* all coefs are s1.14 fixed point */ - /* representing values -2 < x < 2 */ - /* so scale down before using the ordinary s0.15 float->fixed routine */ - - ia0 *= 0.5f; - - // coef - setvec(d, ia0*coef[1]); - setvec(d+4, ia0*coef[2]); - setvec(d+8, ia0*coef[3]); - setvec(d+12, ia0*coef[4]); - setvec(d+16, ia0*coef[5]); - - // state to reset too - setvec(d+28, coef[6]); - setvec(d+32, coef[7]); - -} -void pdp_imageproc_bqt_process(void *x, s16 *image, s16 *state0, s16 *state1, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - pixel_biquad_time_s16(image, state0, state1, d, (width*height)>>2); -} - -void pdp_imageproc_bq_process(void *x, s16 *image, u32 width, u32 height, u32 direction, u32 nbp) -{ - s16 *d = (s16 *)x; - unsigned int i,j; - - - - /* VERTICAL */ - - if ((direction & PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM) - && (direction & PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP)){ - - for(i=0; i<width; i +=4){ - for (j=0; j<nbp; j++){ - pixel_biquad_vertb_s16(image+i, height>>2, width, d, d + (5*4)); - pixel_biquad_verbt_s16(image+i, height>>2, width, d, d + (5*4)); - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM){ - for(i=0; i<width; i +=4){ - for (j=0; j<nbp; j++){ - pixel_biquad_vertb_s16(image+i, height>>2, width, d, d + (5*4)); - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP){ - for(i=0; i<width; i +=4){ - for (j=0; j<nbp; j++){ - pixel_biquad_verbt_s16(image+i, height>>2, width, d, d + (5*4)); - } - } - } - - /* HORIZONTAL */ - - if ((direction & PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT) - && (direction & PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT)){ - - for(i=0; i<(width*height); i +=(width<<2)){ - for (j=0; j<nbp; j++){ - pixel_biquad_horlr_s16(image+i, width>>2, width, d, d + (5*4)); - pixel_biquad_horrl_s16(image+i, width>>2, width, d, d + (5*4)); - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT){ - for(i=0; i<(width*height); i +=(width<<2)){ - for (j=0; j<nbp; j++){ - pixel_biquad_horlr_s16(image+i, width>>2, width, d, d + (5*4)); - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT){ - for(i=0; i<(width*height); i +=(width<<2)){ - for (j=0; j<nbp; j++){ - pixel_biquad_horrl_s16(image+i, width>>2, width, d, d + (5*4)); - } - } - } - -} - -// produce a random image -// note: random number generator can be platform specific -// however, it should be seeded. (same seed produces the same result) -void *pdp_imageproc_random_new(void){return malloc(4*sizeof(s16));} -void pdp_imageproc_random_delete(void *x){free(x);} -void pdp_imageproc_random_setseed(void *x, float seed) -{ - s16 *d = (s16 *)x; - srandom((u32)seed); - d[0] = (s16)random(); - d[1] = (s16)random(); - d[2] = (s16)random(); - d[3] = (s16)random(); - -} -void pdp_imageproc_random_process(void *x, s16 *image, u32 width, u32 height) -{ - s16 *d = (s16 *)x; - unsigned int totalnbpixels = width * height; - pixel_rand_s16(image, totalnbpixels>>2, d); -} - - -/* resampling stuff - this is quite a zoo of data structures - the major point is this: the resampler mmx code is shared for all resampling code - it uses data specified in t_resample_cbrd (Cooked Bilinear Resampler Data) - - then the there are several feeder algorithms. one is the linear mapper. it's - data is specified in t_resample_clrd (Cooked Linear Remapper Data) - - for each feeder algorithm, there are several high level algorithms. like zoom, - rotate, ... -*/ - -typedef struct -{ - u32 lineoffset; - s16 *image; - u32 width; - u32 height; - -} t_resample_id; // Image Data - -/* initialize image meta data (dimensions + location) */ -static void pdp_imageproc_resample_init_id(t_resample_id *x, u32 offset, s16* image, u32 w, u32 h) -{ - x->lineoffset = offset; - x->image = image; - x->width = w; - x->height = h; -} - -// mmx resampling source image resampling data + coefs -typedef struct -{ - // vector data for resampling routine (resampling computation) - u8 reserved[0x60]; //internal data - s16 *address[2]; //64 bit splatted offset address - s16 twowidthm1[4]; //64 bit splatted 2*(width-1) - s16 twoheightm1[4]; //64 bit splatted 2*(height-1) - s16 lineoffset[4]; //64 bit splatted line offset in pixels - -} t_resample_cid; // Cooked Image Data - -/* convert image meta data into a cooked format used by the resampler routine */ -static void pdp_imageproc_resample_init_cid(t_resample_cid *r, t_resample_id *i) -{ - u32 twowm1 = (i->width-1)<<1; - u32 twohm1 = (i->height-1)<<1; - r->address[0] = i->image; - r->address[1] = i->image; - r->twowidthm1[0] = twowm1; - r->twowidthm1[1] = twowm1; - r->twowidthm1[2] = twowm1; - r->twowidthm1[3] = twowm1; - r->twoheightm1[0] = twohm1; - r->twoheightm1[1] = twohm1; - r->twoheightm1[2] = twohm1; - r->twoheightm1[3] = twohm1; - r->lineoffset[0] = i->lineoffset; - r->lineoffset[1] = i->lineoffset; - r->lineoffset[2] = i->lineoffset; - r->lineoffset[3] = i->lineoffset; -} - -// linear mapping data struct (zoom, scale, rotate, shear, ...) -typedef struct -{ - s32 rowstatex[2]; // row state x coord - s32 rowstatey[2]; // row state y coord - s32 colstatex[2]; // column state x coord - s32 colstatey[2]; // column state y coord - s32 rowincx[2]; // row inc vector x coord - s32 rowincy[2]; // row inc vector y coord - s32 colincx[2]; // column inc vector x coord - s32 colincy[2]; // column inc vector y coord -} t_resample_clmd; // Cooked Linear Mapping Data - -/* convert incremental linear remapping vectors to internal cooked format */ -static void pdp_imageproc_resample_cookedlinmap_init(t_resample_clmd *l, s32 sx, s32 sy, s32 rix, s32 riy, s32 cix, s32 ciy) -{ - l->colstatex[0] = l->rowstatex[0] = sx; - l->colstatex[1] = l->rowstatex[1] = sx + rix; - l->colstatey[0] = l->rowstatey[0] = sy; - l->colstatey[1] = l->rowstatey[1] = sy + riy; - l->rowincx[0] = rix << 1; - l->rowincx[1] = rix << 1; - l->rowincy[0] = riy << 1; - l->rowincy[1] = riy << 1; - l->colincx[0] = cix; - l->colincx[1] = cix; - l->colincy[0] = ciy; - l->colincy[1] = ciy; -} - - -/* this struct contains all the data necessary for - bilin interpolation from src -> dst image - (src can be == dst) */ -typedef struct -{ - t_resample_cid csrc; //cooked src image meta data for bilinear interpolator - t_resample_id src; //src image meta - t_resample_id dst; //dst image meta -} t_resample_cbrd; //Bilinear Resampler Data - - -/* this struct contains high level zoom parameters, - all image relative */ -typedef struct -{ - float centerx; - float centery; - float zoomx; - float zoomy; - float angle; -} t_resample_zrd; - - -/* convert floating point center and zoom data to incremental linear remapping vectors */ -static void pdp_imageproc_resample_clmd_init_from_id_zrd(t_resample_clmd *l, t_resample_id *i, t_resample_zrd *z) -{ - double izx = 1.0f / (z->zoomx); - double izy = 1.0f / (z->zoomy); - double scale = (double)0xffffffff; - double scalew = scale / ((double)(i->width - 1)); - double scaleh = scale / ((double)(i->height - 1)); - double cx = ((double)z->centerx) * ((double)(i->width - 1)); - double cy = ((double)z->centery) * ((double)(i->height - 1)); - double angle = z->angle * (-M_PI / 180.0); - double c = cos(angle); - double s = sin(angle); - - /* affine x, y mappings in screen coordinates */ - double mapx(double x, double y){return cx + izx * ( c * (x-cx) + s * (y-cy));} - double mapy(double x, double y){return cy + izy * (-s * (x-cx) + c * (y-cy));} - - u32 tl_x = (u32)(scalew * mapx(0,0)); - u32 tl_y = (u32)(scaleh * mapy(0,0)); - - - u32 row_inc_x = (u32)(scalew * (mapx(1,0)-mapx(0,0))); - u32 row_inc_y = (u32)(scaleh * (mapy(1,0)-mapy(0,0))); - u32 col_inc_x = (u32)(scalew * (mapx(0,1)-mapx(0,0))); - u32 col_inc_y = (u32)(scaleh * (mapy(0,1)-mapy(0,0))); - - - pdp_imageproc_resample_cookedlinmap_init(l, tl_x, tl_y, row_inc_x, row_inc_y, col_inc_x, col_inc_y); -} - -/* this struct contains all data for the zoom object */ -typedef struct -{ - t_resample_cbrd cbrd; // Bilinear Resampler Data - t_resample_clmd clmd; // Cooked Linear Mapping data - t_resample_zrd zrd; // Zoom / Rotate Data -} t_resample_zoom_rotate; - -// zoom + rotate -void *pdp_imageproc_resample_affinemap_new(void) -{ - t_resample_zoom_rotate *z = (t_resample_zoom_rotate *)malloc(sizeof(t_resample_zoom_rotate)); - z->zrd.centerx = 0.5; - z->zrd.centery = 0.5; - z->zrd.zoomx = 1.0; - z->zrd.zoomy = 1.0; - z->zrd.angle = 0.0f; - return (void *)z; -} -void pdp_imageproc_resample_affinemap_delete(void *x){free(x);} -void pdp_imageproc_resample_affinemap_setcenterx(void *x, float f){((t_resample_zoom_rotate *)x)->zrd.centerx = f;} -void pdp_imageproc_resample_affinemap_setcentery(void *x, float f){((t_resample_zoom_rotate *)x)->zrd.centery = f;} -void pdp_imageproc_resample_affinemap_setzoomx(void *x, float f){((t_resample_zoom_rotate *)x)->zrd.zoomx = f;} -void pdp_imageproc_resample_affinemap_setzoomy(void *x, float f){((t_resample_zoom_rotate *)x)->zrd.zoomy = f;} -void pdp_imageproc_resample_affinemap_setangle(void *x, float f){((t_resample_zoom_rotate *)x)->zrd.angle = f;} -void pdp_imageproc_resample_affinemap_process(void *x, s16 *srcimage, s16 *dstimage, u32 width, u32 height) -{ - t_resample_zoom_rotate *z = (t_resample_zoom_rotate *)x; - - /* setup resampler image meta data */ - pdp_imageproc_resample_init_id(&(z->cbrd.src), width, srcimage, width, height); - pdp_imageproc_resample_init_id(&(z->cbrd.dst), width, dstimage, width, height); - pdp_imageproc_resample_init_cid(&(z->cbrd.csrc),&(z->cbrd.src)); - - /* setup linmap data from zoom_rotate parameters */ - pdp_imageproc_resample_clmd_init_from_id_zrd(&(z->clmd), &(z->cbrd.src), &(z->zrd)); - - - /* call assembler routine */ - pixel_resample_linmap_s16(z); -} - - - -// polynomials - - -typedef struct -{ - u32 order; - u8 pad[4]; - s16 coefs[0]; -} t_cheby; - -void *pdp_imageproc_cheby_new(int order) -{ - t_cheby *z; - int i; - if (order < 2) order = 2; - z = (t_cheby *)malloc(sizeof(t_cheby) + (order + 1) * sizeof(s16[4])); - z->order = order; - setvec(z->coefs + 0*4, 0); - setvec(z->coefs + 1*4, 0.25); - for (i=2; i<=order; i++) setvec(z->coefs + i*4, 0); - - return z; -} -void pdp_imageproc_cheby_delete(void *x){free(x);} -void pdp_imageproc_cheby_setcoef(void *x, u32 n, float f) -{ - t_cheby *z = (t_cheby *)x; - if (n <= z->order){ - setvec(z->coefs + n*4, f * 0.25); // coefs are in s2.13 format - } -} -void pdp_imageproc_cheby_process(void *x, s16 *image, u32 width, u32 height, u32 iterations) -{ - t_cheby *z = (t_cheby *)x; - u32 i,j; - for (j=0; j < (height*width); j += width) - for (i=0; i<iterations; i++) - pixel_cheby_s16_3plus(image+j, width>>2, z->order+1, z->coefs); - - //pixel_cheby_s16_3plus(image, (width*height)>>2, z->order+1, z->coefs); -} diff --git a/system/pdp_imageproc_portable.c b/system/pdp_imageproc_portable.c deleted file mode 100644 index 86b91b8..0000000 --- a/system/pdp_imageproc_portable.c +++ /dev/null @@ -1,681 +0,0 @@ -/* - * Pure Data Packet. portable image processing routines. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -#include <stdlib.h> -#include <math.h> -#include "pdp_imageproc.h" - -/* all image dims are legal */ -u32 pdp_imageproc_legalwidth(int i) -{ - if (i>1024) return 1024; - if (i>0) return i; - return 1; -} - -u32 pdp_imageproc_legalheight(int i) -{ - if (i>1024) return 1024; - if (i>0) return i; - return 1; -} -u32 pdp_imageproc_legalwidth_round_down(int i) {return pdp_imageproc_legalwidth(i);} -u32 pdp_imageproc_legalheight_round_down(int i) {return pdp_imageproc_legalheight(i);} - - -// utility stuff -inline static s32 float2fixed(float f) -{ - if (f > 1) f = 1; - if (f < -1) f = -1; - f *= 0x7fff; - return (s32)f; -} - - - -#define CLAMP16(x) (((x) > 0x7fff) ? 0x7fff : (((x) < -0x7fff) ? -0x7fff : (x))) - -// add two images -void pdp_imageproc_add_process(s16 *image, s16 *image2, u32 width, u32 height) -{ - int a, b; - unsigned int i; - for (i=0; i<width*height; i++){ - a = (int)image[i]; - b = (int)image2[i]; - image[i] = (s16)(CLAMP16(a+b)); - } - -} - -// mul two images -void pdp_imageproc_mul_process(s16 *image, s16 *image2, u32 width, u32 height) -{ - int a, b; - unsigned int i; - for (i=0; i<width*height; i++){ - a = (int)image[i]; - b = (int)image2[i]; - image[i] = (s16)((a*b)>>15); - } - -} - -// mix 2 images -void *pdp_imageproc_mix_new(void){return malloc(2*sizeof(s32));} -void pdp_imageproc_mix_delete(void *x) {free (x);} -void pdp_imageproc_mix_setleftgain(void *x, float gain) -{ - s32 *d = (s32 *)x; - d[0] = float2fixed(gain); -} -void pdp_imageproc_mix_setrightgain(void *x, float gain) -{ - s32 *d = (s32 *)x; - d[1] = float2fixed(gain); -} -void pdp_imageproc_mix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i; - s32 a,b; - - for(i=0; i<width*height; i++){ - a = (s32)image[i]; - b = (s32)image2[i]; - a = (a*d[0] + b*d[1]) >> 15; - image[i] = (s16)CLAMP16(a); - } - -} - - -// random mix 2 images -void *pdp_imageproc_randmix_new(void){return malloc(2*sizeof(s32));;} -void pdp_imageproc_randmix_delete(void *x) {free(x);} -void pdp_imageproc_randmix_setthreshold(void *x, float threshold) -{ - s32 *d = (s32 *)x; - if (threshold > 1.0f) threshold = 1.0f; - if (threshold < 0.0f) threshold = 0.0f; - d[0] = float2fixed(threshold); -} -void pdp_imageproc_randmix_setseed(void *x, float seed) -{ - s32 *d = (s32 *)x; - d[1] = float2fixed(seed); -} -void pdp_imageproc_randmix_process(void *x, s16 *image, s16 *image2, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i; - s16 r; - srandom((u32)d[1]); - - - for(i=0; i<width*height; i++){ - // get a random val between 0 and 0x7fff - r = (s16)(random() & 0x7fff); - if (r < d[0]) image[i] = image2[i]; - } -} - -// affine transformation (applies gain + adds offset) -void *pdp_imageproc_affine_new(void){return malloc(2*sizeof(s32));} -void pdp_imageproc_affine_delete(void *x){free(x);} -void pdp_imageproc_affine_setgain(void *x, float gain) -{ - s32 *d = (s32 *)x; - d[0] = float2fixed(gain); -} - -void pdp_imageproc_affine_setoffset(void *x, float offset) -{ - s32 *d = (s32 *)x; - d[1] = float2fixed(offset); -} -void pdp_imageproc_affine_process(void *x, s16 *image, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i; - s32 a; - - for(i=0; i<width*height; i++){ - a = (s32)image[i]; - a = (a*d[0]) >> 15; - a += d[1]; - image[i] = (s16)CLAMP16(a); - } -} - -// 3x1 or 1x3 in place convolution -// orientation -void *pdp_imageproc_conv_new(void){return(malloc(4*sizeof(s32)));} -void pdp_imageproc_conv_delete(void *x){free(x);} -void pdp_imageproc_conv_setmin1(void *x, float val) -{ - s32 *d = (s32 *)x; - d[0] = float2fixed(val); -} -void pdp_imageproc_conv_setzero(void *x, float val) -{ - s32 *d = (s32 *)x; - d[1] = float2fixed(val); -} -void pdp_imageproc_conv_setplus1(void *x, float val) -{ - s32 *d = (s32 *)x; - d[2] = float2fixed(val); -} -void pdp_imageproc_conv_setbordercolor(void *x, float val) -{ - s32 *d = (s32 *)x; - d[3] = float2fixed(val); -} - -static inline void pdp_imageproc_conv_scanline(void *x, s16 *data, u32 count, s32 stride) -{ - s32 *d = (s32 *)x; - s32 a,b,c,r; - u32 i; - - a = d[3]; //border - b = data[0]; - c = data[stride]; - - for(i = 0; i < count-2; i++){ - r = a*d[0] + b*d[1] + c*d[2]; - a = data[0]; - b = data[stride]; - c = data[stride<<1]; - data[0] = (s16)CLAMP16(r>>15); - data += stride; - } - r = a*d[0] + b*d[1] + c*d[2]; - a = data[0]; - b = data[stride]; - c = d[3]; //border - data[0] = (s16)CLAMP16(r>>15); - r = a*d[0] + b*d[1] + c*d[2]; - data[stride] = (s16)CLAMP16(r>>15); - -} - -void pdp_imageproc_conv_process(void *x, s16 *image, u32 width, u32 height, u32 orientation, u32 nbp) -{ - s32 *d = (s32 *)x; - u32 i, j; - - if (orientation == PDP_IMAGEPROC_CONV_HORIZONTAL){ - for(i=0; i<width*height; i+=width) - for(j=0; j<nbp; j++) - pdp_imageproc_conv_scanline(x, image+i, width, 1); - - } - - if (orientation == PDP_IMAGEPROC_CONV_VERTICAL){ - for(i=0; i<width; i++) - for(j=0; j<nbp; j++) - pdp_imageproc_conv_scanline(x, image+i, height, width); - - } - - - - -} - -// apply a gain to an image -void *pdp_imageproc_gain_new(void){return(malloc(2*sizeof(s32)));} -void pdp_imageproc_gain_delete(void *x){free(x);} -void pdp_imageproc_gain_setgain(void *x, float gain) -{ - /* convert float to s16 + shift */ - s32 *d = (s32 *)x; - s32 g; - int i; - float sign; - s32 shift = 0; - - sign = (gain < 0) ? -1 : 1; - gain *= sign; - - /* max shift = 16 */ - for(i=0; i<=16; i++){ - if (gain < 0x4000){ - gain *= 2; - shift++; - } - else break; - } - - gain *= sign; - g = (s32) gain; - - //g = 0x4000; - //shift = 14; - - d[0]=g; - d[1]=shift; -} -void pdp_imageproc_gain_process(void *x, s16 *image, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - s32 a; - u32 i; - for (i=0; i<width*height; i++){ - a = (s32)image[i]; - image[i] = (s16)(CLAMP16((a * d[0]) >> d[1])); - } -} - -// colour rotation for 2 colour planes -void *pdp_imageproc_crot2d_new(void){return malloc(4*sizeof(s32));} -void pdp_imageproc_crot2d_delete(void *x){free(x);} -void pdp_imageproc_crot2d_setmatrix(void *x, float *matrix) -{ - s32 *d = (s32 *)x; - d[0] = float2fixed(matrix[0]); - d[1] = float2fixed(matrix[1]); - d[2] = float2fixed(matrix[2]); - d[3] = float2fixed(matrix[3]); - -} -void pdp_imageproc_crot2d_process(void *x, s16 *image, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i,j; - s32 a1,a2,c1,c2; - - for(i=0, j=width*height; i<width*height; i++, j++){ - c1 = (s32)image[i]; - c2 = (s32)image[j]; - - a1 = d[0] * c1; - a2 = d[1] * c1; - a1+= d[2] * c2; - a2+= d[3] * c2; - - a1 >>= 15; - a2 >>= 15; - - image[i] = (s16)CLAMP16(a1); - image[j] = (s16)CLAMP16(a2); - } -} - -// biquad and biquad time -void *pdp_imageproc_bq_new(void){return malloc((5+2+2)*sizeof(s32));}//5xcoef, 2xstate, 2xsavestate -void pdp_imageproc_bq_delete(void *x){free(x);} -void pdp_imageproc_bq_setcoef(void *x, float *coef) // a0,-a1,-a2,b0,b1,b2,u0,u1 -{ - s32 *d = (s32 *)x; - float ia0 = 1.0f / coef[0]; - - /* all coefs are s1.14 fixed point */ - /* representing values -2 < x < 2 */ - /* so scale down before using the ordinary s0.15 float->fixed routine */ - - ia0 *= 0.5f; - - // coef - d[0] = float2fixed(ia0*coef[1]); // -a1 - d[1] = float2fixed(ia0*coef[2]); // -a2 - d[2] = float2fixed(ia0*coef[3]); // b0 - d[3] = float2fixed(ia0*coef[4]); // b1 - d[4] = float2fixed(ia0*coef[5]); // b2 - - - // state to reset too - d[5] = float2fixed(coef[6]); - d[6] = float2fixed(coef[7]); - -} - -#define A1 d[0] -#define A2 d[1] -#define B0 d[2] -#define B1 d[3] -#define B2 d[4] -/* - # DIRECT FORM II BIQUAD (from pixel_biquad_s16.s) - # - # y[k] = b0 * x[k] + u1[k-1] - # u1[k] = b1 * x[k] + u2[k-1] - a1 * y[k] - # u2[k] = b2 * x[k] - a2 * y[k] -*/ - -/* remark A1 and A2 are already negated) */ - - -static inline void pdp_imageproc_bq_scanline(void *x, s16 *data, u32 count, s32 stride) -{ - - s32 *d = (s32 *)x; - s32 u1,u2, xx, yy; - - u32 i; - - u1 = d[7]; - u2 = d[8]; - - for(i = 0; i < count; i++){ - - xx = (s32)data[0]; - - yy = ((B0 * xx)>>14) + u1; - u1 = ((B1 * xx)>>14) + u2 + ((A1 * yy)>>14); - u2 = ((B2 * xx)>>14) + ((A2 * yy)>>14); - - data[0] = (s16)CLAMP16(yy); - - data += stride; - - } - - d[7] = u1; - d[8] = u2; - -} - -void pdp_imageproc_bqt_process(void *x, s16 *image, s16 *state1, s16 *state2, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i; - s32 u1, u2, xx, yy; - - for (i=0; i<width*height; i++){ - - xx = (s32)image[i]; - u1 = (s32)state1[i]; - u2 = (s32)state2[i]; - - yy = ((B0 * xx)>>14) + u1; - u1 = ((B1 * xx)>>14) + u2 + ((A1 * yy)>>14); - u2 = ((B2 * xx)>>14) + ((A2 * yy)>>14); - - image[i] = (s16)CLAMP16(yy); - state1[i] = (s16)CLAMP16(u1); - state2[i] = (s16)CLAMP16(u2); - } - - -} - -void pdp_imageproc_bq_process(void *x, s16 *data, u32 width, u32 height, u32 direction, u32 nbp) -{ - s32 *d = (s32 *)x; - unsigned int i,j, offset; - - /* VERTICAL */ - offset = (height-1)*width; - - if ((direction & PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM) - && (direction & PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP)){ - - for(i=0; i<width; i++){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+i, height, width); //T->B - pdp_imageproc_bq_scanline(x, data+offset+i, height, -width); //B->T - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM){ - for(i=0; i<width; i++){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+i, height, width); //T->B - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP){ - for(i=0; i<width; i++){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+offset+i, height, -width); //B->T - } - } - } - - /* HORIZONTAL */ - - offset = width-1; - if ((direction & PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT) - && (direction & PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT)){ - - for(i=0; i<(width*height); i += width){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+i, width, 1); //L->R - pdp_imageproc_bq_scanline(x, data+offset+i, width, -1); //R->L - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT){ - for(i=0; i<(width*height); i += width){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+i, width, 1); //L->R - } - } - } - - else if (direction & PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT){ - for(i=0; i<(width*height); i += width){ - for (j=0; j<nbp; j++){ - pdp_imageproc_bq_scanline(x, data+offset+i, width, -1); //R->L - - } - } - } - -} - -// produce a random image -// note: random number generator can be platform specific -// however, it should be seeded. (same seed produces the same result) -void *pdp_imageproc_random_new(void){return malloc(sizeof(s32));} -void pdp_imageproc_random_delete(void *x){free(x);} -void pdp_imageproc_random_setseed(void *x, float seed) -{ - s32 *d = (s32 *)x; - d[0] = float2fixed(seed); -} -void pdp_imageproc_random_process(void *x, s16 *image, u32 width, u32 height) -{ - s32 *d = (s32 *)x; - u32 i; - srandom((u32)d[0]); - for (i=0; i<width*height; i++) image[i] = (s16)(random() & 0xffff); - -} - - - -/* resampling code */ -// zoom + rotate - -/* bilinear resampling core routine */ -/* virtual coordinates are the lowest 16 bits in virt_x and virt_y*/ -static inline s32 pdp_resample_bilin(s16 *image, s32 width, s32 height, s32 virt_x, s32 virt_y) -{ - - s32 fp_x, fp_y, frac_x, frac_y, f, offset, r_1, r_2; - - //virt_x &= 0xffff; - //virt_y &= 0xffff; - - fp_x = virt_x * (width - 1); - fp_y = virt_y * (height - 1); - - frac_x = fp_x & (0xffff); - frac_y = fp_y & (0xffff); - - offset = (fp_x >> 16) + (fp_y >> 16) * width; - image += offset; - - f = 0x10000 - frac_x; - - r_1 = ((f * (s32)(image[0]) + frac_x * (s32)(image[1])))>>16; - - image += width; - - r_2 = ((f * (s32)(image[0]) + frac_x * (s32)(image[1])))>>16; - - f = 0x10000 - frac_y; - - return ((f * r_1 + frac_y * r_2)>>16); - -} - -typedef struct -{ - float centerx; - float centery; - float zoomx; - float zoomy; - float angle; -} t_affine_map; - - -void *pdp_imageproc_resample_affinemap_new(void) -{ - - t_affine_map *a = (t_affine_map *)malloc(sizeof(t_affine_map)); - a->centerx = 0.5; - a->centery = 0.5; - a->zoomx = 1.0; - a->zoomy = 1.0; - a->angle = 0.0f; - return (void *)a; -} -void pdp_imageproc_resample_affinemap_delete(void *x){free(x);} -void pdp_imageproc_resample_affinemap_setcenterx(void *x, float f){((t_affine_map *)x)->centerx = f;} -void pdp_imageproc_resample_affinemap_setcentery(void *x, float f){((t_affine_map *)x)->centery = f;} -void pdp_imageproc_resample_affinemap_setzoomx(void *x, float f){((t_affine_map *)x)->zoomx = f;} -void pdp_imageproc_resample_affinemap_setzoomy(void *x, float f){((t_affine_map *)x)->zoomy = f;} -void pdp_imageproc_resample_affinemap_setangle(void *x, float f){((t_affine_map *)x)->angle = f;} -void pdp_imageproc_resample_affinemap_process(void *x, s16 *src_image, s16 *dst_image, u32 width, u32 height) -{ - t_affine_map *a = (t_affine_map *)x; - double izx = 1.0f / (a->zoomx); - double izy = 1.0f / (a->zoomy); - double scale = (double)0xffffffff; - double scalew = scale / ((double)(width - 1)); - double scaleh = scale / ((double)(height - 1)); - double cx = ((double)a->centerx) * ((double)(width - 1)); - double cy = ((double)a->centery) * ((double)(height - 1)); - double angle = a->angle * (-M_PI / 180.0); - double c = cos(angle); - double s = sin(angle); - - /* affine x, y mappings in screen coordinates */ - double mapx(double x, double y){return cx + izx * ( c * (x-cx) + s * (y-cy));} - double mapy(double x, double y){return cy + izy * (-s * (x-cx) + c * (y-cy));} - - u32 colstate_x = (u32)(scalew * mapx(0,0)); - u32 colstate_y = (u32)(scaleh * mapy(0,0)); - u32 rowstate_x = colstate_x; - u32 rowstate_y = colstate_y; - - u32 row_inc_x = (u32)(scalew * (mapx(1,0)-mapx(0,0))); - u32 row_inc_y = (u32)(scaleh * (mapy(1,0)-mapy(0,0))); - u32 col_inc_x = (u32)(scalew * (mapx(0,1)-mapx(0,0))); - u32 col_inc_y = (u32)(scaleh * (mapy(0,1)-mapy(0,0))); - - u32 i,j; - - for (j=0; j<height; j++){ - for (i=0; i<width; i++){ - *dst_image++ = pdp_resample_bilin(src_image, width, height, rowstate_x>>16, rowstate_y>>16); - rowstate_x += row_inc_x; - rowstate_y += row_inc_y; - } - colstate_x += col_inc_x; - colstate_y += col_inc_y; - rowstate_x = colstate_x; - rowstate_y = colstate_y; - } - -} - - - - - -// polynomials - - - - -typedef struct -{ - u32 order; - s32 coefs[0]; -} t_cheby; - -void *pdp_imageproc_cheby_new(int order) -{ - t_cheby *z; - int i; - if (order < 2) order = 2; - z = (t_cheby *)malloc(sizeof(t_cheby) + (order + 1) * sizeof(s32)); - z->order = order; - z->coefs[0] = 0; - z->coefs[1] = 0x7fff; - for (i=2; i<=order; i++) z->coefs[i] = 0; - return z; -} -void pdp_imageproc_cheby_delete(void *x){free(x);} -void pdp_imageproc_cheby_setcoef(void *x, u32 n, float f) -{ - - t_cheby *z = (t_cheby *)x; - if (n <= z->order){ - z->coefs[n] = (s32)(f * 32767.0f); // coefs are in s16.15 format - } - -} -void pdp_imageproc_cheby_process(void *x, s16 *image, u32 width, u32 height, u32 iterations) -{ - - t_cheby *z = (t_cheby *)x; - u32 i,j,k; - s32 *c = z->coefs; - for (j=0; j < (height*width); j++){ - s32 acc = (s32)image[j]; - for (i=0; i<iterations; i++){ - s32 T2 = 0x7fff; /* 1 */ - s32 T1 = acc; - s32 t; - s32 in = acc; - acc = c[0] + ((in*c[1])>>15); - for (k=2; k<=z->order; k++){ - t = ((T1*in)>>14) - T2; /* T_n = 2 x T_n-1 - T_n-2 */ - T2 = T1; - T1 = t; - acc += ((c[k] * t)>>15); - } - } - image[j] = (s16)(CLAMP16(acc)); - } -} diff --git a/system/pdp_llconv.c b/system/pdp_llconv.c deleted file mode 100644 index 93d2934..0000000 --- a/system/pdp_llconv.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Pure Data Packet system implementation. : low level format conversion code - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* this file contains low level image conversion code - nominated as "the ugliest part of pdp" - some code is mmx, most is not. */ - -#include "pdp_llconv.h" -#include "pdp_mmx.h" - - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - - -#define CLAMP(x) (((x)<0) ? 0 : ((x>255)? 255 : (x))) -#define CLAMP16(x) (((x)<-0x7fff) ? -0x7fff : ((x>0x7fff) ? 0x7fff : (x))) -#define FP(x) ((int)(((float)(x)) * 256.0f)) - - -/* some prototypes for functions defined elsewhere */ -void llconv_yvu_planar_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels); -void llconv_yuv_planar_u8s16(unsigned char* source, short int *dest, int nbpixels); -void llconv_grey_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels); -void llconv_yvu_planar_u8s16(unsigned char* source, short int *dest, int nbpixels); - - -static inline int rgb2y(int r, int g, int b){return (FP(0.257) * r) + (FP(0.504) * g) + (FP(0.098) * b) + FP(16);} -static inline int rgb2v(int r, int g, int b){return (FP(0.439) * r) - (FP(0.368) * g) - (FP(0.071) * b) + FP(128);} -static inline int rgb2u(int r, int g, int b){return -(FP(0.148) * r) - (FP(0.291) * g) + (FP(0.439) * b) + FP(128);} - - -/* "standard" 8 bit conversion routine */ -static void llconv_rgb2yvu(unsigned char* src, unsigned char* dst, int nbpixels) -{ - int r,g,b,y,v,u,i; - for (i=0; i<nbpixels; i++){ - r = src[0]; - g = src[1]; - b = src[2]; - - y = rgb2y(r,g,b); - v = rgb2v(r,g,b); - u = rgb2u(r,g,b); - - dst[0] = CLAMP(y>>8); - dst[1] = CLAMP(v>>8); - dst[2] = CLAMP(u>>8); - - src += 3; - dst += 3; - } -} - - - -/* 8 bit rgb to 16 bit planar subsampled yvu */ -static void llconv_rgb2yvu_planar16sub(unsigned char* src, short int* dst, int w, int h) -{ - int r,g,b,y,v,u,i,j,k; - int size = w*h; - - int voffset = size; - int uoffset = size + (size>>2); - - - int loffset = w * 3; - - k=0; - for (j=0; j<w*h; j+=(w<<1)){ - k = 3 * j; - for (i=0; i<w; i+=2){ - - - // well, this seems to work... strange though - b = src[k]; - g = src[k+1]; - r = src[k+2]; - - y = (FP(0.257) * r) + (FP(0.504) * g) + (FP(0.098) * b) + FP(16); - v = (FP(0.439) * r) - (FP(0.368) * g) - (FP(0.071) * b); - u = -(FP(0.148) * r) - (FP(0.291) * g) + (FP(0.439) * b); - - dst[i+j] = CLAMP16(y >> 1); - - b = src[k+3]; - g = src[k+4]; - r = src[k+5]; - - y = (FP(0.257) * r) + (FP(0.504) * g) + (FP(0.098) * b) + FP(16); - v += (FP(0.439) * r) - (FP(0.368) * g) - (FP(0.071) * b); - u += -(FP(0.148) * r) - (FP(0.291) * g) + (FP(0.439) * b); - - dst[i+j+1] = CLAMP16(y >> 1); - - - - b = src[loffset + k]; - g = src[loffset + k+1]; - r = src[loffset + k+2]; - - y = (FP(0.257) * r) + (FP(0.504) * g) + (FP(0.098) * b) + FP(16); - v = (FP(0.439) * r) - (FP(0.368) * g) - (FP(0.071) * b); - u = -(FP(0.148) * r) - (FP(0.291) * g) + (FP(0.439) * b); - - dst[w+i+j] = CLAMP16(y >> 1); - - b = src[loffset + k+3]; - g = src[loffset + k+4]; - r = src[loffset + k+5]; - - k += 6; - - y = (FP(0.257) * r) + (FP(0.504) * g) + (FP(0.098) * b) + FP(16); - v += (FP(0.439) * r) - (FP(0.368) * g) - (FP(0.071) * b); - u += -(FP(0.148) * r) - (FP(0.291) * g) + (FP(0.439) * b); - - dst[w+i+j+1] = CLAMP16(y >> 1); - - dst[uoffset+ (i>>1) + (j>>2)] = (CLAMP16(u >> 1)); - dst[voffset+ (i>>1) + (j>>2)] = (CLAMP16(v >> 1)); - } - } -} - -/* these seem to be pretty slow */ - -static void llconv_yvu2rgb(unsigned char* src, unsigned char* dst, int nbpixels) -{ - int r,g,b,y,v,u,i; - for (i=0; i<nbpixels; i++){ - y = src[0]; - v = src[1]; - u = src[2]; - - - b = FP(1.164) * (y - 16) + FP(2.018) * (u - 128); - g = FP(1.164) * (y - 16) - FP(0.813) * (v - 128) - FP(0.391) * (u - 128); - r = FP(1.164) * (y - 16) + FP(1.596) * (v - 128); - - dst[0] = CLAMP(r>>8); - dst[1] = CLAMP(g>>8); - dst[2] = CLAMP(b>>8); - - src += 3; - dst += 3; - } -} - - - -/* convert yvu to yuyv */ -static void llconv_yvu2yuyv(unsigned char *src, unsigned char *dst, unsigned int nbpixels) -{ - unsigned int y1, y2, u, v, i; - - for (i = 0; i < nbpixels/2; i++){ - - y1 = src[0]; - y2 = src[3]; - v = (src[1] + src[4]) >> 1; - u = (src[2] + src[5]) >> 1; - dst[0] = y1; - dst[1] = u; - dst[2] = y2; - dst[3] = v; - - src += 6; - dst += 4; - - } - -} - - - -/* convert yuvu packed 8 bit unsigned to yv12 planar 16bit signed */ -static void llconv_yuyv_packed_u8s16(unsigned char* ucsource, short int *sidest, unsigned int w, unsigned int h) -{ - unsigned int i, j; - unsigned int *source = (unsigned int *)ucsource; - - unsigned int *dest = (unsigned int *)sidest; - unsigned int uoffset = (w*h)>>1; - unsigned int voffset = (w*h + ((w*h) >> 2)) >> 1; - - for(j=0; j < (h*w)>>1; j +=(w)){ - for(i=0; i< (w>>1); i+=2){ - unsigned int y,u,v; - unsigned int v00, v01, v10, v11; - v00 = source[i+j]; - v01 = source[i+j+1]; - v10 = source[i+j+(w>>1)]; - v11 = source[i+j+(w>>1)+1]; - - // save luma - dest[i+j] = ((v00 & 0x00ff00ff) << 7); - dest[i+j+1] = ((v01 & 0x00ff00ff) << 7); - dest[i+j+(w>>1)] = ((v10 & 0x00ff00ff) << 7); - dest[i+j+(w>>1)+1] = ((v11 & 0x00ff00ff) << 7); - - // compute chroma - - // mask out luma & shift right - v00 = (v00 & 0xff00ff00)>>1; - v01 = (v01 & 0xff00ff00)>>1; - v10 = (v10 & 0xff00ff00)>>1; - v11 = (v11 & 0xff00ff00)>>1; - - // average 2 scan lines - v00 += v10; - v01 += v11; - - // combine - v = (v01 << 16) | (v00 & 0x0000ffff); - u = (v01 & 0xffff0000) | (v00 >> 16); - - // flip sign bits for u,v - u ^= 0x80008000; - v ^= 0x80008000; - - // save chroma - dest[uoffset + (i>>1) + (j>>2)] = u; - dest[voffset + (i>>1) + (j>>2)] = v; - } - } - - -} - -#define CONVERT(x,y) ((x) + ((y)<<16)) - -void pdp_llconv(void *src, int stype, void *dst, int dtype, int w, int h) -{ - int conversion = CONVERT(stype, dtype); - void *tmpbuf; - - switch(CONVERT(stype, dtype)){ - - case CONVERT( RIF_YVU__P411_U8, RIF_YVU__P411_S16 ): - llconv_yvu_planar_u8s16((unsigned char*)src, (short int *)dst, w*h); - break; - - case CONVERT( RIF_YUV__P411_U8, RIF_YVU__P411_S16 ): - llconv_yuv_planar_u8s16((unsigned char*)src, (short int *)dst, w*h); - break; - - case CONVERT( RIF_YUYV_P____U8, RIF_YVU__P411_S16 ): - llconv_yuyv_packed_u8s16((unsigned char*)src, (short int *)dst, w, h); - break; - - case CONVERT( RIF_RGB__P____U8, RIF_YVU__P411_S16 ): - llconv_rgb2yvu_planar16sub((unsigned char*) src, (short int*) dst, w, h); - break; - - case CONVERT( RIF_YVU__P411_S16, RIF_YVU__P411_U8 ): - llconv_yvu_planar_s16u8((short int*)src, (unsigned char*)dst, w*h); - break; - - case CONVERT( RIF_GREY______S16, RIF_GREY______U8 ): - llconv_grey_s16u8((short int*)src, (unsigned char*)dst, w*h); - break; - default: - post("pdp_llconv: WARNING: no conversion routine defined for (%d)->(%d)", stype, dtype); - - } - -} - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_llconv_mmx.c b/system/pdp_llconv_mmx.c deleted file mode 100644 index 8070bac..0000000 --- a/system/pdp_llconv_mmx.c +++ /dev/null @@ -1,55 +0,0 @@ - -/* - * Pure Data Packet system implementation. : wrapper for mmx low level format conversion code - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -#include "pdp_mmx.h" - - - -/* convert greyscale 8 bit unsigned to 16bit signed */ -void llconv_grey_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - pixel_pack_s16u8_y(src, dst, nbpixels>>3); -} - -/* convert yvu planar 411 16 bit signed to 8 bit unsigned */ -void llconv_yvu_planar_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - pixel_pack_s16u8_y(src, dst, nbpixels>>3); - pixel_pack_s16u8_uv(src + nbpixels, dst + nbpixels, nbpixels>>4); -} - - -/* convert yvu planar 411 8 bit unsigned to yv12 planar 16bit signed */ -void llconv_yvu_planar_u8s16(unsigned char* source, short int *dest, int nbpixels) -{ - pixel_unpack_u8s16_y(source, dest, nbpixels>>3); - pixel_unpack_u8s16_uv(&source[nbpixels], &dest[nbpixels], nbpixels>>4); -} - -/* convert yuv planar 411 8 bit unsigned to yv12 planar 16bit signed */ -void llconv_yuv_planar_u8s16(unsigned char* source, short int *dest, int nbpixels) -{ - pixel_unpack_u8s16_y(source, dest, nbpixels>>3); - pixel_unpack_u8s16_uv(&source[nbpixels], &dest[nbpixels + (nbpixels>>2)], nbpixels>>5); - pixel_unpack_u8s16_uv(&source[nbpixels + (nbpixels>>2)], &dest[nbpixels], nbpixels>>5); -} - diff --git a/system/pdp_llconv_portable.c b/system/pdp_llconv_portable.c deleted file mode 100644 index de65ef5..0000000 --- a/system/pdp_llconv_portable.c +++ /dev/null @@ -1,81 +0,0 @@ - -/* - * Pure Data Packet system implementation. : portable low level format conversion code - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#define CLAMP(x) (((x)<0) ? 0 : ((x>255)? 255 : (x))) -#define FP(x) ((int)(((float)(x)) * 256.0f)) - -void pixel_unpack_portable_u8s16_y(unsigned char *src ,short int *dst, unsigned int nbpixels) -{ - unsigned int i; - for (i=0; i<nbpixels; i++) dst[i] = ((short int)(src[i])) << 7; -} - -void pixel_unpack_portable_u8s16_uv(unsigned char *src ,short int *dst, unsigned int nbpixels) -{ - unsigned int i; - for (i=0; i<nbpixels; i++) dst[i] = (((short int)(src[i])) << 8) ^ 0x8000; -} - - -void pixel_pack_portable_s16u8_y(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - unsigned int i; - for (i=0; i<nbpixels; i++) dst[i] = (unsigned char)(CLAMP(src[i]>>7)); -} - -void pixel_pack_portable_s16u8_uv(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - unsigned int i; - for (i=0; i<nbpixels; i++) dst[i] = (unsigned char)((src[i]^0x8000)>>8); -} - - -/* convert greyscale 8 bit unsigned to 16bit signed */ -void llconv_grey_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - pixel_pack_portable_s16u8_y(src, dst, nbpixels); -} - -/* convert yvu planar 411 16 bit signed to 8 bit unsigned */ -void llconv_yvu_planar_s16u8(short int *src, unsigned char *dst, unsigned int nbpixels) -{ - pixel_pack_portable_s16u8_y(src, dst, nbpixels); - pixel_pack_portable_s16u8_uv(src + nbpixels, dst + nbpixels, nbpixels>>1); - -} - - -/* convert yvu planar 411 8 bit unsigned to yv12 planar 16bit signed */ -void llconv_yvu_planar_u8s16(unsigned char* source, short int *dest, int nbpixels) -{ - pixel_unpack_portable_u8s16_y(source, dest, nbpixels); - pixel_unpack_portable_u8s16_uv(&source[nbpixels], &dest[nbpixels], nbpixels>>1); -} - -/* convert yuv planar 411 8 bit unsigned to yv12 planar 16bit signed */ -void llconv_yuv_planar_u8s16(unsigned char* source, short int *dest, int nbpixels) -{ - pixel_unpack_portable_u8s16_y(source, dest, nbpixels); - pixel_unpack_portable_u8s16_uv(&source[nbpixels], &dest[nbpixels + (nbpixels>>2)], nbpixels>>2); - pixel_unpack_portable_u8s16_uv(&source[nbpixels + (nbpixels>>2)], &dest[nbpixels], nbpixels>>2); -} - - diff --git a/system/pdp_packet.c b/system/pdp_packet.c deleted file mode 100644 index 894c443..0000000 --- a/system/pdp_packet.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Pure Data Packet system implementation: - * code for allocation/deallocation/copying/... - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -#include "pdp.h" -#include <stdio.h> - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - -/* this needs to be able to grow dynamically, think about it later */ -#define PDP_OBJECT_ARRAY_SIZE 1024 -static t_pdp* pdp_stack[PDP_OBJECT_ARRAY_SIZE]; - - -/* some global vars */ -static t_symbol* pdp_sym_register_rw; -static t_symbol* pdp_sym_register_ro; -static t_symbol* pdp_sym_process; - - -/* setup methods */ - -void -pdp_packet_setup(void) -{ - bzero(pdp_stack, PDP_OBJECT_ARRAY_SIZE * sizeof(t_pdp *)); - pdp_sym_register_rw = gensym("register_rw"); - pdp_sym_register_ro = gensym("register_ro"); - pdp_sym_process = gensym("process"); -} - -void -pdp_packet_destroy(void) -{ - int i = 0; - /* dealloc all the data in object stack */ - while ((i < PDP_OBJECT_ARRAY_SIZE) && (pdp_stack[i])) free(pdp_stack[i++]); -} - - -/* private pdp_mem methods */ - - -/* public object manips */ - - -/* alloc method: alloc time is linear in the number of used packets */ -/* think about a better (tree) method when this number grows large */ -int -pdp_packet_new(unsigned int datatype, unsigned int datasize /*without header*/) -{ - unsigned int totalsize = datasize + PDP_HEADER_SIZE; - int i = 0; - unsigned int align; - t_pdp* p; - for (i=0; i < PDP_OBJECT_ARRAY_SIZE; i++){ - p = pdp_stack[i]; - /* check if we can reuse this one if it is already allocated */ - if (p) { - /* remark: if p->size >= totalsize we can give away the packet */ - /* but that would lead to unefficient use if we have a lot of packets */ - /* of different sizes */ - if ((p->users == 0) && (p->size == totalsize)){ - //post("pdp_new_object: can reuse %d", i); - memset(p, 0, PDP_HEADER_SIZE); //initialize header to 0 - p->type = datatype; - p->size = totalsize; - p->users = 1; - return i; - } - else{ - //post("pdp_new_object: can't reuse %d, (%d users)", i, p->users); - //post("size:%d, newsize:%d, type:%d, newtype:%d", p->size, totalsize, p->type, datatype); - } - } - /* allocate new one */ - else { - p = (t_pdp *)malloc(totalsize); - align = ((unsigned int)p) & (PDP_ALIGN - 1); - if (align) post("pdp_new_object: warning data misaligned by %x", align); - pdp_stack[i] = p; - memset(p, 0, PDP_HEADER_SIZE); //initialize header to 0 - p->type = datatype; - p->size = totalsize; - p->users = 1; - //post("pdp_new_object: allocating new (%d)", i); - return i; - } - } - post("pdp_new_object: WARNING: out of memory"); - - return -1; - -} - - -t_pdp* -pdp_packet_header(int handle) -{ - if ((handle >= 0) && (handle < PDP_OBJECT_ARRAY_SIZE)) return pdp_stack[handle]; - else return 0; -} - -void* -pdp_packet_data(int handle) -{ - if ((handle >= 0) && (handle < PDP_OBJECT_ARRAY_SIZE)) - return (char *)(pdp_stack[handle]) + PDP_HEADER_SIZE; - else return 0; -} - - - -int -pdp_packet_copy_ro(int handle) -{ - int out_handle; - - t_pdp* p; - if ((handle >= 0) - && (handle < PDP_OBJECT_ARRAY_SIZE) - && (p = pdp_stack[handle])){ - /* increase the number of users and return */ - p->users++; - out_handle = handle; - } - else out_handle = -1; - - //post("pdp_copy_ro: outhandle:%d", out_handle); - - return out_handle; -} - -int -pdp_packet_copy_rw(int handle) -{ - int out_handle; - - t_pdp* p; - if ((handle >= 0) - && (handle < PDP_OBJECT_ARRAY_SIZE) - && (p = pdp_stack[handle])){ - /* if there are other users, copy the object otherwize return the same handle */ - if (p->users){ - int new_handle = pdp_packet_new(p->type, p->size - PDP_HEADER_SIZE); - t_pdp* new_p = pdp_packet_header(new_handle); - memcpy(new_p, p, p->size); - new_p->users = 1; - out_handle = new_handle; - } - else { - p->users++; - out_handle = handle; - } - //post("pdp_copy_rw: inhandle:%d outhandle:%d", handle, out_handle); - - } - else out_handle = -1; - - return out_handle; -} - -int -pdp_packet_clone_rw(int handle) -{ - int out_handle; - - t_pdp* p; - if ((handle >= 0) - && (handle < PDP_OBJECT_ARRAY_SIZE) - && (p = pdp_stack[handle])){ - - /* clone the packet header, don't copy the data */ - int new_handle = pdp_packet_new(p->type, p->size - PDP_HEADER_SIZE); - t_pdp* new_p = pdp_packet_header(new_handle); - memcpy(new_p, p, PDP_HEADER_SIZE); - new_p->users = 1; - out_handle = new_handle; - } - - else out_handle = -1; - - return out_handle; -} - -void -pdp_packet_mark_unused(int handle) -{ - t_pdp* p; - if ((handle >= 0) && (handle < PDP_OBJECT_ARRAY_SIZE)){ - if (p = pdp_stack[handle]) { - if (p->users) { - p->users--; - //post("pdp_mark_unused: handle %d, users left %d", handle, p->users); - } - else { - post("pdp_mark_unused: WARNING: handle %d has zero users (duplicate pdp_mark_unused ?)", handle); - } - } - else { - post("pdp_mark_unused: WARNING: invalid handle %d: no associated object", handle); - } - } - - else { - /* -1 is the only invalid handle that doesn't trigger a warning */ - if (handle != -1) post("pdp_mark_unused: WARNING: invalid handle %d: out of bound", handle); - } - - -} - -/* remark. if an owner frees a rw copy, he can still pass it along to clients. -the first copy instruction revives the object. maybe free should not be called free but unregister. -as long as no new_object method is called, or no copy on another object is performed, -the "undead" copy can be revived. this smells a bit, i know...*/ - - - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_queue.c b/system/pdp_queue.c deleted file mode 100644 index fe3748e..0000000 --- a/system/pdp_queue.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Pure Data Packet - processor queue module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - - -/* - this is a the processor queue pdp system module - it receives tasks from objects that are schedules to - be computed in another thread. the object is signalled back - when the task is completed. - - this is not a standard pd class. it is a sigleton class - using a standard pd clock to poll for compleded methods on - every scheduler run. this is a hack to do thread synchronization - in a thread unsafe pd. - - */ - -#include "pdp.h" -#include <pthread.h> -#include <unistd.h> -#include <stdio.h> - - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define PDP_QUEUE_SIZE 1024 -#define PDP_QUEUE_DELTIME 1.0f; - - - - -/********************* pdp process queue data *********************/ - -typedef void (*t_pdpmethod)(void *client); - -/* the process queue data record */ -typedef struct process_queue_struct -{ - void *x_owner; /* the object we are dealing with */ - t_pdpmethod x_process; /* the process method */ - t_pdpmethod x_callback; /* the function to be called when finished */ - int *x_queue_id; /* place to store the queue id for task */ -} t_process_queue; - - - -/* clock members */ -static t_clock *pdp_clock; -static double deltime; - -/* some bookkeeping vars */ -static long long ticks; -static long long packets; - -/* queue members */ -static t_process_queue *q; /* queue */ -static int mask; -static int head; /* last entry in queue + 1 */ -static int tail; /* first entry in queque */ -static int curr; /* the object currently processed in other thread */ - -/* pthread vars */ -static pthread_mutex_t mut; -static pthread_cond_t cond_dataready; -static pthread_cond_t cond_processingdone; -static pthread_t thread_id; - -/* synchro pipes */ -static int pipe_fd[2]; - -/* toggle for thread usage */ -static int use_thread; - - - -/* the methods */ -void pdp_queue_wait() -{ - //post("pdp_pq_wait: waiting for pdp_queue_thread to finish processing"); - pthread_mutex_lock(&mut); - while(((curr - head) & mask) != 0){ - - pthread_cond_wait(&cond_processingdone, &mut); - } - pthread_mutex_unlock(&mut); - //post("pdp_pq_wait: pdp_queue_thread has finished processing"); - -} -void pdp_queue_finish(int index) -{ - - if (-1 == index) { - //post("pdp_pq_remove: index == -1"); - return; - } - /* wait for processing thread to finish*/ - pdp_queue_wait(); - - /* invalidate callback at index */ - q[index & mask].x_callback = 0; - q[index & mask].x_queue_id = 0; - -} - -static void pdp_queue_signal_processor(void) -{ - - pthread_mutex_lock(&mut); - //post("signalling process thread"); - pthread_cond_signal(&cond_dataready); - pthread_mutex_unlock(&mut); - //post("signalling process thread done"); - -} - -static void pdp_queue_wait_for_feeder(void) -{ - - - /* only use locking when there is no data */ - if(((curr - head) & mask) == 0){ - pthread_mutex_lock(&mut); - - /* signal processing done */ - //post("pdp_queue_thread: signalling processing is done"); - pthread_cond_signal(&cond_processingdone); - - /* wait until there is an item in the queue */ - while(((curr - head) & mask) == 0){ - //post("waiting for feeder"); - pthread_cond_wait(&cond_dataready, &mut); - //post("waiting for feeder done"); - } - - pthread_mutex_unlock(&mut); - - } -} - -void pdp_queue_add(void *owner, void *process, void *callback, int *queue_id) -{ - int i; - - /* if processing is in not in thread, just call the funcs */ - if (!use_thread){ - //post("pdp_queue_add: calling processing routine directly"); - *queue_id = -1; - ((t_pdpmethod) process)(owner); - ((t_pdpmethod) callback)(owner); - return; - } - - - - /* schedule method in thread queue */ - if (1 == ((tail - head) & mask)) { - post("pdp_queue_add: WARNING: processing queue is full.\n"); - post("pdp_queue_add: WARNING: skipping process method, calling callback directly.\n"); - *queue_id = -1; - ((t_pdpmethod) callback)(owner); - } - - - - i = head & mask; - q[i].x_owner = owner; - q[i].x_process = process; - q[i].x_callback = callback; - q[i].x_queue_id = queue_id; - *queue_id = i; - //post("pdp_queue_add: added method to queue, index %d", i); - - - // increase the packet count - packets++; - - // move head forward - head++; - - pdp_queue_signal_processor(); - -} - - -/* processing thread */ -static void *pdp_queue_thread(void *dummy) -{ - while(1){ - - - /* wait until there is data available */ - pdp_queue_wait_for_feeder(); - - - //post("pdp_queue_thread: processing %d", curr); - - - /* call the process routine */ - (q[curr & mask].x_process)(q[curr & mask].x_owner); - - /* advance */ - curr++; - - - } -} - - -/* call back all the callbacks */ -static void pdp_queue_callback (void) -{ - - /* call callbacks for finished packets */ - while(0 != ((curr - tail) & mask)) - { - int i = tail & mask; - /* invalidate queue id */ - if(q[i].x_queue_id) *q[i].x_queue_id = -1; - /* call callback */ - if(q[i].x_callback) (q[i].x_callback)(q[i].x_owner); - //else post("pdp_pq_tick: callback %d is disabled",i ); - tail++; - } - -} - -/* the clock method */ -static void pdp_queue_tick (void) -{ - /* do work */ - //if (!(ticks % 1000)) post("pdp tick %d", ticks); - - if (!use_thread) return; - - /* call callbacks */ - pdp_queue_callback(); - - /* increase counter */ - ticks++; - - /* set clock for next update */ - clock_delay(pdp_clock, deltime); -} - - -void pdp_queue_use_thread(int t) -{ - /* if thread usage is being disabled, - wait for thread to finish processing first */ - if (t == 0) { - pdp_queue_wait(); - use_thread = 0; - pdp_queue_callback(); - clock_unset(pdp_clock); - } - else { - clock_unset(pdp_clock); - clock_delay(pdp_clock, deltime); - use_thread = 1; - } - -} - -void pdp_queue_setup(void) -{ - pthread_attr_t attr; - - /* setup pdp queue processor object */ - ticks = 0; - deltime = PDP_QUEUE_DELTIME; - - /* setup queue data */ - mask = PDP_QUEUE_SIZE - 1; - head = 0; - tail = 0; - curr = 0; - q = getbytes(PDP_QUEUE_SIZE * sizeof(*q)); - - /* enable threads */ - use_thread = 1; - - /* setup synchro stuff */ - pthread_mutex_init(&mut, NULL); - pthread_cond_init(&cond_dataready, NULL); - pthread_cond_init(&cond_processingdone, NULL); - - - /* allocate the clock */ - pdp_clock = clock_new(0, (t_method)pdp_queue_tick); - - /* set the clock */ - clock_delay(pdp_clock, 0); - - /* start processing thread */ - - /* glibc doc says SCHED_OTHER is default, - but it seems not to be when initiated from a RT thread - so we explicitly set it here */ - pthread_attr_init (&attr); - //pthread_attr_setschedpolicy(&attr, SCHED_FIFO); - pthread_attr_setschedpolicy(&attr, SCHED_OTHER); - pthread_create(&thread_id, &attr, pdp_queue_thread, (void *)0); - - - - /* set default disable/enable thread here */ - pdp_queue_use_thread(0); - -} - - - - - - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_resample.c b/system/pdp_resample.c deleted file mode 100644 index 16a34df..0000000 --- a/system/pdp_resample.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Pure Data Packet system file. - image resampling routines - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -#include "pdp_resample.h" -#include "pdp.h" - -/* - -efficient bilinear resampling ?? -performance: how to eliminate divides? -> virtual coordinates 2^k x 2^k (conf. opengl) - -i.e. 16 bit virtual coordinates: easy modular addressing - -*/ - - -/* code in this file should go out to be replaced by code in pdp_imageproc */ - -static s32 pdp_resample_bilin(s16 *image, s32 width, s32 height, s32 virt_x, s32 virt_y) -{ - - s32 fp_x, fp_y, frac_x, frac_y, f, offset, r_1, r_2; - - virt_x &= 0xffff; - virt_y &= 0xffff; - - fp_x = virt_x * (width - 1); - fp_y = virt_y * (height - 1); - - frac_x = fp_x & (0xffff); - frac_y = fp_y & (0xffff); - - offset = (fp_x >> 16) + (fp_y >> 16) * width; - image += offset; - - f = 0x10000 - frac_x; - - r_1 = ((f * (s32)(image[0]) + frac_x * (s32)(image[1])))>>16; - - image += width; - - r_2 = ((f * (s32)(image[0]) + frac_x * (s32)(image[1])))>>16; - - f = 0x10000 - frac_y; - - return ((f * r_1 + frac_y * r_2)>>16); - -} - - -void pdp_resample_scale_bilin(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h, s32 dst_w, s32 dst_h) -{ - s32 i,j; - s32 virt_x=0; - s32 virt_y=0; /* virtual coordinates in 30 bit */ - s32 scale_x = 0x40000000 / dst_w; - s32 scale_y = 0x40000000 / dst_h; - - for (j=0; j<dst_h; j++){ - for (i=0; i<dst_w; i++){ - *dst_image++ = pdp_resample_bilin(src_image, src_w, src_h, virt_x>>14, virt_y>>14); - virt_x += scale_x; - } - virt_x = 0; - virt_y += scale_y; - } - -} - -void pdp_resample_scale_nn(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h, s32 dst_w, s32 dst_h) -{ - s32 i,j; - s32 x=0; - s32 y=0; - s32 frac_x=0; - s32 frac_y=0; - s32 scale_x = (src_w << 20 ) / dst_w; - s32 scale_y = (src_h << 20 ) / dst_h; - - for (j=0; j<dst_h; j++){ - for (i=0; i<dst_w; i++){ - *dst_image++ = src_image[x+y]; - frac_x += scale_x; - x = frac_x >> 20; - } - x = 0; - frac_x = 0; - frac_y += scale_y; - y = (frac_y >> 20) * src_w; - } - -} - -/* USE pdp_resample_affinemap -void pdp_resample_zoom_tiled_bilin(s16 *src_image, s16 *dst_image, s32 w, s32 h, - float zoom_x, float zoom_y, float center_x_relative, float center_y_relative) -{ - float izx = 1.0f / zoom_x; - float izy = 1.0f / zoom_y; - s32 scale_x = (s32)((float)0x100000 * izx / (float)w); - s32 scale_y = (s32)((float)0x100000 * izy / (float)h); - - s32 top_virt_x = (s32)((1.0f - izx) * (float)0x100000 * center_x_relative); - s32 top_virt_y = (s32)((1.0f - izy) * (float)0x100000 * center_y_relative); - - s32 virt_x = top_virt_x; - s32 virt_y = top_virt_y; - - s32 i,j; - - for (j=0; j<h; j++){ - for (i=0; i<w; i++){ - *dst_image++ = pdp_resample_bilin(src_image, w, h, virt_x>>4, virt_y>>4); - virt_x += scale_x; - } - virt_x = top_virt_x; - virt_y += scale_y; - } - -} -*/ - - -void pdp_resample_halve(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h) -{ - - int dst_x,dst_y; - int src_x = 0; - int src_y = 0; - int dst_w = src_w >> 1; - int dst_h = src_h >> 1; - s32 tmp1,tmp2,tmp3,tmp4; - - for(dst_y = 0; dst_y < dst_h * dst_w; dst_y += dst_w){ - for (dst_x = 0; dst_x < dst_w; dst_x++){ - - tmp1 = (s32)src_image[src_y + src_x]; - tmp2 = (s32)src_image[src_y + src_x + 1]; - tmp3 = (s32)src_image[src_y + src_x + src_w]; - tmp4 = (s32)src_image[src_y + src_x + src_w + 1]; - - tmp1 += tmp2; - tmp3 += tmp4; - - src_x += 2; - - dst_image[dst_x+dst_y] = (s16)((tmp1 + tmp3)>>2); - } - src_y += src_w << 1; - src_x = 0; - } -} diff --git a/system/pdp_type.c b/system/pdp_type.c deleted file mode 100644 index b23b9cd..0000000 --- a/system/pdp_type.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Pure Data Packet system implementation. : code for handling different packet types - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -#include "pdp.h" -#include <stdio.h> - -/* all symbols are C style */ -#ifdef __cplusplus -extern "C" -{ -#endif - - -/****************** packet type checking methods ********************/ - - -/* check if two packets are allocated and of the same type */ -int pdp_type_compat(int packet0, int packet1) -{ - - t_pdp *header0 = pdp_packet_header(packet0); - t_pdp *header1 = pdp_packet_header(packet1); - - if (!(header1)){ - //post("pdp_type_compat: invalid header packet1"); - return 0; - } - if (!(header0)){ - //post("pdp_type_compat: invalid header packet 0"); - return 0; - } - if (header0->type != header1->type){ - //post("pdp_type_compat: types do not match"); - return 0; - } - - return 1; -} - -/* check if two image packets are allocated and of the same type */ -int pdp_type_compat_image(int packet0, int packet1) -{ - t_pdp *header0 = pdp_packet_header(packet0); - t_pdp *header1 = pdp_packet_header(packet1); - - - if (!(pdp_type_compat(packet0, packet1))) return 0; - if (header0->type != PDP_IMAGE){ - //post("pdp_type_compat_image: not a PDP_IMAGE"); - return 0; - } - if (header0->info.image.encoding != header1->info.image.encoding){ - //post("pdp_type_compat_image: encodings differ"); - return 0; - } - if (header0->info.image.width != header1->info.image.width){ - //post("pdp_type_compat_image: image withs differ"); - return 0; - } - if (header0->info.image.height != header1->info.image.height){ - //post("pdp_type_compat_image: image heights differ"); - return 0; - } - return 1; -} - -/* check if packet is a valid image packet */ -int pdp_type_isvalid_image(int packet) -{ - t_pdp *header = pdp_packet_header(packet); - if (!header) return 0; - if (PDP_IMAGE != header->type) return 0; - if ((PDP_IMAGE_YV12 != header->info.image.encoding) - && (PDP_IMAGE_GREY != header->info.image.encoding)) return 0; - - return 1; - -} - - - -int pdp_packet_new_image_yv12(u32 w, u32 h) -{ - t_pdp *header; - int packet; - - - u32 size = w*h; - u32 totalnbpixels = size + (size >> 1); - u32 packet_size = totalnbpixels << 1; - - packet = pdp_packet_new(PDP_IMAGE, packet_size); - header = pdp_packet_header(packet); - - header->info.image.encoding = PDP_IMAGE_YV12; - header->info.image.width = w; - header->info.image.height = h; - - return packet; -} - -int pdp_packet_new_image_grey(u32 w, u32 h) -{ - t_pdp *header; - int packet; - - - u32 size = w*h; - u32 totalnbpixels = size; - u32 packet_size = totalnbpixels << 1; - - packet = pdp_packet_new(PDP_IMAGE, packet_size); - header = pdp_packet_header(packet); - - header->info.image.encoding = PDP_IMAGE_GREY; - header->info.image.width = w; - header->info.image.height = h; - - return packet; -} - - - - -#ifdef __cplusplus -} -#endif diff --git a/system/pdp_ut.c b/system/pdp_ut.c deleted file mode 100644 index 83b4cb0..0000000 --- a/system/pdp_ut.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Pure Data Packet - Utility toolkit objects. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -/* This file contains some small utility pd objects that make working with - pdp objects a lot easier. Mainly as glue to be used in the abstractions - in the distro. */ - -#include "pdp.h" -#include <math.h> - -/* this object does an add, scale, clip operation */ - -t_class *pdp_ut_addscaleclip_class; - -typedef struct pdp_ut_addscaleclip_struct -{ - t_object x_obj; - t_outlet *x_outlet0; - t_float x_min; - t_float x_max; - t_float x_offset; - t_float x_scale; -} t_pdp_ut_addscaleclip; - - -static void pdp_ut_addscaleclip_float(t_pdp_ut_addscaleclip *x, t_floatarg f) -{ - f += x->x_offset; - f *= x->x_scale; - f = (f < x->x_min) ? x->x_min : f; - f = (f > x->x_max) ? x->x_max : f; - outlet_float(x->x_outlet0, f); -} - -static void pdp_ut_addscaleclip_free(t_pdp_ut_addscaleclip *x){} - -void *pdp_ut_addscaleclip_new(t_floatarg offset, t_floatarg scale, t_floatarg min, t_floatarg max) -{ - t_pdp_ut_addscaleclip *x = (t_pdp_ut_addscaleclip *)pd_new(pdp_ut_addscaleclip_class); - x->x_outlet0 = outlet_new(&x->x_obj, &s_float); - x->x_offset = offset; - x->x_scale = scale; - x->x_min = min; - x->x_max = max; - return (void *)x; -} - -void pdp_ut_addscaleclip_setup(void) -{ - pdp_ut_addscaleclip_class = class_new(gensym("pdp_ut_addscaleclip"), (t_newmethod)pdp_ut_addscaleclip_new, - (t_method)pdp_ut_addscaleclip_free, sizeof(t_pdp_ut_addscaleclip), 0, - A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); - class_addfloat(pdp_ut_addscaleclip_class, pdp_ut_addscaleclip_float); -} - - -/* pdp_ut_logmap does a logarithmic parameter mapping [0->1] x -> min(max/min)^x max an add, scale, clip operation */ -/* pdp_ut_logmap_comp does x -> min(max/min)^(1-x) */ -/* pdp_ut_linmap dos x -> min + (max - min * x */ - -t_class *pdp_ut_linmap_class; -t_class *pdp_ut_logmap_class; -t_class *pdp_ut_logmap_comp_class; - -typedef struct pdp_ut_map_struct -{ - t_object x_obj; - t_outlet *x_outlet0; - t_float x_min; - t_float x_max; -} t_pdp_ut_map; - - -static void pdp_ut_logmap_float(t_pdp_ut_map *x, t_floatarg f) -{ - f = (f < 0.0f) ? 0.0f : f; - f = (f > 1.0f) ? 1.0f : f; - - f = x->x_min * pow((x->x_max / x->x_min), f); - - outlet_float(x->x_outlet0, f); -} - -static void pdp_ut_linmap_float(t_pdp_ut_map *x, t_floatarg f) -{ - f = (f < 0.0f) ? 0.0f : f; - f = (f > 1.0f) ? 1.0f : f; - - f = x->x_min + ((x->x_max - x->x_min) * f); - - outlet_float(x->x_outlet0, f); -} - -static void pdp_ut_logmap_comp_float(t_pdp_ut_map *x, t_floatarg f) -{ - f = (f < 0.0f) ? 0.0f : f; - f = (f > 1.0f) ? 1.0f : f; - - f = x->x_min * pow((x->x_max / x->x_min), (1.0f - f)); - - outlet_float(x->x_outlet0, f); -} - -static void pdp_ut_map_free(t_pdp_ut_map *x){} - - -void pdp_ut_map_init(t_pdp_ut_map *x, t_floatarg min, t_floatarg max) -{ - x->x_outlet0 = outlet_new(&x->x_obj, &s_float); - x->x_min = min; - x->x_max = max; -} - -void *pdp_ut_logmap_new(t_floatarg min, t_floatarg max) -{ - t_pdp_ut_map *x = (t_pdp_ut_map *)pd_new(pdp_ut_logmap_class); - pdp_ut_map_init(x, min, max); - return (void *)x; -} - -void *pdp_ut_linmap_new(t_floatarg min, t_floatarg max) -{ - t_pdp_ut_map *x = (t_pdp_ut_map *)pd_new(pdp_ut_linmap_class); - pdp_ut_map_init(x, min, max); - return (void *)x; -} - -void *pdp_ut_logmap_comp_new(t_floatarg min, t_floatarg max) -{ - t_pdp_ut_map *x = (t_pdp_ut_map *)pd_new(pdp_ut_logmap_comp_class); - pdp_ut_map_init(x, min, max); - return (void *)x; -} - -void pdp_ut_logmap_setup(void) -{ - pdp_ut_logmap_class = class_new(gensym("pdp_ut_logmap"), (t_newmethod)pdp_ut_logmap_new, - (t_method)pdp_ut_map_free, sizeof(t_pdp_ut_map), 0, - A_FLOAT, A_FLOAT, A_NULL); - class_addfloat(pdp_ut_logmap_class, pdp_ut_logmap_float); -} - -void pdp_ut_logmap_comp_setup(void) -{ - pdp_ut_logmap_comp_class = class_new(gensym("pdp_ut_logmap_comp"), (t_newmethod)pdp_ut_logmap_comp_new, - (t_method)pdp_ut_map_free, sizeof(t_pdp_ut_map), 0, - A_FLOAT, A_FLOAT, A_NULL); - class_addfloat(pdp_ut_logmap_comp_class, pdp_ut_logmap_comp_float); -} - -void pdp_ut_linmap_setup(void) -{ - pdp_ut_linmap_class = class_new(gensym("pdp_ut_linmap"), (t_newmethod)pdp_ut_linmap_new, - (t_method)pdp_ut_map_free, sizeof(t_pdp_ut_map), 0, - A_FLOAT, A_FLOAT, A_NULL); - class_addfloat(pdp_ut_linmap_class, pdp_ut_linmap_float); -} - - - -#ifdef __cplusplus -extern "C" -{ -#endif - -void pdp_ut_setup(void) -{ - pdp_ut_addscaleclip_setup(); - pdp_ut_logmap_setup(); - pdp_ut_logmap_comp_setup(); - pdp_ut_linmap_setup(); -} - - -#ifdef __cplusplus -} -#endif |