• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GifMakeMapObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GifMakeMapObject函数的典型用法代码示例。如果您正苦于以下问题:C++ GifMakeMapObject函数的具体用法?C++ GifMakeMapObject怎么用?C++ GifMakeMapObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GifMakeMapObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: file

/******************************************************************************
 Close output file (if open), and exit.
******************************************************************************/
static void RGB2GIF(bool OneFileFlag, int NumFiles, char *FileName,
            int ExpNumOfColors, int Width, int Height)
{
    int ColorMapSize;

    GifByteType *RedBuffer = NULL, *GreenBuffer = NULL, *BlueBuffer = NULL,
    *OutputBuffer = NULL;
    ColorMapObject *OutputColorMap = NULL;

    ColorMapSize = 1 << ExpNumOfColors;

    if (NumFiles == 1) {
    LoadRGB(FileName, OneFileFlag,
        &RedBuffer, &GreenBuffer, &BlueBuffer, Width, Height);
    }
    else {
    LoadRGB(NULL, OneFileFlag,
        &RedBuffer, &GreenBuffer, &BlueBuffer, Width, Height);
    }

    if ((OutputColorMap = GifMakeMapObject(ColorMapSize, NULL)) == NULL ||
    (OutputBuffer = (GifByteType *) malloc(Width * Height *
                        sizeof(GifByteType))) == NULL)
    GIF_EXIT("Failed to allocate memory required, aborted.");

    if (GifQuantizeBuffer(Width, Height, &ColorMapSize,
               RedBuffer, GreenBuffer, BlueBuffer,
               OutputBuffer, OutputColorMap->Colors) == GIF_ERROR)
    exit(EXIT_FAILURE);
    free((char *) RedBuffer);
    free((char *) GreenBuffer);
    free((char *) BlueBuffer);

    SaveGif(OutputBuffer, Width, Height, ExpNumOfColors, OutputColorMap);
}
开发者ID:moon-sky,项目名称:fishjam-template-library,代码行数:38,代码来源:gif2rgb.c


示例2: DGifGetScreenDesc

/******************************************************************************
 This routine should be called before any other DGif calls. Note that
 this routine is called automatically from DGif file open routines.
******************************************************************************/
int
DGifGetScreenDesc(GifFileType *GifFile)
{
    int BitsPerPixel;
    bool SortFlag;
    GifByteType Buf[3];
    GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;

    if (!IS_READABLE(Private)) {
        /* This file was NOT open for reading: */
        GifFile->Error = D_GIF_ERR_NOT_READABLE;
        return GIF_ERROR;
    }

    /* Put the screen descriptor into the file: */
    if (DGifGetWord(GifFile, &GifFile->SWidth) == GIF_ERROR ||
        DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR)
        return GIF_ERROR;

    if (READ(GifFile, Buf, 3) != 3) {
        GifFile->Error = D_GIF_ERR_READ_FAILED;
	GifFreeMapObject(GifFile->SColorMap);
	GifFile->SColorMap = NULL;
        return GIF_ERROR;
    }
    GifFile->SColorResolution = (((Buf[0] & 0x70) + 1) >> 4) + 1;
    SortFlag = (Buf[0] & 0x08) != 0;
    BitsPerPixel = (Buf[0] & 0x07) + 1;
    GifFile->SBackGroundColor = Buf[1];
    GifFile->AspectByte = Buf[2]; 
    if (Buf[0] & 0x80) {    /* Do we have global color map? */
	int i;

        GifFile->SColorMap = GifMakeMapObject(1 << BitsPerPixel, NULL);
        if (GifFile->SColorMap == NULL) {
            GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
            return GIF_ERROR;
        }

        /* Get the global color map: */
	GifFile->SColorMap->SortFlag = SortFlag;
        for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
	    /* coverity[check_return] */
            if (READ(GifFile, Buf, 3) != 3) {
                GifFreeMapObject(GifFile->SColorMap);
                GifFile->SColorMap = NULL;
                GifFile->Error = D_GIF_ERR_READ_FAILED;
                return GIF_ERROR;
            }
            GifFile->SColorMap->Colors[i].Red = Buf[0];
            GifFile->SColorMap->Colors[i].Green = Buf[1];
            GifFile->SColorMap->Colors[i].Blue = Buf[2];
        }
    } else {
        GifFile->SColorMap = NULL;
    }

    return GIF_OK;
}
开发者ID:cdotstout,项目名称:rpi-rgb-led-matrix,代码行数:63,代码来源:dgif_lib.c


示例3: genDefColorMap

static ColorMapObject* genDefColorMap() {
	ColorMapObject* cmap = GifMakeMapObject(256, NULL);
	if (cmap != NULL) {
		int iColor;
		for (iColor = 0; iColor < 256; iColor++) {
			cmap->Colors[iColor].Red = (GifByteType) iColor;
			cmap->Colors[iColor].Green = (GifByteType) iColor;
			cmap->Colors[iColor].Blue = (GifByteType) iColor;
		}
	}
	return cmap;
}
开发者ID:kyze8439690,项目名称:Qingbo,代码行数:12,代码来源:gif.c


示例4: main

