NITFAPI(cgm_Picture*) cgm_Picture_construct(const char* name, nitf_Error* error) { cgm_Picture* picture = (cgm_Picture*)NITF_MALLOC(sizeof(cgm_Picture)); if (!picture) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } picture->name = NULL; picture->colorSelectionMode = CGM_DIRECT; picture->edgeWidthSpec = CGM_ABSOLUTE; picture->lineWidthSpec = CGM_ABSOLUTE; picture->vdcExtent = NULL; picture->body = NULL; if (name) { picture->name = (char*)NITF_MALLOC( strlen( name ) + 1 ); strcpy(picture->name, name); } return picture; }
NITFAPI(nitf_SegmentSource *) nitf_SegmentFileSource_construct ( nitf_IOHandle handle, nitf_Off start, int byteSkip, nitf_Error * error ) { static nitf_IDataSource iFileSource = { &FileSource_read, &FileSource_destruct, &FileSource_getSize, &FileSource_setSize }; FileSourceImpl *impl = NULL; nitf_SegmentSource *segmentSource = NULL; impl = (FileSourceImpl *) NITF_MALLOC(sizeof(FileSourceImpl)); if (!impl) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } if (!(impl->io = nitf_IOHandleAdapter_construct(handle, NRT_ACCESS_READONLY, error))) return NULL; impl->byteSkip = byteSkip >= 0 ? byteSkip : 0; impl->mark = impl->start = (start >= 0 ? start : 0); impl->fileSize = nitf_IOInterface_getSize(impl->io, error); if (!NITF_IO_SUCCESS(impl->fileSize)) { NITF_FREE(impl); return NULL; } /* figure out the actual # oif bytes represented by the source */ impl->size = impl->fileSize / (impl->byteSkip + 1); segmentSource = (nitf_SegmentSource *) NITF_MALLOC(sizeof(nitf_SegmentSource)); if (!segmentSource) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } segmentSource->data = impl; segmentSource->iface = &iFileSource; return segmentSource; }
nitf_RESubheader_clone(nitf_RESubheader * source, nitf_Error * error) { nitf_Uint32 subLen; nitf_RESubheader *subhdr = NULL; if (source) { subhdr = (nitf_RESubheader *) NITF_MALLOC(sizeof(nitf_RESubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); if (!subhdr->securityGroup) goto CATCH_ERROR; /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_RE); _NITF_CLONE_FIELD(subhdr, source, NITF_RESTAG); _NITF_CLONE_FIELD(subhdr, source, NITF_RESVER); _NITF_CLONE_FIELD(subhdr, source, NITF_RESCLAS); /* And some ints */ _NITF_CLONE_FIELD(subhdr, source, NITF_RESSHL); subhdr->dataLength = source->dataLength; subhdr->subheaderFields = NULL; NITF_TRY_GET_UINT32(source->subheaderFieldsLength, &subLen, error); if (source->subheaderFields) { subhdr->subheaderFields = (char* )NITF_MALLOC(subLen); if (!subhdr->subheaderFields) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } memcpy(subhdr->subheaderFields, source->subheaderFields, subLen); } return subhdr; } CATCH_ERROR: return NULL; }
NITFAPI(nitf_SegmentSource *) nitf_SegmentReaderSource_construct ( nitf_SegmentReader *reader, nitf_Error * error ) { static nitf_IDataSource iSource = { &SegmentReader_read, &SegmentReader_destruct, &SegmentReader_getSize, &SegmentReader_setSize }; nitf_SegmentSource *segmentSource = NULL; segmentSource = (nitf_SegmentSource *) NITF_MALLOC(sizeof(nitf_SegmentSource)); if (!segmentSource) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } segmentSource->data = reader; segmentSource->iface = &iSource; return segmentSource; }
NITFAPI(nitf_TREEnumerator*) nitf_TREUtils_basicBegin(nitf_TRE* tre, nitf_Error* error) { nitf_TREEnumerator* it = (nitf_TREEnumerator*)NITF_MALLOC(sizeof(nitf_TREEnumerator)); nitf_TRECursor* cursor = (nitf_TRECursor*)NITF_MALLOC(sizeof(nitf_TRECursor)); *cursor = nitf_TRECursor_begin(tre); /*assert(nitf_TRECursor_iterate(cursor, error));*/ it->data = cursor; it->next = basicIncrement; it->hasNext = basicHasNext; it->getFieldDescription = basicGetFieldDescription; return it; }
NITFAPI(nitf_ImageSegment *) nitf_ImageSegment_construct(nitf_Error * error) { nitf_ImageSegment *segment = (nitf_ImageSegment *) NITF_MALLOC(sizeof(nitf_ImageSegment)); if (!segment) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } /* This object gets created NOW */ segment->subheader = NULL; /* The image offset in the file */ segment->imageOffset = 0; /* The image end (offset + length image) */ segment->imageEnd = 0; segment->subheader = nitf_ImageSubheader_construct(error); if (!segment->subheader) { nitf_ImageSegment_destruct(&segment); return NULL; } /* Yes! We have a success */ return segment; }
/* pass in a negative number for bandNum if you don't want a band in the name */ char *makeBandName(const char *rootFile, const char* segment, int segmentNum, int bandNum) { char *file = (char *) NITF_MALLOC(NITF_MAX_PATH); int pos; /* find end slash */ for (pos = strlen(rootFile) - 1; pos && rootFile[pos] != '\\' && rootFile[pos] != '/'; pos--); if (bandNum >= 0) NITF_SNPRINTF(file, NITF_MAX_PATH, "%s__%s_%d_band_%d", &rootFile[pos + 1], segment, segmentNum, bandNum); else NITF_SNPRINTF(file, NITF_MAX_PATH, "%s__%s_%d", &rootFile[pos + 1], segment, segmentNum); /* remove decimals */ for (pos = strlen(file) - 1; pos; pos--) { if (file[pos] == '.') { file[pos] = '_'; } } strcat(file, ".man"); printf("File: %s\n", file); return file; }
void ImageSubheader::setPixelInformation(std::string pvtype, nitf::Uint32 nbpp, nitf::Uint32 abpp, std::string justification, std::string irep, std::string icat, std::vector<nitf::BandInfo>& bands) throw(nitf::NITFException) { const size_t bandCount = bands.size(); nitf_BandInfo ** bandInfo = (nitf_BandInfo **)NITF_MALLOC( sizeof(nitf_BandInfo*) * bandCount); if (!bandInfo) { throw nitf::NITFException(Ctxt(FmtX("Out of Memory"))); } for (size_t i = 0; i < bandCount; i++) { bandInfo[i] = nitf_BandInfo_clone(bands[i].getNative(), &error); if (!bandInfo[i]) throw nitf::NITFException(&error); } NITF_BOOL x = nitf_ImageSubheader_setPixelInformation(getNativeOrThrow(), pvtype.c_str(), nbpp, abpp, justification.c_str(), irep.c_str(), icat.c_str(), static_cast<nitf::Uint32>(bandCount), bandInfo, &error); if (!x) throw nitf::NITFException(&error); }
NITFAPI(cgm_PictureBody*) cgm_PictureBody_construct(nitf_Error* error) { cgm_PictureBody* body = (cgm_PictureBody*)NITF_MALLOC(sizeof(cgm_PictureBody)); if (!body) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } body->auxColor = NULL; body->elements = NULL; body->elements = nitf_List_construct(error); if (!body->elements) { cgm_PictureBody_destruct(&body); return NULL; } body->auxColor = cgm_Color_construct(-1, -1, -1, error); if (!body->auxColor) { cgm_PictureBody_destruct(&body); return NULL; } body->transparency = 1; return body; }
NITFAPI(cgm_Element*) cgm_PolyLineElement_construct(nitf_Error* error) { cgm_Element* element = cgm_Element_construct(CGM_POLYLINE_ELEMENT, error); if (element) { cgm_PolyLineElement* poly = (cgm_PolyLineElement*) NITF_MALLOC(sizeof(cgm_PolyLineElement)); if (!poly) { NITF_FREE(element); return NULL; } poly->attributes = NULL; poly->vertices = nitf_List_construct(error); if (!poly->vertices) { NITF_FREE(poly); NITF_FREE(element); return NULL; } element->data = (NITF_DATA*)poly; } element->print = &polyPrint; element->clone = &polyClone; element->destroy = &polyDestroy; return element; }
NITFAPI(cgm_Element*) cgm_RectangleElement_construct(nitf_Error* error) { cgm_Element* element = cgm_Element_construct(CGM_RECTANGLE_ELEMENT, error); if (element) { cgm_RectangleElement* rect = (cgm_RectangleElement*) NITF_MALLOC(sizeof(cgm_RectangleElement)); if (!rect) { NITF_FREE(element); return NULL; } rect->attributes = NULL; rect->rectangle = NULL; element->data = (NITF_DATA*)rect; } element->print = &rectanglePrint; element->clone = &rectangleClone; element->destroy = &rectangleDestroy; return element; }
nitf_IOInterface* CustomIO::createInterface(CustomIO* me) { static nrt_IIOInterface iIOHandle = { &CustomIO::adapterRead, &CustomIO::adapterWrite, &CustomIO::adapterCanSeek, &CustomIO::adapterSeek, &CustomIO::adapterTell, &CustomIO::adapterGetSize, &CustomIO::adapterGetMode, &CustomIO::adapterClose, &CustomIO::adapterDestruct }; nitf_IOInterface* const impl = (nitf_IOInterface *)NITF_MALLOC(sizeof(nitf_IOInterface)); if (impl == NULL) { return NULL; } memset(impl, 0, sizeof(nitf_IOInterface)); impl->data = me; impl->iface = &iIOHandle; return impl; }
NITFAPI(cgm_Element*) cgm_EllipticalArcElement_construct(nitf_Error* error) { cgm_Element* element = cgm_Element_construct(CGM_ELLIPTICAL_ARC_CENTER_ELEMENT, error); if (element) { cgm_EllipticalArcElement* arc = (cgm_EllipticalArcElement*) NITF_MALLOC(sizeof(cgm_EllipticalArcElement)); if (!arc) { NITF_FREE(element); return NULL; } arc->attributes = NULL; arc->centerX = -1; arc->centerY = -1; arc->end1X = -1; arc->end1Y = -1; arc->end2X = -1; arc->end2Y = -1; arc->startVectorX = -1; arc->endVectorY = -1; element->data = (NITF_DATA*)arc; } element->print = &ellipticalArcPrint; element->clone = &ellipticalArcClone; element->destroy = &ellipticalArcDestroy; return element; }
NITFPRIV(NITF_BOOL) defaultInit(nitf_TRE* tre, const char* id, nitf_Error * error) { nitf_TREDescription* descr; /* create a new private data struct */ tre->priv = nitf_TREPrivateData_construct(error); if (!tre->priv) return NITF_FAILURE; descr = (nitf_TREDescription *) NITF_MALLOC(2 * sizeof(nitf_TREDescription)); if (!descr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NITF_FAILURE; } descr[0].data_type = NITF_BINARY; descr[0].data_count = NITF_TRE_GOBBLE; descr[0].label = _NITF_DEFAULT_TRE_LABEL; descr[0].tag = NITF_TRE_RAW; descr[1].data_type = NITF_END; descr[1].data_count = 0; descr[1].label = NULL; descr[1].tag = NULL; ((nitf_TREPrivateData*)tre->priv)->description = descr; return NITF_SUCCESS; }
NITFAPI(nitf_DownSampler *) nitf_PixelSkip_construct(nitf_Uint32 rowSkip, nitf_Uint32 colSkip, nitf_Error * error) { static nitf_IDownSampler iPixelSkip = { &PixelSkip_apply, &PixelSkip_destruct }; nitf_DownSampler *downsampler; downsampler = (nitf_DownSampler *) NITF_MALLOC(sizeof(nitf_DownSampler)); if (!downsampler) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } downsampler->rowSkip = rowSkip; downsampler->colSkip = colSkip; downsampler->multiBand = 0; downsampler->minBands = 1; downsampler->maxBands = 0; downsampler->types = NITF_DOWNSAMPLER_TYPE_ALL; downsampler->data = NULL; downsampler->iface = &iPixelSkip; return downsampler; }
NITFAPI(nitf_BandInfo *) nitf_BandInfo_construct(nitf_Error * error) { /* Start by allocating the struct */ nitf_BandInfo *info = (nitf_BandInfo *) NITF_MALLOC(sizeof(nitf_BandInfo)); /* Return now if we have a problem above */ if (!info) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } /* This MUST happen before we construct fields */ /* in case destruction is required */ info->lut = NULL; _NITF_CONSTRUCT_FIELD(info, NITF_IREPBAND, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(info, NITF_ISUBCAT, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(info, NITF_IFC, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(info, NITF_IMFLT, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(info, NITF_NLUTS, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(info, NITF_NELUT, NITF_BCS_N); return info; CATCH_ERROR: /* destruct if it was allocated */ if (info) nitf_BandInfo_destruct(&info); return NULL; }
NITFAPI(nitf_TREPrivateData *) nitf_TREPrivateData_construct( nitf_Error * error) { nitf_TREPrivateData *priv = (nitf_TREPrivateData*) NITF_MALLOC( sizeof(nitf_TREPrivateData)); if (!priv) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } priv->length = 0; priv->descriptionName = NULL; priv->description = NULL; priv->userData = NULL; /* create the hashtable for the fields */ priv->hash = nitf_HashTable_construct(NITF_TRE_HASH_SIZE, error); if (!priv->hash) { nitf_TREPrivateData_destruct(&priv); return NULL; } /* ??? change policy? */ nitf_HashTable_setPolicy(priv->hash, NITF_DATA_ADOPT); return priv; }
NITFAPI(cgm_Element*) cgm_CircularArcElement_construct(nitf_Error* error) { cgm_Element* element = cgm_Element_construct( CGM_CIRCULAR_ARC_CENTER_ELEMENT, error); if (element) { cgm_CircularArcElement* arc = (cgm_CircularArcElement*) NITF_MALLOC(sizeof(cgm_CircularArcElement)); if (!arc) { NITF_FREE(element); return NULL; } arc->attributes = NULL; arc->centerX = -1; arc->centerY = -1; arc->startX = -1; arc->startY = -1; arc->endX = -1; arc->endY = -1; arc->radius = -1; element->data = (NITF_DATA*)arc; } element->print = &circularArcPrint; element->clone = &circularArcClone; element->destroy = &circularArcDestroy; return element; }
JNIEXPORT void JNICALL Java_nitf_BandSource_construct (JNIEnv * env, jobject self) { /* make the interface */ static nitf_IDataSource iBandSource = { &BandSource_read, &BandSource_destruct, &BandSource_getSize, &BandSource_setSize }; /* the return bandSource */ nitf_BandSource *bandSource = NULL; BandSourceImpl *impl; /* gets malloc'd for this object */ nitf_Error error; jclass bandSourceClass = (*env)->FindClass(env, "nitf/BandSource"); jmethodID methodID = (*env)->GetStaticMethodID(env, bandSourceClass, "register", "(Lnitf/BandSource;)V"); /* construct the persisent one */ impl = (BandSourceImpl *) NITF_MALLOC(sizeof(BandSourceImpl)); if (!impl) { _ThrowNITFException(env, "Out of memory"); return; } /**************************************************************/ /* THIS IS VERY IMPORTANT... WE MUST MAKE A STRONG GLOBAL REF */ /**************************************************************/ impl->self = (*env)->NewGlobalRef(env, self); bandSource = (nitf_BandSource *) NITF_MALLOC(sizeof(nitf_BandSource)); if (!bandSource) { _ThrowNITFException(env, "Out of Memory"); return; } bandSource->data = impl; bandSource->iface = &iBandSource; _SetObj(env, self, bandSource); /* now, we must also register this type */ (*env)->CallStaticVoidMethod(env, bandSourceClass, methodID, self); }
NITFAPI(nitf_BandSource *) nitf_IOSource_construct(nitf_IOInterface *io, nitf_Off start, int numBytesPerPixel, int pixelSkip, nitf_Error * error) { static nitf_IDataSource iIOSource = { &IOSource_read, &IOSource_destruct, &IOSource_getSize, &IOSource_setSize }; IOSourceImpl *impl; nitf_BandSource *bandSource; impl = (IOSourceImpl *) NITF_MALLOC(sizeof(IOSourceImpl)); if (!impl) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } impl->io = io; impl->numBytesPerPixel = numBytesPerPixel > 0 ? numBytesPerPixel : 1; impl->pixelSkip = pixelSkip >= 0 ? pixelSkip : 0; impl->mark = impl->start = (start >= 0 ? start : 0); impl->size = nitf_IOInterface_getSize(io, error); if (!NITF_IO_SUCCESS(impl->size)) { NITF_FREE(impl); return NULL; } bandSource = (nitf_BandSource *) NITF_MALLOC(sizeof(nitf_BandSource)); if (!bandSource) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } bandSource->data = impl; bandSource->iface = &iIOSource; return bandSource; }
NITFAPI(cgm_Text*) cgm_Text_construct(const char* text, nitf_Error* error) { cgm_Text* v = (cgm_Text*)NITF_MALLOC(sizeof(cgm_Text)); if (!v) { nitf_Error_init(error, NITF_STRERROR( NITF_ERRNO ), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } v->x = v->y = -1; v->str = NULL; if (text) { v->str = (char*)NITF_MALLOC( strlen( text ) + 1 ); strcpy(v->str, text); } return v; }
NITFAPI(NITF_BOOL) nitf_Field_resizeField(nitf_Field *field, size_t newLength, nitf_Error *error) { char fill = 0; /* it must be resizable */ if (!field->resizable) return NITF_FAILURE; if (field && newLength != field->length) { if (field->raw) NITF_FREE(field->raw); field->raw = NULL; /* re-malloc */ field->raw = (char *) NITF_MALLOC(newLength + 1); if (!field->raw) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); goto CATCH_ERROR; } /* set the new length */ field->length = newLength; field->raw[newLength] = 0; /* terminating null byte */ switch (field->type) { case NITF_BCS_A: fill = ' '; break; case NITF_BCS_N: fill = '0'; break; case NITF_BINARY: fill = 0; break; default: nitf_Error_initf(error, NITF_CTXT, NITF_ERR_INVALID_PARAMETER, "Invalid type [%d]", field->type); goto CATCH_ERROR; } memset(field->raw, fill, field->length); } return NITF_SUCCESS; CATCH_ERROR: return NITF_FAILURE; }
nitf_GraphicSubheader_clone(nitf_GraphicSubheader * source, nitf_Error * error) { nitf_GraphicSubheader *subhdr = NULL; if (source) { subhdr = (nitf_GraphicSubheader *) NITF_MALLOC(sizeof(nitf_GraphicSubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_SY); _NITF_CLONE_FIELD(subhdr, source, NITF_SID); _NITF_CLONE_FIELD(subhdr, source, NITF_SNAME); _NITF_CLONE_FIELD(subhdr, source, NITF_SSCLAS); _NITF_CLONE_FIELD(subhdr, source, NITF_ENCRYP); _NITF_CLONE_FIELD(subhdr, source, NITF_SFMT); _NITF_CLONE_FIELD(subhdr, source, NITF_SSTRUCT); _NITF_CLONE_FIELD(subhdr, source, NITF_SDLVL); _NITF_CLONE_FIELD(subhdr, source, NITF_SALVL); _NITF_CLONE_FIELD(subhdr, source, NITF_SLOC); _NITF_CLONE_FIELD(subhdr, source, NITF_SBND1); _NITF_CLONE_FIELD(subhdr, source, NITF_SCOLOR); _NITF_CLONE_FIELD(subhdr, source, NITF_SBND2); _NITF_CLONE_FIELD(subhdr, source, NITF_SRES2); _NITF_CLONE_FIELD(subhdr, source, NITF_SXSHDL); _NITF_CLONE_FIELD(subhdr, source, NITF_SXSOFL); /* init to NULL for safety */ subhdr->extendedSection = NULL; if (source->extendedSection) { subhdr->extendedSection = nitf_Extensions_clone(source->extendedSection, error); if (!subhdr->extendedSection) goto CATCH_ERROR; } return subhdr; } CATCH_ERROR: nitf_GraphicSubheader_destruct(&subhdr); return NULL; }
nitf_TextSubheader_clone(nitf_TextSubheader * source, nitf_Error * error) { nitf_TextSubheader *subhdr = NULL; if (source) { subhdr = (nitf_TextSubheader *) NITF_MALLOC(sizeof(nitf_TextSubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); if (!subhdr->securityGroup) goto CATCH_ERROR; /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_TE); _NITF_CLONE_FIELD(subhdr, source, NITF_TEXTID); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTALVL); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTDT); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTITL); _NITF_CLONE_FIELD(subhdr, source, NITF_TSCLAS); _NITF_CLONE_FIELD(subhdr, source, NITF_ENCRYP); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTFMT); _NITF_CLONE_FIELD(subhdr, source, NITF_TXSHDL); _NITF_CLONE_FIELD(subhdr, source, NITF_TXSOFL); /* init to NULL in case */ subhdr->extendedSection = NULL; if (source->extendedSection) { subhdr->extendedSection = nitf_Extensions_clone(source->extendedSection, error); if (!subhdr->extendedSection) goto CATCH_ERROR; } return subhdr; } CATCH_ERROR: nitf_TextSubheader_destruct(&subhdr); return NULL; }
NITFAPI(nitf_BandSource *) nitf_MemorySource_construct(char *data, nitf_Off size, nitf_Off start, int numBytesPerPixel, int pixelSkip, nitf_Error * error) { static nitf_IDataSource iMemorySource = { &MemorySource_read, &MemorySource_destruct, &MemorySource_getSize, &MemorySource_setSize }; MemorySourceImpl *impl; nitf_BandSource *bandSource; impl = (MemorySourceImpl *) NITF_MALLOC(sizeof(MemorySourceImpl)); if (!impl) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } impl->data = data; impl->size = size; impl->numBytesPerPixel = numBytesPerPixel > 0 ? numBytesPerPixel : 1; impl->mark = impl->start = (start >= 0 ? start : 0); impl->pixelSkip = pixelSkip >= 0 ? pixelSkip : 0; bandSource = (nitf_BandSource *) NITF_MALLOC(sizeof(nitf_BandSource)); if (!bandSource) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } bandSource->data = impl; bandSource->iface = &iMemorySource; return bandSource; }
int main(int argc, char **argv) { int i; char** str = (char**)NITF_MALLOC(sizeof(argc) * sizeof(char*)); for (i = 0; i < argc; i++) { str[i] = (char*)NITF_MALLOC( strlen(argv[i]) + 1); strcpy( str[i], argv[i]); printf("Copied string [%d]: '%s'\n", i, str[i]); } for (i = 0; i < argc; i++) { printf("Deleting string [%d]: '%s'\n", i, str[i]); NITF_FREE( str[i] ); } printf("Deleting master...\n"); NITF_FREE( str ); printf("Done.\n"); return 0; }
NITFAPI(cgm_VertexClose*) cgm_VertexClose_construct(nitf_Error* error) { cgm_VertexClose* v = (cgm_VertexClose*)NITF_MALLOC(sizeof(cgm_VertexClose)); if (!v) { nitf_Error_init(error, NITF_STRERROR( NITF_ERRNO ), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } v->x = v->y = -1; v->edgeOutFlag = CGM_EDGE_CLOSE_TYPE_NOT_SET; return v; }
JNIEXPORT void JNICALL Java_nitf_WriteHandler_construct (JNIEnv *env, jobject self) { /* make the interface */ static nitf_IWriteHandler iWriteHandler = { &WriteHandler_write, &WriteHandler_destruct }; nitf_WriteHandler *writeHandler = NULL; WriteHandlerImpl *impl = NULL; nitf_Error error; /* construct the persisent one */ impl = (WriteHandlerImpl *) NITF_MALLOC(sizeof(WriteHandlerImpl)); if (!impl) { _ThrowNITFException(env, "Out of memory"); return; } /**************************************************************/ /* THIS IS VERY IMPORTANT... WE MUST MAKE A STRONG GLOBAL REF */ /**************************************************************/ impl->self = (*env)->NewGlobalRef(env, self); writeHandler = (nitf_WriteHandler *) NITF_MALLOC(sizeof(nitf_WriteHandler)); if (!writeHandler) { _ThrowNITFException(env, "Out of Memory"); return; } writeHandler->data = impl; writeHandler->iface = &iWriteHandler; _SetObj(env, self, writeHandler); }
nitf_GraphicSubheader_construct(nitf_Error * error) { /* Start by allocating the header */ nitf_GraphicSubheader *subhdr = (nitf_GraphicSubheader *) NITF_MALLOC(sizeof(nitf_GraphicSubheader)); /* Return now if we have a problem above */ if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); goto CATCH_ERROR; } subhdr->extendedSection = NULL; subhdr->securityGroup = NULL; subhdr->securityGroup = nitf_FileSecurity_construct(error); if (!subhdr->securityGroup) goto CATCH_ERROR; _NITF_CONSTRUCT_FIELD(subhdr, NITF_SY, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SID, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SNAME, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SSCLAS, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_ENCRYP, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SFMT, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SSTRUCT, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SDLVL, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SALVL, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SLOC, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SBND1, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SCOLOR, NITF_BCS_A); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SBND2, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SRES2, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SXSHDL, NITF_BCS_N); _NITF_CONSTRUCT_FIELD(subhdr, NITF_SXSOFL, NITF_BCS_N); subhdr->extendedSection = nitf_Extensions_construct(error); if (!subhdr->extendedSection) goto CATCH_ERROR; return subhdr; CATCH_ERROR: if (subhdr) nitf_GraphicSubheader_destruct(&subhdr); return NULL; }
NITFAPI(nitf_SegmentWriter *) nitf_SegmentWriter_construct(nitf_Error *error) { static nitf_IWriteHandler iWriteHandler = { &SegmentWriter_write, &SegmentWriter_destruct }; SegmentWriterImpl *impl = NULL; nitf_SegmentWriter *segmentWriter = NULL; impl = (SegmentWriterImpl *) NITF_MALLOC(sizeof(SegmentWriterImpl)); if (!impl) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); goto CATCH_ERROR; } impl->segmentSource = NULL; segmentWriter = (nitf_SegmentWriter *) NITF_MALLOC(sizeof(nitf_SegmentWriter)); if (!segmentWriter) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); goto CATCH_ERROR; } segmentWriter->data = impl; segmentWriter->iface = &iWriteHandler; return segmentWriter; CATCH_ERROR: if (impl) NITF_FREE(impl); return NULL; }