~ubuntu-branches/ubuntu/oneiric/imagemagick/oneiric-updates

« back to all changes in this revision

Viewing changes to coders/txt.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-06-15 11:05:28 UTC
  • mfrom: (6.2.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110615110528-08jgo07a4846xh8d
Tags: 8:6.6.0.4-3ubuntu1
* Resynchronise with Debian (LP: #797595).  Remaining changes:
  - Make ufraw-batch (universe) a suggestion instead of a recommendation.
  - Make debian/rules install target depend on check; they cannot reliably
    be run in parallel.
  - Don't set MAKEFLAGS in debian/rules; just pass it to the build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
  Image
171
171
    *texture;
172
172
 
173
 
  ssize_t
 
173
  long
174
174
    offset;
175
175
 
176
176
  MagickBooleanType
223
223
  /*
224
224
    Initialize Image structure.
225
225
  */
226
 
  image->columns=(size_t) floor((((double) page.width*
227
 
    image->x_resolution)/delta.x)+0.5);
228
 
  image->rows=(size_t) floor((((double) page.height*
229
 
    image->y_resolution)/delta.y)+0.5);
 
226
  image->columns=(unsigned long) (((page.width*image->x_resolution)/
 
227
    delta.x)+0.5);
 
228
  image->rows=(unsigned long) (((page.height*image->y_resolution)/delta.y)+0.5);
230
229
  image->page.x=0;
231
230
  image->page.y=0;
232
231
  texture=(Image *) NULL;
248
247
  (void) SetImageBackgroundColor(image);
249
248
  draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
250
249
  (void) CloneString(&draw_info->text,image_info->filename);
251
 
  (void) FormatMagickString(geometry,MaxTextExtent,"0x0%+ld%+ld",(long) page.x,
252
 
    (long) page.y);
 
250
  (void) FormatMagickString(geometry,MaxTextExtent,"0x0%+ld%+ld",page.x,page.y);
253
251
  (void) CloneString(&draw_info->geometry,geometry);
254
252
  status=GetTypeMetrics(image,draw_info,&metrics);
255
253
  if (status == MagickFalse)
256
254
    ThrowReaderException(TypeError,"UnableToGetTypeMetrics");
257
 
  page.y=(ssize_t) ceil((double) page.y+metrics.ascent-0.5);
258
 
  (void) FormatMagickString(geometry,MaxTextExtent,"0x0%+ld%+ld",(long) page.x,
259
 
    (long) page.y);
 
255
  page.y=(long) (page.y+metrics.ascent+0.5);
 
256
  (void) FormatMagickString(geometry,MaxTextExtent,"0x0%+ld%+ld",page.x,page.y);
260
257
  (void) CloneString(&draw_info->geometry,geometry);
261
258
  (void) CopyMagickString(filename,image_info->filename,MaxTextExtent);
262
259
  if (*draw_info->text != '\0')
269
266
    */
270
267
    (void) ConcatenateString(&draw_info->text,text);
271
268
    (void) ConcatenateString(&draw_info->text,"\n");
272
 
    offset+=(ssize_t) (metrics.ascent-metrics.descent);
 
269
    offset+=(long) (metrics.ascent-metrics.descent);
273
270
    if (image->previous == (Image *) NULL)
274
271
      {
275
272
        status=SetImageProgress(image,LoadImageTag,offset,image->rows);
277
274
          break;
278
275
      }
279
276
    p=ReadBlobString(image,text);
280
 
    if ((offset < (ssize_t) image->rows) && (p != (char *) NULL))
 
277
    if ((offset < (long) image->rows) && (p != (char *) NULL))
281
278
      continue;
282
279
    if (texture != (Image *) NULL)
283
280
      {
372
369
 
373
370
  long
374
371
    type,
375
 
    x_offset,
376
 
    y,
377
 
    y_offset;
 
372
    x,
 
373
    y;
378
374
 
379
375
  LongPixelPacket
380
376
    pixel;
385
381
  QuantumAny
386
382
    range;
387
383
 
388
 
  register ssize_t
389
 
    i,
390
 
    x;
 
384
  register long
 
385
    i;
391
386
 
392
387
  register PixelPacket
393
388
    *q;
397
392
 
398
393
  unsigned long
399
394
    depth,
400
 
    height,
401
 
    max_value,
402
 
    width;
 
395
    max_value;
403
396
 
404
397
  /*
405
398
    Open image file.
422
415
  (void) ReadBlobString(image,text);
423
416
  if (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) != 0)
424
417
    return(ReadTEXTImage(image_info,image,text,exception));
425
 
  do
 
418
  *colorspace='\0';
 
419
  count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%s",&image->columns,
 
420
    &image->rows,&max_value,colorspace);
 
421
  if (count != 4)
 
422
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
 
423
  for (depth=1; (GetQuantumRange(depth)+1) < max_value; depth++) ;
 
424
  image->depth=depth;
 
425
  LocaleLower(colorspace);
 
426
  i=(long) strlen(colorspace)-1;
 
427
  image->matte=MagickFalse;
 
428
  if ((i > 0) && (colorspace[i] == 'a'))
 
429
    {
 
430
      colorspace[i]='\0';
 
431
      image->matte=MagickTrue;
 
432
    }
 
433
  type=ParseMagickOption(MagickColorspaceOptions,MagickFalse,colorspace);
 
434
  if (type < 0)
 
435
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
 
436
  image->colorspace=(ColorspaceType) type;
 
437
  (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
 
438
  (void) SetImageBackgroundColor(image);
 
439
  range=GetQuantumRange(image->depth);
 
440
  while (ReadBlobString(image,text) != (char *) NULL)
426
441
  {
427
 
    *colorspace='\0';
428
 
    count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%s",&width,&height,&max_value,
429
 
      colorspace);
430
 
    if (count != 4)
431
 
      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
432
 
    image->columns=width;
433
 
    image->rows=height;
434
 
    for (depth=1; (GetQuantumRange(depth)+1) < max_value; depth++) ;
435
 
    image->depth=depth;
436
 
    LocaleLower(colorspace);
437
 
    i=(ssize_t) strlen(colorspace)-1;
438
 
    image->matte=MagickFalse;
439
 
    if ((i > 0) && (colorspace[i] == 'a'))
440
 
      {
441
 
        colorspace[i]='\0';
442
 
        image->matte=MagickTrue;
443
 
      }
444
 
    type=ParseMagickOption(MagickColorspaceOptions,MagickFalse,colorspace);
445
 
    if (type < 0)
446
 
      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
447
 
    image->colorspace=(ColorspaceType) type;
448
 
    (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
449
 
    (void) SetImageBackgroundColor(image);
450
 
    range=GetQuantumRange(image->depth);
451
 
    for (y=0; y < (ssize_t) image->rows; y++)
452
 
    {
453
 
      for (x=0; x < (ssize_t) image->columns; x++)
454
 
      {
455
 
        if (ReadBlobString(image,text) == (char *) NULL)
456
 
          break;
457
 
        if (image->colorspace == CMYKColorspace)
458
 
          {
459
 
            if (image->matte != MagickFalse)
460
 
              count=(ssize_t) sscanf(text,"%ld,%ld: (%u,%u,%u,%u,%u",&x_offset,
461
 
                &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.index,
462
 
                &pixel.opacity);
463
 
            else
464
 
              count=(ssize_t) sscanf(text,"%ld,%ld: (%u,%u,%u,%u",&x_offset,
465
 
                &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.index);
466
 
          }
 
442
    if (image->colorspace == CMYKColorspace)
 
443
      {
 
444
        if (image->matte != MagickFalse)
 
445
          count=(ssize_t) sscanf(text,"%ld,%ld: (%lu,%lu,%lu,%lu,%lu",&x,&y,
 
446
            &pixel.red,&pixel.green,&pixel.blue,&pixel.index,&pixel.opacity);
467
447
        else
468
 
          if (image->matte != MagickFalse)
469
 
            count=(ssize_t) sscanf(text,"%ld,%ld: (%u,%u,%u,%u",&x_offset,
470
 
              &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.opacity);
471
 
          else
472
 
            count=(ssize_t) sscanf(text,"%ld,%ld: (%u,%u,%u",&x_offset,
473
 
              &y_offset,&pixel.red,&pixel.green,&pixel.blue);
474
 
        if (count < 5)
475
 
          continue;
476
 
        q=GetAuthenticPixels(image,x_offset,y_offset,1,1,exception);
477
 
        if (q == (PixelPacket *) NULL)
478
 
          continue;
479
 
        q->red=ScaleAnyToQuantum(pixel.red,range);
480
 
        q->green=ScaleAnyToQuantum(pixel.green,range);
481
 
        q->blue=ScaleAnyToQuantum(pixel.blue,range);
482
 
        if (image->colorspace == CMYKColorspace)
483
 
          {
484
 
            indexes=GetAuthenticIndexQueue(image);
485
 
            *indexes=ScaleAnyToQuantum(pixel.index,range);
486
 
          }
487
 
        if (image->matte != MagickFalse)
488
 
          q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel.opacity,
489
 
            range));
490
 
        if (SyncAuthenticPixels(image,exception) == MagickFalse)
491
 
          break;
 
448
          count=(ssize_t) sscanf(text,"%ld,%ld: (%lu,%lu,%lu,%lu",&x,&y,
 
449
            &pixel.red,&pixel.green,&pixel.blue,&pixel.index);
492
450
      }
493
 
    }
494
 
    (void) ReadBlobString(image,text);
495
 
    if (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) == 0)
 
451
    else
 
452
      if (image->matte != MagickFalse)
 
453
        count=(ssize_t) sscanf(text,"%ld,%ld: (%lu,%lu,%lu,%lu",&x,&y,
 
454
          &pixel.red,&pixel.green,&pixel.blue,&pixel.opacity);
 
455
      else
 
456
        count=(ssize_t) sscanf(text,"%ld,%ld: (%lu,%lu,%lu",&x,&y,
 
457
          &pixel.red,&pixel.green,&pixel.blue);
 
458
    if (count < 5)
 
459
      continue;
 
460
    q=GetAuthenticPixels(image,x,y,1,1,exception);
 
461
    if (q == (PixelPacket *) NULL)
 
462
      continue;
 
463
    q->red=ScaleAnyToQuantum(pixel.red,range);
 
464
    q->green=ScaleAnyToQuantum(pixel.green,range);
 
465
    q->blue=ScaleAnyToQuantum(pixel.blue,range);
 
466
    if (image->colorspace == CMYKColorspace)
496
467
      {
497
 
        /*
498
 
          Allocate next image structure.
499
 
        */
500
 
        AcquireNextImage(image_info,image);
501
 
        if (GetNextImageInList(image) == (Image *) NULL)
502
 
          {
503
 
            image=DestroyImageList(image);
504
 
            return((Image *) NULL);
505
 
          }
506
 
        image=SyncNextImageInList(image);
507
 
        status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
508
 
          GetBlobSize(image));
509
 
        if (status == MagickFalse)
510
 
          break;
 
468
        indexes=GetAuthenticIndexQueue(image);
 
469
        *indexes=ScaleAnyToQuantum(pixel.index,range);
511
470
      }
512
 
  } while (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) == 0);