int main(int argc, char **argv)
{
    int	i, ErrorCode;
    GifFileType *GifFileIn, *GifFileOut = (GifFileType *)NULL;

    if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }
    if (DGifSlurp(GifFileIn) == GIF_ERROR) {
	PrintGifError(GifFileIn->Error);
	exit(EXIT_FAILURE);
    }
    if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }

    /*
     * Your operations on in-core structures go here.  
     * This code just copies the header and each image from the incoming file.
     */
    GifFileOut->SWidth = GifFileIn->SWidth;
    GifFileOut->SHeight = GifFileIn->SHeight;
    GifFileOut->SColorResolution = GifFileIn->SColorResolution;
    GifFileOut->SBackGroundColor = GifFileIn->SBackGroundColor;
    GifFileOut->SColorMap = GifMakeMapObject(
				 GifFileIn->SColorMap->ColorCount,
				 GifFileIn->SColorMap->Colors);

    for (i = 0; i < GifFileIn->ImageCount; i++)
	(void) GifMakeSavedImage(GifFileOut, &GifFileIn->SavedImages[i]);

    /*
     * Note: don't do DGifCloseFile early, as this will
     * deallocate all the memory containing the GIF data!
     *
     * Further note: EGifSpew() doesn't try to validity-check any of this
     * data; it's *your* responsibility to keep your changes consistent.
     * Caveat hacker!
     */
    if (EGifSpew(GifFileOut) == GIF_ERROR)
	PrintGifError(GifFileOut->Error);

    if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
	PrintGifError(ErrorCode);
    if (EGifCloseFile(GifFileOut, &ErrorCode) == GIF_ERROR)
	PrintGifError(ErrorCode);

    return 0;
}
开发者ID:Distrotech,项目名称:giflib,代码行数:51,代码来源:gifsponge.c


示例5: getQuantizedPrArray

bool CMakeGifDoc::addImagesToGif() {
  const PixRectArray &prArray = getQuantizedPrArray();
  if(prArray.size() == 0) {
    return false;
  }
  if(!hasGifFile()) {
    const CSize size = prArray.getMaxSize();
    m_gif = allocateGifFile(size.cx, size.cy);
  }
  const SavedImageArray images(prArray, m_imageSettings.m_colorCount);
  for(size_t i = 0; i < images.size(); i++) {
    GifMakeSavedImage(m_gif, images[i]);
  }

  const SavedImage *image0 = images[0];
  const ColorMapObject *colorMap = image0->ImageDesc.ColorMap;
  m_gif->SColorMap = GifMakeMapObject(colorMap->ColorCount, colorMap->Colors);
  updateTimestamp();
  return true;
}
开发者ID:JesperMikkelsen,项目名称:Big-Numbers,代码行数:20,代码来源:MakeGifDoc.cpp


示例6: saveGif

static void saveGif(ByteOutputStream &out, GifFileType *gf) {
  int error;

  GifFileType *gifOut = NULL;
  try {
    gifOut = EGifOpen(&out, writeGifStreamFunction, &error);
    if(gifOut == NULL) {
      THROWGIFERROR(error);
    }
    gifOut->SWidth           = gf->SWidth;
    gifOut->SHeight          = gf->SHeight;
    gifOut->SColorResolution = gf->SColorResolution;
    gifOut->SBackGroundColor = gf->SBackGroundColor;
    gifOut->SColorMap        = GifMakeMapObject(gf->SColorMap->ColorCount
                                               ,gf->SColorMap->Colors);

    for(int i = 0; i < gf->ImageCount; i++) {
      GifMakeSavedImage(gifOut, &gf->SavedImages[i]);
    }
    if(gifOut->ImageCount > 0) {
      SavedImage *image0 = gifOut->SavedImages;
      addNetscapeBlock(image0);
    }

    EGifSetGifVersion(gifOut, true);
    if(EGifSpew(gifOut) != GIF_OK) {
      THROWGIFERROR(gifOut->Error);
    }
  } catch(Exception e) {
    if(gifOut != NULL) {
      EGifCloseFile(gifOut, &error);
    }
    throw e;
  } catch(...) {
    if(gifOut != NULL) {
      EGifCloseFile(gifOut, &error);
    }
    throw;
  }
}
开发者ID:JesperMikkelsen,项目名称:Big-Numbers,代码行数:40,代码来源:MakeGifDoc.cpp


示例7: EGifOpen

void
AnimatedGifEncoder::new_frame(unsigned char *data, int delay)
{
    if (!gif_file) {
       if (write_func != NULL) {
            int nError;
            gif_file = EGifOpen(write_user_data, write_func, &nError);
            if (!gif_file) throw "EGifOpen in AnimatedGifEncoder::new_frame failed";
        } else if (file_name.empty()) { // memory writer
            int nError;
            gif_file = EGifOpen(&gif, gif_writer, &nError);
            if (!gif_file) throw "EGifOpen in AnimatedGifEncoder::new_frame failed";
        } else {
            int nError;
            gif_file = EGifOpenFileName(file_name.c_str(), FALSE, &nError);
            if (!gif_file) throw "EGifOpenFileName in AnimatedGifEncoder::new_frame failed";
        }
        output_color_map = GifMakeMapObject(color_map_size, ext_web_safe_palette);
        if (!output_color_map) throw "MakeMapObject in AnimatedGifEncoder::new_frame failed";

        gif_buf = (GifByteType *)malloc(sizeof(GifByteType)*width*height);
        if (!gif_buf) throw "malloc in AnimatedGifEncoder::new_frame failed";
    }

    RGBator rgb(data, width, height, buf_type);

    if (web_safe_quantize(width, height, rgb.red, rgb.green, rgb.blue, gif_buf) == GIF_ERROR)
        throw "web_safe_quantize in AnimatedGifEncoder::new_frame failed";

    /*
    if (QuantizeBuffer(width, height, &color_map_size,
        rgb.red, rgb.green, rgb.blue,
        gif_buf, output_color_map->Colors) == GIF_ERROR)
    {
        throw "QuantizeBuffer in AnimatedGifEncoder::new_frame failed";
    }
    */

    if (!headers_set) {
        if (EGifPutScreenDesc(gif_file, width, height,
            color_map_size, 0, output_color_map) == GIF_ERROR)
        {
            throw "EGifPutScreenDesc in AnimatedGifEncoder::new_frame failed";
        }
        char netscape_extension[] = "NETSCAPE2.0";
        EGifPutExtension(gif_file, APPLICATION_EXT_FUNC_CODE, 11, netscape_extension);
        char animation_extension[] = { 1, 1, 0 }; // repeat one time
        EGifPutExtension(gif_file, APPLICATION_EXT_FUNC_CODE, 3, animation_extension);
        headers_set = true;
    }

    char frame_flags = 1 << 2;
    char transp_color_idx = 0;
    if (transparency_color.color_present) {
        int i = find_color_index(output_color_map, color_map_size, transparency_color);
        if (i>=0) {
            frame_flags |= 1;
            transp_color_idx = i;
        }
    }

    char extension[] = {
        frame_flags,
        delay%256, delay/256,
        transp_color_idx
    };
    EGifPutExtension(gif_file, GRAPHICS_EXT_FUNC_CODE, 4, extension);

    if (EGifPutImageDesc(gif_file, 0, 0, width, height, FALSE, NULL) == GIF_ERROR) {
        throw "EGifPutImageDesc in AnimatedGifEncoder::new_frame failed";
    }

    GifByteType *gif_bufp = gif_buf;
    for (int i = 0; i < height; i++) {
        if (EGifPutLine(gif_file, gif_bufp, width) == GIF_ERROR) {
            throw "EGifPutLine in AnimatedGifEncoder::new_frame failed";
        }
        gif_bufp += width;
    }
}
开发者ID:dariusk,项目名称:dfk-gif,代码行数:80,代码来源:gif_encoder.cpp


