Age of Reason

Random musing of books and stuff I am reading.

2005/01/26

Halftone Dithering for Printing

Instructions for printing B&W photo
on ordinary 8x11 paper on a low resolution
ink jet printer with minimum black ink usage.

The trick to get perfect b&w 8x11 inch prints
in less than 10-seconds is to resize, sharpen,
lighten and dither in the correct order.

Here are the steps:

1. Image -> mode -> grayscale.

2. Filter -> sharpen -> unsharp mask
Adjust for contrast here and clear edges.

3. Image -> adjust -> curves
Pull the graph downwards to make the picture
much lighter, as it comes out better on printer.

Experiment by printing a lighter picture
and you will see that the printed picture will
come better than it looks on screen.

4. Image -> Crop
Image size: 11x8 inches (max of height or width).

5. Image -> mode -> bitmap -> halftone screen 600dpi
halftone settings: Freq 60 dot/inch, 45 degrees, round.

6. Optionally save as image.psd (bitmap).
File -> print -> printer setup, Portrait or
Use landscape if width greater than width.


2005/01/22

The Noble Kinsmen

Just finished the play "The Noble Kinsmen"
by Shakespeare and John Fletcher. The 1400s
version of this story by Chaucer was known
as The Knight's Tale in Canterbury Tales.

In this play the two knights and cousins
Palamon and Arcite vie for the love of
fair Emilia from a jail.
The unreality is balanced by the unbalanced
their gaoler's daughter. The greek gods
Mars and Venus symbolize the two knights
and their qualities, prayers and hopes.

The Knighthood bit and Greek setting
is overdone in this quick paced play.

The Knights are shown to be totally self centered
and selfish. They would rather kill their cousin
and noble friend for a lady they never spoken to.
Their caste system will not allow Palamon to fall
in love with a commoner, the jailer's daughter.

In a Hindi movie version of this play,
replete with the motifs of nobility, sacrifice
and equality, Palamon would be the winner of
the jousting and end up marrying the jailer's
daughter and Arcite would marry pricess Emilia.

The play gives you an idea what history was like
400 years back. Knights in ancient Greece?

This one is not difficult nor boring
unlike Shakespeare's history plays.

I should know, since I read Henry V last
week and Henry was the leading bore. Somehow
Henry 5th comes out as a plastic character.
And Kate, Princess Katherine of France comes
out as a dummy. Maybe that was the intention
of the Bard to show the superiority of the
British Army and Language over the French.

2005/01/21

Forgotten promise of the PC

Essential features missing on the PCs:

1. Switch to write-protect the hard disks.

2. Readonly system directory or system on CD.
Go Knoppix.

3. Not crashing or hanging windows on a bad/scratched CD.
No excuse for this one.

4. Trusted portable USB keyboards.
If you can't login securely, what can you do?

5. Switch to power cycle hung laptops.
My Toshiba laptop came with an XP, it used to hang
atleast once a day.

6. User control to underclock CPU, NIC, IDE
No reason for PC to be computing when I don't want it to.

7. Focus-lock for 400ms when fingers are near keyboard.
Don't you hate the pop-up "Press Cancel", suddenly appear
and vanish while you are typing something else in another window?

8. Light touch mouse-buttons and keyboard.
There is no reason the mouse button is so hard to press.
The mouse is really a bad idea, touch screen is the right solution.

9. Instant On/Off, RAM disk for windows.
Linux should fit into 16Mb CF BIOS (maybe also Win95).

10. Read-only and Write-Only switches on USB drives.
Write-only switch is needed when plugging the drive into public machines.

11. All power adaptors (5v..12V) clutter inside the PC.


2005/01/10

Enquire within for LP64

The program enquire.c will tell you a lot about your machine.
Here is how to compile it on HP/UX
> cc +DA2.0W +w1 +M2 enquire.c     


Use the flags +w1 for warnings, +M2 for 64bits

These are the kind of problems you should look out for:


/714: Function "malloc" called with no prototype or definition inscope
/724: Initialization converts default int return type to pointer
/722:.*cast converts 32 bit constant to pointer
/725:.*cast converts 32 bit integer to pointer
/727:.*cast truncates pointer into 32 bit integer
/729:.*converts int* to long*
/732:.*different types treated as unsigned
/740:.*casting to a smaller size may truncate
/530:.*casting from loose to strict alignment
/720:.*Assignment may overflow
A simple example that has many of the problems
> pr -n x.c

1 void main(){
2 int *x, *q, i;
3 long l=-1;
4 x = malloc(sizeof(int)*10);
5 (int*)i;
6 (int) &i;
7 (long*)&i;
8 i = l;
9 }

hp64> cc +DA2.0W +M2 +w1 -Aa x.c

