Lines Matching refs:cube_info
440 const CubeInfo *cube_info,const Quantum *pixel,DoublePixelPacket *alpha_pixel) in AssociateAlphaPixel() argument
445 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixel()
461 static inline void AssociateAlphaPixelInfo(const CubeInfo *cube_info, in AssociateAlphaPixelInfo() argument
467 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixelInfo()
483 static inline size_t ColorToNodeId(const CubeInfo *cube_info, in ColorToNodeId() argument
492 if (cube_info->associate_alpha != MagickFalse) in ColorToNodeId()
497 static MagickBooleanType AssignImageColors(Image *image,CubeInfo *cube_info, in AssignImageColors() argument
512 if (cube_info->quantize_info->colorspace != UndefinedColorspace) in AssignImageColors()
513 (void) TransformImageColorspace(image,cube_info->quantize_info->colorspace, in AssignImageColors()
515 cube_info->transparent_pixels=0; in AssignImageColors()
516 cube_info->transparent_index=(-1); in AssignImageColors()
517 if (SetImageColormap(image,cube_info,exception) == MagickFalse) in AssignImageColors()
522 if (cube_info->quantize_info->dither_method != NoDitherMethod) in AssignImageColors()
523 (void) DitherImage(image,cube_info,exception); in AssignImageColors()
561 cube=(*cube_info); in AssignImageColors()
640 if (cube_info->quantize_info->measure_error != MagickFalse) in AssignImageColors()
642 if ((cube_info->quantize_info->number_colors == 2) && in AssignImageColors()
643 ((cube_info->quantize_info->colorspace == LinearGRAYColorspace) || in AssignImageColors()
644 (cube_info->quantize_info->colorspace == GRAYColorspace))) in AssignImageColors()
672 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in AssignImageColors()
739 static inline void SetAssociatedAlpha(const Image *image,CubeInfo *cube_info) in SetAssociatedAlpha() argument
746 if ((cube_info->quantize_info->number_colors == 2) && in SetAssociatedAlpha()
747 ((cube_info->quantize_info->colorspace == LinearGRAYColorspace) || in SetAssociatedAlpha()
748 (cube_info->quantize_info->colorspace == GRAYColorspace))) in SetAssociatedAlpha()
750 cube_info->associate_alpha=associate_alpha; in SetAssociatedAlpha()
753 static MagickBooleanType ClassifyImageColors(CubeInfo *cube_info, in ClassifyImageColors() argument
788 SetAssociatedAlpha(image,cube_info); in ClassifyImageColors()
789 if (cube_info->quantize_info->colorspace != image->colorspace) in ClassifyImageColors()
791 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
792 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
794 cube_info->quantize_info->colorspace,exception); in ClassifyImageColors()
817 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
822 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
823 cube_info->depth--; in ClassifyImageColors()
839 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
843 node_info=cube_info->root; in ClassifyImageColors()
850 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
860 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
869 cube_info->colors++; in ClassifyImageColors()
878 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
885 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
895 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
903 if (cube_info->colors > cube_info->maximum_colors) in ClassifyImageColors()
905 PruneToCubeDepth(cube_info,cube_info->root); in ClassifyImageColors()
924 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
929 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
930 cube_info->depth--; in ClassifyImageColors()
946 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
950 node_info=cube_info->root; in ClassifyImageColors()
951 for (level=1; level <= cube_info->depth; level++) in ClassifyImageColors()
957 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
967 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
975 if (level == cube_info->depth) in ClassifyImageColors()
976 cube_info->colors++; in ClassifyImageColors()
985 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
992 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
1002 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
1016 if (cube_info->quantize_info->colorspace != image->colorspace) in ClassifyImageColors()
1017 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
1018 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
1095 static void ClosestColor(const Image *image,CubeInfo *cube_info, in ClosestColor() argument
1107 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in ClosestColor()
1110 ClosestColor(image,cube_info,node_info->child[i]); in ClosestColor()
1131 q=(&cube_info->target); in ClosestColor()
1134 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1141 if (distance <= cube_info->distance) in ClosestColor()
1145 if (distance <= cube_info->distance) in ClosestColor()
1149 if (distance <= cube_info->distance) in ClosestColor()
1151 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1156 if (distance <= cube_info->distance) in ClosestColor()
1158 cube_info->distance=distance; in ClosestColor()
1159 cube_info->color_number=node_info->color_number; in ClosestColor()
1241 static void DefineImageColormap(Image *image,CubeInfo *cube_info, in DefineImageColormap() argument
1253 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in DefineImageColormap()
1256 DefineImageColormap(image,cube_info,node_info->child[i]); in DefineImageColormap()
1271 if (cube_info->associate_alpha == MagickFalse) in DefineImageColormap()
1310 if (node_info->number_unique > cube_info->transparent_pixels) in DefineImageColormap()
1312 cube_info->transparent_pixels=node_info->number_unique; in DefineImageColormap()
1313 cube_info->transparent_index=(ssize_t) image->colors; in DefineImageColormap()
1343 static void DestroyCubeInfo(CubeInfo *cube_info) in DestroyCubeInfo() argument
1353 nodes=cube_info->node_queue->next; in DestroyCubeInfo()
1354 cube_info->node_queue->nodes=(NodeInfo *) RelinquishMagickMemory( in DestroyCubeInfo()
1355 cube_info->node_queue->nodes); in DestroyCubeInfo()
1356 cube_info->node_queue=(Nodes *) RelinquishMagickMemory( in DestroyCubeInfo()
1357 cube_info->node_queue); in DestroyCubeInfo()
1358 cube_info->node_queue=nodes; in DestroyCubeInfo()
1359 } while (cube_info->node_queue != (Nodes *) NULL); in DestroyCubeInfo()
1360 if (cube_info->memory_info != (MemoryInfo *) NULL) in DestroyCubeInfo()
1361 cube_info->memory_info=RelinquishVirtualMemory(cube_info->memory_info); in DestroyCubeInfo()
1362 cube_info->quantize_info=DestroyQuantizeInfo(cube_info->quantize_info); in DestroyCubeInfo()
1363 cube_info=(CubeInfo *) RelinquishMagickMemory(cube_info); in DestroyCubeInfo()
1470 static inline ssize_t CacheOffset(CubeInfo *cube_info, in CacheOffset() argument
1484 if (cube_info->associate_alpha != MagickFalse) in CacheOffset()
1489 static MagickBooleanType FloydSteinbergDither(Image *image,CubeInfo *cube_info, in FloydSteinbergDither() argument
1556 cube=(*cube_info); in FloydSteinbergDither()
1690 static void Riemersma(Image *image,CacheView *image_view,CubeInfo *cube_info, in Riemersma() argument
1698 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1700 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1702 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1708 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1710 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1712 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1718 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1720 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1722 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1728 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1730 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1732 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1744 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1746 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1748 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1750 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1752 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1754 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1756 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1762 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1764 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1766 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1768 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1770 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1772 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1774 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1780 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1782 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1784 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1786 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1788 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1790 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1792 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1798 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1800 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1802 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1804 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1806 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1808 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1810 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1820 CubeInfo *cube_info,const unsigned int direction,ExceptionInfo *exception) in RiemersmaDither() argument
1837 p=cube_info; in RiemersmaDither()
1853 AssociateAlphaPixel(image,cube_info,q,&pixel); in RiemersmaDither()
1859 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1865 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1867 i=CacheOffset(cube_info,&pixel); in RiemersmaDither()
1882 id=ColorToNodeId(cube_info,&pixel,index); in RiemersmaDither()
1902 if (cube_info->quantize_info->measure_error == MagickFalse) in RiemersmaDither()
1907 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1917 AssociateAlphaPixelInfo(cube_info,image->colormap+index,&color); in RiemersmaDither()
1921 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1938 static MagickBooleanType DitherImage(Image *image,CubeInfo *cube_info, in DitherImage() argument
1953 if (cube_info->quantize_info->dither_method != RiemersmaDitherMethod) in DitherImage()
1954 return(FloydSteinbergDither(image,cube_info,exception)); in DitherImage()
1958 (void) memset(cube_info->error,0,ErrorQueueLength*sizeof(*cube_info->error)); in DitherImage()
1959 cube_info->x=0; in DitherImage()
1960 cube_info->y=0; in DitherImage()
1966 cube_info->offset=0; in DitherImage()
1967 cube_info->span=(MagickSizeType) image->columns*image->rows; in DitherImage()
1970 Riemersma(image,image_view,cube_info,depth-1,NorthGravity,exception); in DitherImage()
1971 status=RiemersmaDither(image,image_view,cube_info,ForgetGravity,exception); in DitherImage()
2014 *cube_info; in GetCubeInfo() local
2029 cube_info=(CubeInfo *) AcquireMagickMemory(sizeof(*cube_info)); in GetCubeInfo()
2030 if (cube_info == (CubeInfo *) NULL) in GetCubeInfo()
2032 (void) memset(cube_info,0,sizeof(*cube_info)); in GetCubeInfo()
2033 cube_info->depth=depth; in GetCubeInfo()
2034 if (cube_info->depth > MaxTreeDepth) in GetCubeInfo()
2035 cube_info->depth=MaxTreeDepth; in GetCubeInfo()
2036 if (cube_info->depth < 2) in GetCubeInfo()
2037 cube_info->depth=2; in GetCubeInfo()
2038 cube_info->maximum_colors=maximum_colors; in GetCubeInfo()
2042 cube_info->root=GetNodeInfo(cube_info,0,0,(NodeInfo *) NULL); in GetCubeInfo()
2043 if (cube_info->root == (NodeInfo *) NULL) in GetCubeInfo()
2045 cube_info->root->parent=cube_info->root; in GetCubeInfo()
2046 cube_info->quantize_info=CloneQuantizeInfo(quantize_info); in GetCubeInfo()
2047 if (cube_info->quantize_info->dither_method == NoDitherMethod) in GetCubeInfo()
2048 return(cube_info); in GetCubeInfo()
2053 cube_info->memory_info=AcquireVirtualMemory(length,sizeof(*cube_info->cache)); in GetCubeInfo()
2054 if (cube_info->memory_info == (MemoryInfo *) NULL) in GetCubeInfo()
2056 cube_info->cache=(ssize_t *) GetVirtualMemoryBlob(cube_info->memory_info); in GetCubeInfo()
2060 (void) memset(cube_info->cache,(-1),sizeof(*cube_info->cache)*length); in GetCubeInfo()
2067 cube_info->weights[ErrorQueueLength-i-1]=PerceptibleReciprocal(weight); in GetCubeInfo()
2075 weight+=cube_info->weights[i]; in GetCubeInfo()
2079 cube_info->weights[i]/=weight; in GetCubeInfo()
2080 sum+=cube_info->weights[i]; in GetCubeInfo()
2082 cube_info->weights[0]+=1.0-sum; in GetCubeInfo()
2083 return(cube_info); in GetCubeInfo()
2114 static NodeInfo *GetNodeInfo(CubeInfo *cube_info,const size_t id, in GetNodeInfo() argument
2120 if (cube_info->free_nodes == 0) in GetNodeInfo()
2135 nodes->next=cube_info->node_queue; in GetNodeInfo()
2136 cube_info->node_queue=nodes; in GetNodeInfo()
2137 cube_info->next_node=nodes->nodes; in GetNodeInfo()
2138 cube_info->free_nodes=NodesInAList; in GetNodeInfo()
2140 cube_info->nodes++; in GetNodeInfo()
2141 cube_info->free_nodes--; in GetNodeInfo()
2142 node_info=cube_info->next_node++; in GetNodeInfo()
2477 *cube_info; in KmeansImage() local
2496 cube_info=GetCubeInfo(quantize_info,depth,number_colors); in KmeansImage()
2497 if (cube_info == (CubeInfo *) NULL) in KmeansImage()
2503 status=ClassifyImageColors(cube_info,image,exception); in KmeansImage()
2506 if (cube_info->colors > cube_info->maximum_colors) in KmeansImage()
2507 ReduceImageColors(image,cube_info); in KmeansImage()
2508 status=SetImageColormap(image,cube_info,exception); in KmeansImage()
2510 DestroyCubeInfo(cube_info); in KmeansImage()
2925 static void PruneChild(CubeInfo *cube_info,const NodeInfo *node_info) in PruneChild() argument
2939 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneChild()
2942 PruneChild(cube_info,node_info->child[i]); in PruneChild()
2953 cube_info->nodes--; in PruneChild()
2981 static void PruneLevel(CubeInfo *cube_info,const NodeInfo *node_info) in PruneLevel() argument
2992 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneLevel()
2995 PruneLevel(cube_info,node_info->child[i]); in PruneLevel()
2996 if (node_info->level == cube_info->depth) in PruneLevel()
2997 PruneChild(cube_info,node_info); in PruneLevel()
3026 static void PruneToCubeDepth(CubeInfo *cube_info,const NodeInfo *node_info) in PruneToCubeDepth() argument
3037 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneToCubeDepth()
3040 PruneToCubeDepth(cube_info,node_info->child[i]); in PruneToCubeDepth()
3041 if (node_info->level > cube_info->depth) in PruneToCubeDepth()
3042 PruneChild(cube_info,node_info); in PruneToCubeDepth()
3079 *cube_info; in QuantizeImage() local
3128 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImage()
3129 if (cube_info == (CubeInfo *) NULL) in QuantizeImage()
3132 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImage()
3138 if (cube_info->colors > cube_info->maximum_colors) in QuantizeImage()
3139 ReduceImageColors(image,cube_info); in QuantizeImage()
3140 status=AssignImageColors(image,cube_info,exception); in QuantizeImage()
3142 DestroyCubeInfo(cube_info); in QuantizeImage()
3180 *cube_info; in QuantizeImages() local
3240 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImages()
3241 if (cube_info == (CubeInfo *) NULL) in QuantizeImages()
3253 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImages()
3268 ReduceImageColors(images,cube_info); in QuantizeImages()
3274 status=AssignImageColors(image,cube_info,exception); in QuantizeImages()
3286 DestroyCubeInfo(cube_info); in QuantizeImages()
3323 static size_t QuantizeErrorFlatten(const CubeInfo *cube_info, in QuantizeErrorFlatten() argument
3333 if (offset >= (ssize_t) cube_info->nodes) in QuantizeErrorFlatten()
3337 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in QuantizeErrorFlatten()
3340 n+=QuantizeErrorFlatten(cube_info,node_info->child[i],offset+n, in QuantizeErrorFlatten()
3370 static void Reduce(CubeInfo *cube_info,const NodeInfo *node_info) in Reduce() argument
3381 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in Reduce()
3384 Reduce(cube_info,node_info->child[i]); in Reduce()
3385 if (node_info->quantize_error <= cube_info->pruning_threshold) in Reduce()
3386 PruneChild(cube_info,node_info); in Reduce()
3393 cube_info->colors++; in Reduce()
3394 if (node_info->quantize_error < cube_info->next_threshold) in Reduce()
3395 cube_info->next_threshold=node_info->quantize_error; in Reduce()
3469 static void ReduceImageColors(const Image *image,CubeInfo *cube_info) in ReduceImageColors() argument
3482 cube_info->next_threshold=0.0; in ReduceImageColors()
3483 if (cube_info->colors > cube_info->maximum_colors) in ReduceImageColors()
3491 quantize_error=(double *) AcquireQuantumMemory(cube_info->nodes, in ReduceImageColors()
3495 (void) QuantizeErrorFlatten(cube_info,cube_info->root,0, in ReduceImageColors()
3497 qsort(quantize_error,cube_info->nodes,sizeof(double), in ReduceImageColors()
3499 if (cube_info->nodes > (110*(cube_info->maximum_colors+1)/100)) in ReduceImageColors()
3500 cube_info->next_threshold=quantize_error[cube_info->nodes-110* in ReduceImageColors()
3501 (cube_info->maximum_colors+1)/100]; in ReduceImageColors()
3505 for (span=cube_info->colors; cube_info->colors > cube_info->maximum_colors; ) in ReduceImageColors()
3507 cube_info->pruning_threshold=cube_info->next_threshold; in ReduceImageColors()
3508 cube_info->next_threshold=cube_info->root->quantize_error-1; in ReduceImageColors()
3509 cube_info->colors=0; in ReduceImageColors()
3510 Reduce(cube_info,cube_info->root); in ReduceImageColors()
3511 offset=(MagickOffsetType) span-cube_info->colors; in ReduceImageColors()
3513 cube_info->maximum_colors+1); in ReduceImageColors()
3553 *cube_info; in RemapImage() local
3569 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImage()
3571 if (cube_info == (CubeInfo *) NULL) in RemapImage()
3574 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImage()
3580 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImage()
3581 status=AssignImageColors(image,cube_info,exception); in RemapImage()
3583 DestroyCubeInfo(cube_info); in RemapImage()
3621 *cube_info; in RemapImages() local
3647 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImages()
3649 if (cube_info == (CubeInfo *) NULL) in RemapImages()
3652 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImages()
3658 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImages()
3662 status=AssignImageColors(image,cube_info,exception); in RemapImages()
3667 DestroyCubeInfo(cube_info); in RemapImages()
3917 MagickBooleanType SetImageColormap(Image *image,CubeInfo *cube_info, in SetImageColormap() argument
3923 number_colors=MagickMax(cube_info->maximum_colors,cube_info->colors); in SetImageColormap()
3928 DefineImageColormap(image,cube_info,cube_info->root); in SetImageColormap()