示例8: MCImageEncodeGIF

bool MCImageEncodeGIF(MCImageIndexedBitmap *p_indexed, IO_handle p_stream, uindex_t &r_bytes_written)
{
	bool t_success = true;

	int32_t t_transparent = -1;
	uindex_t t_palette_size;
	uindex_t t_depth;


	t_depth = GifBitSize(p_indexed->palette_size);
	// GIF requires palette size to be 2^depth
	t_palette_size = 1 << t_depth;

	int t_err = 0;
	GifFileType *t_gif = nil;
	ColorMapObject *t_colormap = nil;
	
	MCGIFWriteContext t_context;
	t_context.stream = p_stream;
	t_context.byte_count = 0;

	t_success = nil != (t_gif = EGifOpen(&t_context, gif_writeFunc, &t_err));

	if (t_success)
		t_success = nil != (t_colormap = GifMakeMapObject(t_palette_size, nil));

	if (t_success)
	{
		for (uindex_t i = 0; i < p_indexed->palette_size; i++)
		{
			t_colormap->Colors[i].Red = p_indexed->palette[i].red;
			t_colormap->Colors[i].Green = p_indexed->palette[i].green;
			t_colormap->Colors[i].Blue = p_indexed->palette[i].blue;
		}
		for (uindex_t i = p_indexed->palette_size; i < t_palette_size; i++)
		{
			t_colormap->Colors[i].Red =
				t_colormap->Colors[i].Green =
				t_colormap->Colors[i].Blue = 0;
		}

		if (MCImageIndexedBitmapHasTransparency(p_indexed))
		{
			t_transparent = p_indexed->transparent_index;
			t_colormap->Colors[t_transparent].Red =
				t_colormap->Colors[t_transparent].Green = 
				t_colormap->Colors[t_transparent].Blue = 0xFF;
		}

		t_success = GIF_OK == EGifPutScreenDesc(t_gif, p_indexed->width, p_indexed->height, t_depth, 0, t_colormap);
	}

	if (t_success)
	{
		if (t_transparent != -1)
		{
			GraphicsControlBlock t_gcb;
			MCMemoryClear(&t_gcb, sizeof(t_gcb));
			t_gcb.TransparentColor = t_transparent;

			GifByteType t_extension[4];

			uindex_t t_extension_size;
			t_extension_size = EGifGCBToExtension(&t_gcb, t_extension);

			// Should always be 4 bytes
			MCAssert(t_extension_size == sizeof(t_extension));

			t_success = GIF_OK == EGifPutExtension(t_gif, GRAPHICS_EXT_FUNC_CODE, sizeof(t_extension), t_extension);
		}
	}

	if (t_success)
		t_success = GIF_OK == EGifPutImageDesc(t_gif, 0, 0, p_indexed->width, p_indexed->height, false, nil);

	for (uindex_t y = 0; t_success && y < p_indexed->height; y++)
		t_success = GIF_OK == EGifPutLine(t_gif, (uint8_t*)p_indexed->data + y * p_indexed->stride, p_indexed->width);

	int t_error_code;
	if (GIF_ERROR == EGifCloseFile(t_gif, &t_error_code))
		t_success = false;

	GifFreeMapObject(t_colormap);

	if (t_success)
		r_bytes_written = t_context.byte_count;

	return t_success;
}
开发者ID:soapdog,项目名称:livecode,代码行数:89,代码来源:igif.cpp


示例9: gif_encode

