xmubingo / webp

Automatically exported from code.google.com/p/webp
0 stars 0 forks source link

api to write to/read from container #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What is the expected output? 
an api

Currently, people have to do bit manipulation

Original issue reported on code.google.com by rab...@google.com on 10 Oct 2010 at 3:13

GoogleCodeExporter commented 9 years ago
An API similar to jpeg or tiff libraries would be nice.  Also simple tools.
There likely exists some riff tools and libraries already.

Original comment by fbarch...@chromium.org on 11 Nov 2010 at 6:12

GoogleCodeExporter commented 9 years ago
Frank,

jpeg is container-agnostic. TIFF is field-based.

I've got something in the making, whose API would be like:

======== BEGIN ================================================

typedef struct WebPRIFF WebPRIFF;   // main opaque object.

// Error codes
typedef enum { WEBP_RIFF_OK = 1,
               WEBP_RIFF_ERROR = 0,
               WEBP_RIFF_NOT_FOUND = -1,
               WEBP_RIFF_INVALID_ARGUMENT = -2,
               WEBP_RIFF_INVALID_PARAMETER = -3
             } WebPRiffError;

//-----------------------------------------------------------------------------
// Life of a RIFF object

WebPRIFF* WebPRIFFNew();                 // create object
void WebPDelete(WebPRIFF* const riff);   // release memory

//-----------------------------------------------------------------------------
// Writing

// Main call for adding information to the container.
// "What" can be one of:
//   "image" (raw bytes): the raw VP8 compressed bits. Mandatory.
//   "comment" (stringz): comment, can be added several times
//   "author" (stringz): describes the author. Only one allowed.
//   "copyright" (stringz): copyright information. Only one allowed.
//   "title" (stringz): title of the image. Only one such allowed.
//   "metadata" (raw bytes): unstructured metadata blob. Can be repeated.
//   "icc" (raw bytes): unstructured ICC profile. Only one such allowed.
// (TODO: list non-exhaustive).
// The associated data is pointed to using 'data' pointer and 'size' 
information.
// If 'copy_data' is true, the source data will be copied and owned by the RIFF
// object. Otherwise, ownership is left to the caller along with the
// responsability of making sure the data lifespan is longer than that of the
// RIFF object (at least until WebPRIFFAssemble() is called).
WebPRiffError WebPRIFFAdd(WebPRIFF* const riff,
                          const char* const what,
                          const uint8_t* data, uint32_t size,
                          int copy_data);

// Sugar-on-top'ed version of WebPRIFFAdd(), for literal data like comments,
// copyright, artist, etc..
inline WebPRiffError WebPRIFFAddString(WebPRIFF* const riff,
      const char* const what, const char* data, int copy_data) {
  return data ? WebPRIFFAdd(riff, what, data, strlen(data) + 1, copy_data);
              : WEBP_RIFF_INVALID_ARGUMENT;
}

// Final assembly: will collect all the data chunks into a final WebP file.
// The result is stored in the *output_data and *output_size. This data is
// still owned by the RIFF object and will be deleted by calling
// WebPRIFFDelete() (or by calling WebPRIFFAssemble() again).
WebPRiffError WebPRIFFAssemble(WebPRIFF* const riff,
                               uint8_t** output_data, uint32_t* output_size);

//-----------------------------------------------------------------------------
// Reading

// This function will parse the supplied 'data' (with length 'size') and
// the chunks information, making them ready for retrieval through calls
// to WebPRIFFGetString() and WebPRIFFGetData(). The object is not frozen
// and can be subsequently edited by calls to WebPRIFFAdd().
// If copy_data is true, the input data will be copied into the object.
// Otherwise, the supplied data is only referenced and must be made available
// at all time to the RIFF object.
WebPRiffError WebPRIFFAnalyze(WebPRIFF* const riff,
                              const uint8_t* data, uint32_t size,
                              int copy_data);

// Retrieve raw data associated with a chunk name (see list of the
// possible 'what' strings in WebPRIFFAdd() description above).
// The location of the data (which must not be modified) is placed into
// 'data' and 'data_size' pointers. This data is only guarantied to remain
// valid until the next call to WebPRIFFAdd().
WebPRiffError WebPRIFFGetData(WebPRIFF* const riff, const char* const what,
                              const uint8_t** data, uint32_t* data_size);

// Retrieves a string-typed information. See WebPRIFFAdd() for a description
// of the possible strings for 'what' parameter. Is just a sugar version of
// WebPRIFFGetData() above, specifically for string-typed data chunks.
const char* WebPRIFFGetString(WebPRIFF* const riff, const char* const what);

======== END ================================================

I think it covers most practical use-cases.

Comments most welcome!

Original comment by s...@google.com on 11 Nov 2010 at 7:01

GoogleCodeExporter commented 9 years ago
How would you deal with multiple chunks with the same name?
If dealing with a very large file, it would be nice if you could iterate thru 
chunks, and potentially not have them all in memory.
An example that shows how to use the API would be good.  ie how do I printf the 
first comment?

Original comment by fbarch...@google.com on 24 Nov 2010 at 10:41

GoogleCodeExporter commented 9 years ago
WebpMux has been release and in current in flux...

Original comment by pascal.m...@gmail.com on 29 Nov 2011 at 3:51

GoogleCodeExporter commented 9 years ago
libwebpmux is stable and available as part of the libwebp-0.3.0 release.

https://groups.google.com/a/webmproject.org/d/msg/webp-discuss/WF84vomYtos/AP3jD
RRKeqYJ

Original comment by jz...@google.com on 3 Apr 2013 at 6:58