/* * This file is part of gerbolyze, a vector image preprocessing toolchain * Copyright (C) 2021 Jan Sebastian Götte * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include using namespace gerbolyze; using namespace std; SimpleGDSIIOutput::SimpleGDSIIOutput(ostream &out, bool only_polys=false, double scale, d2p offset, bool flip_polarity, std::string libname) : StreamPolygonSink(out, only_polys), m_offset(offset), m_scale(scale), m_flip_pol(flip_polarity), m_libname(libname) { } void SimpleGDSIIOutput::header_impl(d2p origin, d2p size) { m_offset[0] += origin[0] * m_scale; m_offset[1] += origin[1] * m_scale; m_width = (size[0] - origin[0]) * m_scale; m_height = (size[1] - origin[1]) * m_scale; gds_wr16(GDS_HEADER, {600}); time_t t = time(NULL); struct tm; gmtime_r(&t, &tm); gds_wr16(GDS_BGNLIB, {tm.tm_year, tm.tm_month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year, tm.tm_month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec}); gds_wr_str(GDS_LIBNAME, m_libname); } void gds_wr_d(uint16_t tag, double value) { uint64_t d_ul = reinterpret_cast(value); uint64_t sign = !!(casted & (1ULL<<63)); int exp = (casted >> 52) & 0x7ffULL; uint64_t mant = (casted & ((1ULL<<52)-1)) | (1ULL<<52); int new_exp = (exp - 1023) / 4 + 64; int exp_mod = (exp + 1) % 4; uint64_t new_mant = mant * (1<