void *
gif_encode(Image *image, int single, int *size)
{
    int width = image->columns;
    int height = image->rows;
    int total = width * height;
    GifByteType red[total];
    GifByteType green[total];
    GifByteType blue[total];

    // Quantize the images using IM/GM first, to reduce
    // their number of colors to 256.
    int count = GetImageListLength(image);
    QuantizeInfo info;
    GetQuantizeInfo(&info);
    info.dither = 0;
    info.number_colors = NCOLORS;
    QuantizeImage(&info, image);
    if (count > 1) {
#ifdef _MAGICK_USES_IM
        RemapImages(&info, image->next, image);
#else
        MapImages(image->next, image, 0);
#endif
    }

    if (!acquire_image_pixels(image, red, green, blue)) {
        return NULL;
    }

    size_t frame_size = sizeof(Frame) + total;
    Frame *frames = malloc(frame_size * count);

    ColorMapObject *palette = GifMakeMapObject(NCOLORS, NULL);
    int palette_size = NCOLORS;

    // Quantize again using giflib, since it yields a palette which produces
    // better compression, reducing the file size by 20%. Note that this second
    // quantization is very fast, because the image already has 256 colors, so
    // its effect on performance is negligible.
    if (GifQuantizeBuffer(width, height, &palette_size, red, green, blue, frames->data, palette->Colors) == GIF_ERROR) {
        GifFreeMapObject(palette);
        free(frames);
        return NULL;
    }

    frames->width = width;
    frames->height = height;
    frames->duration = image->delay;
    GifColorType *colors = palette->Colors;

    Image *cur = image->next;
    PixelCache *cache = pixel_cache_new();
    unsigned char *p = (unsigned char*)frames;
    int ii;
    for (ii = 1; ii < count; ii++, cur = cur->next) {
        p += frame_size;
        Frame *frame = (Frame*)p;
        frame->width = width;
        frame->height = height;
        frame->duration = cur->delay;
        GifPixelType *data = frame->data;
        
        if (!aprox_image_pixels(cur, colors, palette_size, cache, data)) {
            GifFreeMapObject(palette);
            free(frames);
            pixel_cache_free(cache);
            return NULL;
        }
    }
    pixel_cache_free(cache);
    void *ret = gif_save(image, palette, frames, count, frame_size, size);
    GifFreeMapObject(palette);
    free(frames);
    return ret;
}
开发者ID:cortex,项目名称:magick,代码行数:76,代码来源:gif.c


示例10: rgb

void
GifEncoder::encode()
{
    RGBator rgb(data, width, height, buf_type);

    int color_map_size = 256;
    ColorMapObject *output_color_map = GifMakeMapObject(256, ext_web_safe_palette);
    LOKI_ON_BLOCK_EXIT(GifFreeMapObject, output_color_map);
    if (!output_color_map)
        throw "MakeMapObject in GifEncoder::encode failed";

    GifByteType *gif_buf = (GifByteType *)malloc(sizeof(GifByteType)*width*height);
    LOKI_ON_BLOCK_EXIT(free, gif_buf);
    if (!gif_buf)
        throw "malloc in GifEncoder::encode failed";

    if (web_safe_quantize(width, height, rgb.red, rgb.green, rgb.blue, gif_buf) == GIF_ERROR)
        throw "web_safe_quantize in GifEncoder::encode failed";

    /*
    if (QuantizeBuffer(width, height, &color_map_size,
        rgb.red, rgb.green, rgb.blue,
        gif_buf, output_color_map->Colors) == GIF_ERROR)
    {
        throw "QuantizeBuffer in GifEncoder::encode failed";
    }
    */

    int nError;
    GifFileType *gif_file = EGifOpen(&gif, gif_writer, &nError);
    LOKI_ON_BLOCK_EXIT(EGifCloseFile, gif_file);
    if (!gif_file)
        throw "EGifOpen in GifEncoder::encode failed";

    if (EGifPutScreenDesc(gif_file, width, height,
        color_map_size, 0, output_color_map) == GIF_ERROR)
    {
        throw "EGifPutScreenDesc in GifEncoder::encode failed";
    }

    if (transparency_color.color_present) {
        int i = find_color_index(output_color_map, color_map_size, transparency_color);
        if (i) {
            char extension[] = {
                1, // enable transparency
                0, 0, // no time delay
                i // transparency color index
            };
            EGifPutExtension(gif_file, GRAPHICS_EXT_FUNC_CODE, 4, extension);
        }
    }

    if (EGifPutImageDesc(gif_file, 0, 0, width, height, FALSE, NULL) == GIF_ERROR) {
        throw "EGifPutImageDesc in GifEncoder::encode failed";
    }

    GifByteType *gif_bufp = gif_buf;
    for (int i = 0; i < height; i++) {
        if (EGifPutLine(gif_file, gif_bufp, width) == GIF_ERROR)
            throw "EGifPutLine in GifEncoder::encode failed";
        gif_bufp += width;
    }
}
开发者ID:dariusk,项目名称:dfk-gif,代码行数:63,代码来源:gif_encoder.cpp


示例11: main

