There is good weird and there is bad weird, and despite whatever glow of unearned nostalgia has gathered about it over the years, the 1971 ''Willy Wonka and the Chocolate Factory" is mostly bad weird. Directed by journeyman director Mel Stuart, it has the feel of a pilot episode for a child's first acid trip, up to and including the shock-cuts of worms and rotting food. Only Gene Wilder's fey Willy Wonka and Peter Ostrum as a choirboy Charlie Bucket save it; the rest is ''H.R. Pufnstuf" gone tediously wrong.
Roald Dahl, by contrast, wrote books that are very nearly the working definition of good weird -- fanciful, rebellious, tinged with the un-
happiness kids know is always out there, no matter how much the grown-ups simper. What director Tim Burton, screenwriter John August, and star Johnny Depp have fashioned out of ''Charlie and the Chocolate Factory," Dahl's most celebrated novel, is pretty good weird, too -- five minutes into the film, my 8-year-old grinned and said ''This is odd" -- but weird it is, and not just because Depp does his level best to convince us he's Michael Jackson.
Seriously. His Willy Wonka has ashen pancake make-up and an unsettling lack of wrinkles (except for one nervous little crease that goes tick-tick-tick under his right eye); under a top hat encircled by a lavender ribbon, he wears his hair in a pageboy of the sort Bette Davis favored in her later years. His voice is a sing-song pitched somewhere between Mr. Rogers and Carol Channing. In many ways, he's a bigger baby than anyone else in the movie.
In the trailers, this looked like a recipe for disaster. In the film itself, Depp's performance works surprisingly well, because there's an idea behind it and a good one. Willy is the sort of celebrity our culture coins all too easily these days; the youthful superstar whose drive sends him to the top and whose early fame isolates him into increasing eccentricity. (He has father issues to boot: In flashbacks, we learn that Wonka Sr., played by Christopher Lee, was a domineering dentist with no patience for sweets or the cavities they produce.) Depp creates something close to Howard Hughes as a self-made chocolatier, Brian Wilson with a factory instead of a sandbox -- and, yes, the King of Pop in a spun-sugar Neverland.
All of which sounds like Burton and company have ventured far beyond the confines of the book. I'm happy to report, then, that ''Charlie and the Chocolate Factory" is much more faithful to its source than the 1971 film, and for the better. August's script often transposes Dahl's dialogue word for word from page to screen, where it shimmers wryly. And while Wonka's new psychological demons would drag the proceedings down in the hands of other filmmakers, Burton keeps things inventively and garishly delightful for the most part. The movie's overlong and there are lumps in the batter, but this is a ''Charlie" that the author would recognize as upholding his playfully dyspeptic tradition.
It also has in Freddie Highmore (''Finding Neverland") a Charlie Bucket so gentle and kindhearted that you're immediately won over. The early scenes are remarkably assured, with Charlie, his loving if hapless parents (Helena Bonham Carter and Noah Taylor), and his bedridden grandparents (four grandparents, one bed) all jammed into a squalid, trapezoidal shack a few blocks from the chocolate factory. In quick bursts of exposition, Burton gives us Wonka's rise to fame, his retreat from the world, the frenzied global search for the Golden Tickets -- and he shows us enough of the first four winners to convince us they're horrid beasts who deserve whatever they get.
Charlie finds the fifth ticket, of course, and with his Grandpa Joe (David Kelly, the skinny walking stick from ''Waking Ned Devine") arrives at the factory gates at the appointed hour, along with the other children and their parents. And in we go.
Burton's chocolate factory is, at first, not terribly different from Stuart's. It feels setbound; you can almost hear the squeak of the Styrofoam. But it keeps opening out into wider and more epic vistas, and slowly Dahl's dark fancifulness comes to life. (How do you get whipped cream? Well, how do you think?) By the end, as Wonka and Charlie ride that great glass elevator, the movie has acquired some of the expansiveness of the recent ''Hitchhiker's Guide to the Galaxy." Willy Wonka could build a planet, too -- he'd just make it out of penuche.
Someone has to get jettisoned along the way, though, and as your kids already know, it's those nasty other children. To be honest, Tim Burton was made for this sort of enjoyable cruelty: always better at details than sustained storytelling, he gives us Augustus Gloop (Philip Wiegratz) as an unrepentant Bavarian fatty, Veruca Salt (Julia Winter) as an entitled little snot with an ascot-wearing patsy for a father (Edward Fox), Violet Beauregarde (Annasophia Robb, of the recent ''Because of Winn-Dixie") as a gum-chewing power kid who shares with her bubblehead mother (Missi Pyle) a taste for blue track suits, and Mike Teavee (Jordan Fry) as a videogame-addict know-it-all.
Depp's Wonka looks at these nightmares and politely bares his teeth; he and we are happy to see them sucked into the ductwork of their own greed, sad only that Highmore fades into the background during the proceedings (we're as surprised as Willy Wonka when Charlie's still standing at the end).
These sequences -- Violet eats a stick of gum she shouldn't and turns into an immense blueberry, Veruca insists on having one of those cute nut-shelling squirrels and finds herself stuffed down a garbage chute, and so on and so forth -- are the big set pieces of this ''Charlie and the Chocolate Factory," and the awful truth is that their cleverness becomes wearying after a while, especially when you realize each will end with a big musical number featuring the Oompa-Loompas (stone-faced actor Deep Roy, digitally multiplied 165-fold). The movie weighs a ton, as expensive Hollywood kitsch usually does, and it's to Burton and Depp's credit that it doesn't completely buckle under its own mass. (And that squirrel sequence is a keeper -- funny, scary, and brilliant.)
When ''Charlie" does lose control -- in the Mike Teavee showdown, which references old movies in amusing but self-congratulatory ways, or in the lugubrious ''emotional closure" finale that lets Wonka lay his daddy issues to rest -- it's because the director is serving his own obsessions rather than Dahl's. Depp, however, finds a middle path. His Willy Wonka occasionally references earlier roles (there's an ''Edward Scissorhands" sight gag and a shout-out to the pink angora sweaters of ''Ed Wood"), but he's mostly something new: a man-child whose well-meaning egocentricity both speaks to our times while remaining strangely true to the author's distrust of anyone over 3 feet tall.
''I don't want a grown-up person at all," Dahl had Willy Wonka tell Charlie in the book. ''A grown-up won't listen to me; he won't learn." Maybe so, but enough apparently were listening to make this ''Chocolate Factory" remarkably close to an everlasting gobstopper.
Ty Burr can be reached at tburr@globe.com.