This paper presents a pixel-by-pixel spatial prediction method for lossless intra coding within High Efficiency Video Coding (HEVC). Previous pixel-by-pixel spatial prediction methods use only two neighboring pixels for prediction, based on the angular projection idea borrowed from block-based intra prediction in lossy coding, or are based on ad hoc methods applied in some intra modes. This paper explores a pixel-by-pixel prediction method which uses three neighboring pixels for prediction according to a two-dimensional correlation model, and develops a unified prediction algorithm applied in all intra modes with optimized prediction weights and neighbors. The prediction weights for each intra mode are determined from a two-stage offline optimization algorithm and a number of aspects are analyzed to determine a good trade-off between complexity and coding gain. The method is implemented in the HEVC reference software and experimental results show that it can achieve an average 1134% bitrate reduction over the default lossless intra coding in HEVC, which is among the best reported results. The method decreases average decoding time by 12.7% while increasing average encoding time by 9.7%. (C) 2016 Elsevier B.V. All rights reserved.