| 6821 | } |
| 6822 | |
| 6823 | void WriteChannelInfo(std::vector<unsigned char> &data, |
| 6824 | const std::vector<ChannelInfo> &channels) { |
| 6825 | |
| 6826 | size_t sz = 0; |
| 6827 | |
| 6828 | // Calculate total size. |
| 6829 | for (int c = 0; c < channels.size(); c++) { |
| 6830 | sz += strlen(channels[c].name.c_str()) + 1; // +1 for \0 |
| 6831 | sz += 16; // 4 * int |
| 6832 | } |
| 6833 | data.resize(sz + 1); |
| 6834 | |
| 6835 | unsigned char *p = &data.at(0); |
| 6836 | |
| 6837 | for (int c = 0; c < channels.size(); c++) { |
| 6838 | memcpy(p, channels[c].name.c_str(), strlen(channels[c].name.c_str())); |
| 6839 | p += strlen(channels[c].name.c_str()); |
| 6840 | (*p) = '\0'; |
| 6841 | p++; |
| 6842 | |
| 6843 | int pixelType = channels[c].pixelType; |
| 6844 | int xSampling = channels[c].xSampling; |
| 6845 | int ySampling = channels[c].ySampling; |
| 6846 | if (IsBigEndian()) { |
| 6847 | swap4(reinterpret_cast<unsigned int*>(&pixelType)); |
| 6848 | swap4(reinterpret_cast<unsigned int*>(&xSampling)); |
| 6849 | swap4(reinterpret_cast<unsigned int*>(&ySampling)); |
| 6850 | } |
| 6851 | |
| 6852 | memcpy(p, &pixelType, sizeof(int)); |
| 6853 | p += sizeof(int); |
| 6854 | |
| 6855 | (*p) = channels[c].pLinear; |
| 6856 | p += 4; |
| 6857 | |
| 6858 | memcpy(p, &xSampling, sizeof(int)); |
| 6859 | p += sizeof(int); |
| 6860 | |
| 6861 | memcpy(p, &ySampling, sizeof(int)); |
| 6862 | p += sizeof(int); |
| 6863 | } |
| 6864 | |
| 6865 | (*p) = '\0'; |
| 6866 | } |
| 6867 | |
| 6868 | void CompressZip(unsigned char *dst, unsigned long long &compressedSize, |
| 6869 | const unsigned char *src, unsigned long srcSize) { |
no test coverage detected