Morphine is the principle drug derived from opium. It has ==two -OH groups==, making it ==polar== (so it is well-soluble in blood, but does not cross the blood-brain barrier easily).
Codeine is a ==semi-synthetic== drug - it is found in opium at low levels and is usually chemically prepared from morphin by ==methylation== (one -OH group is substituted with ==methyl ether==). This makes codeine less polar than morphine, so it crosses the blood-brain barrier more easily, but does not bind that well to the opioid receptor, which makes it a weaker analgesic.
Diamorphine (heroin) is produced from morphine by en ==esterification== reaction in which both -OH groups are converted into ==ethanoate (ester) groups== by reacting with ==ethanoic acid== CH3COOH or ==ethanoic anhydride== (CH3CO)2O. This significantly reduces the polarity, makinf it the fastest acting and mist active opioid (however, with a lot of side effects).
\