本文整理汇总了C++中GifMakeMapObject函数的典型用法代码示例。如果您正苦于以下问题:C++ GifMakeMapObject函数的具体用法?C++ GifMakeMapObject怎么用?C++ GifMakeMapObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GifMakeMapObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
//.........这里部分代码省略.........