/******************************************************************************
 Interpret the command line and scan the given GIF file.
******************************************************************************/
int main(int argc, char **argv)
{
    int	i, j, l, c, LevelStep, LogNumLevels, ErrorCode, Count = 0; 
    bool Error, LevelsFlag = false, SizeFlag = false, HelpFlag = false;
    GifRowType Line;
    ColorMapObject *ColorMap;
    GifFileType *GifFile;

    if ((Error = GAGetArgs(argc, argv, CtrlStr,
		&GifNoisyPrint, &LevelsFlag, &NumLevels,
		&SizeFlag, &ImageWidth, &ImageHeight,
		&HelpFlag)) != false) {
	GAPrintErrMsg(Error);
	GAPrintHowTo(CtrlStr);
	exit(EXIT_FAILURE);
    }

    if (HelpFlag) {
	(void)fprintf(stderr, VersionStr, GIFLIB_MAJOR, GIFLIB_MINOR);
	GAPrintHowTo(CtrlStr);
	exit(EXIT_SUCCESS);
    }

    /* Make sure the number of levels is power of 2 (up to 32 levels.). */
    for (i = 1; i < 6; i++) if (NumLevels == (1 << i)) break;
    if (i == 6) GIF_EXIT("#Lvls (-l option) is not power of 2 up to 32.");
    LogNumLevels = i + 3;		       /* Multiple by 8 (see below). */
    LevelStep = 256 / NumLevels;

    /* Make sure the image dimension is a multiple of NumLevels horizontally */
    /* and 7 (White, Red, Green, Blue and Yellow Cyan Magenta) vertically.   */
    ImageWidth = (ImageWidth / NumLevels) * NumLevels;
    ImageHeight = (ImageHeight / 7) * 7;

    /* Open stdout for the output file: */
    if ((GifFile = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }

    /* Dump out screen description with given size and generated color map:  */
    /* The color map has 7 NumLevels colors for White, Red, Green and then   */
    /* The secondary colors Yellow Cyan and magenta.			     */
    if ((ColorMap = GifMakeMapObject(8 * NumLevels, NULL)) == NULL)
	GIF_EXIT("Failed to allocate memory required, aborted.");

    for (i = 0; i < 8; i++)				   /* Set color map. */
	for (j = 0; j < NumLevels; j++) {
	    l = LevelStep * j;
	    c = i * NumLevels + j;
	    ColorMap->Colors[c].Red = (i == 0 || i == 1 || i == 4 || i == 6) * l;
	    ColorMap->Colors[c].Green =	(i == 0 || i == 2 || i == 4 || i == 5) * l;
	    ColorMap->Colors[c].Blue = (i == 0 || i == 3 || i == 5 || i == 6) * l;
	}

    if (EGifPutScreenDesc(GifFile, ImageWidth, ImageHeight, LogNumLevels, 0, ColorMap) == GIF_ERROR) {
	PrintGifError(GifFile->Error);
    }

    /* Dump out the image descriptor: */
    if (EGifPutImageDesc(GifFile,
			 0, 0, ImageWidth, ImageHeight, 
			 false, NULL) == GIF_ERROR) {

	PrintGifError(GifFile->Error);
	exit(EXIT_FAILURE);
    }

    GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]:     ",
		    PROGRAM_NAME, GifFile->Image.Left, GifFile->Image.Top,
		    GifFile->Image.Width, GifFile->Image.Height);

    /* Allocate one scan line to be used for all image.			     */
    if ((Line = (GifRowType) malloc(sizeof(GifPixelType) * ImageWidth)) == NULL)
	GIF_EXIT("Failed to allocate memory required, aborted.");

    /* Dump the pixels: */
    for (c = 0; c < 7; c++) {
	for (i = 0, l = 0; i < NumLevels; i++)
	    for (j = 0; j < ImageWidth / NumLevels; j++)
		Line[l++] = i + NumLevels * c;
	for (i = 0; i < ImageHeight / 7; i++) {
	    if (EGifPutLine(GifFile, Line, ImageWidth) == GIF_ERROR) {
		PrintGifError(GifFile->Error);
		exit(EXIT_FAILURE);
	    }
	    GifQprintf("\b\b\b\b%-4d", Count++);
	}
    }

    if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }

    return 0;
}
开发者ID:Distrotech,项目名称:giflib,代码行数:100,代码来源:gifwedge.c


示例12: GifMakeSavedImage

/*
 * Append an image block to the SavedImages array
 */
SavedImage *
GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
{
    if (GifFile->SavedImages == NULL)
        GifFile->SavedImages = (SavedImage *)malloc(sizeof(SavedImage));
    else
        GifFile->SavedImages = (SavedImage *)realloc(GifFile->SavedImages,
                               sizeof(SavedImage) * (GifFile->ImageCount + 1));

    if (GifFile->SavedImages == NULL)
        return ((SavedImage *)NULL);
    else {
        SavedImage *sp = &GifFile->SavedImages[GifFile->ImageCount++];
        memset((char *)sp, '\0', sizeof(SavedImage));

        if (CopyFrom != NULL) {
            memcpy((char *)sp, CopyFrom, sizeof(SavedImage));

            /*
             * Make our own allocated copies of the heap fields in the
             * copied record.  This guards against potential aliasing
             * problems.
             */

            /* first, the local color map */
            if (sp->ImageDesc.ColorMap != NULL) {
                sp->ImageDesc.ColorMap = GifMakeMapObject(
                                         CopyFrom->ImageDesc.ColorMap->ColorCount,
                                         CopyFrom->ImageDesc.ColorMap->Colors);
                if (sp->ImageDesc.ColorMap == NULL) {
                    FreeLastSavedImage(GifFile);
                    return (SavedImage *)(NULL);
                }
            }

            /* next, the raster */
            sp->RasterBits = (unsigned char *)malloc(sizeof(GifPixelType) *
                                                   CopyFrom->ImageDesc.Height *
                                                   CopyFrom->ImageDesc.Width);
            if (sp->RasterBits == NULL) {
                FreeLastSavedImage(GifFile);
                return (SavedImage *)(NULL);
            }
            memcpy(sp->RasterBits, CopyFrom->RasterBits,
                   sizeof(GifPixelType) * CopyFrom->ImageDesc.Height *
                   CopyFrom->ImageDesc.Width);

            /* finally, the extension blocks */
            if (sp->ExtensionBlocks != NULL) {
                sp->ExtensionBlocks = (ExtensionBlock *)malloc(
                                      sizeof(ExtensionBlock) *
                                      CopyFrom->ExtensionBlockCount);
                if (sp->ExtensionBlocks == NULL) {
                    FreeLastSavedImage(GifFile);
                    return (SavedImage *)(NULL);
                }
                memcpy(sp->ExtensionBlocks, CopyFrom->ExtensionBlocks,
                       sizeof(ExtensionBlock) * CopyFrom->ExtensionBlockCount);
            }
        }

        return (sp);
    }
}
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:67,代码来源:gifalloc.c


示例13: GifUnionColorMap

