computing first and last pixel relative to the threadId