added new error code for file write and fixed byte order in tga saving