RenderMan API  23.0
dtex.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 1986-2019 Pixar. All rights reserved.
5 #
6 # The information in this file (the "Software") is provided for the exclusive
7 # use of the software licensees of Pixar ("Licensees"). Licensees have the
8 # right to incorporate the Software into other products for use by other
9 # authorized software licensees of Pixar, without fee. Except as expressly
10 # permitted herein, the Software may not be disclosed to third parties, copied
11 # or duplicated in any form, in whole or in part, without the prior written
12 # permission of Pixar.
13 #
14 # The copyright notices in the Software and this entire statement, including the
15 # above license grant, this restriction and the following disclaimer, must be
16 # included in all copies of the Software, in whole or in part, and all permitted
17 # derivative works of the Software, unless such copies or derivative works are
18 # solely in the form of machine-executable object code generated by a source
19 # language processor.
20 #
21 # PIXAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL PIXAR BE
23 # LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
25 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. IN NO CASE WILL
27 # PIXAR'S TOTAL LIABILITY FOR ALL DAMAGES ARISING OUT OF OR IN CONNECTION WITH
28 # THE USE OR PERFORMANCE OF THIS SOFTWARE EXCEED $50.
29 #
30 # Pixar
31 # 1200 Park Ave
32 # Emeryville CA 94608
33 #
34 # ------------------------------------------------------------------------------
35 */
36 
37 
38 #ifndef DTEX_H
39 #define DTEX_H
40 
41 /*
42  ******
43  NOTICE: The dtex API is now deprecated and will be removed
44  in a future release
45  ******
46 
47  *
48  * libdtex
49  *
50  * This library provides the structures and functions necessary to create,
51  * load, and modify deep texture map files. It maintains a tile cache
52  * under the covers, making it possible to work on files without loading
53  * them entirely into memory.
54  *
55  * The API supports an arbitrary number of images in a single file, each
56  * with its own resolution, tile size, and view matrices.
57  *
58  * The library can read and write old deep shadow files in addition to
59  * newer, more general deep texture files. Deep shadow files are
60  * limited to a single sub-image, but otherwise have the same API as the
61  * newer interface.
62  */
63 
64 
65 #include "prmanapi.h" // for PRMANAPI, uint64_t
66 
67 /* The following struct types aren't exported; users may only
68  access members through the API calls defined below. */
69 
70 typedef struct DtexFile DtexFile;
71 typedef struct DtexImage DtexImage;
72 typedef struct DtexMetadata DtexMetadata;
73 typedef struct DtexPixel DtexPixel;
74 typedef struct DtexCache DtexCache;
76 
77 /* DtexCreate and DtexOpen let the user specify their
78  own file access functions, in case read() and write() aren't
79  good enough. Following are the types for these functions: */
80 
81 typedef void *(*DtexCreateFunc)(const char *name);
82 typedef void *(*DtexOpenFunc)(const char *name, const char *mode);
83 typedef long (*DtexReadFunc)(void *handle, char *data, long seek, long size);
84 typedef long (*DtexWriteFunc)(void *handle, char *data, long seek, long size);
85 typedef void (*DtexCloseFunc)(void *handle);
86 
87 /* DtexAccessor encapsulates the various file access functions. A
88  pointer to one of these can be passed to DtexCreate() or
89  DtexOpen() if nonstandard file access methods are needed. */
90 
91 typedef struct DtexAccessor
92 {
93  DtexCreateFunc createFunc; /* function to create a file */
94  DtexOpenFunc openFunc; /* function to open a file */
95  DtexReadFunc readFunc; /* function to read from a file handle */
96  DtexWriteFunc writeFunc; /* function to write to a file handle */
97  DtexCloseFunc closeFunc; /* function to close a file handle */
98 } DtexAccessor;
99 
100 /* The following types are similiar, but add support for large 2GB+ files
101  * with 64 bit offsets. */
102 
103 typedef long (*DtexLargeReadFunc)(void *handle, char *data, uint64_t seek, long size);
104 typedef long (*DtexLargeWriteFunc)(void *handle, char *data, uint64_t seek, long size);
105 
106 typedef struct DtexLargeAccessor
107 {
108  DtexLargeReadFunc readFunc; /* function to read from a file handle */
109  DtexLargeWriteFunc writeFunc; /* function to write to a file handle */
111 
112 /* Tile compression type. */
113 typedef enum DtexCompression
114 {
120 } DtexCompression;
121 
122 /* Type of data stored with each pixel. (Note that the depth is always
123  stored as a float. */
124 typedef enum DtexDataType
125 {
131 } DtexDataType;
132 
133 /* Error codes: */
134 
135 enum{
136  DTEX_NOMETADATA = -14, /* Metadata entry was not found or was invalid */
137  DTEX_BADCHANNEL = -13, /* Channel mismatch between pixels or tiles */
138  DTEX_READONLY = -12, /* Attempt to modify file loaded as read only */
139  DTEX_CAPACITY = -11, /* Tried to go past 2GB on a small capacity file */
140  DTEX_TILECOMPRESSION = -10, /* Something happened during tile compression */
141  DTEX_UNFINISHED = -9, /* Illegal operation on pixel with unresolved
142  compression state */
143  DTEX_RANGE = -8, /* Out of range parameter */
144  DTEX_NOMEM = -7, /* Ran out of memory */
145  DTEX_EMPTY = -6, /* Illegal operation on an empty structure */
146  DTEX_NOIMAGE = -5, /* The specified image was not found */
147  DTEX_UNSUPPORTED = -4, /* The specified operation is not supported. */
148  DTEX_BADFILE = -3, /* File was corrupt */
149  DTEX_NOFILE = -2, /* File was not found or was invalid */
150  DTEX_ERR = -1, /* File was not found or was invalid */
151  DTEX_NOERR = 0 /* No worries */
152 };
153 
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157 
158 /*
159  *********************************************************************
160  * CACHE FUNCTIONS:
161  *********************************************************************
162  *
163  * The following functions are used to maintain deep texture tile
164  * caches.
165  */
166 
167 /* ----------------------------------------------------------------- */
168 
169 PRMANAPI extern DtexCache * DtexCreateCache(int numTiles,
170  DtexAccessor *accessor);
171 /*
172  * create a new tile cache. accessor specifies a set of I/O functions
173  * to use upon faults. If accessor is NULL, standard system calls
174  * are used.
175  */
176 
177 /* ----------------------------------------------------------------- */
178 
180  int numTilesPerThread, DtexAccessor *accessor,
181  DtexLargeAccessor *largeAccessor);
182 /*
183  * Create a new tile cache that is safe for read-only use in a
184  * multithreaded environment. Accessor specifies a set of I/O functions to
185  * use upon faults. LargeAccessor provides 64-bit offset versions. If
186  * either is NULL, standard system call are used.
187  */
188 
189 /* ----------------------------------------------------------------- */
190 
192  DtexLargeAccessor *accessor);
193 
194 /*
195  * Specify a set of I/O functions to use upon faults when dealing with
196  * large capacity files. If not called, default implementations using
197  * standard system calls are used.
198  */
199 
200 /* ----------------------------------------------------------------- */
201 
202 PRMANAPI extern int DtexDestroyCache(DtexCache *c);
203 
204 /* ----------------------------------------------------------------- */
205 
206 PRMANAPI extern int DtexSyncCache(DtexCache *dsc);
207 
208 /*
209  * write out all modified tiles of all files in the cache, causing the
210  * files on disk to reflect any changes that have been made.
211  */
212 
213 /* ----------------------------------------------------------------- */
214 
215 /*
216  *********************************************************************
217  * FILE OPENING/CLOSING FUNCTIONS:
218  *********************************************************************
219  *
220  * The following functions are used to create new deep texture files,
221  * or to open existing deep texture files.
222  */
223 
224 /* ----------------------------------------------------------------- */
225 
226 PRMANAPI extern int DtexIsDeepFile(const char *name,
227  DtexCache *cache,
228  int *version);
229 /*
230  * Attempt to open a file with the given filename, and check whether it
231  * appears to be a deep texture file. Returns DTEX_NOERR and sets version
232  * to the file format version if the file is a deep texture file.
233  */
234 
235 /* ----------------------------------------------------------------- */
236 
237 PRMANAPI extern int DtexOpenFile(const char *name,
238  const char *mode,
239  DtexCache *cache,
240  DtexFile **result);
241 /*
242  * Open a deep texture file with the given filename, managed by the
243  * given cache.
244  */
245 
246 /* ----------------------------------------------------------------- */
247 
248 PRMANAPI extern int DtexCreateFile(const char *name,
249  DtexCache *cache,
250  DtexFile **result);
251 
252 /*
253  * Open a deep texture file with the given filename, managed by the
254  * given cache.
255  */
256 
257 /* ----------------------------------------------------------------- */
258 
259 #define DTEX_CREATE_FILE_PARAMS_VERSION 1
260 
261 typedef struct {
262  int version; // DTEX_CREATE_FILE_PARAMS_VERSION
265 
266 PRMANAPI extern int DtexCreateFileEx(const char *name,
267  DtexCache *cache,
268  DtexFile **result,
269  DtexCreateFileParams *params);
270 
271 /*
272  * Open a deep texture file with the given filename, managed by the
273  * given cache. Force new format
274  */
275 
276 /* ----------------------------------------------------------------- */
277 
278 PRMANAPI extern int DtexFileVersion(DtexFile *f);
279 /*
280  * return the format version of the given file.
281  */
282 
283 /* ----------------------------------------------------------------- */
284 
285 PRMANAPI extern int DtexGetFileMetadata(DtexFile *f, DtexMetadata **result);
286 /*
287  * return a handle to the file-wide metadata.
288  */
289 
290 /* ----------------------------------------------------------------- */
291 
292 PRMANAPI extern int DtexAddImage(DtexFile *f,
293  const char *name,
294  int numChan,
295  int w, int h,
296  int tw, int th, /* tile width and height */
297  float *NP,
298  float *Nl,
299  enum DtexCompression compression,
300  enum DtexDataType datatype,
301  DtexImage **result);
302 /*
303  * Add an image to the given file.
304  */
305 
306 /* ----------------------------------------------------------------- */
307 
308 #define DTEX_DEEPOPACITY_VERSION 1
309 #define DTEX_AREASHADOW_VERSION 1
310 #define DTEX_DEEPCOMP_VERSION 1
311 
312 #define DTEX_ADD_IMAGE_PARAMS_VERSION 1
313 
314 typedef struct {
315  int version; // DTEX_ADD_IMAGE_PARAMS_VERSION
316  char const *formatType; // "deepopacity", "areashadow", or "deepcomp"
317  int formatVersion; // DTEX_DEEPOPACITY_VERSION, etc.
319 
320 PRMANAPI extern int DtexAddImageEx(DtexFile *f,
321  const char *name,
322  int numChan,
323  int w, int h,
324  int tw, int th, /* tile width and height */
325  float *NP,
326  float *Nl,
327  enum DtexCompression compression,
328  enum DtexDataType datatype,
329  DtexImage **result,
330  DtexAddImageParams *params);
331 /*
332  * Add an image to the given file. May take additional parameters such as
333  * formatType and formatVersion.
334  */
335 
336 /* ----------------------------------------------------------------- */
337 
338 PRMANAPI extern int DtexCountImages(DtexFile *f);
339 
340 /*
341  * Return the number of images in the given file.
342  */
343 
344 /* ----------------------------------------------------------------- */
345 
346 /*
347  * If the given file contains an image with the given name, return a
348  * pointer to it. Returns DTEX_NOIMAGE if the given image doesn't exist.
349  * The resulting pointer is guaranteed to be valid until DtexClose() is
350  * called on the containing
351  * file.
352  */
353 
354 PRMANAPI extern int DtexGetImageByName(DtexFile *f,
355  const char *name,
356  DtexImage **result);
357 
358 /* ----------------------------------------------------------------- */
359 
360 /*
361  * Return the nth image from the given file. Returns DTEX_NOFILE
362  * if the file doesn't exist, or DTEX_NOIMAGE if the given image doesn't
363  * exist. The resulting pointer is guaranteed to be valid until
364  * DtexClose() is called on the containing file.
365  */
366 
368  int index,
369  DtexImage **result);
370 
371 /* ----------------------------------------------------------------- */
372 
373 PRMANAPI extern int DtexClose(DtexFile *ds);
374 /*
375  * close a deep texture file, writing out all modified tiles.
376  */
377 
378 /* ----------------------------------------------------------------- */
379 
380 PRMANAPI extern int DtexSync(DtexFile *ds);
381 
382 /*
383  * write out all modified tiles of deep texture "ds", causing the
384  * file on disk to reflect any changes that have been made.
385  */
386 
387 /* ----------------------------------------------------------------- */
388 
389 /*
390  *********************************************************************
391  * FILE ACCESS FUNCTIONS:
392  *********************************************************************
393  *
394  * The following functions let the user access and modify the
395  * contents of an open deep texture file.
396  */
397 
398 /* ----------------------------------------------------------------- */
399 
400 PRMANAPI extern int DtexWidth(DtexImage *i);
401 /*
402  * return the width of the given image in pixels
403  */
404 
405 /* ----------------------------------------------------------------- */
406 
407 PRMANAPI extern char *DtexImageName(DtexImage *i);
408 /*
409  * return the name of the given image. The resulting pointer is
410  * guaranteed to be valid until DtexClose() is called on the containing
411  * file.
412  */
413 
414 /* ----------------------------------------------------------------- */
415 
416 PRMANAPI extern int DtexNumChan(DtexImage *i);
417 /*
418  * return the number of channels in the given image
419  */
420 
421 /* ----------------------------------------------------------------- */
422 
423 PRMANAPI extern int DtexHeight(DtexImage *i);
424 /*
425  * return the height of the given image in pixels
426  */
427 
428 /* ----------------------------------------------------------------- */
429 
430 PRMANAPI extern int DtexTileWidth(DtexImage *i);
431 /*
432  * return the width of the tiles in the given image, in pixels
433  */
434 
435 /* ----------------------------------------------------------------- */
436 
437 PRMANAPI extern int DtexTileHeight(DtexImage *i);
438 /*
439  * return the height of the tiles in the given deep texture, in pixels
440  */
441 
442 /* ----------------------------------------------------------------- */
443 
444 PRMANAPI extern int DtexNP(DtexImage *i, float *NP);
445 /*
446  * copy the projection matrix from the given image to NP.
447  */
448 
449 /* ----------------------------------------------------------------- */
450 
451 PRMANAPI extern int DtexNl(DtexImage *i, float *Nl);
452 /*
453  * copy the light-space matrix from the given image to Nl.
454  */
455 
456 /* ----------------------------------------------------------------- */
457 
459 /*
460  * return the compression type of the image.
461  */
462 
463 /* ----------------------------------------------------------------- */
464 
466 /*
467  * return the data type of the image.
468  */
469 
470 /* ----------------------------------------------------------------- */
471 
472 PRMANAPI extern int DtexGetImageMetadata(DtexImage *i, DtexMetadata **result);
473 /*
474  * return a handle to the metadata associated with the image.
475  */
476 
477 /* ----------------------------------------------------------------- */
478 
479 PRMANAPI extern int DtexSetPixelData(DtexImage *img,
480  int x, int y,
481  int numChan,
482  int numPoints,
483  float *data);
484 /*
485  * copy the given pixel data into pixel x,y of the specified image.
486  * numChan indicates how many channels of data are being provided,
487  * and numPoints indicates how many points there are. data should
488  * point to numPoints*(numChan+1) floats.
489  */
490 
491 /* ----------------------------------------------------------------- */
492 
493 PRMANAPI extern int DtexSetPixel(DtexImage *img,
494  int x, int y,
495  DtexPixel *pix);
496 /*
497  * copy the given pixel into pixel x,y of the specified image. pix
498  * must have either the same number of channels as img, or one channel.
499  *
500  * If pix has any unresolved compression state, DTEX_ERR is returned.
501  * Call DtexFinishPixel before you use DtexSetPixel.
502  */
503 
504 /* ----------------------------------------------------------------- */
505 
506 PRMANAPI extern int DtexGetPixel(DtexImage *img,
507  int x, int y,
508  DtexPixel *pix);
509 /*
510  * copy the pixel at position x,y in "ds" into the given pixel
511  * structure. The pixel structure is resized if necessary, and if
512  * the number of channels in pix is different than the number of
513  * channels in img, pix is modified to match.
514  *
515  * Returns DTEX_NOERR if no error, DTEX_RANGE if the requested pixel
516  * is outside the image, or DTEX_BADFILE if the file is found to be
517  * corrupt.
518  */
519 
520 /* ----------------------------------------------------------------- */
521 
522 PRMANAPI extern int DtexEval(DtexImage *img,
523  int x, int y,
524  float z,
525  int n,
526  float *data);
527 /*
528  * look up the pixel's interpolated value at depth z, and put the
529  * result in data. n must indicate how many floats are
530  * allocated in data, and must be no less than the number of
531  * channels in the image.
532  */
533 
534 /* ----------------------------------------------------------------- */
535 
536 PRMANAPI extern int DtexGetZRange(DtexImage *img,
537  int x, int y,
538  float *min,
539  float *max);
540 /*
541  * computes the range over which the specified pixel is defined.
542  * if the pixel is non-empty, the range is returned in min and max
543  * and the function returns DTEX_NOERR. If the pixel is empty,
544  * DTEX_EMPTY is returned and min and max are undefined.
545  */
546 
547 /* ----------------------------------------------------------------- */
548 
549 PRMANAPI extern int DtexGetMeanDepth(DtexImage *img,
550  int x, int y,
551  float *mean,
552  float *alpha);
553 /*
554  * computes the mean depth found in the pixel and the overall
555  * coverage. This is useful for displaying deep images.
556  */
557 
558 /* ----------------------------------------------------------------- */
559 
560 /*
561  *********************************************************************
562  * METADATA STRUCTURE FUNCTIONS:
563  *********************************************************************
564  */
565 
566 /* ----------------------------------------------------------------- */
567 
568 PRMANAPI extern int DtexMetadataSet(DtexMetadata *meta,
569  char const *token,
570  void const *value);
571 /*
572  * Add or update a metadata field associated with an image or file. The
573  * token is a string specifying the type and name of the field and
574  * is given in the standard RenderMan style, e.g., ``float bbox[6]``.
575  * Supported types are: float, int, point, color, vector, normal, hpoint,
576  * matrix, and string.
577  *
578  * The associated data to write is given by the value pointer. In the
579  * case of string data, this should point to ``char *`` pointers that
580  * point to the strings themselves (i.e., argv style). If the value
581  * pointer is null, the metadata field will be removed if it exists.
582  */
583 
584 /* ----------------------------------------------------------------- */
585 
586 PRMANAPI extern int DtexMetadataCount(DtexMetadata *meta);
587 /*
588  * Return how many metadata fields the image has.
589  */
590 
591 /* ----------------------------------------------------------------- */
592 
594  int index,
595  char const **token,
596  void const **value);
597 /*
598  * The metadata fields are retrieved in no particular order.
599  * This function is simply a convenience for enumerating all attached
600  * metadata. Returns DTEX_NOMETADATA if the given field doesn't exists.
601  * The resulting pointers, stored in token and value are valid until
602  * either DtexClose() is called on the containing file, or until
603  * DtexSetMetadata() modifies this particular field. Data behind these
604  * pointers must not be changed.
605  */
606 
607 /* ----------------------------------------------------------------- */
608 
610  char const *name,
611  char const **token,
612  void const **value);
613 /*
614  * Metadata fields may also be retrieved by an unadorned name.
615  */
616 
617 /* ----------------------------------------------------------------- */
618 
619 /*
620  *********************************************************************
621  * PIXEL STRUCTURE FUNCTIONS:
622  *********************************************************************
623  *
624  * Because deep texture pixels are varying in size, a pixel's storage
625  * must be dynamically allocated. This library
626  * provides a type, DtexPixel, which allows users to build and evaluate
627  * pixels. The structure is fairly heavyweight because it stores
628  * auxiliary information related to compression. We don't recommend
629  * allocating an entire image of these structures yourself; keep
630  * a small number of DtexPixel's around, and use DtexSetPixel to
631  * modify a DtexImage.
632  *
633  * The following functions let the user create, modify, and
634  * destroy DtexPixel's. Pixels may be cleared with DtexClearPixel().
635  * New datapoints may be added (in increasing Z order) with
636  * DtexAppendPixel(). If compression is used, a pixel must
637  * be DtexFinish()'ed before lookups can be performed in the pixel.
638  */
639 
640 /* ----------------------------------------------------------------- */
641 
642 PRMANAPI extern DtexPixel * DtexMakePixel(int numChan);
643 /*
644  * create a DtexPixel structure. It should be destroyed with
645  * DtexDestroyPixel, not free().
646  */
647 
648 /* ----------------------------------------------------------------- */
649 
650 PRMANAPI extern void DtexDestroyPixel(DtexPixel *pix);
651 /*
652  * free a DtexPixel structure.
653  */
654 
655 /* ----------------------------------------------------------------- */
656 
657 PRMANAPI extern int DtexClearPixel(DtexPixel *pix, int numChan);
658 /*
659  * set the specified pixel structure to be empty. Its allocation
660  * stays around, but the pixel is marked as empty.
661  */
662 
663 /* ----------------------------------------------------------------- */
664 
665 PRMANAPI extern int DtexEmptyPixel(DtexPixel *pix);
666 
667 /*
668  * Clear out all the allocation in the given pixel, but don't free
669  * the pixel itself.
670  */
671 
672 /* ----------------------------------------------------------------- */
673 
674 PRMANAPI extern int DtexSpecifyPixel(DtexPixel *pix,int numChan,int numPoints,
675  float *data);
676 
677 /*
678  * Set the given pixel to have numChan channels and set its data
679  * directly. Assumes no compression.
680  */
681 
682 /* ----------------------------------------------------------------- */
683 
685 
686 /*
687  * Return 1 if the specific pixel has duplicates for all its values,
688  * zero otherwise. If the pixel has no control points, returns 1.
689  */
690 
691 /* ----------------------------------------------------------------- */
692 
693 PRMANAPI extern int DtexPixelGetNumChan(DtexPixel *pix);
694 /*
695  * Return the number of channels in the pixel.
696  */
697 
698 /* ----------------------------------------------------------------- */
699 
700 PRMANAPI extern int DtexPixelGetNumPoints(DtexPixel *pix);
701 /*
702  * Return the number of control points in the pixel. Returns zero
703  * if there are no control points, -1 if the point has unresolved
704  * compression state.
705  */
706 
707 /* ----------------------------------------------------------------- */
708 
709 PRMANAPI extern int DtexPixelGetPoint(DtexPixel *pix, int i, float *z, float *data);
710 /*
711  * Get the i'th control point in the given pixel. If the indicated
712  * control point is accessible, z and data are set, and DTEX_NOERR
713  * is returned. If the pixel does not exist, DTEX_NOPOINT is
714  * returned and *z and *data are undefined. If the pixel has
715  * unresolved compression state, DTEX_UNFINISHED is returned and
716  * *z and *data are undefined.
717  */
718 
719 /* ----------------------------------------------------------------- */
720 
721 PRMANAPI extern int DtexPixelSetPoint(DtexPixel *pix, int i, float z, float *data);
722 
723 /*
724  * Modify the i'th control point in the given pixel. If the indicated
725  * control point is accessible, and if the supplied z is legal,
726  * the pixel is modified and DTEX_NOERR
727  * is returned. If the pixel does not exist, DTEX_NOPOINT is
728  * returned. If the pixel has unresolved compression state,
729  * DTEX_UNFINISHED is returned and *z and *data are undefined.
730  */
731 
732 /* ----------------------------------------------------------------- */
733 
734 PRMANAPI extern int DtexCopyPixel(DtexPixel *dest,
735  DtexPixel *src);
736 /*
737  * copy src to dest. If dest has a different number of channels
738  * than src, dest is modified to match. This includes current
739  * compression state.
740  */
741 
742 
743 /* ----------------------------------------------------------------- */
744 PRMANAPI extern int DtexMergePixel(DtexPixel *dest,
745  DtexPixel *src);
746 /*
747  * Merges data from src to dest - the resulting data in dest will have
748  * all control points that were present in both pixels. Both pixels
749  * must have the same number of channels, and must not have unresolved
750  * compression state.
751  */
752 
753 PRMANAPI extern int DtexMergePixelEx(DtexPixel *dest, DtexPixel *src,
754  int rgbChannel, int alphaChannel);
755 /*
756  * Like DtexMergePixel, this merges data from src into dest. In addition,
757  * it can correctly handle embedding geometry in volumes and overlapping
758  * volumes. These volume segments are flagged with a negative alpha and
759  * extend to the next sample in the pixel. There must be at least one
760  * non-volume sample marking the end of chain (which may be completely
761  * transparent).
762  *
763  * This assumes a four channel RGBA pixel function when splitting and
764  * merging volume regions. The rgbChannel must be the index of the first
765  * color channel, with the assumption that all three color channels are
766  * contiguous. The alphaChannel must be the index of the alpha channel.
767  * Any additional channels will be copied unchanged from the most recent
768  * volume sample.
769  */
770 
771 /* ----------------------------------------------------------------- */
772 
773 PRMANAPI extern int DtexFinishPixel(DtexPixel *dest);
774 /*
775  * If the specified pixel is in "compress mode" (non-zero compression),
776  * this function finishes compression and sets compression error to zero.
777  * This must be called before any lookups on the pixel structure.
778  *
779  * If the pixel already has a zero compression error, this function has
780  * no effect.
781  */
782 
783 /* ----------------------------------------------------------------- */
784 
785 PRMANAPI extern int DtexAppendPixel(DtexPixel *pix,
786  float z,
787  int n,
788  float *data,
789  float error);
790 /*
791  * add a data point to the end of the specified pixel. n must
792  * specify how many floats are stored in data, and must match
793  * the number of channels in the pixel.
794  */
795 
796 /* ----------------------------------------------------------------- */
797 
798 PRMANAPI extern int DtexEvalPixel(DtexPixel *pix,
799  float z,
800  int n,
801  float *data);
802 /*
803  * evaluate the pixel's function at depth z, and put the
804  * result in data. n must indicate how many floats are
805  * allocated in data, and must be no less than the number of
806  * channels in the image.
807  */
808 
809 
810 /* ----------------------------------------------------------------- */
811 
812 PRMANAPI extern int DtexCompositePixel(DtexPixel *pix,
813  int rgbChannel,
814  int alphaChannel,
815  float *data);
816 /*
817  * Composite a four channel RGBA pixel function and store the result
818  * in data. rgbChannel must be the index of the first color channel,
819  * with the assumption that all three color channels are
820  * contiguous. alphaChannel must be the index of the alpha
821  * channel. data must be a buffer of at least four floats. If the
822  * pixel is empty, DTEX_EMPTY is returned and data is filled with
823  * zeros. Otherwise, data[0], data[1], and data[2] contain the
824  * composited color values and data[3] contains the composited alpha
825  * value, and DTEX_NOERR is returned.
826  */
827 
828 
829 /* ----------------------------------------------------------------- */
830 
831 PRMANAPI extern int DtexGetPixelZRange(DtexPixel *pix,
832  float *min,
833  float *max);
834 /*
835  * computes the range over which the specified pixel is defined.
836  * if the pixel is non-empty, the range is returned in min and max
837  * and the function returns DTEX_NOERR. If the pixel is empty,
838  * DTEX_EMPTY is returned and min and max are undefined. If the pixel
839  * has unresolved compression state, DTEX_UNFINISHED is returned and
840  * min and max are undefined.
841  */
842 
843 /* ----------------------------------------------------------------- */
844 
845 PRMANAPI extern int DtexPrintPixel(DtexPixel *p);
846 /*
847  * print a representation of the given pixel to stdout
848  */
849 
850 /* ----------------------------------------------------------------- */
851 
852 PRMANAPI extern int DtexAveragePixels(int n,
853  DtexPixel **pixels,
854  float *weights,
855  float error,
856  DtexPixel *result);
857 /*
858  * compute the weighted pointwise average of the given pixels and put the
859  * result in result.
860  */
861 
862 /* ----------------------------------------------------------------- */
863 
864 PRMANAPI extern void DtexPrintStats(void);
865 
866 /* ----------------------------------------------------------------- */
867 
868 /* Create a new Deep filter */
869 
871 
872 /* Create a new Deep filter */
873 
874 #define DTEX_CREATE_DEEP_FILTER_PARAMS_VERSION 2
875 
876 typedef struct {
877  // v1...
878  int version;
879  float error;
883  // v2...
884  float deptherror;
886 
888 
889 /* Destroy a new Deep filter */
890 
891 PRMANAPI extern void DtexDestroyDeepFilter(DtexDeepFilter *filter);
892 
893 /*
894  * Prepare the given filter to take samples. numChan is the number of
895  * channels (in addition to z) per delta. numSamples is the number of
896  * samples in the filter. numDeltas is an array with numSamples values
897  * indicating, for each sample, how many deltas are in that sample.
898  * filterWeights is an array with numSamples floats indicating, for each
899  * sample, what that sample's filterweight is. totalNumDeltas is the
900  * sum of the values in numDeltas.
901  *
902  * When this function is done, all the samples will be set up. The
903  * user can then run through and fill in the actual deltas.
904  */
905 
906 PRMANAPI extern float *DtexGetDeepFilterData(DtexDeepFilter *filter,
907  int numChan,
908  int numSamples,
909  int *numDeltas,
910  float *filterWeights,
911  int totalNumDeltas);
912 
913 /* ----------------------------------------------------------------- */
914 
915 /* Execute the given filter to produce point data. pointData must
916  contain enough space to hold "totalNumDeltas" deltas as specified
917  in DtexGetDeepFilterData.
918 
919  If assumeSmooth is non-zero, the computation will assume that the
920  underlying function is smooth, and that any discontinuities encountered
921  are part of the sampling error. It will thus not try to reproduce
922  discontinuities.
923 
924 */
925 
927  float *pointData,
928  float error,
929  int assumeSmooth);
930 
931 /* Execute the given filter to produce point data. pointData must
932  contain enough space to hold "totalNumDeltas" deltas as specified
933  in DtexGetDeepFilterData.
934 
935  If assumeSmooth is non-zero, the computation will assume that the
936  underlying function is smooth, and that any discontinuities encountered
937  are part of the sampling error. It will thus not try to reproduce
938  discontinuities.
939 
940  The filter is assumed to have been configured with relevant error
941  and other configurations via DtexCreateDeepFilterEx
942 */
943 
944 
946  float *pointData);
947 
948 /* ----------------------------------------------------------------- */
949 
950 /* Given a series of points, compress it. */
951 
952 PRMANAPI extern int DtexCompressPointData(float *pointData,
953  int numChan,
954  int numPoints,
955  float *result,
956  float error);
957 
958 /* ----------------------------------------------------------------- */
959 
960 /* Compress one pixel and put the result in another. Doesn't work
961  * in place. (dest must not == src.)
962  */
963 
964 PRMANAPI extern int
965 DtexCompressPixel(DtexPixel *src,DtexPixel *dest,float error);
966 
967 /* ----------------------------------------------------------------- */
968 
969 PRMANAPI extern void
970 DtexQueryMemory(unsigned long *current,unsigned long *peak);
971 
972 #ifdef __cplusplus
973 }
974 #endif
975 
976 #endif /* DTEX_H */
977 
PRMANAPI int DtexMetadataSet(DtexMetadata *meta, char const *token, void const *value)
struct DtexMetadata DtexMetadata
Definition: dtex.h:72
PRMANAPI int DtexEval(DtexImage *img, int x, int y, float z, int n, float *data)
PRMANAPI int DtexMetadataGetByIndex(DtexMetadata *meta, int index, char const **token, void const **value)
PRMANAPI int DtexAppendPixel(DtexPixel *pix, float z, int n, float *data, float error)
PRMANAPI int DtexCompressPixel(DtexPixel *src, DtexPixel *dest, float error)
PRMANAPI int DtexWidth(DtexImage *i)
DtexDataType
Definition: dtex.h:124
PRMANAPI int DtexCreateFileEx(const char *name, DtexCache *cache, DtexFile **result, DtexCreateFileParams *params)
PRMANAPI int DtexIsPixelMonochrome(DtexPixel *p)
PRMANAPI int DtexClearPixel(DtexPixel *pix, int numChan)
struct DtexLargeAccessor DtexLargeAccessor
PRMANAPI int DtexAddImage(DtexFile *f, const char *name, int numChan, int w, int h, int tw, int th, float *NP, float *Nl, enum DtexCompression compression, enum DtexDataType datatype, DtexImage **result)
PRMANAPI int DtexMetadataCount(DtexMetadata *meta)
PRMANAPI int DtexEmptyPixel(DtexPixel *pix)
int forceFormatVersion
Definition: dtex.h:263
DtexOpenFunc openFunc
Definition: dtex.h:94
DtexCreateFunc createFunc
Definition: dtex.h:93
DtexLargeWriteFunc writeFunc
Definition: dtex.h:109
PRMANAPI int DtexEvalPixel(DtexPixel *pix, float z, int n, float *data)
PRMANAPI float * DtexGetDeepFilterData(DtexDeepFilter *filter, int numChan, int numSamples, int *numDeltas, float *filterWeights, int totalNumDeltas)
#define PRMANAPI
Definition: prmanapi.h:111
PRMANAPI void DtexQueryMemory(unsigned long *current, unsigned long *peak)
PRMANAPI int DtexGetImageByIndex(DtexFile *f, int index, DtexImage **result)
int formatVersion
Definition: dtex.h:317
PRMANAPI int DtexCompressPointData(float *pointData, int numChan, int numPoints, float *result, float error)
PRMANAPI int DtexHeight(DtexImage *i)
PRMANAPI int DtexIsDeepFile(const char *name, DtexCache *cache, int *version)
PRMANAPI int DtexTileHeight(DtexImage *i)
PRMANAPI int DtexComputeDeepPointData(DtexDeepFilter *filter, float *pointData, float error, int assumeSmooth)
PRMANAPI int DtexGetImageByName(DtexFile *f, const char *name, DtexImage **result)
PRMANAPI DtexPixel * DtexMakePixel(int numChan)
PRMANAPI int DtexDestroyCache(DtexCache *c)
PRMANAPI int DtexCountImages(DtexFile *f)
PRMANAPI DtexCompression DtexGetCompression(DtexImage *i)
void *(* DtexCreateFunc)(const char *name)
Definition: dtex.h:81
PRMANAPI void DtexDestroyPixel(DtexPixel *pix)
PRMANAPI int DtexPrintPixel(DtexPixel *p)
PRMANAPI int DtexSync(DtexFile *ds)
PRMANAPI int DtexNP(DtexImage *i, float *NP)
PRMANAPI int DtexTileWidth(DtexImage *i)
PRMANAPI DtexDataType DtexGetDataType(DtexImage *i)
PRMANAPI int DtexComputeDeepPointDataEx(DtexDeepFilter *filter, float *pointData)
PRMANAPI int DtexPixelSetPoint(DtexPixel *pix, int i, float z, float *data)
PRMANAPI DtexCache * DtexCreateCache(int numTiles, DtexAccessor *accessor)
struct DtexCache DtexCache
Definition: dtex.h:74
Definition: dtex.h:150
PRMANAPI int DtexFinishPixel(DtexPixel *dest)
PRMANAPI int DtexNl(DtexImage *i, float *Nl)
PRMANAPI DtexCache * DtexCreateReadOnlyCache(int numTilesPerThread, DtexAccessor *accessor, DtexLargeAccessor *largeAccessor)
PRMANAPI DtexDeepFilter * DtexCreateDeepFilterEx(DtexCreateDeepFilterParams *p)
PRMANAPI int DtexGetZRange(DtexImage *img, int x, int y, float *min, float *max)
PRMANAPI void DtexDestroyDeepFilter(DtexDeepFilter *filter)
DtexWriteFunc writeFunc
Definition: dtex.h:96
PRMANAPI int DtexSyncCache(DtexCache *dsc)
PRMANAPI int DtexPixelGetPoint(DtexPixel *pix, int i, float *z, float *data)
struct DtexAccessor DtexAccessor
struct DtexImage DtexImage
Definition: dtex.h:71
PRMANAPI int DtexAveragePixels(int n, DtexPixel **pixels, float *weights, float error, DtexPixel *result)
PRMANAPI void DtexPrintStats(void)
DtexReadFunc readFunc
Definition: dtex.h:95
PRMANAPI int DtexCopyPixel(DtexPixel *dest, DtexPixel *src)
void *(* DtexOpenFunc)(const char *name, const char *mode)
Definition: dtex.h:82
long(* DtexWriteFunc)(void *handle, char *data, long seek, long size)
Definition: dtex.h:84
struct DtexFile DtexFile
Definition: dtex.h:70
PRMANAPI int DtexMetadataGetByName(DtexMetadata *meta, char const *name, char const **token, void const **value)
PRMANAPI int DtexSetLargeAccessor(DtexCache *c, DtexLargeAccessor *accessor)
PRMANAPI int DtexPixelGetNumChan(DtexPixel *pix)
struct DtexDeepFilter DtexDeepFilter
Definition: dtex.h:75
PRMANAPI int DtexSetPixelData(DtexImage *img, int x, int y, int numChan, int numPoints, float *data)
PRMANAPI int DtexMergePixelEx(DtexPixel *dest, DtexPixel *src, int rgbChannel, int alphaChannel)
long(* DtexLargeReadFunc)(void *handle, char *data, uint64_t seek, long size)
Definition: dtex.h:103
PRMANAPI int DtexGetFileMetadata(DtexFile *f, DtexMetadata **result)
PRMANAPI int DtexGetPixel(DtexImage *img, int x, int y, DtexPixel *pix)
long(* DtexLargeWriteFunc)(void *handle, char *data, uint64_t seek, long size)
Definition: dtex.h:104
PRMANAPI int DtexGetImageMetadata(DtexImage *i, DtexMetadata **result)
PRMANAPI DtexDeepFilter * DtexCreateDeepFilter(void)
PRMANAPI int DtexCreateFile(const char *name, DtexCache *cache, DtexFile **result)
PRMANAPI int DtexGetPixelZRange(DtexPixel *pix, float *min, float *max)
DtexCloseFunc closeFunc
Definition: dtex.h:97
PRMANAPI int DtexGetMeanDepth(DtexImage *img, int x, int y, float *mean, float *alpha)
struct DtexPixel DtexPixel
Definition: dtex.h:73
long(* DtexReadFunc)(void *handle, char *data, long seek, long size)
Definition: dtex.h:83
PRMANAPI int DtexSetPixel(DtexImage *img, int x, int y, DtexPixel *pix)
PRMANAPI int DtexCompositePixel(DtexPixel *pix, int rgbChannel, int alphaChannel, float *data)
PRMANAPI int DtexOpenFile(const char *name, const char *mode, DtexCache *cache, DtexFile **result)
void(* DtexCloseFunc)(void *handle)
Definition: dtex.h:85
PRMANAPI int DtexSpecifyPixel(DtexPixel *pix, int numChan, int numPoints, float *data)
char const * formatType
Definition: dtex.h:316
DtexLargeReadFunc readFunc
Definition: dtex.h:108
PRMANAPI int DtexPixelGetNumPoints(DtexPixel *pix)
PRMANAPI char * DtexImageName(DtexImage *i)
PRMANAPI int DtexNumChan(DtexImage *i)
PRMANAPI int DtexFileVersion(DtexFile *f)
PRMANAPI int DtexClose(DtexFile *ds)
DtexCompression
Definition: dtex.h:113
PRMANAPI int DtexMergePixel(DtexPixel *dest, DtexPixel *src)
PRMANAPI int DtexAddImageEx(DtexFile *f, const char *name, int numChan, int w, int h, int tw, int th, float *NP, float *Nl, enum DtexCompression compression, enum DtexDataType datatype, DtexImage **result, DtexAddImageParams *params)