SSAO page updated.

SSAO page updated. http://meshula.net/wordpress/?p=145

Post to Twitter Post to Delicious Post to Facebook

TextScanner, now in C

Long time ago, I posted a text scanner on flipcode (link). Couple of years later, I posted an update with all kinds of snazzy new features, a namespace, and what not.

Today, I’m reposting, with a hardcore regression to C.

-> TextScanner.h
-> TextScanner.c

This version has fewer fancy features, fewer lines of code, and more straight up dealing with text. It has the functions that proved most useful and robust over the years. It has no internal state, making it first of all threadsafe, and secondly data-oriented.

Here’s a preview of the public API. Give it a try if you need this sort of thing. Feedback welcome!


// Get Token
EXTERNC char const* tsGetToken (char const* pCurr, char const* pEnd, char delim, char const** resultStringBegin, uint32_t* stringLength);
EXTERNC char const* tsGetTokenWSDelimited (char const* pCurr, char const* pEnd, char const** resultStringBegin, uint32_t* stringLength);
EXTERNC char const* tsGetTokenAlphaNumeric (char const* pCurr, char const* pEnd, char const** resultStringBegin, uint32_t* stringLength);
EXTERNC char const* tsGetNameSpacedTokenAlphaNumeric(char const* pCurr, char const* pEnd, char namespaceChar, char const** resultStringBegin, uint32_t* stringLength);

// Get Value
EXTERNC char const* tsGetString (char const* pCurr, char const* pEnd, char const** resultStringBegin, uint32_t* stringLength);
EXTERNC char const* tsGetInt16 (char const* pCurr, char const* pEnd, int16_t* result);
EXTERNC char const* tsGetInt32 (char const* pCurr, char const* pEnd, int32_t* result);
EXTERNC char const* tsGetUInt32 (char const* pCurr, char const* pEnd, uint32_t* result);
EXTERNC char const* tsGetHex (char const* pCurr, char const* pEnd, uint32_t* result);
EXTERNC char const* tsGetFloat (char const* pcurr, char const* pEnd, float* result);

