(CNN) -- You could call "The Ghost Writer" the Polanski film that almost wasn't.
Under the circumstances, it's a miracle that Roman Polanski's political thriller, which stars Pierce Brosnan and Ewan McGregor, even made it to the screen.
After the filmmaker was arrested in Switzerland last year -- while "The Ghost Writer" was in post production -- there was talk that another director might have to finish the feature.
That didn't happen -- but Polanski did end up editing the feature from his jail cell, according to the movie's stars.
"He would be in his nine-foot by four-foot cell, edit the movie and give it to the warden. The warden would give it to his lawyer [who would] then give it to the editor," Brosnan told CNN.
"I think he had no other option," adds McGregor of Polanski's efforts to complete the film.
Polanski was arrested in September for an outstanding U.S. arrest warrant dating back to 1978. In 1977 he pleaded to guilty to a single count of having unlawful sexual intercourse with a minor, acknowledging he had sex with a 13-year-old girl in California. He fled the United States before sentencing.
Polanski, who is fighting extradition, is under house arrest in Switzerland and was unable to attend the premiere at Berlin.
Based on Robert Harris's bestselling novel "The Ghost," the feature is about a writer (McGregor) hired to pen the memoirs of Adam Lang (Brosnan), a disgraced British former prime minister accused of war crimes.
McGregor told CNN about his alarm shortly after Polanski's arrest at talk that another director might be brought in to finish post production.
"I was very worried about that," he said. "I thought it would be a great pity for him not to be able to finish it because he's such a perfectionist, and he's such a passionate filmmaker.
"And personally speaking, selfishly, I thought the same. I thought it would be a great pity to be in the only Polanski film that wasn't finished by Polanski."
The movie, which is in the running for the Golden Bear, the top award at Berlin, couldn't be more timely.
Brosnan's character bears an uncanny resemblance to Tony Blair, the former British prime minister who faced a grilling at a public inquiry earlier this year over his controversial decision to send UK troops to Iraq in 2003.
"He [Harris] wrote the book over three years ago," said McGregor, "and we made the film a year ago and still, in the last month or two, so many things have come to light with Blair having to answer for his decision-making to take the UK into the war.
"Reality gets a little closer to our movie every day it would seem."
Brosnan may seem to be channeling pure Blair, but he is definitely not playing the former prime minister, he said.
"When I met Mr Polanski, I said, 'All broad indications seem to point to one man and one man only and that's Tony Blair.' And he said, 'No, no. You're not playing Tony Blair.'"
Nevertheless, Brosnan admits he did use Blair as a source of inspiration.
"I tipped my hat to the man," he told CNN. "All the ingredients and emblems around the story are very much of the time of Tony Blair's time as prime minister.
"So I looked at Tony Blair's work and his performance as prime minister and worked according to that."
Brosnan also recounted how he found out about Polanski's arrest.
"I had done my looping on the film, like, three days before and spoken to Mr Polanski and he was very ebullient and ready to finish the film and then came his arrest."
Polanski was arrested in September on his way from France, where he has lived for decades, to the Zurich Film Festival, where he was to collect an award for lifetime achievement.
Polanski's storied career has included "Rosemary's Baby" and "Chinatown." In 2003 he won a best director Oscar for "The Pianist," collected on his behalf by Harrison Ford (Polanski has not returned to the United States since he fled.)
But his approach to work has still to lose any of its intensity. McGregor recalls how the first day of shooting on "The Ghost Writer" lasted 22 hours and how Polanski, who he described as "quite a taskmaster," had "more energy than all of us combined."
Brosnan adds that Polanski was very intense and passionate about each day's work.
"Every day was like 'day one' with him ... Everybody's alert, everybody wants to do their best for him. You are in the house of Polanski, you're in his domain," he said.
While the film has earned glowing reviews, Polanski, ever the perfectionist, isn't completely satisfied, Brosnan says, and is "still frustrated" about a sound effect at the beginning of the film.
The former James Bond says that he was very aware of it while watching "The Ghost Writer" at Berlin because Polanski told him about the precise effect he wanted.
"I thought ... he's absolutely right, if only they had done that one sound effect," Brosnan said.