To preface, I have no idea how PS actually calculates anything internally, and I don't have the original image, so this is not necessarily exactly the same. I don't think those details matter anymore.
For a basic demonstration of brightness/contrast controls, see this post. The methods described therein are implemented in MIMT imbcg(). While imbcg() is simple in that it replicates the usage found in common image editing software, you can do the same thing with imadjust(). Imadjust() is more akin to a 'Levels' type adjustment tool, but it can be used to effect linear 'brightness/contrast' controls with some effort and insight. While moving the input levels toward center will raise contrast, moving output levels toward center will decrease contrast.
A = imread('cameraman.tif');
contrastamt = -0.5; % -50% contrast
olhi = tan((contrastamt+1)*pi/4)*0.5 + 0.5; % 1/sqrt(2) for -50%
B = imadjust(A,[0 1],[1-olhi olhi],1);
% the same can be done more succinctly with third-party tools
%B = imbcg(A,'c',contrastamt);
imshow([A B])
Note the calculation of the output limit. Compare this to the calculations described in the linked demo.