EXTERNC char const* tsScanForCharacter (char const* pCurr, char const* pEnd, char delim);
EXTERNC char const* tsScanBackwardsForCharacter (char const* pCurr, char const* pEnd, char delim);
EXTERNC char const* tsScanForWhiteSpace (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanBackwardsForWhiteSpace (char const* pCurr, char const* pStart);
EXTERNC char const* tsScanForNonWhiteSpace (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanForTrailingNonWhiteSpace (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanForQuote (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanForEndOfLine (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanForLastCharacterOnLine (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanForBeginningOfNextLine (char const* pCurr, char const* pEnd);
EXTERNC char const* tsScanPastCPPComments (char const* pCurr, char const* pEnd);
EXTERNC char const* tsSkipCommentsAndWhitespace (char const* pCurr, char const*const pEnd);

EXTERNC _Bool tsIsWhiteSpace(char test);
EXTERNC _Bool tsIsNumeric (char test);
EXTERNC _Bool tsIsAlpha (char test);
EXTERNC _Bool tsIsIn (const char* testString, char test);

Post to Twitter Post to Delicious Post to Facebook

No deadly clicks!

Application Consumer Grading

  • No deadly clicks
  • No deadly data
  • No cracks to fall through
  • No leaks
  • No random crashes
  • Survives complete usage cycle
  • Can survive running in a kiosk for days

Post to Twitter Post to Delicious Post to Facebook

A little on color grading

Color grading, or color timing, is the process of adjusting the color balance and exposure of footage.

The shots that make up a show can be corrected so that they all have similar characteristics. Footage can be corrected for natural skin tones. Different shots can be adjusted so that exposure levels go together well. Video shot with incorrect white balance can be corrected.

When shots are edited together, color can be adjusted to emphasize or suppress the transition between shots. For example, a shot cutting between a daylit exterior and an incandescent lit interior will have a jarring color shift from bluish to orange. The interior shot can be balanced more to blue so that the transition is more subtle.

Saturation and shadow detail can be manipulated; shadows can be ‘crushed’ to increase contrast and remove detail. A bleach bypass process effectively prints a black and white version of an image over top of a desaturated version of the original.

Color and light manipulation is best done on set. Ideally, you’ll shoot something like the Gretag-Macbeth color checker to aid the grading process by having a standard reference.

Color grading can be used as a story telling tool.

A shot involving a character leaving an airplane for a bright environment might have the second shot balanced to emphasize the shock of going outside. A nostalgic scene may have a sepia tint. Colors may be desaturated in a sequence to make the feeling a bit unreal. A red tint might be introduced to communicate tension. If a movie has two timelines, one in the present, and one in the past, all the shots in the past might be graded in a different way as a subtle cue to the viewer as to which timeline they’re viewing.

For further reading and practical examples, I highly recommend this article:
http://digitalfilms.wordpress.com/2009/12/05/color-grading-effects-demystified/

Post to Twitter Post to Delicious Post to Facebook

Photos of Sculpture

I was struck by the look of some sculpture recently, and processed some photos to capture my impressions.

The slideshow is visible after the jump. On mobile, you can view it here: link. If your reader is not flash-enabled, you can view the slideshow here: link.

Tapping a picture in the slideshow will take you to its flickr page where you can see it larger.

Post to Twitter Post to Delicious Post to Facebook

Abandoned Nike base

Out on a recent hike, I stumbled across an abandoned Nike missile base. Three silos welded shut, rusting, filling with water in the rain. An apocalypse that might have been, abandoned to ruin. Mushrooms dotted the site, and the rocks were cleaved through with planes of quartz, giving the whole a mythic feel.

The slideshow is visible after the jump. On mobile, you can view it here: link. If your reader is not flash-enabled, you can view the slideshow here: link.

Tapping a picture in the slideshow will take you to its flickr page where you can see it larger.

Post to Twitter Post to Delicious Post to Facebook

Now more delicious.

My delicious book mark tag cloud (does not show up in some RSS readers) -

Post to Twitter Post to Delicious Post to Facebook

Goldfish Existential

Goldfish existential

Lo-mobbed iPhone photography. Click pic to enlarge.

Post to Twitter Post to Delicious Post to Facebook

Communicating Sequential Processes

The book Communicating Sequential Processes introduces a formal calculus of processes; its formalisms and structures are reflected in the design of modern concurrent languages and libraries such as occam, libthread, Go, CHP, and more.



This article is a brief overview of the book Communicating Sequential Processes, by C.A.R. Hoare, June 21, 2004, first published in 1985 by Prentice Hall International, and obtained online at:

http://www.usingcsp.com/

I took a lot of notes while reading the book, and thought that the notes might help others tackle the subject matter. I’d appreciate any corrections or suggestions on how to make this article more useful.

Introduction

The intent of the theory in Communicating Sequential Processes is threefold:



  • . To describe interesting applications

  • . Be efficiently implementable

  • . Assist the programmer in specification, deign, verification, and validation of systems.

Processes


A process is the behavior pattern of an object. Behavior is described as a pattern wherein events lead to other behaviors. Events are instantaneous actions – atomic actions without duration. There’s nothing special about an event, there imply no causality. Events are not considered to be sent or received, rather, they merely represent that something has occurred, and therefore a further pattern of action is expected. Another way to describe an event is as a synchronization primitive that one or more processes can engage with.


We might denote some sample processes:


(guestsArrived -> LETS_EAT)
(keyTurned -> ENGINE_STARTS)


Generally, we might write:

(x -> P)

which we read as “x then P”. The process described engages in event “x”, then behaves as described by “P”. The arrow operator always takes an event on the left and a process on the right. The arrow operator is right associative, which means that we could write:


(x -> (y -> P)) = (x -> y -> P)


CSP defines two special primitive processes, STOP and SKIP. SKIP is a process that is always ready to go, and immediately terminates successfully. STOP is a process that is never ready, does nothing, and never terminates. It is mostly used as dummy item.


Since actions are instantaneous, we need to represent extended actions as a pair of events indicating the start and the end. In CSP, timing is ignored since timing can be treated independently of logical correctness. Simultaneity is not a concept; if it is important that two events occur simultaneously, they are treated as a single event.


A machine that accepts two coins, dispenses two chocolates, and stops can be described as:



(coin -> (choc -> (coin -> (choc -> STOP))))


If this sequence was to repeat indefinitely, recursion could be used. A clock might be described by ticks:



(tick -> CLOCK)


A CLOCK can emit a single tick, and we can define


CLOCK = (tick -> CLOCK)

This can then be expanded via substitution as many times as we want.


CLOCK = (tick -> tick -> tick -> tick ->(tick -> CLOCK))

If the chocolate vending machine described earlier has an unlimited supply of chocolate, it could be defined as


VM = (coin -> (choc -> VM))

These recursions have a prefix, which is to say: they start with a one or more events. Such an equation is called guarded, and all guarded equations have a solution.

We can prove that all guarded equations have a solution: every guarded equation can have a process substituted that just makes the chain longer but still satisfies the original equation.

This lets us say that two processes that behave the same are the same process, which comes in handy for proofs and simplifications.

Recursion can be mutual:


CLOCKA = (ticka -> CLOCKB)
CLOCKB = (tickb -> CLOCKA)

Choices are indicated with a bar. This equation


(x -> P |
y -> Q |
z -> R)

says that if x occurs behavior P results; if event y occurs behavior Q happens; and if z occurs, R results. No other event is engaged with this process.

This idea can be used to implement a copy process.


COPYBIT =
(in.0 -> out.0 -> X |
in.1 -> out.1 -> X)

The only distinction between the notions of input and output in a process is that the environment can provide an input of in.0, or in.1, but the corresponding output has no choices.

Traces are a record of events. The trace of the coin for chocolate machine described earlier would be . Various algebraic laws are introduced, ultimately for the purpose of proving whether two traces are equivalent. Two processes that generate the same trace are identical, so the utility of proving traces are identical is that it might be easier to algebraically reduce traces to each other than it might be to reduce the corresponding processes in order to prove equivalence.

Specifications are defined (for example, x never exceeds 10); and satisfactions go with them – one asserts that for every possible observation of a process, the specification will be true. An algebra for conjunction of specifications is developed. The notions of traces and specifications are important for proving that a system works properly.

Concurrency

P || Q indicates two processes that share an alphabet and proceed in lock-step synchronization; in other words, in parallel, not concurrently. Should one process expect an event that does not come from the other, a deadlock occurs. Deadlock means that each process is prepared to engage in further action; but the the further actions are different, and nothing further can happen.

An algebra on the || operator is defined, and the dining philosophers problem explored, including the deadlock situation where all philosophers sit simultaneously. Various solutions to the problem are derived.

Algebraic tools on concurrency are developed, allowing for various transformations on processes. The utility of the algebra is that processes can be broken down, and composed such that details of processes can be hidden so that processes can operate in a common environment but not interact with each other. Actions can be further labeled so that the action engages only a single process.

Nondeterminism

Nondeterminism is introduced to describe situations where multiple actions are possible, but the choice cannot be anticipated; it is made at the time the action occurs. For example, a process cannot know which lever a user might pull, until the moment the lever is pulled:


(leftLever -> A) [] (rightLever-> B)

Rules are developed to determine what should happen if two events are available simultaneously, or if an event can satisfy two processes simultaneously.

Refusals are defined as the set of actions that result in deadlock in a first step. The existence of a known refusal can be used to implement an alternate choice that does not result in a deadlock for the requested action.

Concealment is introduced to hide members of the alphabet whose occurrence requires simultaneous participation with the environment. In other words, if an action is strictly an internal transition, there is no need to expose that action to the alphabet the environment can use on a process. Unfortunately, the introduction of concealment means that guarded recursions are not constructive, and therefore liable to have more than one solution. Divergence describes the case where non-determinism is required to describe a process since no solution is otherwise possible.

Interleaving is similar to the || operator. If two processes with the same alphabet are interleaved -


P ||| Q

then one or the other of the processes can engage an action. If P cannot accept an action, then Q can take it, and vice versa. If both can accept it, then one or the other will take it, nondeterministically. If neither can take it, deadlock results. An algebra is developed, as well as the behavior of traces and refusals, and the use of specifications.

Communications

A communication is a special class of event described as a pair, c.v where c is the name of a channel where the communication takes place, and v is the value of the passed message. There are functions that can pick these apart:


channel(c.v) = c, message(c.v) = v

Channels are defined to be unidirectional, and between two processes. A channel is a potential set of events; one event for each value that might be communicated down the channel. Channels are named into the alphabet of actions, for example, a copy process might be written as


COPY(left, right) = (left?x -> right!x -> X)

The question mark denotes input, the exclamation mark, output, so the equation says any value x communicable on left arriving on the left channel results in the value x being emitted from the right channel, followed by process X.

More complex expressions are introduced using if/then/else statements to perform transformations on an input stream. The choice operator can be used to invoke different processes when different actions arrive, as developed in previous chapters. The concurrency operator || is extended when P || Q communicate via channel. In that case, the definition of concurrent actions is extended to say that actions can occur when P outputs a value on c that is expected as an input on Q, and vice versa. Communication can thus be regarded as a special case of the prefix operator. Internal communications can be concealed. Similarly to previous chapters, proving the absence of deadlock between communicating processes can be proven.

Since two processes are connected by a single channel, any network of non-stopping processes free of cycles cannot deadlock, since any acyclic graph can be decomposed into subgraphs connected only by a single arrow.

Various examples show how data flow networks can be set up to compute streams of results from streams of input data. In general, if processes describe an operation, any mathematical expression can be described as processes communicating via channels. When the networks are large but regular, a subscripted notation can describe an iterative array. If the connection diagram has no directed cycles, the array is known as a systolic array.

Processes that have only two channels in their alphabet, namely an input and an output, are called pipes.


P >> Q (P pipes to Q)

Concatenated pipes can become a single pipe through concealment. Pipes are associative if the connected channels are capable of transmitting the same kind of message. The process within a pipe may transform the stream.

The chaining operator connects two processes by just one channel, and so can’t deadlock. It can however introduce a new danger of livelock, which results when P and Q spend all their time communicating with each other and never the external world. To prove that livelock is not a danger, P must be left-guarded in the sense that the sequence of outputs of P must be bounded by some function of the sequence of inputs. Q must be right-guarded in the sense that it must output no more symbols than are input.

Buffers are special processes that output exactly their input, possibly after some delay. When non-empty, a buffer is always ready to output. A buffer is free of livelock.

Protocols describe two processes, a transmitter and a receiver, connected in series as a buffer. (T >> R). In practice T and R might be connected by a process WIRE, which might not behave exactly as a buffer, due to unreliability. A protocol is a layered process that allows a nondeterministic process to behave as a buffer, by layering communication, usually involving a second backflowing channel used for handshaking. Various laws are described to prove the correctness of a protocol.

Sequential processes

A process P might be broken broken down into two processes that must execute in sequence. This is denoted


P = Q ; R

A repeating process or loop can be defined recursively:


P = (P ; X) = P ; P ; P ; P ; …

A sequence of symbols is said to be a sentence of process P if P terminates successfully after engaging in the corresponding sequence of actions. The set of all such sentences is called the language accepted by P. The notation of describing sequential processes may thus be used to define the grammar of a language. This treatment is familiar to anyone who has studied parsers.

Algebraic treatment of deterministic and non-deterministic is presented.

Interrupts are defined as a sequential composition (P ∆ Q) where the progress of P is interrupted on occurrence of the first event of Q, and P is never resumed. A catastrophe is an interrupt that occurs for some unspecified reason; the catastrophe symbol can be used to specify a recovery process Q. A restart facility is one such recovery process. Checkpoints can indicate restarts of lesser severity than restarting the whole system.

Assignments, conditionals, and loops are defined to encompass the most important aspects of conventional sequential programming. There are no surprises here.

Shared resources

Since channels cannot explicitly be shared, methods, such as labeling or interleaving must be contrived to create enough separate channels for independent communication in a way that the equations are satisfied.

The problem of interference is introduced, wherein two processes attempt to modify a shared variable, but since both read the initial value before either completes its write, a transaction is lost. A critical region is proposed as a possible solution to the problem. A mutex is also suggested. Finally, it is noted that atomic operations are best, since no ambiguity of sequence can result. It is reasonably proposed that each shared resource in a system be specifically designed for its purpose, and that pure storage not be explicitly shared in a concurrent system design.

Discussion

The central premise driving CSP is that a single job should be able to take advantage of the parallelism provided by a computer’s hardware.

Shared storage is a typical hardware solution to this, but has the problem previously introduced of interference.

Fork and join, wherein the locus of program control can be split such that two processors execute the same program independently, and then rejoined when a specific label is waited upon by both processors simultaneously, is deemed unnecessarily complicated to use, and therefore problem prone.

Dijkstra proposed that forked processes should execute to completion and that the join should be implicit when all forked processes have completed. These processes would have no shared interaction, save through channels. This notion forms the basis of the concurrent processes in CSP.

Dijkstra further proposed critical regions should protect shared storage so that concurrent processes could share variables. Variables declared as shared give a compiler a hint that a critical region can surround operations on that variable automatically. Such a pattern might look like this:


shared n : integer
with n do n := n + 1;

Synchronization between processes could be further elaborated:


with n when condition do critical region

Condition is tested on entry, and the critical region executed immediately if possible, or deferred until condition is satisfied. There is a potential performance problem if many processes need to enter the critical region, although this is a semantically elegant solution.

Monitors are described. In modern parlance, a monitor is a class with private member variables; all meaningful operations on data occur within method calls, these method calls internally are made to operate sequentially by protecting the execution of each method with a semaphore.

Specific embodiments of concurrency in Pascal Plus, Ada, a language named CSP, and Occam are described. Certain advantages and limitations are mentioned.

We are reminded that a pipe is a unidirectional channel between two processes. Multiple buffered channels are a natural generalization to allow any process to communicate with any other in either direction. Unfortunately multiple buffered channels can allow deadlock. It is noted that the ARPAnet is such a system, and that mathematical treatment is complicated.

The book ends by noting that the case for the practical application of CSP is overstated, but nonetheless, it has presented a sound mathematical basis for reasoning about specifications, designs, and implementations.

The mathematical treatment convinced me of the practicality of the approach and its correctness. I did feel that without automated tools, calculating the correctness of a process in anything but the most trivial processes would be cumbersome.

This article has been a brief overview of a complex subject, mostly I am hoping to provide a bit of a glimpse as to what the book covers in order to pique your interest. I encourage you to read the book and work through the proofs to get a stronger understanding of the theoretical foundations. As multicore, concurrent, and parallel processes become more and more prevalent, the concepts in CSP are going to become increasingly relevant today.

Footnote:

If you wish to experiment with some of the concepts in CSP, a useful implementation written in Haskell can be found here:

http://chplib.wordpress.com/2009/11/16/an-introduction-to-communicating-sequential-processes/

Post to Twitter Post to Delicious Post to Facebook

Discoveries & Developments, Sept. 2009

Discoveries & Developments is a collection of new things that caught my attention. I hope to catch interesting new trends and breakthroughs as they happen. My themes as always are science and technological trends in the world of film and games.

September Topline: Lucidity from LucasArts, Eskil Steenberg’s Love

Sept 21, Lucasarts posted a mp3 from Lucidity.
http://lucasartsworkshop.wordpress.com/2009/09/21/something-svenskt-this-way-comes/

Sept 22, Mordy Koots trailer, live action composited into a game engine.
http://www.personalizemedia.com/thumbs-up-for-aussie-innovation-live-action-film-in-game/

Transistors could be made from paper.
http://www.physorg.com/news172837799.html

Sept 25, Are the Fraggles coming back?
http://www.drdoozer.com/

Trooper 57 on SpaceBook
http://www.neatorama.com/2009/09/14/spacebook/

Screenspace Ambient Occlusion live on a web page
http://kode80.com/2009/09/26/papervision-ssao-preview/

Sept 26, Don’t plant a seed, and dig it up every day to see how it’s doing.
http://lovefromdevelopment.blogspot.com/2009/09/plant-seed-watch-it-grow-innovation-in.html

Sept 28, Gutworms can cure asthma. This would be a good Fringe episode.
http://www.sciencedaily.com/releases/2009/09/090928095341.htm

Sept 28, Paxton Gate remains cool.
http://www.paxtongate.com/

Sept 29, Eskil Steenberg gets philosophical about carrying around a $10,000 bill.
http://iloapp.quelsolaar.com/blog/news?Home&post=49

Sept 30, @kamidphish notes that “a superior pilot uses his superior judgment to avoid having to exercise his superior skill.”

A Tsunami does not wash up at Ocean Beach.

A rather good post on level building and balancing at the LucasArts Workshop blog.
http://lucasartsworkshop.wordpress.com/2009/09/30/enemies-in-danger-pt-1-of-an-epic-post/

Post to Twitter Post to Delicious Post to Facebook

Arima Toy Museum

Tapping a picture will take you to its flickr page where you can see it larger.

Mobile readers please click here to see the pictures.

For Google Reader, and other non-flash enabled readers, please click here.

These pictures were taken at the Arima Toy Museum in Japan. Their special exhibition when we visited featured traditional German woodcrafts. The regular exhibits included many other fascinating antique toys, automata, and more.


View Larger Map

Post to Twitter Post to Delicious Post to Facebook

San Francisco

All effects accomplished in camera during shooting, with no processing later. (iPhone + TiltShiftGen as camera app)

I adjusted vignetting, saturation, contrast, and blur, adjusted exposure using the interactive spot meter, then snapped the pics.

Downrezzed to fit on screen.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.


MOMA


Robot HQ


Robot HQ 2


Lombard





Post to Twitter Post to Delicious Post to Facebook

Document Arc at the Doors of Perception

There’s an extremely cool tool at Neoformix. It analyzes text for similarities and generates an arc map relating concepts. I tried it on Photons at the Doors of Perception and was impressed to see that it was able to distill the basic thesis of my post: Perception is an energetic exchange between a mind and its environment. Or perhaps, I was able to use the tool to spot my basic thesis. Either way, I plan to use the Document Arc Diagram tool to analyze more subjects.

Post to Twitter Post to Delicious Post to Facebook

Earthrise, 1 Nov 2009

Earthrise

This image was snapped as MLOTS passed over Thiessen Crater on the Moon’s farside. Today is the full moon as viewed from Earth, and if you look carefully the new Earth is dimly visible as it rises above the limb of the moon. This was a lucky shot as the window on the docking alignment portal is not always aligned towards Earth.

The Meshula Labs Orbital Transfer Station (MLOTS) at its current altitude completes a lunar orbit every 8 hours. Its primary function is electromagnetic capture of incoming vehicles from Earth bound for one of the Lunar Research, Resource, or Habitation Stations. To schedule an orbital transfer please contact MLOTS Logimetric Operations on standard frequencies.

(PS, the configuration and lighting in the painting is correct for the place, time, and date indicated…:)

Post to Twitter Post to Delicious Post to Facebook

Too much online?

Time online and quality of life are intimately related; the relationship is an ongoing transformation, and we’re in the thick of it. We’re in the midst of a massive social transformation, and taking a step back is a natural reaction, and part of the transformative process. Overall though, it’s got tsunami force, and time online is only going to increase. The social and technological aspects are evolving so rapidly though, the time we spend online a year from now might even not be recognizable from today’s standpoint.

(In response to: a post by Mark Evans)

Post to Twitter Post to Delicious Post to Facebook

Bad Behavior has blocked 924 access attempts in the last 7 days.