/*******************************************************************************
 Compute the union of two given color maps and return it.  If result can't
 fit into 256 colors, NULL is returned, the allocated union otherwise.
 ColorIn1 is copied as is to ColorUnion, while colors from ColorIn2 are
 copied iff they didn't exist before.  ColorTransIn2 maps the old
 ColorIn2 into the ColorUnion color map table./
*******************************************************************************/
ColorMapObject *
GifUnionColorMap(const ColorMapObject *ColorIn1,
              const ColorMapObject *ColorIn2,
              GifPixelType ColorTransIn2[])
{
    int i, j, CrntSlot, RoundUpTo, NewGifBitSize;
    ColorMapObject *ColorUnion;

    /*
     * We don't worry about duplicates within either color map; if
     * the caller wants to resolve those, he can perform unions
     * with an empty color map.
     */

    /* Allocate table which will hold the result for sure. */
    ColorUnion = GifMakeMapObject(MAX(ColorIn1->ColorCount,
                               ColorIn2->ColorCount) * 2, NULL);

    if (ColorUnion == NULL)
        return (NULL);

    /*
     * Copy ColorIn1 to ColorUnion.
     */
    for (i = 0; i < ColorIn1->ColorCount; i++)
        ColorUnion->Colors[i] = ColorIn1->Colors[i];
    CrntSlot = ColorIn1->ColorCount;

    /*
     * Potentially obnoxious hack:
     *
     * Back CrntSlot down past all contiguous {0, 0, 0} slots at the end
     * of table 1.  This is very useful if your display is limited to
     * 16 colors.
     */
    while (ColorIn1->Colors[CrntSlot - 1].Red == 0
           && ColorIn1->Colors[CrntSlot - 1].Green == 0
           && ColorIn1->Colors[CrntSlot - 1].Blue == 0)
        CrntSlot--;

    /* Copy ColorIn2 to ColorUnion (use old colors if they exist): */
    for (i = 0; i < ColorIn2->ColorCount && CrntSlot <= 256; i++) {
        /* Let's see if this color already exists: */
        for (j = 0; j < ColorIn1->ColorCount; j++)
            if (memcmp (&ColorIn1->Colors[j], &ColorIn2->Colors[i],
                        sizeof(GifColorType)) == 0)
                break;

        if (j < ColorIn1->ColorCount)
            ColorTransIn2[i] = j;    /* color exists in Color1 */
        else {
            /* Color is new - copy it to a new slot: */
            ColorUnion->Colors[CrntSlot] = ColorIn2->Colors[i];
            ColorTransIn2[i] = CrntSlot++;
        }
    }

    if (CrntSlot > 256) {
        GifFreeMapObject(ColorUnion);
        return ((ColorMapObject *) NULL);
    }

    NewGifBitSize = GifBitSize(CrntSlot);
    RoundUpTo = (1 << NewGifBitSize);

    if (RoundUpTo != ColorUnion->ColorCount) {
        register GifColorType *Map = ColorUnion->Colors;

        /*
         * Zero out slots up to next power of 2.
         * We know these slots exist because of the way ColorUnion's
         * start dimension was computed.
         */
        for (j = CrntSlot; j < RoundUpTo; j++)
            Map[j].Red = Map[j].Green = Map[j].Blue = 0;

        /* perhaps we can shrink the map? */
        if (RoundUpTo < ColorUnion->ColorCount) {
            GifColorType *new_map = (GifColorType *)realloc(Map,
                                 sizeof(GifColorType) * RoundUpTo);
            if( new_map == NULL ) {
                GifFreeMapObject(ColorUnion);
                return ((ColorMapObject *) NULL);
            }
            ColorUnion->Colors = new_map;
        }
    }

    ColorUnion->ColorCount = RoundUpTo;
    ColorUnion->BitsPerPixel = NewGifBitSize;

    return (ColorUnion);
}
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:100,代码来源:gifalloc.c


示例14: fprintf

/******************************************************************************
 Modify the given colormap according to global variables setting.
******************************************************************************/
static ColorMapObject *ModifyColorMap(ColorMapObject *ColorMap)
{
    int i, Dummy, Red, Green, Blue;

    if (SaveFlag) {
	/* Save this color map to ColorFile: */
	for (i = 0; i < ColorMap->ColorCount; i++)
	    fprintf(ColorFile, "%3d %3d %3d %3d\n", i,
		    ColorMap->Colors[i].Red,
		    ColorMap->Colors[i].Green,
		    ColorMap->Colors[i].Blue);
	return(ColorMap);
    }
    else if (LoadFlag) {
	/* Read the color map in ColorFile into this color map: */
	for (i = 0; i < ColorMap->ColorCount; i++) {
	    if (feof(ColorFile))
		GIF_EXIT("Color file to load color map from, too small.");
	    if (fscanf(ColorFile, "%3d %3d %3d %3d\n", &Dummy, &Red, &Green, &Blue) == 4) {
		ColorMap->Colors[i].Red = Red;
		ColorMap->Colors[i].Green = Green;
		ColorMap->Colors[i].Blue = Blue;
	    }
	}
	return(ColorMap);
    }
    else if (GammaFlag) {
	/* Apply gamma correction to this color map: */
	double Gamma1 = 1.0 / Gamma;
	for (i = 0; i < ColorMap->ColorCount; i++) {
	    ColorMap->Colors[i].Red =
		((int) (255 * pow(ColorMap->Colors[i].Red / 255.0, Gamma1)));
	    ColorMap->Colors[i].Green =
		((int) (255 * pow(ColorMap->Colors[i].Green / 255.0, Gamma1)));
	    ColorMap->Colors[i].Blue =
		((int) (255 * pow(ColorMap->Colors[i].Blue / 255.0, Gamma1)));
	}
	return(ColorMap);
    }
    else if (TranslateFlag) {
	ColorMapObject *NewMap;
	int Max = 0;

	/* Read the translation table in TranslateFile: */
	for (i = 0; i < ColorMap->ColorCount; i++) {
	    int tmp;
	    if (feof(TranslateFile))
		GIF_EXIT("Color file to load color map from, too small.");
	    if (fscanf(TranslateFile, "%3d %3d\n", &Dummy, &tmp) == 2) {
		Translation[i] = tmp & 0xff;
		if (Translation[i] > Max)
		    Max = Translation[i];
	    }
	}

	if ((NewMap = GifMakeMapObject(1 << GifBitSize(Max+1), NULL)) == NULL)
	    GIF_EXIT("Out of memory while allocating color map!");

	/* Apply the translation; we'll do it to the pixels, too */
	for (i = 0; i < ColorMap->ColorCount; i++) {
	    NewMap->Colors[i] = ColorMap->Colors[Translation[i]];
	}
	
	return(NewMap);
    }
    else
    {
	GIF_EXIT("Nothing to do!");
	return(ColorMap);
    }
}
开发者ID:alepharchives,项目名称:alcextra,代码行数:74,代码来源:gifclrmp.c


