tif_luv.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. /*
  2. * Copyright (c) 1997 Greg Ward Larson
  3. * Copyright (c) 1997 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the names of
  9. * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any
  10. * advertising or publicity relating to the software without the specific,
  11. * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE
  18. * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. #include "tiffiop.h"
  25. #ifdef LOGLUV_SUPPORT
  26. /*
  27. * TIFF Library.
  28. * LogLuv compression support for high dynamic range images.
  29. *
  30. * Contributed by Greg Larson.
  31. *
  32. * LogLuv image support uses the TIFF library to store 16 or 10-bit
  33. * log luminance values with 8 bits each of u and v or a 14-bit index.
  34. *
  35. * The codec can take as input and produce as output 32-bit IEEE float values
  36. * as well as 16-bit integer values. A 16-bit luminance is interpreted
  37. * as a sign bit followed by a 15-bit integer that is converted
  38. * to and from a linear magnitude using the transformation:
  39. *
  40. * L = 2^( (Le+.5)/256 - 64 ) # real from 15-bit
  41. *
  42. * Le = floor( 256*(log2(L) + 64) ) # 15-bit from real
  43. *
  44. * The actual conversion to world luminance units in candelas per sq. meter
  45. * requires an additional multiplier, which is stored in the TIFFTAG_STONITS.
  46. * This value is usually set such that a reasonable exposure comes from
  47. * clamping decoded luminances above 1 to 1 in the displayed image.
  48. *
  49. * The 16-bit values for u and v may be converted to real values by dividing
  50. * each by 32768. (This allows for negative values, which aren't useful as
  51. * far as we know, but are left in case of future improvements in human
  52. * color vision.)
  53. *
  54. * Conversion from (u,v), which is actually the CIE (u',v') system for
  55. * you color scientists, is accomplished by the following transformation:
  56. *
  57. * u = 4*x / (-2*x + 12*y + 3)
  58. * v = 9*y / (-2*x + 12*y + 3)
  59. *
  60. * x = 9*u / (6*u - 16*v + 12)
  61. * y = 4*v / (6*u - 16*v + 12)
  62. *
  63. * This process is greatly simplified by passing 32-bit IEEE floats
  64. * for each of three CIE XYZ coordinates. The codec then takes care
  65. * of conversion to and from LogLuv, though the application is still
  66. * responsible for interpreting the TIFFTAG_STONITS calibration factor.
  67. *
  68. * By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white
  69. * point of (x,y)=(1/3,1/3). However, most color systems assume some other
  70. * white point, such as D65, and an absolute color conversion to XYZ then
  71. * to another color space with a different white point may introduce an
  72. * unwanted color cast to the image. It is often desirable, therefore, to
  73. * perform a white point conversion that maps the input white to [1 1 1]
  74. * in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT
  75. * tag value. A decoder that demands absolute color calibration may use
  76. * this white point tag to get back the original colors, but usually it
  77. * will be ignored and the new white point will be used instead that
  78. * matches the output color space.
  79. *
  80. * Pixel information is compressed into one of two basic encodings, depending
  81. * on the setting of the compression tag, which is one of COMPRESSION_SGILOG
  82. * or COMPRESSION_SGILOG24. For COMPRESSION_SGILOG, greyscale data is
  83. * stored as:
  84. *
  85. * 1 15
  86. * |-+---------------|
  87. *
  88. * COMPRESSION_SGILOG color data is stored as:
  89. *
  90. * 1 15 8 8
  91. * |-+---------------|--------+--------|
  92. * S Le ue ve
  93. *
  94. * For the 24-bit COMPRESSION_SGILOG24 color format, the data is stored as:
  95. *
  96. * 10 14
  97. * |----------|--------------|
  98. * Le' Ce
  99. *
  100. * There is no sign bit in the 24-bit case, and the (u,v) chromaticity is
  101. * encoded as an index for optimal color resolution. The 10 log bits are
  102. * defined by the following conversions:
  103. *
  104. * L = 2^((Le'+.5)/64 - 12) # real from 10-bit
  105. *
  106. * Le' = floor( 64*(log2(L) + 12) ) # 10-bit from real
  107. *
  108. * The 10 bits of the smaller format may be converted into the 15 bits of
  109. * the larger format by multiplying by 4 and adding 13314. Obviously,
  110. * a smaller range of magnitudes is covered (about 5 orders of magnitude
  111. * instead of 38), and the lack of a sign bit means that negative luminances
  112. * are not allowed. (Well, they aren't allowed in the real world, either,
  113. * but they are useful for certain types of image processing.)
  114. *
  115. * The desired user format is controlled by the setting the internal
  116. * pseudo tag TIFFTAG_SGILOGDATAFMT to one of:
  117. * SGILOGDATAFMT_FLOAT = IEEE 32-bit float XYZ values
  118. * SGILOGDATAFMT_16BIT = 16-bit integer encodings of logL, u and v
  119. * Raw data i/o is also possible using:
  120. * SGILOGDATAFMT_RAW = 32-bit unsigned integer with encoded pixel
  121. * In addition, the following decoding is provided for ease of display:
  122. * SGILOGDATAFMT_8BIT = 8-bit default RGB gamma-corrected values
  123. *
  124. * For grayscale images, we provide the following data formats:
  125. * SGILOGDATAFMT_FLOAT = IEEE 32-bit float Y values
  126. * SGILOGDATAFMT_16BIT = 16-bit integer w/ encoded luminance
  127. * SGILOGDATAFMT_8BIT = 8-bit gray monitor values
  128. *
  129. * Note that the COMPRESSION_SGILOG applies a simple run-length encoding
  130. * scheme by separating the logL, u and v bytes for each row and applying
  131. * a PackBits type of compression. Since the 24-bit encoding is not
  132. * adaptive, the 32-bit color format takes less space in many cases.
  133. *
  134. * Further control is provided over the conversion from higher-resolution
  135. * formats to final encoded values through the pseudo tag
  136. * TIFFTAG_SGILOGENCODE:
  137. * SGILOGENCODE_NODITHER = do not dither encoded values
  138. * SGILOGENCODE_RANDITHER = apply random dithering during encoding
  139. *
  140. * The default value of this tag is SGILOGENCODE_NODITHER for
  141. * COMPRESSION_SGILOG to maximize run-length encoding and
  142. * SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn
  143. * quantization errors into noise.
  144. */
  145. #include <stdio.h>
  146. #include <stdlib.h>
  147. #include <math.h>
  148. /*
  149. * State block for each open TIFF
  150. * file using LogLuv compression/decompression.
  151. */
  152. typedef struct logLuvState LogLuvState;
  153. struct logLuvState {
  154. int encoder_state; /* 1 if encoder correctly initialized */
  155. int user_datafmt; /* user data format */
  156. int encode_meth; /* encoding method */
  157. int pixel_size; /* bytes per pixel */
  158. uint8* tbuf; /* translation buffer */
  159. tmsize_t tbuflen; /* buffer length */
  160. void (*tfunc)(LogLuvState*, uint8*, tmsize_t);
  161. TIFFVSetMethod vgetparent; /* super-class method */
  162. TIFFVSetMethod vsetparent; /* super-class method */
  163. };
  164. #define DecoderState(tif) ((LogLuvState*) (tif)->tif_data)
  165. #define EncoderState(tif) ((LogLuvState*) (tif)->tif_data)
  166. #define SGILOGDATAFMT_UNKNOWN -1
  167. #define MINRUN 4 /* minimum run length */
  168. /*
  169. * Decode a string of 16-bit gray pixels.
  170. */
  171. static int
  172. LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
  173. {
  174. static const char module[] = "LogL16Decode";
  175. LogLuvState* sp = DecoderState(tif);
  176. int shft;
  177. tmsize_t i;
  178. tmsize_t npixels;
  179. unsigned char* bp;
  180. int16* tp;
  181. int16 b;
  182. tmsize_t cc;
  183. int rc;
  184. (void)s;
  185. assert(s == 0);
  186. assert(sp != NULL);
  187. npixels = occ / sp->pixel_size;
  188. if (sp->user_datafmt == SGILOGDATAFMT_16BIT)
  189. tp = (int16*) op;
  190. else {
  191. if(sp->tbuflen < npixels) {
  192. TIFFErrorExt(tif->tif_clientdata, module,
  193. "Translation buffer too short");
  194. return (0);
  195. }
  196. tp = (int16*) sp->tbuf;
  197. }
  198. _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
  199. bp = (unsigned char*) tif->tif_rawcp;
  200. cc = tif->tif_rawcc;
  201. /* get each byte string */
  202. for (shft = 8; shft >= 0; shft -=8) {
  203. for (i = 0; i < npixels && cc > 0; ) {
  204. if (*bp >= 128) { /* run */
  205. if( cc < 2 )
  206. break;
  207. rc = *bp++ + (2-128);
  208. b = (int16)(*bp++ << shft);
  209. cc -= 2;
  210. while (rc-- && i < npixels)
  211. tp[i++] |= b;
  212. } else { /* non-run */
  213. rc = *bp++; /* nul is noop */
  214. while (--cc && rc-- && i < npixels)
  215. tp[i++] |= (int16)*bp++ << shft;
  216. }
  217. }
  218. if (i != npixels) {
  219. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  220. TIFFErrorExt(tif->tif_clientdata, module,
  221. "Not enough data at row %lu (short %I64d pixels)",
  222. (unsigned long) tif->tif_row,
  223. (unsigned __int64) (npixels - i));
  224. #else
  225. TIFFErrorExt(tif->tif_clientdata, module,
  226. "Not enough data at row %lu (short %llu pixels)",
  227. (unsigned long) tif->tif_row,
  228. (unsigned long long) (npixels - i));
  229. #endif
  230. tif->tif_rawcp = (uint8*) bp;
  231. tif->tif_rawcc = cc;
  232. return (0);
  233. }
  234. }
  235. (*sp->tfunc)(sp, op, npixels);
  236. tif->tif_rawcp = (uint8*) bp;
  237. tif->tif_rawcc = cc;
  238. return (1);
  239. }
  240. /*
  241. * Decode a string of 24-bit pixels.
  242. */
  243. static int
  244. LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
  245. {
  246. static const char module[] = "LogLuvDecode24";
  247. LogLuvState* sp = DecoderState(tif);
  248. tmsize_t cc;
  249. tmsize_t i;
  250. tmsize_t npixels;
  251. unsigned char* bp;
  252. uint32* tp;
  253. (void)s;
  254. assert(s == 0);
  255. assert(sp != NULL);
  256. npixels = occ / sp->pixel_size;
  257. if (sp->user_datafmt == SGILOGDATAFMT_RAW)
  258. tp = (uint32 *)op;
  259. else {
  260. if(sp->tbuflen < npixels) {
  261. TIFFErrorExt(tif->tif_clientdata, module,
  262. "Translation buffer too short");
  263. return (0);
  264. }
  265. tp = (uint32 *) sp->tbuf;
  266. }
  267. /* copy to array of uint32 */
  268. bp = (unsigned char*) tif->tif_rawcp;
  269. cc = tif->tif_rawcc;
  270. for (i = 0; i < npixels && cc >= 3; i++) {
  271. tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2];
  272. bp += 3;
  273. cc -= 3;
  274. }
  275. tif->tif_rawcp = (uint8*) bp;
  276. tif->tif_rawcc = cc;
  277. if (i != npixels) {
  278. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  279. TIFFErrorExt(tif->tif_clientdata, module,
  280. "Not enough data at row %lu (short %I64d pixels)",
  281. (unsigned long) tif->tif_row,
  282. (unsigned __int64) (npixels - i));
  283. #else
  284. TIFFErrorExt(tif->tif_clientdata, module,
  285. "Not enough data at row %lu (short %llu pixels)",
  286. (unsigned long) tif->tif_row,
  287. (unsigned long long) (npixels - i));
  288. #endif
  289. return (0);
  290. }
  291. (*sp->tfunc)(sp, op, npixels);
  292. return (1);
  293. }
  294. /*
  295. * Decode a string of 32-bit pixels.
  296. */
  297. static int
  298. LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
  299. {
  300. static const char module[] = "LogLuvDecode32";
  301. LogLuvState* sp;
  302. int shft;
  303. tmsize_t i;
  304. tmsize_t npixels;
  305. unsigned char* bp;
  306. uint32* tp;
  307. uint32 b;
  308. tmsize_t cc;
  309. int rc;
  310. (void)s;
  311. assert(s == 0);
  312. sp = DecoderState(tif);
  313. assert(sp != NULL);
  314. npixels = occ / sp->pixel_size;
  315. if (sp->user_datafmt == SGILOGDATAFMT_RAW)
  316. tp = (uint32*) op;
  317. else {
  318. if(sp->tbuflen < npixels) {
  319. TIFFErrorExt(tif->tif_clientdata, module,
  320. "Translation buffer too short");
  321. return (0);
  322. }
  323. tp = (uint32*) sp->tbuf;
  324. }
  325. _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
  326. bp = (unsigned char*) tif->tif_rawcp;
  327. cc = tif->tif_rawcc;
  328. /* get each byte string */
  329. for (shft = 24; shft >= 0; shft -=8) {
  330. for (i = 0; i < npixels && cc > 0; ) {
  331. if (*bp >= 128) { /* run */
  332. if( cc < 2 )
  333. break;
  334. rc = *bp++ + (2-128);
  335. b = (uint32)*bp++ << shft;
  336. cc -= 2;
  337. while (rc-- && i < npixels)
  338. tp[i++] |= b;
  339. } else { /* non-run */
  340. rc = *bp++; /* nul is noop */
  341. while (--cc && rc-- && i < npixels)
  342. tp[i++] |= (uint32)*bp++ << shft;
  343. }
  344. }
  345. if (i != npixels) {
  346. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  347. TIFFErrorExt(tif->tif_clientdata, module,
  348. "Not enough data at row %lu (short %I64d pixels)",
  349. (unsigned long) tif->tif_row,
  350. (unsigned __int64) (npixels - i));
  351. #else
  352. TIFFErrorExt(tif->tif_clientdata, module,
  353. "Not enough data at row %lu (short %llu pixels)",
  354. (unsigned long) tif->tif_row,
  355. (unsigned long long) (npixels - i));
  356. #endif
  357. tif->tif_rawcp = (uint8*) bp;
  358. tif->tif_rawcc = cc;
  359. return (0);
  360. }
  361. }
  362. (*sp->tfunc)(sp, op, npixels);
  363. tif->tif_rawcp = (uint8*) bp;
  364. tif->tif_rawcc = cc;
  365. return (1);
  366. }
  367. /*
  368. * Decode a strip of pixels. We break it into rows to
  369. * maintain synchrony with the encode algorithm, which
  370. * is row by row.
  371. */
  372. static int
  373. LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  374. {
  375. tmsize_t rowlen = TIFFScanlineSize(tif);
  376. if (rowlen == 0)
  377. return 0;
  378. assert(cc%rowlen == 0);
  379. while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) {
  380. bp += rowlen;
  381. cc -= rowlen;
  382. }
  383. return (cc == 0);
  384. }
  385. /*
  386. * Decode a tile of pixels. We break it into rows to
  387. * maintain synchrony with the encode algorithm, which
  388. * is row by row.
  389. */
  390. static int
  391. LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  392. {
  393. tmsize_t rowlen = TIFFTileRowSize(tif);
  394. if (rowlen == 0)
  395. return 0;
  396. assert(cc%rowlen == 0);
  397. while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) {
  398. bp += rowlen;
  399. cc -= rowlen;
  400. }
  401. return (cc == 0);
  402. }
  403. /*
  404. * Encode a row of 16-bit pixels.
  405. */
  406. static int
  407. LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  408. {
  409. static const char module[] = "LogL16Encode";
  410. LogLuvState* sp = EncoderState(tif);
  411. int shft;
  412. tmsize_t i;
  413. tmsize_t j;
  414. tmsize_t npixels;
  415. uint8* op;
  416. int16* tp;
  417. int16 b;
  418. tmsize_t occ;
  419. int rc=0, mask;
  420. tmsize_t beg;
  421. (void)s;
  422. assert(s == 0);
  423. assert(sp != NULL);
  424. npixels = cc / sp->pixel_size;
  425. if (sp->user_datafmt == SGILOGDATAFMT_16BIT)
  426. tp = (int16*) bp;
  427. else {
  428. tp = (int16*) sp->tbuf;
  429. if(sp->tbuflen < npixels) {
  430. TIFFErrorExt(tif->tif_clientdata, module,
  431. "Translation buffer too short");
  432. return (0);
  433. }
  434. (*sp->tfunc)(sp, bp, npixels);
  435. }
  436. /* compress each byte string */
  437. op = tif->tif_rawcp;
  438. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  439. for (shft = 8; shft >= 0; shft -=8) {
  440. for (i = 0; i < npixels; i += rc) {
  441. if (occ < 4) {
  442. tif->tif_rawcp = op;
  443. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  444. if (!TIFFFlushData1(tif))
  445. return (0);
  446. op = tif->tif_rawcp;
  447. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  448. }
  449. mask = 0xff << shft; /* find next run */
  450. for (beg = i; beg < npixels; beg += rc) {
  451. b = (int16) (tp[beg] & mask);
  452. rc = 1;
  453. while (rc < 127+2 && beg+rc < npixels &&
  454. (tp[beg+rc] & mask) == b)
  455. rc++;
  456. if (rc >= MINRUN)
  457. break; /* long enough */
  458. }
  459. if (beg-i > 1 && beg-i < MINRUN) {
  460. b = (int16) (tp[i] & mask);/*check short run */
  461. j = i+1;
  462. while ((tp[j++] & mask) == b)
  463. if (j == beg) {
  464. *op++ = (uint8)(128-2+j-i);
  465. *op++ = (uint8)(b >> shft);
  466. occ -= 2;
  467. i = beg;
  468. break;
  469. }
  470. }
  471. while (i < beg) { /* write out non-run */
  472. if ((j = beg-i) > 127) j = 127;
  473. if (occ < j+3) {
  474. tif->tif_rawcp = op;
  475. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  476. if (!TIFFFlushData1(tif))
  477. return (0);
  478. op = tif->tif_rawcp;
  479. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  480. }
  481. *op++ = (uint8) j; occ--;
  482. while (j--) {
  483. *op++ = (uint8) (tp[i++] >> shft & 0xff);
  484. occ--;
  485. }
  486. }
  487. if (rc >= MINRUN) { /* write out run */
  488. *op++ = (uint8) (128-2+rc);
  489. *op++ = (uint8) (tp[beg] >> shft & 0xff);
  490. occ -= 2;
  491. } else
  492. rc = 0;
  493. }
  494. }
  495. tif->tif_rawcp = op;
  496. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  497. return (1);
  498. }
  499. /*
  500. * Encode a row of 24-bit pixels.
  501. */
  502. static int
  503. LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  504. {
  505. static const char module[] = "LogLuvEncode24";
  506. LogLuvState* sp = EncoderState(tif);
  507. tmsize_t i;
  508. tmsize_t npixels;
  509. tmsize_t occ;
  510. uint8* op;
  511. uint32* tp;
  512. (void)s;
  513. assert(s == 0);
  514. assert(sp != NULL);
  515. npixels = cc / sp->pixel_size;
  516. if (sp->user_datafmt == SGILOGDATAFMT_RAW)
  517. tp = (uint32*) bp;
  518. else {
  519. tp = (uint32*) sp->tbuf;
  520. if(sp->tbuflen < npixels) {
  521. TIFFErrorExt(tif->tif_clientdata, module,
  522. "Translation buffer too short");
  523. return (0);
  524. }
  525. (*sp->tfunc)(sp, bp, npixels);
  526. }
  527. /* write out encoded pixels */
  528. op = tif->tif_rawcp;
  529. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  530. for (i = npixels; i--; ) {
  531. if (occ < 3) {
  532. tif->tif_rawcp = op;
  533. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  534. if (!TIFFFlushData1(tif))
  535. return (0);
  536. op = tif->tif_rawcp;
  537. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  538. }
  539. *op++ = (uint8)(*tp >> 16);
  540. *op++ = (uint8)(*tp >> 8 & 0xff);
  541. *op++ = (uint8)(*tp++ & 0xff);
  542. occ -= 3;
  543. }
  544. tif->tif_rawcp = op;
  545. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  546. return (1);
  547. }
  548. /*
  549. * Encode a row of 32-bit pixels.
  550. */
  551. static int
  552. LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  553. {
  554. static const char module[] = "LogLuvEncode32";
  555. LogLuvState* sp = EncoderState(tif);
  556. int shft;
  557. tmsize_t i;
  558. tmsize_t j;
  559. tmsize_t npixels;
  560. uint8* op;
  561. uint32* tp;
  562. uint32 b;
  563. tmsize_t occ;
  564. int rc=0, mask;
  565. tmsize_t beg;
  566. (void)s;
  567. assert(s == 0);
  568. assert(sp != NULL);
  569. npixels = cc / sp->pixel_size;
  570. if (sp->user_datafmt == SGILOGDATAFMT_RAW)
  571. tp = (uint32*) bp;
  572. else {
  573. tp = (uint32*) sp->tbuf;
  574. if(sp->tbuflen < npixels) {
  575. TIFFErrorExt(tif->tif_clientdata, module,
  576. "Translation buffer too short");
  577. return (0);
  578. }
  579. (*sp->tfunc)(sp, bp, npixels);
  580. }
  581. /* compress each byte string */
  582. op = tif->tif_rawcp;
  583. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  584. for (shft = 24; shft >= 0; shft -=8) {
  585. for (i = 0; i < npixels; i += rc) {
  586. if (occ < 4) {
  587. tif->tif_rawcp = op;
  588. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  589. if (!TIFFFlushData1(tif))
  590. return (0);
  591. op = tif->tif_rawcp;
  592. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  593. }
  594. mask = 0xff << shft; /* find next run */
  595. for (beg = i; beg < npixels; beg += rc) {
  596. b = tp[beg] & mask;
  597. rc = 1;
  598. while (rc < 127+2 && beg+rc < npixels &&
  599. (tp[beg+rc] & mask) == b)
  600. rc++;
  601. if (rc >= MINRUN)
  602. break; /* long enough */
  603. }
  604. if (beg-i > 1 && beg-i < MINRUN) {
  605. b = tp[i] & mask; /* check short run */
  606. j = i+1;
  607. while ((tp[j++] & mask) == b)
  608. if (j == beg) {
  609. *op++ = (uint8)(128-2+j-i);
  610. *op++ = (uint8)(b >> shft);
  611. occ -= 2;
  612. i = beg;
  613. break;
  614. }
  615. }
  616. while (i < beg) { /* write out non-run */
  617. if ((j = beg-i) > 127) j = 127;
  618. if (occ < j+3) {
  619. tif->tif_rawcp = op;
  620. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  621. if (!TIFFFlushData1(tif))
  622. return (0);
  623. op = tif->tif_rawcp;
  624. occ = tif->tif_rawdatasize - tif->tif_rawcc;
  625. }
  626. *op++ = (uint8) j; occ--;
  627. while (j--) {
  628. *op++ = (uint8)(tp[i++] >> shft & 0xff);
  629. occ--;
  630. }
  631. }
  632. if (rc >= MINRUN) { /* write out run */
  633. *op++ = (uint8) (128-2+rc);
  634. *op++ = (uint8)(tp[beg] >> shft & 0xff);
  635. occ -= 2;
  636. } else
  637. rc = 0;
  638. }
  639. }
  640. tif->tif_rawcp = op;
  641. tif->tif_rawcc = tif->tif_rawdatasize - occ;
  642. return (1);
  643. }
  644. /*
  645. * Encode a strip of pixels. We break it into rows to
  646. * avoid encoding runs across row boundaries.
  647. */
  648. static int
  649. LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  650. {
  651. tmsize_t rowlen = TIFFScanlineSize(tif);
  652. if (rowlen == 0)
  653. return 0;
  654. assert(cc%rowlen == 0);
  655. while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) {
  656. bp += rowlen;
  657. cc -= rowlen;
  658. }
  659. return (cc == 0);
  660. }
  661. /*
  662. * Encode a tile of pixels. We break it into rows to
  663. * avoid encoding runs across row boundaries.
  664. */
  665. static int
  666. LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
  667. {
  668. tmsize_t rowlen = TIFFTileRowSize(tif);
  669. if (rowlen == 0)
  670. return 0;
  671. assert(cc%rowlen == 0);
  672. while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) {
  673. bp += rowlen;
  674. cc -= rowlen;
  675. }
  676. return (cc == 0);
  677. }
  678. /*
  679. * Encode/Decode functions for converting to and from user formats.
  680. */
  681. #include "uvcode.h"
  682. #ifndef UVSCALE
  683. #define U_NEU 0.210526316
  684. #define V_NEU 0.473684211
  685. #define UVSCALE 410.
  686. #endif
  687. #ifndef M_LN2
  688. #define M_LN2 0.69314718055994530942
  689. #endif
  690. #ifndef M_PI
  691. #define M_PI 3.14159265358979323846
  692. #endif
  693. #undef log2 /* Conflict with C'99 function */
  694. #define log2(x) ((1./M_LN2)*log(x))
  695. #undef exp2 /* Conflict with C'99 function */
  696. #define exp2(x) exp(M_LN2*(x))
  697. static int tiff_itrunc(double x, int m)
  698. {
  699. if( m == SGILOGENCODE_NODITHER )
  700. return (int)x;
  701. /* Silence CoverityScan warning about bad crypto function */
  702. /* coverity[dont_call] */
  703. return (int)(x + rand()*(1./RAND_MAX) - .5);
  704. }
  705. #if !LOGLUV_PUBLIC
  706. static
  707. #endif
  708. double
  709. LogL16toY(int p16) /* compute luminance from 16-bit LogL */
  710. {
  711. int Le = p16 & 0x7fff;
  712. double Y;
  713. if (!Le)
  714. return (0.);
  715. Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.);
  716. return (!(p16 & 0x8000) ? Y : -Y);
  717. }
  718. #if !LOGLUV_PUBLIC
  719. static
  720. #endif
  721. int
  722. LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */
  723. {
  724. if (Y >= 1.8371976e19)
  725. return (0x7fff);
  726. if (Y <= -1.8371976e19)
  727. return (0xffff);
  728. if (Y > 5.4136769e-20)
  729. return tiff_itrunc(256.*(log2(Y) + 64.), em);
  730. if (Y < -5.4136769e-20)
  731. return (~0x7fff | tiff_itrunc(256.*(log2(-Y) + 64.), em));
  732. return (0);
  733. }
  734. static void
  735. L16toY(LogLuvState* sp, uint8* op, tmsize_t n)
  736. {
  737. int16* l16 = (int16*) sp->tbuf;
  738. float* yp = (float*) op;
  739. while (n-- > 0)
  740. *yp++ = (float)LogL16toY(*l16++);
  741. }
  742. static void
  743. L16toGry(LogLuvState* sp, uint8* op, tmsize_t n)
  744. {
  745. int16* l16 = (int16*) sp->tbuf;
  746. uint8* gp = (uint8*) op;
  747. while (n-- > 0) {
  748. double Y = LogL16toY(*l16++);
  749. *gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y)));
  750. }
  751. }
  752. static void
  753. L16fromY(LogLuvState* sp, uint8* op, tmsize_t n)
  754. {
  755. int16* l16 = (int16*) sp->tbuf;
  756. float* yp = (float*) op;
  757. while (n-- > 0)
  758. *l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth));
  759. }
  760. #if !LOGLUV_PUBLIC
  761. static
  762. #endif
  763. void
  764. XYZtoRGB24(float xyz[3], uint8 rgb[3])
  765. {
  766. double r, g, b;
  767. /* assume CCIR-709 primaries */
  768. r = 2.690*xyz[0] + -1.276*xyz[1] + -0.414*xyz[2];
  769. g = -1.022*xyz[0] + 1.978*xyz[1] + 0.044*xyz[2];
  770. b = 0.061*xyz[0] + -0.224*xyz[1] + 1.163*xyz[2];
  771. /* assume 2.0 gamma for speed */
  772. /* could use integer sqrt approx., but this is probably faster */
  773. rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r)));
  774. rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g)));
  775. rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b)));
  776. }
  777. #if !LOGLUV_PUBLIC
  778. static
  779. #endif
  780. double
  781. LogL10toY(int p10) /* compute luminance from 10-bit LogL */
  782. {
  783. if (p10 == 0)
  784. return (0.);
  785. return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.));
  786. }
  787. #if !LOGLUV_PUBLIC
  788. static
  789. #endif
  790. int
  791. LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */
  792. {
  793. if (Y >= 15.742)
  794. return (0x3ff);
  795. else if (Y <= .00024283)
  796. return (0);
  797. else
  798. return tiff_itrunc(64.*(log2(Y) + 12.), em);
  799. }
  800. #define NANGLES 100
  801. #define uv2ang(u, v) ( (NANGLES*.499999999/M_PI) \
  802. * atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES )
  803. static int
  804. oog_encode(double u, double v) /* encode out-of-gamut chroma */
  805. {
  806. static int oog_table[NANGLES];
  807. static int initialized = 0;
  808. register int i;
  809. if (!initialized) { /* set up perimeter table */
  810. double eps[NANGLES], ua, va, ang, epsa;
  811. int ui, vi, ustep;
  812. for (i = NANGLES; i--; )
  813. eps[i] = 2.;
  814. for (vi = UV_NVS; vi--; ) {
  815. va = UV_VSTART + (vi+.5)*UV_SQSIZ;
  816. ustep = uv_row[vi].nus-1;
  817. if (vi == UV_NVS-1 || vi == 0 || ustep <= 0)
  818. ustep = 1;
  819. for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) {
  820. ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
  821. ang = uv2ang(ua, va);
  822. i = (int) ang;
  823. epsa = fabs(ang - (i+.5));
  824. if (epsa < eps[i]) {
  825. oog_table[i] = uv_row[vi].ncum + ui;
  826. eps[i] = epsa;
  827. }
  828. }
  829. }
  830. for (i = NANGLES; i--; ) /* fill any holes */
  831. if (eps[i] > 1.5) {
  832. int i1, i2;
  833. for (i1 = 1; i1 < NANGLES/2; i1++)
  834. if (eps[(i+i1)%NANGLES] < 1.5)
  835. break;
  836. for (i2 = 1; i2 < NANGLES/2; i2++)
  837. if (eps[(i+NANGLES-i2)%NANGLES] < 1.5)
  838. break;
  839. if (i1 < i2)
  840. oog_table[i] =
  841. oog_table[(i+i1)%NANGLES];
  842. else
  843. oog_table[i] =
  844. oog_table[(i+NANGLES-i2)%NANGLES];
  845. }
  846. initialized = 1;
  847. }
  848. i = (int) uv2ang(u, v); /* look up hue angle */
  849. return (oog_table[i]);
  850. }
  851. #undef uv2ang
  852. #undef NANGLES
  853. #if !LOGLUV_PUBLIC
  854. static
  855. #endif
  856. int
  857. uv_encode(double u, double v, int em) /* encode (u',v') coordinates */
  858. {
  859. register int vi, ui;
  860. if (v < UV_VSTART)
  861. return oog_encode(u, v);
  862. vi = tiff_itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
  863. if (vi >= UV_NVS)
  864. return oog_encode(u, v);
  865. if (u < uv_row[vi].ustart)
  866. return oog_encode(u, v);
  867. ui = tiff_itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
  868. if (ui >= uv_row[vi].nus)
  869. return oog_encode(u, v);
  870. return (uv_row[vi].ncum + ui);
  871. }
  872. #if !LOGLUV_PUBLIC
  873. static
  874. #endif
  875. int
  876. uv_decode(double *up, double *vp, int c) /* decode (u',v') index */
  877. {
  878. int upper, lower;
  879. register int ui, vi;
  880. if (c < 0 || c >= UV_NDIVS)
  881. return (-1);
  882. lower = 0; /* binary search */
  883. upper = UV_NVS;
  884. while (upper - lower > 1) {
  885. vi = (lower + upper) >> 1;
  886. ui = c - uv_row[vi].ncum;
  887. if (ui > 0)
  888. lower = vi;
  889. else if (ui < 0)
  890. upper = vi;
  891. else {
  892. lower = vi;
  893. break;
  894. }
  895. }
  896. vi = lower;
  897. ui = c - uv_row[vi].ncum;
  898. *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
  899. *vp = UV_VSTART + (vi+.5)*UV_SQSIZ;
  900. return (0);
  901. }
  902. #if !LOGLUV_PUBLIC
  903. static
  904. #endif
  905. void
  906. LogLuv24toXYZ(uint32 p, float XYZ[3])
  907. {
  908. int Ce;
  909. double L, u, v, s, x, y;
  910. /* decode luminance */
  911. L = LogL10toY(p>>14 & 0x3ff);
  912. if (L <= 0.) {
  913. XYZ[0] = XYZ[1] = XYZ[2] = 0.;
  914. return;
  915. }
  916. /* decode color */
  917. Ce = p & 0x3fff;
  918. if (uv_decode(&u, &v, Ce) < 0) {
  919. u = U_NEU; v = V_NEU;
  920. }
  921. s = 1./(6.*u - 16.*v + 12.);
  922. x = 9.*u * s;
  923. y = 4.*v * s;
  924. /* convert to XYZ */
  925. XYZ[0] = (float)(x/y * L);
  926. XYZ[1] = (float)L;
  927. XYZ[2] = (float)((1.-x-y)/y * L);
  928. }
  929. #if !LOGLUV_PUBLIC
  930. static
  931. #endif
  932. uint32
  933. LogLuv24fromXYZ(float XYZ[3], int em)
  934. {
  935. int Le, Ce;
  936. double u, v, s;
  937. /* encode luminance */
  938. Le = LogL10fromY(XYZ[1], em);
  939. /* encode color */
  940. s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
  941. if (!Le || s <= 0.) {
  942. u = U_NEU;
  943. v = V_NEU;
  944. } else {
  945. u = 4.*XYZ[0] / s;
  946. v = 9.*XYZ[1] / s;
  947. }
  948. Ce = uv_encode(u, v, em);
  949. if (Ce < 0) /* never happens */
  950. Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
  951. /* combine encodings */
  952. return (Le << 14 | Ce);
  953. }
  954. static void
  955. Luv24toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
  956. {
  957. uint32* luv = (uint32*) sp->tbuf;
  958. float* xyz = (float*) op;
  959. while (n-- > 0) {
  960. LogLuv24toXYZ(*luv, xyz);
  961. xyz += 3;
  962. luv++;
  963. }
  964. }
  965. static void
  966. Luv24toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
  967. {
  968. uint32* luv = (uint32*) sp->tbuf;
  969. int16* luv3 = (int16*) op;
  970. while (n-- > 0) {
  971. double u, v;
  972. *luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314);
  973. if (uv_decode(&u, &v, *luv&0x3fff) < 0) {
  974. u = U_NEU;
  975. v = V_NEU;
  976. }
  977. *luv3++ = (int16)(u * (1L<<15));
  978. *luv3++ = (int16)(v * (1L<<15));
  979. luv++;
  980. }
  981. }
  982. static void
  983. Luv24toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
  984. {
  985. uint32* luv = (uint32*) sp->tbuf;
  986. uint8* rgb = (uint8*) op;
  987. while (n-- > 0) {
  988. float xyz[3];
  989. LogLuv24toXYZ(*luv++, xyz);
  990. XYZtoRGB24(xyz, rgb);
  991. rgb += 3;
  992. }
  993. }
  994. static void
  995. Luv24fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
  996. {
  997. uint32* luv = (uint32*) sp->tbuf;
  998. float* xyz = (float*) op;
  999. while (n-- > 0) {
  1000. *luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth);
  1001. xyz += 3;
  1002. }
  1003. }
  1004. static void
  1005. Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
  1006. {
  1007. uint32* luv = (uint32*) sp->tbuf;
  1008. int16* luv3 = (int16*) op;
  1009. while (n-- > 0) {
  1010. int Le, Ce;
  1011. if (luv3[0] <= 0)
  1012. Le = 0;
  1013. else if (luv3[0] >= (1<<12)+3314)
  1014. Le = (1<<10) - 1;
  1015. else if (sp->encode_meth == SGILOGENCODE_NODITHER)
  1016. Le = (luv3[0]-3314) >> 2;
  1017. else
  1018. Le = tiff_itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
  1019. Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15),
  1020. sp->encode_meth);
  1021. if (Ce < 0) /* never happens */
  1022. Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
  1023. *luv++ = (uint32)Le << 14 | Ce;
  1024. luv3 += 3;
  1025. }
  1026. }
  1027. #if !LOGLUV_PUBLIC
  1028. static
  1029. #endif
  1030. void
  1031. LogLuv32toXYZ(uint32 p, float XYZ[3])
  1032. {
  1033. double L, u, v, s, x, y;
  1034. /* decode luminance */
  1035. L = LogL16toY((int)p >> 16);
  1036. if (L <= 0.) {
  1037. XYZ[0] = XYZ[1] = XYZ[2] = 0.;
  1038. return;
  1039. }
  1040. /* decode color */
  1041. u = 1./UVSCALE * ((p>>8 & 0xff) + .5);
  1042. v = 1./UVSCALE * ((p & 0xff) + .5);
  1043. s = 1./(6.*u - 16.*v + 12.);
  1044. x = 9.*u * s;
  1045. y = 4.*v * s;
  1046. /* convert to XYZ */
  1047. XYZ[0] = (float)(x/y * L);
  1048. XYZ[1] = (float)L;
  1049. XYZ[2] = (float)((1.-x-y)/y * L);
  1050. }
  1051. #if !LOGLUV_PUBLIC
  1052. static
  1053. #endif
  1054. uint32
  1055. LogLuv32fromXYZ(float XYZ[3], int em)
  1056. {
  1057. unsigned int Le, ue, ve;
  1058. double u, v, s;
  1059. /* encode luminance */
  1060. Le = (unsigned int)LogL16fromY(XYZ[1], em);
  1061. /* encode color */
  1062. s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
  1063. if (!Le || s <= 0.) {
  1064. u = U_NEU;
  1065. v = V_NEU;
  1066. } else {
  1067. u = 4.*XYZ[0] / s;
  1068. v = 9.*XYZ[1] / s;
  1069. }
  1070. if (u <= 0.) ue = 0;
  1071. else ue = tiff_itrunc(UVSCALE*u, em);
  1072. if (ue > 255) ue = 255;
  1073. if (v <= 0.) ve = 0;
  1074. else ve = tiff_itrunc(UVSCALE*v, em);
  1075. if (ve > 255) ve = 255;
  1076. /* combine encodings */
  1077. return (Le << 16 | ue << 8 | ve);
  1078. }
  1079. static void
  1080. Luv32toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
  1081. {
  1082. uint32* luv = (uint32*) sp->tbuf;
  1083. float* xyz = (float*) op;
  1084. while (n-- > 0) {
  1085. LogLuv32toXYZ(*luv++, xyz);
  1086. xyz += 3;
  1087. }
  1088. }
  1089. static void
  1090. Luv32toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
  1091. {
  1092. uint32* luv = (uint32*) sp->tbuf;
  1093. int16* luv3 = (int16*) op;
  1094. while (n-- > 0) {
  1095. double u, v;
  1096. *luv3++ = (int16)(*luv >> 16);
  1097. u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5);
  1098. v = 1./UVSCALE * ((*luv & 0xff) + .5);
  1099. *luv3++ = (int16)(u * (1L<<15));
  1100. *luv3++ = (int16)(v * (1L<<15));
  1101. luv++;
  1102. }
  1103. }
  1104. static void
  1105. Luv32toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
  1106. {
  1107. uint32* luv = (uint32*) sp->tbuf;
  1108. uint8* rgb = (uint8*) op;
  1109. while (n-- > 0) {
  1110. float xyz[3];
  1111. LogLuv32toXYZ(*luv++, xyz);
  1112. XYZtoRGB24(xyz, rgb);
  1113. rgb += 3;
  1114. }
  1115. }
  1116. static void
  1117. Luv32fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
  1118. {
  1119. uint32* luv = (uint32*) sp->tbuf;
  1120. float* xyz = (float*) op;
  1121. while (n-- > 0) {
  1122. *luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth);
  1123. xyz += 3;
  1124. }
  1125. }
  1126. static void
  1127. Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
  1128. {
  1129. uint32* luv = (uint32*) sp->tbuf;
  1130. int16* luv3 = (int16*) op;
  1131. if (sp->encode_meth == SGILOGENCODE_NODITHER) {
  1132. while (n-- > 0) {
  1133. *luv++ = (uint32)luv3[0] << 16 |
  1134. (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
  1135. (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
  1136. luv3 += 3;
  1137. }
  1138. return;
  1139. }
  1140. while (n-- > 0) {
  1141. *luv++ = (uint32)luv3[0] << 16 |
  1142. (tiff_itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
  1143. (tiff_itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
  1144. luv3 += 3;
  1145. }
  1146. }
  1147. static void
  1148. _logLuvNop(LogLuvState* sp, uint8* op, tmsize_t n)
  1149. {
  1150. (void) sp; (void) op; (void) n;
  1151. }
  1152. static int
  1153. LogL16GuessDataFmt(TIFFDirectory *td)
  1154. {
  1155. #define PACK(s,b,f) (((b)<<6)|((s)<<3)|(f))
  1156. switch (PACK(td->td_samplesperpixel, td->td_bitspersample, td->td_sampleformat)) {
  1157. case PACK(1, 32, SAMPLEFORMAT_IEEEFP):
  1158. return (SGILOGDATAFMT_FLOAT);
  1159. case PACK(1, 16, SAMPLEFORMAT_VOID):
  1160. case PACK(1, 16, SAMPLEFORMAT_INT):
  1161. case PACK(1, 16, SAMPLEFORMAT_UINT):
  1162. return (SGILOGDATAFMT_16BIT);
  1163. case PACK(1, 8, SAMPLEFORMAT_VOID):
  1164. case PACK(1, 8, SAMPLEFORMAT_UINT):
  1165. return (SGILOGDATAFMT_8BIT);
  1166. }
  1167. #undef PACK
  1168. return (SGILOGDATAFMT_UNKNOWN);
  1169. }
  1170. static tmsize_t
  1171. multiply_ms(tmsize_t m1, tmsize_t m2)
  1172. {
  1173. return _TIFFMultiplySSize(NULL, m1, m2, NULL);
  1174. }
  1175. static int
  1176. LogL16InitState(TIFF* tif)
  1177. {
  1178. static const char module[] = "LogL16InitState";
  1179. TIFFDirectory *td = &tif->tif_dir;
  1180. LogLuvState* sp = DecoderState(tif);
  1181. assert(sp != NULL);
  1182. assert(td->td_photometric == PHOTOMETRIC_LOGL);
  1183. if( td->td_samplesperpixel != 1 )
  1184. {
  1185. TIFFErrorExt(tif->tif_clientdata, module,
  1186. "Sorry, can not handle LogL image with %s=%d",
  1187. "Samples/pixel", td->td_samplesperpixel);
  1188. return 0;
  1189. }
  1190. /* for some reason, we can't do this in TIFFInitLogL16 */
  1191. if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
  1192. sp->user_datafmt = LogL16GuessDataFmt(td);
  1193. switch (sp->user_datafmt) {
  1194. case SGILOGDATAFMT_FLOAT:
  1195. sp->pixel_size = sizeof (float);
  1196. break;
  1197. case SGILOGDATAFMT_16BIT:
  1198. sp->pixel_size = sizeof (int16);
  1199. break;
  1200. case SGILOGDATAFMT_8BIT:
  1201. sp->pixel_size = sizeof (uint8);
  1202. break;
  1203. default:
  1204. TIFFErrorExt(tif->tif_clientdata, module,
  1205. "No support for converting user data format to LogL");
  1206. return (0);
  1207. }
  1208. if( isTiled(tif) )
  1209. sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength);
  1210. else if( td->td_rowsperstrip < td->td_imagelength )
  1211. sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
  1212. else
  1213. sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_imagelength);
  1214. if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 ||
  1215. (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
  1216. TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
  1217. return (0);
  1218. }
  1219. return (1);
  1220. }
  1221. static int
  1222. LogLuvGuessDataFmt(TIFFDirectory *td)
  1223. {
  1224. int guess;
  1225. /*
  1226. * If the user didn't tell us their datafmt,
  1227. * take our best guess from the bitspersample.
  1228. */
  1229. #define PACK(a,b) (((a)<<3)|(b))
  1230. switch (PACK(td->td_bitspersample, td->td_sampleformat)) {
  1231. case PACK(32, SAMPLEFORMAT_IEEEFP):
  1232. guess = SGILOGDATAFMT_FLOAT;
  1233. break;
  1234. case PACK(32, SAMPLEFORMAT_VOID):
  1235. case PACK(32, SAMPLEFORMAT_UINT):
  1236. case PACK(32, SAMPLEFORMAT_INT):
  1237. guess = SGILOGDATAFMT_RAW;
  1238. break;
  1239. case PACK(16, SAMPLEFORMAT_VOID):
  1240. case PACK(16, SAMPLEFORMAT_INT):
  1241. case PACK(16, SAMPLEFORMAT_UINT):
  1242. guess = SGILOGDATAFMT_16BIT;
  1243. break;
  1244. case PACK( 8, SAMPLEFORMAT_VOID):
  1245. case PACK( 8, SAMPLEFORMAT_UINT):
  1246. guess = SGILOGDATAFMT_8BIT;
  1247. break;
  1248. default:
  1249. guess = SGILOGDATAFMT_UNKNOWN;
  1250. break;
  1251. #undef PACK
  1252. }
  1253. /*
  1254. * Double-check samples per pixel.
  1255. */
  1256. switch (td->td_samplesperpixel) {
  1257. case 1:
  1258. if (guess != SGILOGDATAFMT_RAW)
  1259. guess = SGILOGDATAFMT_UNKNOWN;
  1260. break;
  1261. case 3:
  1262. if (guess == SGILOGDATAFMT_RAW)
  1263. guess = SGILOGDATAFMT_UNKNOWN;
  1264. break;
  1265. default:
  1266. guess = SGILOGDATAFMT_UNKNOWN;
  1267. break;
  1268. }
  1269. return (guess);
  1270. }
  1271. static int
  1272. LogLuvInitState(TIFF* tif)
  1273. {
  1274. static const char module[] = "LogLuvInitState";
  1275. TIFFDirectory* td = &tif->tif_dir;
  1276. LogLuvState* sp = DecoderState(tif);
  1277. assert(sp != NULL);
  1278. assert(td->td_photometric == PHOTOMETRIC_LOGLUV);
  1279. /* for some reason, we can't do this in TIFFInitLogLuv */
  1280. if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
  1281. TIFFErrorExt(tif->tif_clientdata, module,
  1282. "SGILog compression cannot handle non-contiguous data");
  1283. return (0);
  1284. }
  1285. if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
  1286. sp->user_datafmt = LogLuvGuessDataFmt(td);
  1287. switch (sp->user_datafmt) {
  1288. case SGILOGDATAFMT_FLOAT:
  1289. sp->pixel_size = 3*sizeof (float);
  1290. break;
  1291. case SGILOGDATAFMT_16BIT:
  1292. sp->pixel_size = 3*sizeof (int16);
  1293. break;
  1294. case SGILOGDATAFMT_RAW:
  1295. sp->pixel_size = sizeof (uint32);
  1296. break;
  1297. case SGILOGDATAFMT_8BIT:
  1298. sp->pixel_size = 3*sizeof (uint8);
  1299. break;
  1300. default:
  1301. TIFFErrorExt(tif->tif_clientdata, module,
  1302. "No support for converting user data format to LogLuv");
  1303. return (0);
  1304. }
  1305. if( isTiled(tif) )
  1306. sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength);
  1307. else if( td->td_rowsperstrip < td->td_imagelength )
  1308. sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
  1309. else
  1310. sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_imagelength);
  1311. if (multiply_ms(sp->tbuflen, sizeof (uint32)) == 0 ||
  1312. (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
  1313. TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
  1314. return (0);
  1315. }
  1316. return (1);
  1317. }
  1318. static int
  1319. LogLuvFixupTags(TIFF* tif)
  1320. {
  1321. (void) tif;
  1322. return (1);
  1323. }
  1324. static int
  1325. LogLuvSetupDecode(TIFF* tif)
  1326. {
  1327. static const char module[] = "LogLuvSetupDecode";
  1328. LogLuvState* sp = DecoderState(tif);
  1329. TIFFDirectory* td = &tif->tif_dir;
  1330. tif->tif_postdecode = _TIFFNoPostDecode;
  1331. switch (td->td_photometric) {
  1332. case PHOTOMETRIC_LOGLUV:
  1333. if (!LogLuvInitState(tif))
  1334. break;
  1335. if (td->td_compression == COMPRESSION_SGILOG24) {
  1336. tif->tif_decoderow = LogLuvDecode24;
  1337. switch (sp->user_datafmt) {
  1338. case SGILOGDATAFMT_FLOAT:
  1339. sp->tfunc = Luv24toXYZ;
  1340. break;
  1341. case SGILOGDATAFMT_16BIT:
  1342. sp->tfunc = Luv24toLuv48;
  1343. break;
  1344. case SGILOGDATAFMT_8BIT:
  1345. sp->tfunc = Luv24toRGB;
  1346. break;
  1347. }
  1348. } else {
  1349. tif->tif_decoderow = LogLuvDecode32;
  1350. switch (sp->user_datafmt) {
  1351. case SGILOGDATAFMT_FLOAT:
  1352. sp->tfunc = Luv32toXYZ;
  1353. break;
  1354. case SGILOGDATAFMT_16BIT:
  1355. sp->tfunc = Luv32toLuv48;
  1356. break;
  1357. case SGILOGDATAFMT_8BIT:
  1358. sp->tfunc = Luv32toRGB;
  1359. break;
  1360. }
  1361. }
  1362. return (1);
  1363. case PHOTOMETRIC_LOGL:
  1364. if (!LogL16InitState(tif))
  1365. break;
  1366. tif->tif_decoderow = LogL16Decode;
  1367. switch (sp->user_datafmt) {
  1368. case SGILOGDATAFMT_FLOAT:
  1369. sp->tfunc = L16toY;
  1370. break;
  1371. case SGILOGDATAFMT_8BIT:
  1372. sp->tfunc = L16toGry;
  1373. break;
  1374. }
  1375. return (1);
  1376. default:
  1377. TIFFErrorExt(tif->tif_clientdata, module,
  1378. "Inappropriate photometric interpretation %d for SGILog compression; %s",
  1379. td->td_photometric, "must be either LogLUV or LogL");
  1380. break;
  1381. }
  1382. return (0);
  1383. }
  1384. static int
  1385. LogLuvSetupEncode(TIFF* tif)
  1386. {
  1387. static const char module[] = "LogLuvSetupEncode";
  1388. LogLuvState* sp = EncoderState(tif);
  1389. TIFFDirectory* td = &tif->tif_dir;
  1390. switch (td->td_photometric) {
  1391. case PHOTOMETRIC_LOGLUV:
  1392. if (!LogLuvInitState(tif))
  1393. return (0);
  1394. if (td->td_compression == COMPRESSION_SGILOG24) {
  1395. tif->tif_encoderow = LogLuvEncode24;
  1396. switch (sp->user_datafmt) {
  1397. case SGILOGDATAFMT_FLOAT:
  1398. sp->tfunc = Luv24fromXYZ;
  1399. break;
  1400. case SGILOGDATAFMT_16BIT:
  1401. sp->tfunc = Luv24fromLuv48;
  1402. break;
  1403. case SGILOGDATAFMT_RAW:
  1404. break;
  1405. default:
  1406. goto notsupported;
  1407. }
  1408. } else {
  1409. tif->tif_encoderow = LogLuvEncode32;
  1410. switch (sp->user_datafmt) {
  1411. case SGILOGDATAFMT_FLOAT:
  1412. sp->tfunc = Luv32fromXYZ;
  1413. break;
  1414. case SGILOGDATAFMT_16BIT:
  1415. sp->tfunc = Luv32fromLuv48;
  1416. break;
  1417. case SGILOGDATAFMT_RAW:
  1418. break;
  1419. default:
  1420. goto notsupported;
  1421. }
  1422. }
  1423. break;
  1424. case PHOTOMETRIC_LOGL:
  1425. if (!LogL16InitState(tif))
  1426. return (0);
  1427. tif->tif_encoderow = LogL16Encode;
  1428. switch (sp->user_datafmt) {
  1429. case SGILOGDATAFMT_FLOAT:
  1430. sp->tfunc = L16fromY;
  1431. break;
  1432. case SGILOGDATAFMT_16BIT:
  1433. break;
  1434. default:
  1435. goto notsupported;
  1436. }
  1437. break;
  1438. default:
  1439. TIFFErrorExt(tif->tif_clientdata, module,
  1440. "Inappropriate photometric interpretation %d for SGILog compression; %s",
  1441. td->td_photometric, "must be either LogLUV or LogL");
  1442. return (0);
  1443. }
  1444. sp->encoder_state = 1;
  1445. return (1);
  1446. notsupported:
  1447. TIFFErrorExt(tif->tif_clientdata, module,
  1448. "SGILog compression supported only for %s, or raw data",
  1449. td->td_photometric == PHOTOMETRIC_LOGL ? "Y, L" : "XYZ, Luv");
  1450. return (0);
  1451. }
  1452. static void
  1453. LogLuvClose(TIFF* tif)
  1454. {
  1455. LogLuvState* sp = (LogLuvState*) tif->tif_data;
  1456. TIFFDirectory *td = &tif->tif_dir;
  1457. assert(sp != 0);
  1458. /*
  1459. * For consistency, we always want to write out the same
  1460. * bitspersample and sampleformat for our TIFF file,
  1461. * regardless of the data format being used by the application.
  1462. * Since this routine is called after tags have been set but
  1463. * before they have been recorded in the file, we reset them here.
  1464. * Note: this is really a nasty approach. See PixarLogClose
  1465. */
  1466. if( sp->encoder_state )
  1467. {
  1468. /* See PixarLogClose. Might avoid issues with tags whose size depends
  1469. * on those below, but not completely sure this is enough. */
  1470. td->td_samplesperpixel =
  1471. (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3;
  1472. td->td_bitspersample = 16;
  1473. td->td_sampleformat = SAMPLEFORMAT_INT;
  1474. }
  1475. }
  1476. static void
  1477. LogLuvCleanup(TIFF* tif)
  1478. {
  1479. LogLuvState* sp = (LogLuvState *)tif->tif_data;
  1480. assert(sp != 0);
  1481. tif->tif_tagmethods.vgetfield = sp->vgetparent;
  1482. tif->tif_tagmethods.vsetfield = sp->vsetparent;
  1483. if (sp->tbuf)
  1484. _TIFFfree(sp->tbuf);
  1485. _TIFFfree(sp);
  1486. tif->tif_data = NULL;
  1487. _TIFFSetDefaultCompressionState(tif);
  1488. }
  1489. static int
  1490. LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap)
  1491. {
  1492. static const char module[] = "LogLuvVSetField";
  1493. LogLuvState* sp = DecoderState(tif);
  1494. int bps, fmt;
  1495. switch (tag) {
  1496. case TIFFTAG_SGILOGDATAFMT:
  1497. sp->user_datafmt = (int) va_arg(ap, int);
  1498. /*
  1499. * Tweak the TIFF header so that the rest of libtiff knows what
  1500. * size of data will be passed between app and library, and
  1501. * assume that the app knows what it is doing and is not
  1502. * confused by these header manipulations...
  1503. */
  1504. switch (sp->user_datafmt) {
  1505. case SGILOGDATAFMT_FLOAT:
  1506. bps = 32;
  1507. fmt = SAMPLEFORMAT_IEEEFP;
  1508. break;
  1509. case SGILOGDATAFMT_16BIT:
  1510. bps = 16;
  1511. fmt = SAMPLEFORMAT_INT;
  1512. break;
  1513. case SGILOGDATAFMT_RAW:
  1514. bps = 32;
  1515. fmt = SAMPLEFORMAT_UINT;
  1516. TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
  1517. break;
  1518. case SGILOGDATAFMT_8BIT:
  1519. bps = 8;
  1520. fmt = SAMPLEFORMAT_UINT;
  1521. break;
  1522. default:
  1523. TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
  1524. "Unknown data format %d for LogLuv compression",
  1525. sp->user_datafmt);
  1526. return (0);
  1527. }
  1528. TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
  1529. TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, fmt);
  1530. /*
  1531. * Must recalculate sizes should bits/sample change.
  1532. */
  1533. tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t) -1;
  1534. tif->tif_scanlinesize = TIFFScanlineSize(tif);
  1535. return (1);
  1536. case TIFFTAG_SGILOGENCODE:
  1537. sp->encode_meth = (int) va_arg(ap, int);
  1538. if (sp->encode_meth != SGILOGENCODE_NODITHER &&
  1539. sp->encode_meth != SGILOGENCODE_RANDITHER) {
  1540. TIFFErrorExt(tif->tif_clientdata, module,
  1541. "Unknown encoding %d for LogLuv compression",
  1542. sp->encode_meth);
  1543. return (0);
  1544. }
  1545. return (1);
  1546. default:
  1547. return (*sp->vsetparent)(tif, tag, ap);
  1548. }
  1549. }
  1550. static int
  1551. LogLuvVGetField(TIFF* tif, uint32 tag, va_list ap)
  1552. {
  1553. LogLuvState *sp = (LogLuvState *)tif->tif_data;
  1554. switch (tag) {
  1555. case TIFFTAG_SGILOGDATAFMT:
  1556. *va_arg(ap, int*) = sp->user_datafmt;
  1557. return (1);
  1558. default:
  1559. return (*sp->vgetparent)(tif, tag, ap);
  1560. }
  1561. }
  1562. static const TIFFField LogLuvFields[] = {
  1563. { TIFFTAG_SGILOGDATAFMT, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogDataFmt", NULL},
  1564. { TIFFTAG_SGILOGENCODE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogEncode", NULL}
  1565. };
  1566. int
  1567. TIFFInitSGILog(TIFF* tif, int scheme)
  1568. {
  1569. static const char module[] = "TIFFInitSGILog";
  1570. LogLuvState* sp;
  1571. assert(scheme == COMPRESSION_SGILOG24 || scheme == COMPRESSION_SGILOG);
  1572. /*
  1573. * Merge codec-specific tag information.
  1574. */
  1575. if (!_TIFFMergeFields(tif, LogLuvFields,
  1576. TIFFArrayCount(LogLuvFields))) {
  1577. TIFFErrorExt(tif->tif_clientdata, module,
  1578. "Merging SGILog codec-specific tags failed");
  1579. return 0;
  1580. }
  1581. /*
  1582. * Allocate state block so tag methods have storage to record values.
  1583. */
  1584. tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LogLuvState));
  1585. if (tif->tif_data == NULL)
  1586. goto bad;
  1587. sp = (LogLuvState*) tif->tif_data;
  1588. _TIFFmemset((void*)sp, 0, sizeof (*sp));
  1589. sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
  1590. sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ?
  1591. SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
  1592. sp->tfunc = _logLuvNop;
  1593. /*
  1594. * Install codec methods.
  1595. * NB: tif_decoderow & tif_encoderow are filled
  1596. * in at setup time.
  1597. */
  1598. tif->tif_fixuptags = LogLuvFixupTags;
  1599. tif->tif_setupdecode = LogLuvSetupDecode;
  1600. tif->tif_decodestrip = LogLuvDecodeStrip;
  1601. tif->tif_decodetile = LogLuvDecodeTile;
  1602. tif->tif_setupencode = LogLuvSetupEncode;
  1603. tif->tif_encodestrip = LogLuvEncodeStrip;
  1604. tif->tif_encodetile = LogLuvEncodeTile;
  1605. tif->tif_close = LogLuvClose;
  1606. tif->tif_cleanup = LogLuvCleanup;
  1607. /*
  1608. * Override parent get/set field methods.
  1609. */
  1610. sp->vgetparent = tif->tif_tagmethods.vgetfield;
  1611. tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */
  1612. sp->vsetparent = tif->tif_tagmethods.vsetfield;
  1613. tif->tif_tagmethods.vsetfield = LogLuvVSetField; /* hook for codec tags */
  1614. return (1);
  1615. bad:
  1616. TIFFErrorExt(tif->tif_clientdata, module,
  1617. "%s: No space for LogLuv state block", tif->tif_name);
  1618. return (0);
  1619. }
  1620. #endif /* LOGLUV_SUPPORT */
  1621. /* vim: set ts=8 sts=8 sw=8 noet: */
  1622. /*
  1623. * Local Variables:
  1624. * mode: c
  1625. * c-basic-offset: 8
  1626. * fill-column: 78
  1627. * End:
  1628. */