513
 
  (void) CloseBlob(image);
 
471
    if (image->matte != MagickFalse)
 
472
      q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel.opacity,
 
473
        range));
 
474
    if (SyncAuthenticPixels(image,exception) == MagickFalse)
 
475
      break;
 
476
  }
514
477
  return(GetFirstImageInList(image));
515
478
}
516
479
 
534
497
%
535
498
%  The format of the RegisterTXTImage method is:
536
499
%
537
 
%      size_t RegisterTXTImage(void)
 
500
%      unsigned long RegisterTXTImage(void)
538
501
%
539
502
*/
540
 
ModuleExport size_t RegisterTXTImage(void)
 
503
ModuleExport unsigned long RegisterTXTImage(void)
541
504
{
542
505
  MagickInfo
543
506
    *entry;
546
509
  entry->decoder=(DecodeImageHandler *) ReadTXTImage;
547
510
  entry->encoder=(EncodeImageHandler *) WriteTXTImage;
548
511
  entry->raw=MagickTrue;
 
512
  entry->adjoin=MagickFalse;
549
513
  entry->endian_support=MagickTrue;
550
514
  entry->description=ConstantString("Text");
551
515
  entry->module=ConstantString("TXT");
553
517
  entry=SetMagickInfo("TXT");
554
518
  entry->decoder=(DecodeImageHandler *) ReadTXTImage;
555
519
  entry->encoder=(EncodeImageHandler *) WriteTXTImage;
 
520
  entry->adjoin=MagickFalse;
556
521
  entry->description=ConstantString("Text");
557
522
  entry->magick=(IsImageFormatHandler *) IsTXT;
558
523
  entry->module=ConstantString("TXT");
616
581
    colorspace[MaxTextExtent],
617
582
    tuple[MaxTextExtent];
618
583
 
619
 
  ssize_t
 
584
  long
620
585
    y;
621
586
 
622
587
  MagickBooleanType
623
588
    status;
624
589
 
625
 
  MagickOffsetType
626
 
    scene;
627
 
 
628
590
  MagickPixelPacket
629
591
    pixel;
630
592
 
634
596
  register const PixelPacket
635
597
    *p;
636
598
 
637
 
  register ssize_t
 
599
  register long
638
600
    x;
639
601
 
640
602
  /*
649
611
  status=OpenBlob(image_info,image,WriteBlobMode,&image->exception);
650
612
  if (status == MagickFalse)
651
613
    return(status);
652
 
  scene=0;
653
 
  do
 
614
  (void) CopyMagickString(colorspace,MagickOptionToMnemonic(
 
615
    MagickColorspaceOptions,(long) image->colorspace),MaxTextExtent);
 
616
  LocaleLower(colorspace);
 
617
  image->depth=GetImageQuantumDepth(image,MagickTrue);
 
618
  if (image->matte != MagickFalse)
 
619
    (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
 
620
  (void) FormatMagickString(buffer,MaxTextExtent,
 
621
    "# ImageMagick pixel enumeration: %lu,%lu,%lu,%s\n",image->columns,
 
622
    image->rows,(unsigned long) GetQuantumRange(image->depth),colorspace);
 
623
  (void) WriteBlobString(image,buffer);
 
624
  GetMagickPixelPacket(image,&pixel);
 
625
  for (y=0; y < (long) image->rows; y++)
654
626
  {
655
 
    (void) CopyMagickString(colorspace,MagickOptionToMnemonic(
656
 
      MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
657
 
    LocaleLower(colorspace);
658
 
    image->depth=GetImageQuantumDepth(image,MagickTrue);
659
 
    if (image->matte != MagickFalse)
660
 
      (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
661
 
    (void) FormatMagickString(buffer,MaxTextExtent,
662
 
      "# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double)
663
 
      image->columns,(double) image->rows,(double)
664
 
      GetQuantumRange(image->depth),colorspace);
665
 
    (void) WriteBlobString(image,buffer);
666
 
    GetMagickPixelPacket(image,&pixel);
667
 
    for (y=0; y < (ssize_t) image->rows; y++)
 
627
    p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
 
628
    if (p == (const PixelPacket *) NULL)
 
629
      break;
 
630
    indexes=GetVirtualIndexQueue(image);
 
631
    for (x=0; x < (long) image->columns; x++)
668
632
    {
669
 
      p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
670
 
      if (p == (const PixelPacket *) NULL)
671
 
        break;
672
 
      indexes=GetVirtualIndexQueue(image);
673
 
      for (x=0; x < (ssize_t) image->columns; x++)
674
 
      {
675
 
        (void) FormatMagickString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double)
676
 
          x,(double) y);
677
 
        (void) WriteBlobString(image,buffer);
678
 
        SetMagickPixelPacket(image,p,indexes+x,&pixel);
679
 
        (void) CopyMagickString(tuple,"(",MaxTextExtent);
680
 
        ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
681
 
        (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
682
 
        ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
683
 
        (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
684
 
        ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
685
 
        if (pixel.colorspace == CMYKColorspace)
686
 
          {
687
 
            (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
688
 
            ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
689
 
          }
690
 
        if (pixel.matte != MagickFalse)
691
 
          {
692
 
            (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
693
 
            ConcatenateColorComponent(&pixel,AlphaChannel,X11Compliance,tuple);
694
 
          }
695
 
        (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
696
 
        (void) WriteBlobString(image,tuple);
697
 
        (void) WriteBlobString(image,"  ");
698
 
        GetColorTuple(&pixel,MagickTrue,tuple);
699
 
        (void) FormatMagickString(buffer,MaxTextExtent,"%s",tuple);
700
 
        (void) WriteBlobString(image,buffer);
701
 
        (void) WriteBlobString(image,"  ");
702
 
        (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
703
 
          &image->exception);
704
 
        (void) WriteBlobString(image,tuple);
705
 
        (void) WriteBlobString(image,"\n");
706
 
        p++;
707
 
      }
708
 
      status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
709
 
        image->rows);
710
 
      if (status == MagickFalse)
711
 
        break;
 
633
      (void) FormatMagickString(buffer,MaxTextExtent,"%ld,%ld: ",x,y);
 
634
      (void) WriteBlobString(image,buffer);
 
635
      SetMagickPixelPacket(image,p,indexes+x,&pixel);
 
636
      (void) CopyMagickString(tuple,"(",MaxTextExtent);
 
637
      ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
 
638
      (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
 
639
      ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
 
640
      (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
 
641
      ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
 
642
      if (pixel.colorspace == CMYKColorspace)
 
643
        {
 
644
          (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
 
645
          ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
 
646
        }
 
647
      if (pixel.matte != MagickFalse)
 
648
        {
 
649
          (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
 
650
          ConcatenateColorComponent(&pixel,AlphaChannel,X11Compliance,tuple);
 
651
        }
 
652
      (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
 
653
      (void) WriteBlobString(image,tuple);
 
654
      (void) WriteBlobString(image,"  ");
 
655
      GetColorTuple(&pixel,MagickTrue,tuple);
 
656
      (void) FormatMagickString(buffer,MaxTextExtent,"%s",tuple);
 
657
      (void) WriteBlobString(image,buffer);
 
658
      (void) WriteBlobString(image,"  ");
 
659
      (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
 
660
        &image->exception);
 
661
      (void) WriteBlobString(image,tuple);
 
662
      (void) WriteBlobString(image,"\n");
 
663
      p++;
712
664
    }
713
 
    if (GetNextImageInList(image) == (Image *) NULL)
714
 
      break;
715
 
    image=SyncNextImageInList(image);
716
 
    status=SetImageProgress(image,SaveImagesTag,scene++,
717
 
      GetImageListLength(image));
 
665
    status=SetImageProgress(image,SaveImageTag,y,image->rows);
718
666
    if (status == MagickFalse)
719
667
      break;
720
 
  } while (image_info->adjoin != MagickFalse);
 
668
  }
721
669
  (void) CloseBlob(image);
722
670
  return(MagickTrue);
723
671
}