void RasterRenderer::GenerateUnshadedImage(bool is_terrain, unsigned height_scale) { const int min_height = is_terrain ? min(1000, (int)height_matrix.get_minimum()) : 0; const int height_factor = is_terrain ? max(2000, (int)height_matrix.get_maximum()) - min_height : 0; const short *src = height_matrix.GetData(); const BGRColor *oColorBuf = color_table + 64 * 256; BGRColor *dest = image->GetTopRow(); for (unsigned y = height_matrix.get_height(); y > 0; --y) { BGRColor *p = dest; dest = image->GetNextRow(dest); for (unsigned x = height_matrix.get_width(); x > 0; --x) { short h = *src++; if (gcc_likely(!RasterBuffer::is_special(h))) { h = height_factor > 0 ? (h - min_height) * 254 / height_factor : min(254, h >> height_scale); *p++ = oColorBuf[h]; } else if (!RasterBuffer::is_water(h)) { // we're in the water, so look up the color for water *p++ = oColorBuf[255]; } else { /* outside the terrain file bounds: white background */ *p++ = BGRColor(0xff, 0xff, 0xff); } }
bool TCPClientPort::OnSocketEvent(SocketDescriptor _socket, unsigned mask) { if (gcc_likely(!connecting.IsDefined())) /* connection already established: let SocketPort handle reading from the connection */ return SocketPort::OnSocketEvent(_socket, mask); /* connection ready: check connect error */ assert(_socket == connecting); io_thread->Remove(connecting.ToFileDescriptor()); int s_err = 0; socklen_t s_err_size = sizeof(s_err); if (getsockopt(connecting.Get(), SOL_SOCKET, SO_ERROR, &s_err, &s_err_size) < 0) s_err = errno; if (s_err == 0) { /* connection has been established successfully */ Set(std::move(connecting)); connecting.SetUndefined(); } else { /* there was a problem */ connecting.Close(); StateChanged(); } return true; }
void RasterRenderer::GenerateUnshadedImage(unsigned height_scale) { const short *src = height_matrix.GetData(); const BGRColor *oColorBuf = color_table + 64 * 256; BGRColor *dest = image->GetTopRow(); for (unsigned y = height_matrix.GetHeight(); y > 0; --y) { BGRColor *p = dest; dest = image->GetNextRow(dest); for (unsigned x = height_matrix.GetWidth(); x > 0; --x) { short h = *src++; if (gcc_likely(!RasterBuffer::IsSpecial(h))) { if (h < 0) h = 0; h = min(254, h >> height_scale); *p++ = oColorBuf[h]; } else if (RasterBuffer::IsWater(h)) { // we're in the water, so look up the color for water *p++ = oColorBuf[255]; } else { /* outside the terrain file bounds: white background */ *p++ = BGRColor(0xff, 0xff, 0xff); } } }
void RasterRenderer::GenerateUnshadedImage(unsigned height_scale, const unsigned contour_height_scale) { const short *src = height_matrix.GetData(); const BGRColor *oColorBuf = color_table + 64 * 256; BGRColor *dest = image->GetTopRow(); for (unsigned y = height_matrix.GetHeight(); y > 0; --y) { BGRColor *p = dest; dest = image->GetNextRow(dest); unsigned contour_row_base = ContourInterval(*src, contour_height_scale); unsigned char *contour_this_column_base = contour_column_base; for (unsigned x = height_matrix.GetWidth(); x > 0; --x) { int h = *src++; if (gcc_likely(!RasterBuffer::IsSpecial(h))) { if (h < 0) h = 0; const unsigned contour_interval = ContourInterval(h, contour_height_scale); h = std::min(254, h >> height_scale); if (gcc_unlikely((contour_interval != contour_row_base) || (contour_interval != *contour_this_column_base))) { *p++ = oColorBuf[h-64*256]; *contour_this_column_base = contour_row_base = contour_interval; } else { *p++ = oColorBuf[h]; } } else if (RasterBuffer::IsWater(h)) { // we're in the water, so look up the color for water *p++ = oColorBuf[255]; } else { /* outside the terrain file bounds: white background */ *p++ = BGRColor(0xff, 0xff, 0xff); } contour_this_column_base++; } }