message: gltfpack: Unify texture embedding flows
  Instead of having two separate equivalent code path based on whether we
  got the embedded image content through data URI or buffer view, we
  extract the data into a string and then share the processing code after
  that.
diff: @@ -2769,20 +2769,30 @@ bool encodeBasisData(const std::string& data, std::string& result, bool normal_m
  void writeImage(std::string& json, std::vector<BufferView>& views, const cgltf_image& image, const ImageInfo& info, size_t index, const char* input_path, const char* output_path, const Settings& settings)
  {
  - comma(json);
  - append(json, "{");
  - if (image.uri)
  - {
  + std::string img_data;
  std::string mime_type;
  - std::string img;
  - if (parseDataUri(image.uri, mime_type, img))
  + if (image.uri && parseDataUri(image.uri, mime_type, img_data))
  + {
  + // we will re-embed img_data below
  + }
  + else if (image.buffer_view && image.buffer_view->buffer->data && image.mime_type)
  + {
  + const cgltf_buffer_view* view = image.buffer_view;
  +
  + img_data.assign(static_cast<const char*>(view->buffer->data) + view->offset, view->size);
  + mime_type = image.mime_type;
  + }
  +
  + comma(json);
  + append(json, "{");
  + if (!img_data.empty())
  {
  if (settings.texture_basis)
  {
  std::string encoded;
  - if (encodeBasisData(img, encoded, info.normal_map, output_path))
  + if (encodeBasisData(img_data, encoded, info.normal_map, output_path))
  {
  writeEmbeddedImage(json, views, encoded.c_str(), encoded.size(), "image/basis");
  }
  @@ -2793,10 +2803,12 @@ void writeImage(std::string& json, std::vector<BufferView>& views, const cgltf_i
  }
  else
  {
  - writeEmbeddedImage(json, views, img.c_str(), img.size(), mime_type.c_str());
  + writeEmbeddedImage(json, views, img_data.c_str(), img_data.size(), mime_type.c_str());
  }
  }
  - else if (settings.texture_basis)
  + else if (image.uri)
  + {
  + if (settings.texture_basis)
  {
  std::string full_path = getFullPath(image.uri, input_path);
  std::string basis_path = getFileName(image.uri) + ".basis";
  @@ -2849,29 +2861,6 @@ void writeImage(std::string& json, std::vector<BufferView>& views, const cgltf_i
  append(json, "\"");
  }
  }
  - else if (image.buffer_view && image.buffer_view->buffer->data && image.mime_type)
  - {
  - const cgltf_buffer_view* view = image.buffer_view;
  - std::string img(static_cast<const char*>(view->buffer->data) + view->offset, view->size);
  -
  - if (settings.texture_basis)
  - {
  - std::string encoded;
  -
  - if (encodeBasisData(img, encoded, info.normal_map, output_path))
  - {
  - writeEmbeddedImage(json, views, encoded.c_str(), encoded.size(), "image/basis");
  - }
  - else
  - {
  - fprintf(stderr, "Warning: unable to encode image %d with Basis, skipping\n", int(index));
  - }
  - }
  - else
  - {
  - writeEmbeddedImage(json, views, img.c_str(), img.size(), image.mime_type);
  - }
  - }
  else
  {
  fprintf(stderr, "Warning: ignoring image %d since it has no URI and no valid buffer data\n", int(index));
  