line 4: warning 714: Function "malloc" called with no prototype or definition in scope.
line 4: warning 724: LP64 migration: Assignment converts default int return type to pointer "x".
line 5: warning 725: LP64 migration: Cast converts 32 bit integer to pointer.
line 6: warning 727: LP64 migration: Cast truncates pointer into 32 bit integer.
line 7: warning 530: LP64 migration: Casting from loose to strict alignment: Resulting pointer may be misaligned.
line 7: warning 729: LP64 migration: Cast converts int* to long*.
line 8: warning 720: LP64 migration: Assignment may overflow integer "i".


Sorting LP64 warnings by problem types for ease in fixing

> make 2>&1 | grep LP64 | xsort 'warning:\s+\S+:' | align warn > lp64.log
> vim -q lp64.log
> emacs lp64.log
> M-x compilation-minor-mode
> M-x next-error
; if emacs can't find files, set
; (setq compilation-search-path '("dir1" "dir2")) C-x C-e
To be continued.

2005/01/08

Shakespeare on Screen

Just finished reading "Richard II" in Folger paperback.
Nice piece of lyrical work.
This is the story of the downfall of a foolish English King,
he is confused by his belief that God has made him the King
and he can do no wrong.

It whetted my appetite for more, so I am starting on
King Henry V, Oxford large print, edited by Roma Gill.
Earlier I tried watching Kenneth Branagh as Henry V on DVD,
it was a colourful melodrama with incoherent dialogues.
Proving that media is not the message.
However Kenneth's other movie "Much Ado about Nothing" was
very well done and worth watching.

If you are a language fan (rather than a movie buff)
these are also worth watching:
Mel Gibson as Hamlet,
Brando in Julius Caesar,
Zeffirelli's Romeo and Juliet
Midsummer night's dream 1999,
As you like it
from 1937.
Taylor and Burton in Taming the Shrew, 1967.

I remember seeing Twelfth Night and Merchant of Venice,
and a few more, but recall nothing notable to recommend.

2005/01/04

Double Quoted Shells.

Ever had trouble putting quotes inside bash aliases?
Then read on, for Bash and sh allow extra ordinary
levels of quotations. The examples below would be
unthinkable in csh and other simplistic shells.

Of course DOS users would rather drag and drop
filenames with spaces in them.



To avoid the disease quototitis we will use the
abbreviations dq (") and sq('). Note that dq
inside sq strings are ignored.

1. To expand a shell variable inside a 'string':
1.1 End the sq string.
1.2 Put the variable in dq (to prevent extra spaces),
1.3 Start sq string again.

> perl -e 'print("...'"$HOME"'...\n");'
...c:/mosh...

2. To insert sq inside a sq-string:
2.1 close sq string.
2.2 put standalone backslashed sq
2.3 start sq string again.

> perl -e 'print "I just can'\''t do that!\n";'
I just can't do that!

> echo 'aaa'"'"'bbb'
aaa'bbb

3. To use single quotes inside an alias,
3.1 close quote,
3.2 dq sq dq
3.3 open quote

> alias nut='net use |perl -lne '"'"'print("$1=$2") if s,\\,/,g && m@\s([A-Z]):\s+(//\S+)@'"'"
^^^^^ (close sq, open dq, insert sq, close dq, open sq again).

> alias vq='vim +'"'"' ":call Mosh_Quick_Fix()" '"'"' '
^^^^^ (close sq, open dq, insert sq, close dq, open sq again).
> alias vq
vq="vim +'\" :call Mosh_Quick_Fix()\" ' "

4. Use dq to preserve spaces:
> x='A
B'
> echo $x # single line, newlines in $x are converted to spaces.
A B
> echo "$x" # newlines \n are preserved.
A
B

5. Passing dq to emacs from a function:
ediff(){ ${EMACS:=emacs} --eval "(ediff-files \"$1\" \"$2\")" }

6. Passing arguments to perl
> echo PWDLEN=$(perl -e 'print length(shift);' $PWD)
> echo PWDLEN=$(perl -e 'print length($ARGV[0]);' $PWD)



Well you knew that? If not, get a copy of "Kernighan and Pike".
However Regexp are better done with expr and perl. ATT made
the perfect shell, but the implementation of regexp eluded them
until Henry spencer wrote the free bugfree regexp library.
Finally Larry Wall perfected the Camel (no relation of Caml).

Traditionally you can do plain literal subst OLD by NEW in VAR.

>VAR=${VAR/OLD/NEW}

You will have to come out of your shell to play with regexps:

subst(){
eval "VAL=\$$1"
VAL2=$(perl -e '($f,$a,$b)=(shift,shift,shift);$f=~s/$a/$b/gi;print $f' $VAL $2 $3)
eval "$1=\"$VAL2\""
}
>subst PATH '/usr/\w+/bin' '/usr/bin' # changes PATH =~ s,/usr/\w+/bin,/usr/bin,ig


Regexp can be eagerly quantified. see 'man perlre' for details.