Each country has linear demand and supply:
$D_i(P)=a_i-b_i\,P$
$S_i(P)=\max(0,\,-c_i+d_i\,P)$
Autarky: $P_i^A=(a_i+c_i)/(b_i+d_i)$. World price clears $X_1=M_2$.
Each country has its own demand curve $D_i(P)=a_i-b_i P$ and supply curve $S_i(P)=\max(0,\,-c_i+d_i P)$. In autarky, each market clears at its own price $P_i^A$ where $D_i=S_i$.
The middle panel constructs the world market by horizontally summing Country 1's excess supply $ES_1(P)=S_1(P)-D_1(P)$ for prices above $P_1^A$ and Country 2's excess demand $ED_2(P)=D_2(P)-S_2(P)$ for prices below $P_2^A$. They intersect at the world price $P^W$, which clears global trade: $X_1=M_2$.
The horizontal dashed line at $P^W$ is the bridge across all three panels — it's the same price everywhere under free trade. At that price, Country 1 produces more than it consumes (the gap is exports) and Country 2 consumes more than it produces (the gap is imports). The country with the lower autarky price has the comparative advantage and becomes the exporter.