1 #define PRO9517 //GG_010997
2 // 1) Le swap ne fonctionne pas correctement sur DEC
3 // car X11XColor.pixel est int et non long (::Read(),::Write()).
4 // 2) Initialiser la table des couleurs avant d'ecrire
5 // le fichier temporaire (::Write())
8 // Ne pas initialiser una AsciiString avec '\0' dans le
9 // constructeur de AlienImage_X11XWDAlienData sinon RAISE !
11 #define TEST //GG_140699
12 // Check file extension, must be ".xwd".
15 # include <X11/Xlib.h>
17 #include <Aspect_GenericColorMap.hxx>
18 #include <Image_PseudoColorImage.hxx>
19 #include <AlienImage_MemoryOperations.hxx>
20 #include <AlienImage_X11XColor.hxx>
21 #include <AlienImage_X11XWDAlienData.ixx>
22 #include <Aspect_ColorMapEntry.hxx>
23 #include <Standard.hxx>
26 static int Verbose = 0 ;
31 AlienImage_X11XWDAlienData::AlienImage_X11XWDAlienData()
37 void AlienImage_X11XWDAlienData::SetName( const TCollection_AsciiString& aName)
39 { myName = aName + TCollection_AsciiString( "\0" ) ;
40 myHeader.header_size = sizeof( myHeader ) + myName.Length() ;
43 const TCollection_AsciiString& AlienImage_X11XWDAlienData::Name() const
45 { return ( myName ) ; }
47 void AlienImage_X11XWDAlienData::Clear()
49 { Standard_Integer size ;
51 myHeader.header_size = sizeof( myHeader ) ;
52 /* Size of the entire file header (bytes).*/
53 myHeader.file_version = 0 ; /* XWD_FILE_VERSION */
54 myHeader.pixmap_format= 0; /* Pixmap format */
55 myHeader.pixmap_depth = 0 ; /* Pixmap depth */
56 myHeader.pixmap_width = 0 ; /* Pixmap width */
57 myHeader.pixmap_height= 0 ; /* Pixmap height */
58 myHeader.xoffset = 0 ; /* Bitmap x offset */
59 myHeader.byte_order = 0; /* MSBFirst, LSBFirst */
60 myHeader.bitmap_unit = 0 ; /* Bitmap unit */
61 myHeader.bitmap_bit_order = 0; /* MSBFirst, LSBFirst */
62 myHeader.bitmap_pad = 0 ; /* Bitmap scanline pad */
63 myHeader.bits_per_pixel = 0 ; /* Bits per pixel */
64 myHeader.bytes_per_line =0 ; /* Bytes per scanline */
65 myHeader.visual_class = 0 ; /* Class of colormap */
66 myHeader.red_mask = 0 ; /* Z red mask */
67 myHeader.green_mask = 0 ; /* Z green mask */
68 myHeader.blue_mask = 0 ; /* Z blue mask */
69 myHeader.bits_per_rgb = 0 ; /* Log2 of distinct color values */
70 myHeader.colormap_entries = 0 ; /* Number of entries in colormap */
71 myHeader.ncolors = 0 ; /* Number of Color structures */
72 myHeader.window_width = 0 ; /* Window width */
73 myHeader.window_height= 0 ; /* Window height */
74 myHeader.window_x = 0 ; /* Window upper left X coordinate */
75 myHeader.window_y = 0 ; /* Window upper left Y coordinate */
76 myHeader.window_bdrwidth =0 ; /* Window border width */
81 //Free all allocated memory
82 Standard::Free(myData) ;
87 size = ( Standard_Integer )
88 myHeader.ncolors * sizeof( AlienImage_X11XColor ) ;
89 //Free all allocated memory
90 Standard::Free(myColors);
96 Standard_Boolean AlienImage_X11XWDAlienData::Write( OSD_File& file ) const
98 { Standard_Integer size, i ;
99 unsigned long swaptest = 1;
100 AlienImage_X11XWDFileHeader TheHeader = myHeader ;
102 if ( myData == NULL ) return( Standard_False ) ;
103 if ( TheHeader.ncolors &&
104 myColors == NULL ) return( Standard_False ) ;
107 // Write out TheHeader information
109 size = ( Standard_Integer ) TheHeader.header_size - sizeof( TheHeader ) ;
112 // Add '\0' at the end of name
113 TheHeader.header_size++ ;
116 if (*(char *) &swaptest) {
117 AlienImage_X11XWDFileHeader SwapHeader = TheHeader ;
119 AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &SwapHeader,
121 file.Write( &SwapHeader , sizeof( SwapHeader ) ) ;
124 const Standard_Address pHeader = ( Standard_Address ) &TheHeader ;
126 file.Write( pHeader, sizeof( TheHeader ) ) ;
129 if ( file.Failed() ) {
131 file.Seek( 0, OSD_FromBeginning ) ;
132 return( Standard_False ) ;
135 size = ( Standard_Integer ) TheHeader.header_size - sizeof( TheHeader ) ;
139 Standard_Address pend = Standard_Address( &end ) ;
141 file.Write( myName, myName.Length() ) ;
143 file.Write( pend, 1 ) ;
146 if ( file.Failed() ) {
148 file.Seek( 0, OSD_FromBeginning ) ;
149 return( Standard_False ) ;
152 // write out the color map buffer
154 if ( TheHeader.ncolors ) {
155 size = ( Standard_Integer ) TheHeader.ncolors
156 * sizeof( AlienImage_X11XColor ) ;
158 if (*(char *) &swaptest) {
159 Standard_Address palloc =
160 Standard::Allocate( size ) ;
162 const AlienImage_X11XColor *p = ( AlienImage_X11XColor * ) myColors ;
163 AlienImage_X11XColor *pp = ( AlienImage_X11XColor * ) palloc ;
165 for (i = 0 ; (unsigned int ) i < TheHeader.ncolors; i++,p++,pp++) {
166 pp->pixel = p->pixel;
168 pp->green = p->green;
170 pp->flags = p->flags;
171 AlienImage_MemoryOperations::SwapLong (
172 (Standard_Address) &(pp->pixel), sizeof(int));
173 AlienImage_MemoryOperations::SwapShort(
174 (Standard_Address) &(pp->red) , 3 * sizeof(short));
177 const AlienImage_X11XColor *p = ( AlienImage_X11XColor * ) palloc ;
179 for (i = 0 ; i < TheHeader.ncolors; i++,p++) {
180 AlienImage_MemoryOperations::SwapLong (
181 (Standard_Address) &(p->pixel), sizeof(long));
182 AlienImage_MemoryOperations::SwapShort(
183 (Standard_Address) &(p->red) , 3 * sizeof(short));
187 file.Write( palloc, size ) ;
189 //Free all allocated memory
190 Standard::Free(palloc) ;
193 file.Write( myColors, size ) ;
196 if ( file.Failed() ) {
198 file.Seek( 0, OSD_FromBeginning ) ;
199 return( Standard_False ) ;
205 file.Write( myData, DataSize() ) ;
207 if ( file.Failed() ) {
209 file.Seek( 0, OSD_FromBeginning ) ;
210 return( Standard_False ) ;
215 return( Standard_True ) ;
220 Standard_Boolean AlienImage_X11XWDAlienData::Read( OSD_File& file )
222 { Standard_Integer bblcount, i, size ;
223 unsigned long swaptest = 1;
224 Standard_Address pheader = ( Standard_Address ) &myHeader ;
227 OSD_Path path; file.Path(path);
228 TCollection_AsciiString ext = path.Extension(); ext.LowerCase();
229 if( ext != ".xwd" ) {
230 TCollection_AsciiString sysname; path.SystemName(sysname);
232 cout << " *** AlienImage_X11XWDAlienData::Read('" << sysname << "'). must have an '.xwd' extension" << endl;
234 return Standard_False;
238 // Read in myHeader information
240 file.Read( pheader, sizeof( myHeader ), bblcount ) ;
242 if ( file.Failed() || ( bblcount != sizeof( myHeader ) ) ) {
244 file.Seek( 0, OSD_FromBeginning ) ;
245 return( Standard_False ) ;
248 if (*(char *) &swaptest)
249 AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &myHeader,
252 // check to see if the dump file is in the proper format */
253 if (myHeader.file_version != XWD_FILE_VERSION) {
254 // ERROR "XWD file format version mismatch."
256 if (*(char *) &swaptest)
257 AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &myHeader,
260 if (myHeader.file_version != XWD_FILE_VERSION) {
261 // ERROR "XWD file format version mismatch."
262 file.Seek( 0, OSD_FromBeginning ) ;
263 return( Standard_False ) ;
266 // Data come from a swaped computer ??
271 if (myHeader.header_size < sizeof(myHeader)) {
272 // ERROR "XWD header size is too small."
273 file.Seek( 0, OSD_FromBeginning ) ;
274 return( Standard_False ) ;
278 if ( Verbose ) cout << myHeader << endl << flush ;
281 // read in window name
283 size = ( Standard_Integer ) myHeader.header_size - sizeof( myHeader ) ;
287 TCollection_AsciiString name( bblcount ) ;
289 TCollection_AsciiString name( bblcount , '\0') ;
292 file.Read( name, size ) ; bblcount = name.Length() ;
297 if ( file.Failed() || ( bblcount != size ) ) {
299 file.Seek( 0, OSD_FromBeginning ) ;
300 return( Standard_False ) ;
306 if ( Verbose ) cout << myName << endl << flush ;
311 // read in the color map buffer
313 if ( myHeader.ncolors ) {
314 size = ( Standard_Integer ) myHeader.ncolors
315 * sizeof( AlienImage_X11XColor ) ;
317 myColors = Standard::Allocate( size ) ;
319 file.Read( myColors, size, bblcount ) ;
321 if ( file.Failed() || ( bblcount != size ) ) {
323 file.Seek( 0, OSD_FromBeginning ) ;
324 return( Standard_False ) ;
327 if ( *(char *) &swaptest ) {
328 AlienImage_X11XColor *p
329 = ( AlienImage_X11XColor * )myColors ;
330 for (i = 0 ; (unsigned int ) i < myHeader.ncolors; i++,p++) {
332 AlienImage_MemoryOperations::SwapLong (
333 (Standard_Address) &(p->pixel), sizeof(int));
335 AlienImage_MemoryOperations::SwapLong (
336 (Standard_Address) &(p->pixel), sizeof(long));
338 AlienImage_MemoryOperations::SwapShort(
339 (Standard_Address) &(p->red) , 3 * sizeof(short));
345 AlienImage_X11XColor *p = ( AlienImage_X11XColor * )myColors;
347 for (i = 0 ; i < myHeader.ncolors; i++,p++) {
348 cout << *p << endl << flush ;
356 myData = Standard::Allocate( DataSize() ) ;
358 file.Read( myData, DataSize(), bblcount ) ;
360 if ( file.Failed() || ( bblcount != DataSize() ) ) {
362 file.Seek( 0, OSD_FromBeginning ) ;
363 return( Standard_False ) ;
367 return( Standard_True ) ;
371 Handle_Image_Image AlienImage_X11XWDAlienData::ToImage() const
373 { if ( myHeader.pixmap_depth <= 8 &&
375 myHeader.pixmap_format == ZPixmap) {
376 return( ToPseudoColorImage() ) ;
378 else if ( myHeader.visual_class == TrueColor &&
379 myHeader.pixmap_format == ZPixmap) {
380 return( ToColorImage() ) ;
383 Standard_TypeMismatch_Raise_if( Standard_True,
384 "Attempt to convert a X11XWDAlienData to a unknown Image_Image type");
390 void AlienImage_X11XWDAlienData::FromImage( const Handle_Image_Image& anImage )
392 { if ( anImage->Type() == Image_TOI_PseudoColorImage ) {
393 Handle(Image_PseudoColorImage) aPImage =
394 Handle(Image_PseudoColorImage)::DownCast(anImage) ;
396 FromPseudoColorImage( aPImage ) ;
398 else if ( anImage->Type() == Image_TOI_ColorImage ) {
399 Handle(Image_ColorImage) aCImage =
400 Handle(Image_ColorImage)::DownCast(anImage) ;
402 FromColorImage( aCImage ) ;
405 Standard_TypeMismatch_Raise_if( Standard_True,
406 "Attempt to convert a unknown Image_Image type to a X11XWDAlienData");
410 //------------------------------------------------------------------------------
412 //------------------------------------------------------------------------------
415 void AlienImage_X11XWDAlienData::FromPseudoColorImage(
416 const Handle_Image_PseudoColorImage& anImage)
418 { Standard_Integer size, i ;
420 /* Size of the entire file header (bytes).*/
421 myHeader.header_size = sizeof(myHeader) + myName.Length() ;
422 myHeader.file_version = XWD_FILE_VERSION ; /* XWD_FILE_VERSION */
423 myHeader.pixmap_format = ZPixmap ; /* Pixmap format */
424 myHeader.pixmap_depth = 8 ; /* Pixmap depth */
425 myHeader.pixmap_width = anImage->Width() ;/* Pixmap width */
426 myHeader.pixmap_height = anImage->Height() ;/* Pixmap height */
427 myHeader.xoffset = 0 ; /* Bitmap x offset */
428 myHeader.byte_order = MSBFirst; /* MSBFirst, LSBFirst */
429 myHeader.bitmap_unit = 32 ; /* Bitmap unit */
430 myHeader.bitmap_bit_order = MSBFirst; /* MSBFirst, LSBFirst */
431 myHeader.bitmap_pad = 32 ; /* Bitmap scanline pad */
432 myHeader.bits_per_pixel = 8 ; /* Bits per pixel */
433 /* Bytes per scanline */
434 size = ( Standard_Integer ) ( anImage->Width() * myHeader.bits_per_pixel );
436 myHeader.bytes_per_line = size / myHeader.bitmap_unit ;
437 if ( size % myHeader.bitmap_pad ) myHeader.bytes_per_line += 1 ;
439 myHeader.bytes_per_line *= ( myHeader.bitmap_unit / 8 ) ;
441 myHeader.visual_class = PseudoColor ; /* Class of colormap */
442 myHeader.red_mask = 0 ; /* Z red mask */
443 myHeader.green_mask = 0 ; /* Z green mask */
444 myHeader.blue_mask = 0 ; /* Z blue mask */
445 myHeader.bits_per_rgb = 8 ; /* Log2 of distinct color values */
446 myHeader.colormap_entries = 256 ; /* Number of entries in colormap */
447 myHeader.ncolors = (anImage->ColorMap())->Size() ;
448 /* Number of Color structures */
449 myHeader.window_width = anImage->Width() ; /* Window width */
450 myHeader.window_height = anImage->Height() ; /* Window height */
451 myHeader.window_x = 0 ; /* Window upper left X coordinate */
452 myHeader.window_y = 0 ; /* Window upper left Y coordinate */
453 myHeader.window_bdrwidth = 0 ; /* Window border width */
455 size = ( Standard_Integer ) myHeader.ncolors
456 * sizeof( AlienImage_X11XColor ) ;
458 myColors = Standard::Allocate( size ) ;
460 AlienImage_X11XColor *p = ( AlienImage_X11XColor * )myColors ;
461 Aspect_ColorMapEntry aCentry ;
463 for ( i = 1 ; (unsigned int ) i <= myHeader.ncolors ; i++, p++ ) {
465 p->red = p->green = p->blue = 0 ;
468 aCentry = (anImage->ColorMap())->Entry( i ) ;
470 if ( aCentry.IsAllocated() == Standard_True ) {
471 p->flags = DoRed | DoGreen | DoBlue ;
472 p->pixel = aCentry.Index() ;
473 p->red = ( unsigned short )
474 ( (aCentry.Color()).Red() * 0xffff + 0.5 ) ;
475 p->green = ( unsigned short )
476 ( (aCentry.Color()).Green() * 0xffff + 0.5 ) ;
477 p->blue = ( unsigned short )
478 ( (aCentry.Color()).Blue() * 0xffff + 0.5 ) ;
482 if ( anImage->Size() ) {
483 Standard_Integer x, y ;
485 myData = Standard::Allocate( DataSize() ) ;
487 for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
488 for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
490 ( anImage->Pixel( anImage->LowerX()+x ,
491 anImage->LowerY()+y )).Value() ) ;
498 void AlienImage_X11XWDAlienData::FromColorImage(
499 const Handle_Image_ColorImage& anImage)
503 /* Size of the entire file header (bytes).*/
504 myHeader.header_size = sizeof(myHeader) + myName.Length() ;
505 myHeader.file_version = XWD_FILE_VERSION ; /* XWD_FILE_VERSION */
506 myHeader.pixmap_format = ZPixmap ; /* Pixmap format */
507 myHeader.pixmap_depth = 24 ; /* Pixmap depth */
508 myHeader.pixmap_width = anImage->Width() ;/* Pixmap width */
509 myHeader.pixmap_height = anImage->Height() ;/* Pixmap height */
510 myHeader.xoffset = 0 ; /* Bitmap x offset */
511 myHeader.byte_order = MSBFirst; /* MSBFirst, LSBFirst */
512 myHeader.bitmap_unit = 32 ; /* Bitmap unit */
513 myHeader.bitmap_bit_order = MSBFirst; /* MSBFirst, LSBFirst */
514 myHeader.bitmap_pad = 32 ; /* Bitmap scanline pad */
515 myHeader.bits_per_pixel = 32 ; /* Bits per pixel */
516 /* Bytes per scanline */
517 size = anImage->Width() * myHeader.bits_per_pixel ;
519 myHeader.bytes_per_line = size / myHeader.bitmap_unit ;
520 if ( size % myHeader.bitmap_pad ) myHeader.bytes_per_line += 1 ;
522 myHeader.bytes_per_line *= ( myHeader.bitmap_unit / 8 ) ;
524 myHeader.visual_class = TrueColor ; /* Class of colormap */
525 myHeader.red_mask = 0xff ; /* Z red mask */
526 myHeader.green_mask = 0xff00 ; /* Z green mask */
527 myHeader.blue_mask = 0xff0000 ; /* Z blue mask */
528 myHeader.bits_per_rgb = 8 ; /* Log2 of distinct color values */
529 myHeader.colormap_entries = 256 ; /* Number of entries in colormap */
530 myHeader.ncolors = 0 ; /* Number of Color structures */
531 myHeader.window_width = anImage->Width() ; /* Window width */
532 myHeader.window_height = anImage->Height() ; /* Window height */
533 myHeader.window_x = 0 ; /* Window upper left X coordinate */
534 myHeader.window_y = 0 ; /* Window upper left Y coordinate */
535 myHeader.window_bdrwidth = 0 ; /* Window border width */
540 if ( anImage->Size() ) {
541 Standard_Integer x, y, pix, c ;
542 const Standard_Integer rs = RedShift() ;
543 const Standard_Integer gs = GreenShift() ;
544 const Standard_Integer bs = BlueShift() ;
545 const Standard_Integer ColorRange =
546 Standard_Integer( ( 1 << myHeader.bits_per_rgb ) - 1 );
549 myData = Standard::Allocate( DataSize() ) ;
551 for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
552 for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
553 col = anImage->Pixel( anImage->LowerX()+x ,
554 anImage->LowerY()+y ).Value() ;
558 c = ( Standard_Integer ) ( col.Red() * ColorRange + 0.5 );
559 c = ( Standard_Integer ) (( c << rs ) & myHeader.red_mask) ;
562 c = ( Standard_Integer ) ( col.Green() * ColorRange + 0.5 );
563 c = ( Standard_Integer ) (( c << gs ) & myHeader.green_mask) ;
566 c = ( Standard_Integer ) ( col.Blue() * ColorRange + 0.5 );
567 c = ( Standard_Integer ) (( c << bs ) & myHeader.blue_mask) ;
570 SetPixel( x, y, pix ) ;
577 Handle_Image_ColorImage AlienImage_X11XWDAlienData::ToColorImage() const
579 { Aspect_ColorPixel CPixel ;
580 Quantity_Color acolor ;
581 Handle(Image_ColorImage) ret_image = NULL ;
582 Standard_Integer pix,x,y ;
583 Standard_Real r,g,b, maxcol ;
585 if ( myHeader.visual_class == TrueColor &&
586 myHeader.pixmap_format == ZPixmap) {
587 ret_image = new Image_ColorImage( 0,0,
588 (Standard_Integer)myHeader.pixmap_width,
589 (Standard_Integer)myHeader.pixmap_height ) ;
591 maxcol = ( 1 << myHeader.bits_per_rgb ) - 1 ;
593 for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
594 for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
595 pix = Pixel( x, y ) ;
597 r = ( ( pix & myHeader.red_mask ) >> RedShift() ) / maxcol ;
598 g = ( ( pix & myHeader.green_mask ) >> GreenShift() ) / maxcol ;
599 b = ( ( pix & myHeader.blue_mask ) >> BlueShift() ) / maxcol ;
601 acolor.SetValues( r,g,b, Quantity_TOC_RGB ) ;
602 CPixel.SetValue ( acolor ) ;
604 ret_image->SetPixel( ret_image->LowerX()+x ,
605 ret_image->LowerY()+y, CPixel ) ;
611 return( ret_image ) ;
614 Handle_Image_PseudoColorImage AlienImage_X11XWDAlienData::ToPseudoColorImage()
617 { Standard_Real r,g,b ;
618 Standard_Integer x, y ;
619 const Standard_Real XRange = Standard_Real( Standard_Integer(0xffff) );
620 const Standard_Integer newColorSize =
621 Standard_Integer(myHeader.colormap_entries*sizeof(AlienImage_X11XColor));
622 Handle(Image_PseudoColorImage) ret_image = NULL ;
624 if ( myHeader.pixmap_depth <= 8 &&
626 myHeader.pixmap_format == ZPixmap) {
627 // unsigned long int i, j, ncol ;
628 unsigned long int i, ncol ;
629 Aspect_ColorMapEntry Centry ;
630 Quantity_Color color ;
631 AlienImage_X11XColor *p ;
632 AlienImage_X11XColor *newColor ;
633 Standard_Address palloc ;
634 Aspect_IndexPixel IPixel ;
636 palloc = Standard::Allocate( newColorSize ) ;
638 newColor = ( AlienImage_X11XColor * ) palloc ;
640 p = ( AlienImage_X11XColor * )myColors;
642 for ( i = 0 ; i < myHeader.ncolors ; i++, p++ ) newColor[p->pixel] = *p;
643 for ( i = 0 ; i < myHeader.colormap_entries ; i++ ) newColor[i].flags = 0 ;
645 for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
646 for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
647 newColor[ Pixel( x, y ) ].flags = DoRed | DoGreen | DoBlue ;
651 for ( i = ncol = 0 ; i < myHeader.colormap_entries ; i++ ) {
652 if ( newColor[i].flags ) ncol++ ;
655 Handle(Aspect_GenericColorMap) colormap =
656 new Aspect_GenericColorMap();
658 for ( i = 0 ; i < myHeader.colormap_entries ; i++ ) {
659 if ( newColor[i].flags ) {
660 r = ( Standard_Real ) newColor[i].red / XRange ;
661 g = ( Standard_Real ) newColor[i].green / XRange ;
662 b = ( Standard_Real ) newColor[i].blue / XRange ;
663 color.SetValues( r,g,b, Quantity_TOC_RGB );
664 Centry.SetValue( Standard_Integer(newColor[i].pixel), color ) ;
665 colormap->AddEntry( Centry ) ;
669 ret_image = new Image_PseudoColorImage( 0,0,
670 Standard_Integer(myHeader.pixmap_width),
671 Standard_Integer(myHeader.pixmap_height),
674 for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
675 for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
676 IPixel.SetValue( Pixel( x, y ) ) ;
677 ret_image->SetPixel( ret_image->LowerX()+x ,
678 ret_image->LowerY()+y, IPixel ) ;
683 //Free all allocated memory
684 Standard::Free(palloc);
691 Standard_Integer AlienImage_X11XWDAlienData::DataSize() const
694 if ( myHeader.pixmap_format != ZPixmap)
695 return( myHeader.bytes_per_line * myHeader.pixmap_height
696 * myHeader.pixmap_depth );
698 return( myHeader.bytes_per_line * myHeader.pixmap_height);
701 void AlienImage_X11XWDAlienData::SetPixel(
702 const Standard_Integer x,
703 const Standard_Integer y,
704 const Standard_Integer value )
707 unsigned long int pixel_size ;
709 Standard_OutOfRange_Raise_if(
710 ( x < 0 || (unsigned int ) x >= myHeader.pixmap_width ||
711 y < 0 || (unsigned int ) y >= myHeader.pixmap_height ),
712 "Index out of range in X11XWDAlienData::Pixel");
714 pixel_size = ( unsigned long int ) myHeader.bytes_per_line /
715 myHeader.pixmap_width;
717 p = ( unsigned char * ) myData ;
718 p += y * myHeader.bytes_per_line + x * pixel_size ;
720 if ( pixel_size == 1 ) {
721 *p = ( unsigned char ) value ;
723 else if ( pixel_size == 2 ) {
724 *( ( unsigned short int * ) p ) = ( unsigned short int ) value ;
726 else if ( pixel_size == 4 ) {
727 *( ( unsigned long int * ) p ) = ( unsigned long int ) value ;
731 Standard_Integer AlienImage_X11XWDAlienData::Pixel(
732 const Standard_Integer x, const Standard_Integer y ) const
735 unsigned long int pixel_size ;
736 unsigned long int pix ;
737 Standard_Integer ret ;
739 Standard_OutOfRange_Raise_if(
740 ( x < 0 || (unsigned int ) x >= myHeader.pixmap_width ||
741 y < 0 || (unsigned int ) y >= myHeader.pixmap_height ),
742 "Index out of range in X11XWDAlienData::Pixel");
744 pixel_size = ( unsigned long int ) myHeader.bytes_per_line /
745 myHeader.pixmap_width;
747 p = ( unsigned char * ) myData ;
748 p += y * myHeader.bytes_per_line + x * pixel_size ;
750 if ( pixel_size == 1 ) {
751 pix = ( unsigned long int ) *p ;
753 else if ( pixel_size == 2 ) {
754 pix = *( ( unsigned short int * ) p ) ;
757 pix = *( ( unsigned long int * ) p ) ;
760 ret = Standard_Integer ( pix );
766 Standard_Integer AlienImage_X11XWDAlienData::RedShift() const
768 { Standard_Integer shift = 0 ;
770 Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
771 "Attempt to get RedShift from a non TrueColor X11XWDImage" ) ;
773 if ( ( myHeader.red_mask >> myHeader.bits_per_rgb ) == 0 ) {
776 else if ( ( myHeader.red_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
777 shift = Standard_Integer( myHeader.bits_per_rgb ) ;
780 shift = Standard_Integer( 2 * myHeader.bits_per_rgb );
785 Standard_Integer AlienImage_X11XWDAlienData::GreenShift() const
787 { Standard_Integer shift = 0 ;
789 Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
790 "Attempt to get GreenShift from a non TrueColor X11XWDImage" ) ;
792 if ( ( myHeader.green_mask >> myHeader.bits_per_rgb ) == 0 ) {
795 else if ( ( myHeader.green_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
796 shift = Standard_Integer( myHeader.bits_per_rgb ) ;
799 shift = Standard_Integer( 2 * myHeader.bits_per_rgb ) ;
804 Standard_Integer AlienImage_X11XWDAlienData::BlueShift() const
806 { Standard_Integer shift = 0 ;
808 Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
809 "Attempt to get BlueShift from a non TrueColor X11XWDImage" ) ;
811 if ( ( myHeader.blue_mask >> myHeader.bits_per_rgb ) == 0 ) {
814 else if ( ( myHeader.blue_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
815 shift = Standard_Integer( myHeader.bits_per_rgb ) ;
818 shift = Standard_Integer( 2 * myHeader.bits_per_rgb ) ;