示例15: main

/******************************************************************************
 Interpret the command line, prepar global data and call the Gif routines.
******************************************************************************/
int main(int argc, char **argv)
{
    int	NumFiles, ImageWidth, ImageHeight, Dummy, Red, Green, Blue, ErrorCode;
    static bool Error,
	ImageSizeFlag = false, ColorMapFlag = false, HelpFlag = false,
	TextifyFlag = false;
    char **FileName = NULL, *ColorMapFile;
    ColorMapObject *ColorMap;
    FILE *InColorMapFile;

    if ((Error = GAGetArgs(argc, argv, CtrlStr, &GifNoisyPrint,
		&ImageSizeFlag, &ImageWidth, &ImageHeight,
		&ColorMapFlag, &ColorMapFile,
		&TextifyFlag,
		&HelpFlag,
		&NumFiles, &FileName)) != false ||
		(NumFiles > 1 && !HelpFlag)) {
	if (Error)
	    GAPrintErrMsg(Error);
	else if (NumFiles > 1)
	    GIF_MESSAGE("Error in command line parsing - one GIF file please.");
	GAPrintHowTo(CtrlStr);
	exit(EXIT_FAILURE);
    }

    if (HelpFlag) {
	(void)fprintf(stderr, VersionStr, GIFLIB_MAJOR, GIFLIB_MINOR);
	GAPrintHowTo(CtrlStr);
	exit(EXIT_SUCCESS);
    }

    if (ImageSizeFlag) {
	if (ColorMapFlag) {
	    int ColorMapSize;

	    /* Read color map from given file: */
	    if ((InColorMapFile = fopen(ColorMapFile, "rt")) == NULL) {
		GIF_MESSAGE("Failed to open COLOR MAP file (not exists!?).");
		exit(EXIT_FAILURE);
	    }
	    if ((ColorMap = GifMakeMapObject(256, NULL)) == NULL) {
		GIF_MESSAGE("Failed to allocate bitmap, aborted.");
		exit(EXIT_FAILURE);
	    }

	    for (ColorMapSize = 0;
		 ColorMapSize < 256 && !feof(InColorMapFile);
		 ColorMapSize++) {
		if (fscanf(InColorMapFile, "%3d %3d %3d %3d\n",
			   &Dummy, &Red, &Green, &Blue) == 4) {
		    ColorMap->Colors[ColorMapSize].Red = Red;
		    ColorMap->Colors[ColorMapSize].Green = Green;
		    ColorMap->Colors[ColorMapSize].Blue = Blue;
		}
	    }
	}
	else {
	    ColorMap = GifMakeMapObject(EGA_PALETTE_SIZE, EGAPalette);
	}

	if (NumFiles == 1) {
	    int InFileHandle;
    #ifdef _WIN32
	    if ((InFileHandle = open(*FileName, O_RDONLY | O_BINARY)) == -1) {
    #else
	    if ((InFileHandle = open(*FileName, O_RDONLY)) == -1) {
    #endif /* _WIN32 */
		GIF_MESSAGE("Failed to open RAW image file (not exists!?).");
		exit(EXIT_FAILURE);
	    }
	    dup2(InFileHandle, 0);		       /* Make stdin from this file. */
	}
	else {
    #ifdef _WIN32
	    _setmode(0, O_BINARY);		  /* Make sure it is in binary mode. */
    #endif /* _WIN32 */
	}

	/* Convert Raw image from stdin to GIF file in stdout: */
	Raw2Gif(ImageWidth, ImageHeight, ColorMap);
    }
    else {
	GifFileType *GifFile;

	if (NumFiles == 1) {
	    if ((GifFile = DGifOpenFileName(*FileName, &ErrorCode)) == NULL) {
		PrintGifError(ErrorCode);
		exit(EXIT_FAILURE);
	    }
	}
	else {
	    /* Use stdin instead: */
	    if ((GifFile = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
		PrintGifError(ErrorCode);
		exit(EXIT_FAILURE);
	    }
	}
//.........这里部分代码省略.........
开发者ID:alepharchives,项目名称:alcextra,代码行数:101,代码来源:gif2raw.c


示例16: gifconv_lossless2gif

unsigned char *
gifconv_lossless2gif(void *image_data,
                     unsigned short width, unsigned short height,
                     void *index_data,
                     unsigned short index_data_count,
                     int tag_no, int format,
                     unsigned long *length) {
    GifFileType *GifFile = NULL;
    GifColorType *Colors = NULL;
    int ColorCount;
    my_gif_buffer gif_buff;
    gif_uint_32 gif_width = 0, gif_height = 0;
    int bpp;
    gif_bytep gif_image_data = NULL;
    gif_uint_32 x, y;
    gif_colorp gif_palette = NULL;
//    int trans_index = -1;
    int i;
    if (format != 3) {
        fprintf(stderr, "jpegconv_lossless2gif: format=%d not implemented yes.\n", format);
        return NULL;
    }
    bpp = 8;
    gif_width = width;
    gif_height = height;
    ColorCount = 256;
    Colors = calloc(sizeof(GifColorType), ColorCount);

    gif_buff.data = NULL;
    gif_buff.data_len = 0;
    gif_buff.data_offset = 0;
#if GIFLIB_MAJOR >= 5
    GifFile = EGifOpen(& gif_buff, gif_data_write_func, NULL);
#else
    GifFile = EGifOpen(& gif_buff, gif_data_write_func);
#endif
    if (GifFile == NULL) {
        fprintf(stderr, "gifconv_lossless2gif: can't open GIFFile\n");
        return NULL;
    }
    GifFile->SWidth  = gif_width;
    GifFile->SHeight = gif_height;
    GifFile->SColorResolution = bpp;

    gif_palette = (gif_colorp) malloc(sizeof(gif_color)*index_data_count);

    if (tag_no == 20) {
        swf_rgb_t *rgb_list  = index_data;
        for (i=0 ; i < index_data_count ; i++) {
            Colors[i].Red   = rgb_list[i].red;
            Colors[i].Green = rgb_list[i].green;
            Colors[i].Blue  = rgb_list[i].blue;
        }
    } else {
        swf_rgba_t *rgba_list  = index_data;
        for (i=0 ; i < index_data_count ; i++) {
//            if (rgba_list[i].alpha)
            Colors[i].Red   = rgba_list[i].red;
            Colors[i].Green = rgba_list[i].green;
            Colors[i].Blue  = rgba_list[i].blue;
//                gif_palette[i].alpha = ;
        }
    }
    GifFile->SBackGroundColor = 0; // XXX
    gif_image_data = (gif_bytep) calloc(sizeof(unsigned char), gif_width * gif_height);
    i = 0;
    for (y=0 ; y < gif_height ; y++) {
        for (x=0 ; x < gif_width ; x++) {
            unsigned char *data = image_data;
            gif_image_data[i] = data[x + y*((gif_width +3) & -4)];
            i++;
        }
    }

    GifFile->SavedImages[0].RasterBits = gif_image_data;
#if GIFLIB_MAJOR >= 5
    GifFile->SColorMap = GifMakeMapObject(ColorCount, Colors);
#else
    GifFile->SColorMap = MakeMapObject(ColorCount, Colors);
#endif
    EGifSpew(GifFile); // XXX

    free(gif_image_data);

    if (GifFile) {
#if GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1 || GIFLIB_MAJOR > 5
        EGifCloseFile(GifFile, NULL);
#else
        EGifCloseFile(GifFile);
#endif
    }
    *length = gif_buff.data_offset;
    return gif_buff.data;
}
开发者ID:withgod,项目名称:swfed,代码行数:94,代码来源:swf_gif.c


示例17: main


//.........这里部分代码省略.........
   input_file = fopen(argv[1],"rb");
   if (input_file == NULL) {
      printf("vol_gif: oops -- can not open %s\n",argv[1]);
      exit(-1);
      }
   if (((x0 + dx) > nx) || ((y0 + dy) > ny) || ((z0 + dz) > nz)) {
      printf("vol_gif: oops -- region too large\n");
      exit(-1);
      }
   printf("read %s\n",argv[1]);
   if (format == 'f') {
      count = 0;
      while (fread(&f,sizeof(f),1,input_file) != 0) {
         if (f > fmax) fmax = f;
         if (f < fmin) fmin = f;
         count += 1;
         }
      }
   else if (format == 'i') {
      count = 0;
      while (fread(&i,sizeof(i),1,input_file) != 0) {
         if (i > fmax) fmax = i;
         if (i < fmin) fmin = i;
         count += 1;
         }
      }
   printf("   %" PRIu64 " points, min %f, max %f\n",count,fmin,fmax);
   printf("   nx ny nz: %d %d %d\n",nx,ny,nz);
   rewind(input_file);
   //
   // set up color map
   //
#if GIFLIB_MAJOR >= 5
   GIFcmap = GifMakeMapObject(256, NULL);
#else
   GIFcmap = MakeMapObject(256, NULL);
#endif
   for (i = 0; i < 256; i++) {
      GIFcmap->Colors[i].Red = i;
      GIFcmap->Colors[i].Green = i;
      GIFcmap->Colors[i].Blue = i;
      }
   //
   // open GIF file
   //
   printf("write %s\n",argv[2]);

   EGifPutScreenDesc(GIFfile,dx,dy,8,0,GIFcmap);
   unsigned char loop_count[] = {1,0,0};
#if GIFLIB_MAJOR >= 5
   GIFfile = EGifOpenFileName(argv[2], 0, NULL);
   EGifPutExtension(GIFfile, APPLICATION_EXT_FUNC_CODE, 11, "NETSCAPE2.0");
   EGifPutExtension(GIFfile, APPLICATION_EXT_FUNC_CODE, 3, loop_count);
#else
   GIFfile = EGifOpenFileName(argv[2], 0);
   EGifPutExtensionFirst(GIFfile, APPLICATION_EXT_FUNC_CODE, 11, "NETSCAPE2.0");
   EGifPutExtensionLast(GIFfile, APPLICATION_EXT_FUNC_CODE, 3, loop_count);
#endif


   unsigned char delay_count[5] = { 
      0, // no transparency
      0, // delay time
      0, // delay time
      0 // transparent index not used
      };
开发者ID:shohei,项目名称:fabmodules_jp,代码行数:67,代码来源:vol_gif.c


示例18: CSLFetchBoolean

GDALDataset *
GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, 
               int bStrict, char ** papszOptions, 
               GDALProgressFunc pfnProgress, void * pProgressData )

{
    int  nBands = poSrcDS->GetRasterCount();
    int  nXSize = poSrcDS->GetRasterXSize();
    int  nYSize = poSrcDS->GetRasterYSize();
    int	 bInterlace = FALSE;

/* ----------------------------------- 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GinPageGetOpaque函数代码示例发布时间:2022-05-30
下一篇:
C++ GifFreeMapObject函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap