Writing an Emboss filter turned out to be easier than I thought. The principle is that a pixel in the image is replaced either by a highlight or a shadow, depending if the boundaries in the picture are light or dark.
If the contrast is low, then it becomes gray.
Here is the code for an emboss filter in Realbasic.
Function Emboss(tmpPic as picture) As picture dim width as integer = tmpPic.Width dim height as integer = tmpPic.Height dim srcSurf as RGBSurface = tmpPic.RGBSurface Dim dst as Picture dst = NewPicture(width, height, 32) dim dstSurf as RGBSurface = dst.RGBSurface dim i, j as integer dim upperLeft, LowerRight as Color dim redDiff, greenDiff, blueDiff, Diff as integer dim grayColor as integer dim newColor as Color for i = 0 to height - 1 for j = 0 to width - 1 if i > 0 and j > 0 then upperLeft = srcSurf.Pixel(j-1,i-1) end if if i < height - 2 and j < width - 2 then LowerRight = srcSurf.Pixel(j+1,i+1) end if redDiff = bitwise.bitAnd(LowerRight.Red, 255) - bitwise.bitAnd(upperLeft.Red, 255) redDiff = bitwise.bitAnd(LowerRight.Green, 255) - bitwise.bitAnd(upperLeft.Green, 255) blueDiff = bitwise.bitAnd(lowerRight.Blue, 255) - bitwise.bitAnd(upperLeft.Blue, 255) diff = redDiff if (abs(greenDiff) > abs(diff)) then diff = greenDiff end if if (abs(blueDiff) > abs(diff)) then diff = blueDiff end if grayColor = 128 + diff if (grayColor > 255) then grayColor = 255 elseif (grayColor < 0) then grayColor = 0 end if newColor = RGB(grayColor, grayColor, grayColor) dstSurf.Pixel(j, i) = newColor next next Return dst End Function