tif_luv.c 44 KB

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