Lines Matching refs:blob

49 #include "MagickCore/blob.h"
50 #include "MagickCore/blob-private.h"
187 % AttachBlob() attaches a blob to the BlobInfo structure.
191 % void AttachBlob(BlobInfo *blob_info,const void *blob,const size_t length)
197 % o blob: the address of a character stream in one of the image formats
200 % o length: This size_t integer reflects the length in bytes of the blob.
203 MagickExport void AttachBlob(BlobInfo *blob_info,const void *blob,
215 blob_info->data=(unsigned char *) blob;
232 % BlobToFile() writes a blob to a file. It returns MagickFalse if an error
237 % MagickBooleanType BlobToFile(char *filename,const void *blob,
242 % o filename: Write the blob to this file.
244 % o blob: the address of a blob.
246 % o length: This length in bytes of the blob.
251 MagickExport MagickBooleanType BlobToFile(char *filename,const void *blob,
265 assert(blob != (const void *) NULL);
277 count=write(file,(const char *) blob+i,MagickMin(length-i,SSIZE_MAX));
307 % blob as an image.
311 % Image *BlobToImage(const ImageInfo *image_info,const void *blob,
318 % o blob: the address of a character stream in one of the image formats
321 % o length: This size_t integer reflects the length in bytes of the blob.
326 MagickExport Image *BlobToImage(const ImageInfo *image_info,const void *blob,
348 if ((blob == (const void *) NULL) || (length == 0))
355 blob_info->blob=(void *) blob;
371 Native blob support for this image format.
379 (void) DetachBlob(image->blob);
384 Write blob to a temporary file on disk.
386 blob_info->blob=(void *) NULL;
389 status=BlobToFile(blob_info->filename,blob,length,exception);
437 % CloneBlobInfo() makes a duplicate of the given blob info structure, or if
438 % blob info is NULL, a new one.
446 % o blob_info: the blob info.
517 assert(image->blob != (BlobInfo *) NULL);
518 if (image->blob->type == UndefinedStream)
521 switch (image->blob->type)
529 if (image->blob->synchronize != MagickFalse)
530 status=fsync(fileno(image->blob->file_info.file));
531 status=ferror(image->blob->file_info.file);
537 (void) gzerror(image->blob->file_info.gzfile,&status);
544 (void) BZ2_bzerror(image->blob->file_info.bzfile,&status);
552 if ((image->blob->file_info.file != (FILE *) NULL) &&
553 (image->blob->synchronize != MagickFalse))
555 (void) fsync(fileno(image->blob->file_info.file));
556 status=ferror(image->blob->file_info.file);
561 image->blob->status=status < 0 ? MagickTrue : MagickFalse;
562 image->blob->size=GetBlobSize(image);
563 image->extent=image->blob->size;
564 image->blob->eof=MagickFalse;
565 if (image->blob->exempt != MagickFalse)
567 image->blob->type=UndefinedStream;
568 return(image->blob->status);
570 switch (image->blob->type)
577 status=fclose(image->blob->file_info.file);
583 status=pclose(image->blob->file_info.file);
590 status=gzclose(image->blob->file_info.gzfile);
597 BZ2_bzclose(image->blob->file_info.bzfile);
605 if (image->blob->file_info.file != (FILE *) NULL)
606 status=fclose(image->blob->file_info.file);
610 (void) DetachBlob(image->blob);
611 image->blob->status=status < 0 ? MagickTrue : MagickFalse;
612 return(image->blob->status);
627 % DestroyBlob() deallocates memory associated with a blob.
647 assert(image->blob != (BlobInfo *) NULL);
648 assert(image->blob->signature == MagickCoreSignature);
650 LockSemaphoreInfo(image->blob->semaphore);
651 image->blob->reference_count--;
652 assert(image->blob->reference_count >= 0);
653 if (image->blob->reference_count == 0)
655 UnlockSemaphoreInfo(image->blob->semaphore);
659 if (image->blob->mapped != MagickFalse)
661 (void) UnmapBlob(image->blob->data,image->blob->length);
662 RelinquishMagickResource(MapResource,image->blob->length);
664 if (image->blob->semaphore != (SemaphoreInfo *) NULL)
665 RelinquishSemaphoreInfo(&image->blob->semaphore);
666 image->blob->signature=(~MagickCoreSignature);
667 image->blob=(BlobInfo *) RelinquishMagickMemory(image->blob);
682 % DetachBlob() detaches a blob from the BlobInfo structure.
734 % blob of the specified image is referenced by other images. If the reference
735 % count is higher then 1 a new blob is assigned to the specified image.
749 *blob;
758 assert(image->blob != (BlobInfo *) NULL);
759 assert(image->blob->signature == MagickCoreSignature);
761 LockSemaphoreInfo(image->blob->semaphore);
762 assert(image->blob->reference_count >= 0);
763 if (image->blob->reference_count > 1)
765 UnlockSemaphoreInfo(image->blob->semaphore);
768 blob=CloneBlobInfo(image->blob);
770 image->blob=blob;
785 % DiscardBlobBytes() discards bytes in a blob.
845 % DuplicateBlob() duplicates a blob descriptor.
867 image->blob=ReferenceBlob(duplicate->blob);
883 % a blob or file.
900 assert(image->blob != (BlobInfo *) NULL);
901 assert(image->blob->type != UndefinedStream);
902 switch (image->blob->type)
910 image->blob->eof=feof(image->blob->file_info.file) != 0 ? MagickTrue :
916 image->blob->eof=MagickFalse;
926 (void) BZ2_bzerror(image->blob->file_info.bzfile,&status);
927 image->blob->eof=status == BZ_UNEXPECTED_EOF ? MagickTrue : MagickFalse;
933 image->blob->eof=MagickFalse;
939 return((int) image->blob->eof);
966 % o blob: FileToBlob() returns the contents of a file as a blob. If
971 % o extent: The maximum length of the blob.
973 % o length: On return, this reflects the actual length of the blob.
994 *blob;
1029 blob=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*blob));
1030 for (i=0; blob != (unsigned char *) NULL; i+=count)
1032 count=read(file,blob+i,quantum);
1041 blob=(unsigned char *) RelinquishMagickMemory(blob);
1044 blob=(unsigned char *) ResizeQuantumMemory(blob,i+quantum+1,
1045 sizeof(*blob));
1051 if (blob == (unsigned char *) NULL)
1059 blob=(unsigned char *) RelinquishMagickMemory(blob);
1064 blob[*length]='\0';
1065 return(blob);
1069 blob=(unsigned char *) NULL;
1071 blob=(unsigned char *) AcquireQuantumMemory(*length+MagickPathExtent,
1072 sizeof(*blob));
1073 if (blob == (unsigned char *) NULL)
1083 (void) memcpy(blob,map,*length);
1091 count=read(file,blob+i,(size_t) MagickMin(*length-i,SSIZE_MAX));
1102 blob=(unsigned char *) RelinquishMagickMemory(blob);
1107 blob[*length]='\0';
1112 blob=(unsigned char *) RelinquishMagickMemory(blob);
1115 return(blob);
1153 assert(image->blob != (BlobInfo *) NULL);
1154 assert(image->blob->type != UndefinedStream);
1156 if (image->blob->type != BlobStream)
1158 extent=(MagickSizeType) (image->blob->offset+(MagickOffsetType) length);
1159 if (extent >= image->blob->extent)
1161 extent=image->blob->extent+image->blob->quantum+length;
1162 image->blob->quantum<<=1;
1166 q=image->blob->data+image->blob->offset;
1168 image->blob->offset+=length;
1169 if (image->blob->offset >= (MagickOffsetType) image->blob->length)
1170 image->blob->length=(size_t) image->blob->offset;
1191 *blob;
1208 blob=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*blob));
1209 if (blob == (unsigned char *) NULL)
1218 count=read(file,blob,quantum);
1226 count=WriteBlobStream(image,length,blob);
1236 blob=(unsigned char *) RelinquishMagickMemory(blob);
1252 % GetBlobError() returns MagickTrue if the blob associated with the specified
1270 return(image->blob->status);
1285 % GetBlobFileHandle() returns the file handle associated with the image blob.
1300 return(image->blob->file_info.file);
1352 % GetBlobProperties() returns information about an image blob.
1369 return(&image->blob->properties);
1384 % GetBlobSize() returns the current length of the image file or blob; zero is
1405 assert(image->blob != (BlobInfo *) NULL);
1407 switch (image->blob->type)
1411 extent=image->blob->size;
1416 extent=image->blob->size;
1421 if (fstat(fileno(image->blob->file_info.file),&image->blob->properties) == 0)
1422 extent=(MagickSizeType) image->blob->properties.st_size;
1427 extent=image->blob->size;
1436 status=GetPathAttributes(image->filename,&image->blob->properties);
1438 extent=(MagickSizeType) image->blob->properties.st_size;
1445 extent=(MagickSizeType) image->blob->length;
1479 return(image->blob->data);
1511 return(image->blob->stream);
1527 % image as a formatted blob and its length. The magick member of the Image
1528 % structure determines the format of the returned blob (GIF, JPEG, PNG,
1543 % o length: return the actual length of the blob.
1561 *blob;
1572 blob=(unsigned char *) NULL;
1585 return(blob);
1591 Native blob support for this image format.
1594 blob_info->blob=AcquireQuantumMemory(MagickMaxBlobExtent,
1596 if (blob_info->blob == NULL)
1602 image->blob->exempt=MagickTrue;
1605 *length=image->blob->length;
1606 blob=DetachBlob(image->blob);
1608 blob=RelinquishMagickMemory(blob);
1610 blob=ResizeQuantumMemory(blob,*length+1,sizeof(unsigned char));
1622 Write file to disk in blob image format.
1641 blob=FileToBlob(unique,~0UL,length,exception);
1647 return(blob);
1706 assert(image->blob != (BlobInfo *) NULL);
1707 assert(image->blob->type != UndefinedStream);
1779 % image sequence as a blob and its length. The magick member of the ImageInfo
1780 % structure determines the format of the returned blob (GIF, JPEG, PNG, etc.)
1784 % sequence is returned as a blob.
1797 % o length: return the actual length of the blob.
1815 *blob;
1826 blob=(unsigned char *) NULL;
1839 return(blob);
1850 Native blob support for this images format.
1853 blob_info->blob=(void *) AcquireQuantumMemory(MagickMaxBlobExtent,
1855 if (blob_info->blob == (void *) NULL)
1861 images->blob->exempt=MagickTrue;
1864 *length=images->blob->length;
1865 blob=DetachBlob(images->blob);
1867 blob=RelinquishMagickMemory(blob);
1869 blob=ResizeQuantumMemory(blob,*length+1,sizeof(unsigned char));
1882 Write file to disk in blob images format.
1901 blob=FileToBlob(unique,~0UL,length,exception);
1907 return(blob);
2011 byte_image->blob=CloneBlobInfo((BlobInfo *) NULL);
2077 % IsBlobExempt() returns true if the blob is exempt.
2094 return(image->blob->exempt);
2109 % IsBlobSeekable() returns true if the blob is seekable.
2129 switch (image->blob->type)
2159 % IsBlobTemporary() returns true if the blob is temporary.
2176 return(image->blob->temporary);
2417 status=setvbuf(image->blob->file_info.file,(char *) NULL,size == 0 ?
2445 if (image_info->blob != (void *) NULL)
2448 image->blob->stream=(StreamHandler) image_info->stream;
2449 AttachBlob(image->blob,image_info->blob,image_info->length);
2452 (void) DetachBlob(image->blob);
2464 image->blob->synchronize=image_info->synchronize;
2467 image->blob->stream=(StreamHandler) image_info->stream;
2470 image->blob->type=FifoStream;
2492 image->blob->file_info.file=(*type == 'r') ? stdin : stdout;
2495 setmode(fileno(image->blob->file_info.file),_O_BINARY);
2497 image->blob->type=StandardStream;
2498 image->blob->exempt=MagickTrue;
2508 image->blob->file_info.file=fdopen(StringToLong(filename+3),fileMode);
2511 setmode(fileno(image->blob->file_info.file),_O_BINARY);
2513 image->blob->type=StandardStream;
2514 image->blob->exempt=MagickTrue;
2534 image->blob->file_info.file=(FILE *) popen_utf8(sanitize_command,
2537 if (image->blob->file_info.file == (FILE *) NULL)
2542 image->blob->type=PipeStream;
2543 image->blob->exempt=MagickTrue;
2547 status=GetPathAttributes(filename,&image->blob->properties);
2549 if ((status != MagickFalse) && S_ISFIFO(image->blob->properties.st_mode))
2551 image->blob->file_info.file=(FILE *) fopen_utf8(filename,type);
2552 if (image->blob->file_info.file == (FILE *) NULL)
2557 image->blob->type=FileStream;
2558 image->blob->exempt=MagickTrue;
2597 image->blob->file_info.file=image_info->file;
2598 image->blob->type=FileStream;
2599 image->blob->exempt=MagickTrue;
2604 image->blob->file_info.file=(FILE *) fopen_utf8(filename,type);
2605 if (image->blob->file_info.file != (FILE *) NULL)
2613 image->blob->type=FileStream;
2616 count=fread(magick,1,sizeof(magick),image->blob->file_info.file);
2617 (void) fseek(image->blob->file_info.file,-((off_t) count),SEEK_CUR);
2619 (void) fflush(image->blob->file_info.file);
2627 if (image->blob->file_info.file != (FILE *) NULL)
2628 (void) fclose(image->blob->file_info.file);
2629 image->blob->file_info.file=(FILE *) NULL;
2630 image->blob->file_info.gzfile=gzopen(filename,type);
2631 if (image->blob->file_info.gzfile != (gzFile) NULL)
2632 image->blob->type=ZipStream;
2638 if (image->blob->file_info.file != (FILE *) NULL)
2639 (void) fclose(image->blob->file_info.file);
2640 image->blob->file_info.file=(FILE *) NULL;
2641 image->blob->file_info.bzfile=BZ2_bzopen(filename,type);
2642 if (image->blob->file_info.bzfile != (BZFILE *) NULL)
2643 image->blob->type=BZipStream;
2646 if (image->blob->type == FileStream)
2660 length=(size_t) image->blob->properties.st_size;
2667 *blob;
2669 blob=MapBlob(fileno(image->blob->file_info.file),ReadMode,0,
2671 if (blob == (void *) NULL)
2679 image->blob->exempt=MagickFalse;
2682 (void) fclose(image->blob->file_info.file);
2683 image->blob->file_info.file=(FILE *) NULL;
2685 AttachBlob(image->blob,blob,length);
2686 image->blob->mapped=MagickTrue;
2701 image->blob->file_info.gzfile=gzopen(filename,type);
2702 if (image->blob->file_info.gzfile != (gzFile) NULL)
2703 image->blob->type=ZipStream;
2710 image->blob->file_info.bzfile=BZ2_bzopen(filename,type);
2711 if (image->blob->file_info.bzfile != (BZFILE *) NULL)
2712 image->blob->type=BZipStream;
2717 image->blob->file_info.file=(FILE *) fopen_utf8(filename,type);
2718 if (image->blob->file_info.file != (FILE *) NULL)
2720 image->blob->type=FileStream;
2724 image->blob->status=MagickFalse;
2725 if (image->blob->type != UndefinedStream)
2726 image->blob->size=GetBlobSize(image);
2754 % Image *PingBlob(const ImageInfo *image_info,const void *blob,
2761 % o blob: the address of a character stream in one of the image formats
2764 % o length: This size_t integer reflects the length in bytes of the blob.
2786 MagickExport Image *PingBlob(const ImageInfo *image_info,const void *blob,
2801 if ((blob == (const void *) NULL) || (length == 0))
2808 ping_info->blob=(void *) AcquireQuantumMemory(length,sizeof(unsigned char));
2809 if (ping_info->blob == (const void *) NULL)
2815 (void) memcpy(ping_info->blob,blob,length);
2819 ping_info->blob=(void *) RelinquishMagickMemory(ping_info->blob);
2836 % ReadBlob() reads data from the blob or image file and returns it. It
2869 assert(image->blob != (BlobInfo *) NULL);
2870 assert(image->blob->type != UndefinedStream);
2876 switch (image->blob->type)
2888 count=(ssize_t) fread(q,1,length,image->blob->file_info.file);
2893 c=getc(image->blob->file_info.file);
2901 c=getc(image->blob->file_info.file);
2909 c=getc(image->blob->file_info.file);
2917 c=getc(image->blob->file_info.file);
2935 count=(ssize_t) gzread(image->blob->file_info.gzfile,q,
2941 c=gzgetc(image->blob->file_info.gzfile);
2949 c=gzgetc(image->blob->file_info.gzfile);
2957 c=gzgetc(image->blob->file_info.gzfile);
2965 c=gzgetc(image->blob->file_info.gzfile);
2980 count=(ssize_t) BZ2_bzread(image->blob->file_info.bzfile,q,(int) length);
2991 if (image->blob->offset >= (MagickOffsetType) image->blob->length)
2993 image->blob->eof=MagickTrue;
2996 p=image->blob->data+image->blob->offset;
2997 count=(ssize_t) MagickMin(length,image->blob->length-image->blob->offset);
2998 image->blob->offset+=count;
3000 image->blob->eof=MagickTrue;
3812 % ReadBlobStream() reads data from the blob or image file and returns it. It
3841 assert(image->blob != (BlobInfo *) NULL);
3842 assert(image->blob->type != UndefinedStream);
3844 if (image->blob->type != BlobStream)
3850 if (image->blob->offset >= (MagickOffsetType) image->blob->length)
3853 image->blob->eof=MagickTrue;
3856 data=image->blob->data+image->blob->offset;
3857 *count=(ssize_t) MagickMin(length,image->blob->length-image->blob->offset);
3858 image->blob->offset+=(*count);
3860 image->blob->eof=MagickTrue;
3876 % ReadBlobString() reads characters from a blob or file until a newline
3938 % blob returning a pointer to the blob.
3949 MagickExport BlobInfo *ReferenceBlob(BlobInfo *blob)
3951 assert(blob != (BlobInfo *) NULL);
3952 assert(blob->signature == MagickCoreSignature);
3953 if (blob->debug != MagickFalse)
3955 LockSemaphoreInfo(blob->semaphore);
3956 blob->reference_count++;
3957 UnlockSemaphoreInfo(blob->semaphore);
3958 return(blob);
3973 % SeekBlob() sets the offset in bytes from the beginning of a blob or file
3988 % treated relative to the beginning of the blob as follows:
4002 assert(image->blob != (BlobInfo *) NULL);
4003 assert(image->blob->type != UndefinedStream);
4004 switch (image->blob->type)
4014 if (fseek(image->blob->file_info.file,offset,whence) < 0)
4016 image->blob->offset=TellBlob(image);
4023 if (gzseek(image->blob->file_info.gzfile,(off_t) offset,whence) < 0)
4026 image->blob->offset=TellBlob(image);
4042 image->blob->offset=offset;
4047 if ((image->blob->offset+offset) < 0)
4049 image->blob->offset+=offset;
4054 if (((MagickOffsetType) image->blob->length+offset) < 0)
4056 image->blob->offset=image->blob->length+offset;
4060 if (image->blob->offset < (MagickOffsetType)
4061 ((off_t) image->blob->length))
4063 image->blob->eof=MagickFalse;
4066 if (image->blob->offset < (MagickOffsetType)
4067 ((off_t) image->blob->extent))
4069 if (image->blob->immutable != MagickFalse)
4071 image->blob->eof=MagickTrue;
4074 image->blob->extent=(size_t) (image->blob->offset+image->blob->quantum);
4075 image->blob->quantum<<=1;
4076 image->blob->data=(unsigned char *) ResizeQuantumMemory(image->blob->data,
4077 image->blob->extent+1,sizeof(*image->blob->data));
4079 if (image->blob->data == NULL)
4081 (void) DetachBlob(image->blob);
4087 return(image->blob->offset);
4102 % SetBlobExempt() sets the blob exempt status.
4113 % o exempt: Set to true if this blob is exempt from being closed.
4122 image->blob->exempt=exempt;
4137 % SetBlobExtent() ensures enough space is allocated for the blob. If the
4149 % o extent: the blob maximum extent.
4159 assert(image->blob != (BlobInfo *) NULL);
4160 assert(image->blob->type != UndefinedStream);
4161 switch (image->blob->type)
4186 image->blob->file_info.file);
4188 if (image->blob->synchronize != MagickFalse)
4193 file=fileno(image->blob->file_info.file);
4215 if (image->blob->mapped != MagickFalse)
4223 (void) UnmapBlob(image->blob->data,image->blob->length);
4224 RelinquishMagickResource(MapResource,image->blob->length);
4234 image->blob->file_info.file);
4236 if (image->blob->synchronize != MagickFalse)
4241 file=fileno(image->blob->file_info.file);
4251 image->blob->data=(unsigned char*) MapBlob(fileno(
4252 image->blob->file_info.file),WriteMode,0,(size_t) extent);
4253 image->blob->extent=(size_t) extent;
4254 image->blob->length=(size_t) extent;
4258 image->blob->extent=(size_t) extent;
4259 image->blob->data=(unsigned char *) ResizeQuantumMemory(image->blob->data,
4260 image->blob->extent+1,sizeof(*image->blob->data));
4262 if (image->blob->data == (unsigned char *) NULL)
4264 (void) DetachBlob(image->blob);
4286 % attributes if it is an blob.
4306 assert(image->blob != (BlobInfo *) NULL);
4307 assert(image->blob->type != UndefinedStream);
4309 switch (image->blob->type)
4317 status=fflush(image->blob->file_info.file);
4323 status=gzflush(image->blob->file_info.gzfile,Z_SYNC_FLUSH);
4330 status=BZ2_bzflush(image->blob->file_info.bzfile);
4354 % TellBlob() obtains the current value of the blob or file position.
4374 assert(image->blob != (BlobInfo *) NULL);
4375 assert(image->blob->type != UndefinedStream);
4377 switch (image->blob->type)
4384 offset=ftell(image->blob->file_info.file);
4392 offset=(MagickOffsetType) gztell(image->blob->file_info.gzfile);
4402 offset=image->blob->offset;
4462 % WriteBlob() writes data to a blob or image file. It returns the number of
4476 % o data: The address of the data to write to the blob or file.
4494 assert(image->blob != (BlobInfo *) NULL);
4495 assert(image->blob->type != UndefinedStream);
4500 switch (image->blob->type)
4513 image->blob->file_info.file);
4518 c=putc((int) *p++,image->blob->file_info.file);
4525 c=putc((int) *p++,image->blob->file_info.file);
4532 c=putc((int) *p++,image->blob->file_info.file);
4539 c=putc((int) *p++,image->blob->file_info.file);
4556 count=(ssize_t) gzwrite(image->blob->file_info.gzfile,(void *) data,
4562 c=gzputc(image->blob->file_info.gzfile,(int) *p++);
4569 c=gzputc(image->blob->file_info.gzfile,(int) *p++);
4576 c=gzputc(image->blob->file_info.gzfile,(int) *p++);
4583 c=gzputc(image->blob->file_info.gzfile,(int) *p++);
4597 count=(ssize_t) BZ2_bzwrite(image->blob->file_info.bzfile,(void *) data,
4604 count=(ssize_t) image->blob->stream(image,data,length);
4612 if ((image->blob->offset+(MagickOffsetType) length) >=
4613 (MagickOffsetType) image->blob->extent)
4615 if (image->blob->mapped != MagickFalse)
4617 image->blob->extent+=length+image->blob->quantum;
4618 image->blob->quantum<<=1;
4619 image->blob->data=(unsigned char *) ResizeQuantumMemory(
4620 image->blob->data,image->blob->extent+1,sizeof(*image->blob->data));
4622 if (image->blob->data == (unsigned char *) NULL)
4624 (void) DetachBlob(image->blob);
4628 q=image->blob->data+image->blob->offset;
4630 image->blob->offset+=length;
4631 if (image->blob->offset >= (MagickOffsetType) image->blob->length)
4632 image->blob->length=(size_t) image->blob->offset;
4651 % WriteBlobByte() write an integer to a blob. It returns the number of bytes
5217 % WriteBlobString() write a string to a blob. It returns the number of